Skip to content

Commit

Permalink
Styled searching options -- #1133 (#1135)
Browse files Browse the repository at this point in the history
* checkboxes

* fixes

* fixes

* styled
  • Loading branch information
vmonakhov authored Aug 21, 2024
1 parent 96c9959 commit fa1f669
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/components/LexicalEntryByIds/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class Perspective extends PureComponent {
mode={mode}
id={id}
entriesIds={entriesIds}
filter={perspective.filter}
filter={perspective.filter.value}
submitFilter={submitFilter}
toggleMode={this.toggleMode}
/>
Expand All @@ -154,7 +154,7 @@ class Perspective extends PureComponent {
entitiesMode={entitiesMode}
entriesIds={entriesIds}
page={page}
filter={perspective.filter}
filter={perspective.filter.value}
className="content"
changePage={this.changePage}
/>
Expand Down
11 changes: 8 additions & 3 deletions src/components/PerspectiveView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,8 @@ export const LexicalEntryByIds = compose(
})
)(LexicalEntryViewBaseByIds);

const PerspectiveViewWrapper = ({ id, className, mode, entitiesMode, page, data, filter, sortByField }) => {
const PerspectiveViewWrapper = ({ id, className, mode, entitiesMode, page, data,
filter, sortByField, isCaseSens, isRegexp }) => {
if (data.error) {
return null;
}
Expand Down Expand Up @@ -1049,8 +1050,8 @@ const PerspectiveViewWrapper = ({ id, className, mode, entitiesMode, page, data,
offset={ROWS_PER_PAGE * (page - 1)}
filter={filter}
isEditMode={mode === "edit"}
isCaseSens={true}
isRegexp={false}
isCaseSens={isCaseSens}
isRegexp={isRegexp}
columns={columns}
reRender={reRender}
/>
Expand All @@ -1064,12 +1065,16 @@ PerspectiveViewWrapper.propTypes = {
mode: PropTypes.string.isRequired,
entitiesMode: PropTypes.string.isRequired,
filter: PropTypes.string,
isCaseSens: PropTypes.bool,
isRegexp: PropTypes.bool,
data: PropTypes.object.isRequired,
sortByField: PropTypes.object
};

PerspectiveViewWrapper.defaultProps = {
filter: "",
isCaseSens: true,
isRegexp: false,
sortByField: null
};

Expand Down
6 changes: 3 additions & 3 deletions src/ducks/perspective.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ function params(state = {}, action = {}) {
}
}

function filter(state = "", action = {}) {
switch (action.type) {
function filter(state = { value: "", isCaseSens: true, isRegexp: false }, { type, payload }) {
switch (type) {
case SET_FILTER:
return action.payload;
return payload;
default:
return state;
}
Expand Down
41 changes: 35 additions & 6 deletions src/pages/Perspective/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -1061,21 +1061,29 @@ const Tools = ({
};

const handlers = compose(
withState("value", "updateValue", props => props.filter),
withState("value", "updateValue", props => props.filter.value),
withState("isCaseSens", "setCaseSens", true),
withState("isRegexp", "setRegexp", false),
withHandlers({
onChange(props) {
return event => props.updateValue(event.target.value);
},
onSubmit(props) {
return event => {
event.preventDefault();
props.submitFilter(props.value);
props.submitFilter(props.value, props.isCaseSens, props.isRegexp);
};
},
onToggleCaseSens(props) {
return (e, { checked }) => props.setCaseSens(checked);
},
onToggleRegexp(props) {
return (e, { checked }) => props.setRegexp(checked);
}
})
);

const Filter = handlers(({ value, onChange, onSubmit }) => {
const Filter = handlers(({ value, onChange, onSubmit, isCaseSens, onToggleCaseSens, isRegexp, onToggleRegexp }) => {
const getTranslation = useContext(TranslationContext);

return (
Expand All @@ -1085,6 +1093,20 @@ const Filter = handlers(({ value, onChange, onSubmit }) => {
<button type="submit" className="white">
<i className="search link icon" />
</button>
<div className="lingvo-search-entities__checkboxes">
<Checkbox
label={getTranslation("A ≠ a")}
checked={isCaseSens}
onChange={onToggleCaseSens}
className="lingvo-checkbox_labeled"
/>
<Checkbox
label={getTranslation("a .*")}
checked={isRegexp}
onChange={onToggleRegexp}
className="lingvo-checkbox_labeled"
/>
</div>
</form>
</div>
);
Expand Down Expand Up @@ -1193,7 +1215,10 @@ const ModeSelector = compose(
launchValency={launchValency}
/>
<Menu.Menu position="right">
<Filter filter={filter} submitFilter={submitFilter} />
<Filter
filter={filter}
submitFilter={submitFilter}
/>
</Menu.Menu>
</Menu>
);
Expand Down Expand Up @@ -1349,7 +1374,9 @@ const Perspective = ({
mode={mode}
id={id}
baseUrl={baseUrl}
filter={perspective.filter}
filter={perspective.filter.value}
isCaseSens={perspective.filter.isCaseSens}
isRegexp={perspective.filter.isRegexp}
submitFilter={submitFilter}
openCognateAnalysisModal={openCognateAnalysisModal}
openPhonemicAnalysisModal={openPhonemicAnalysisModal}
Expand All @@ -1371,7 +1398,9 @@ const Perspective = ({
mode={mode}
entitiesMode={info.entitiesMode}
page={page}
filter={perspective.filter}
filter={perspective.filter.value}
isCaseSens={perspective.filter.isCaseSens}
isRegexp={perspective.filter.isRegexp}
className="content"
activeDndProvider={dndProvider}
/>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Perspective/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function init({ location }) {
return request(getParams(location));
}

function submitFilter(value) {
return setFilter(value);
function submitFilter(value, isCaseSens, isRegexp) {
return setFilter({value, isCaseSens, isRegexp});
}

function openCognateAnalysisModal(perspectiveId, mode = "") {
Expand Down
23 changes: 23 additions & 0 deletions src/pages/Perspective/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -693,3 +693,26 @@

}
/* /lingvo perspective component text */

/* lingvo searching options */
.lingvo-search-entities__checkboxes {
margin-left: 1.5em;
border: gray solid;
border-radius: 30px;

.lingvo-checkbox_labeled {
margin-right: 0.5em;
padding: 0.5em;

& label {
color: white !important;
font-size: 1.2em !important;
font-weight: bold;

&:hover {
text-decoration: underline;
}
}
}
}
/* /lingvo searching options */

0 comments on commit fa1f669

Please sign in to comment.