Skip to content

Commit

Permalink
STCOM-1223 Add support for new match option containsAny in `<Advanc…
Browse files Browse the repository at this point in the history
…edSearch>` (#2162)
  • Loading branch information
BogdanDenis authored Oct 31, 2023
1 parent d3e75cc commit d27151a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Add `hasMatchSelection` to `<AdvancedSearch>` to hide/show search match selection dropdown. Refs STCOM-1211.
* Add z-index of 1 to callout out to have it always render on top of sibling elements. Fixes STCOM-1217.
* Make `<SearchField>` support input and textarea as an input field. Refs STCOM-1220.
* Add support for new match option `containsAll` in `<AdvancedSearch>`. Refs STCOM-1223.

## [12.0.0](https://github.com/folio-org/stripes-components/tree/v12.0.0) (2023-10-11)
[Full Changelog](https://github.com/folio-org/stripes-components/compare/v11.0.0...v12.0.0)
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ export {
useAdvancedSearch,
defaultQueryBuilder as defaultAdvancedSearchQueryBuilder,
BOOLEAN_OPERATORS as ADVANCED_SEARCH_BOOLEAN_OPERATORS,
MATCH_OPTIONS as ADVANCED_SEARCH_MATCH_OPTIONS,
FIELD_NAMES as ADVANCED_SEARCH_FIELD_NAMES,
} from './lib/AdvancedSearch';

/* specific use */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const propTypes = {
})).isRequired,
};

const TEXTAREA_HEIGHT = 1;

const AdvancedSearchRow = ({
index,
rowState,
Expand All @@ -46,33 +48,17 @@ const AdvancedSearchRow = ({
}) => {
const intl = useIntl();

const booleanOptions = useMemo(() => [{
id: BOOLEAN_OPERATORS.AND,
label: intl.formatMessage({ id: 'stripes-components.advancedSearch.boolean.and' }),
value: BOOLEAN_OPERATORS.AND,
}, {
id: BOOLEAN_OPERATORS.OR,
label: intl.formatMessage({ id: 'stripes-components.advancedSearch.boolean.or' }),
value: BOOLEAN_OPERATORS.OR,
}, {
id: BOOLEAN_OPERATORS.NOT,
label: intl.formatMessage({ id: 'stripes-components.advancedSearch.boolean.not' }),
value: BOOLEAN_OPERATORS.NOT,
}], [intl]);
const booleanOptions = useMemo(() => Object.values(BOOLEAN_OPERATORS).map(boolOption => ({
id: boolOption,
label: intl.formatMessage({ id: `stripes-components.advancedSearch.boolean.${boolOption}` }),
value: boolOption,
})), [intl]);

const matchOptions = useMemo(() => [{
id: MATCH_OPTIONS.EXACT_PHRASE,
label: intl.formatMessage({ id: 'stripes-components.advancedSearch.match.exactPhrase' }),
value: MATCH_OPTIONS.EXACT_PHRASE,
}, {
id: MATCH_OPTIONS.CONTAINS_ALL,
label: intl.formatMessage({ id: 'stripes-components.advancedSearch.match.containsAll' }),
value: MATCH_OPTIONS.CONTAINS_ALL,
}, {
id: MATCH_OPTIONS.STARTS_WITH,
label: intl.formatMessage({ id: 'stripes-components.advancedSearch.match.startsWith' }),
value: MATCH_OPTIONS.STARTS_WITH,
}], [intl]);
const matchOptions = useMemo(() => Object.values(MATCH_OPTIONS).map(matchOption => ({
id: matchOption,
label: intl.formatMessage({ id: `stripes-components.advancedSearch.match.${matchOption}` }),
value: matchOption,
})), [intl]);

return (
<div
Expand Down Expand Up @@ -100,6 +86,7 @@ const AdvancedSearchRow = ({
</Col>
<Col xs>
<TextArea
rows={TEXTAREA_HEIGHT}
data-test-advanced-search-query
aria-label={intl.formatMessage({ id: 'stripes-components.advancedSearch.field.label' })}
onChange={(e) => onChange(index, FIELD_NAMES.QUERY, e.target.value)}
Expand Down
1 change: 1 addition & 0 deletions lib/AdvancedSearch/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export const MATCH_OPTIONS = {
EXACT_PHRASE: 'exactPhrase',
CONTAINS_ALL: 'containsAll',
STARTS_WITH: 'startsWith',
CONTAINS_ANY: 'containsAny',
};
6 changes: 5 additions & 1 deletion lib/AdvancedSearch/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export { default as AdvancedSearch } from './AdvancedSearch';
export { default as useAdvancedSearch } from './hooks/useAdvancedSearch';
export { default as defaultQueryBuilder } from './utilities/defaultQueryBuilder';
export { BOOLEAN_OPERATORS } from './constants';
export {
FIELD_NAMES,
BOOLEAN_OPERATORS,
MATCH_OPTIONS,
} from './constants';
1 change: 1 addition & 0 deletions translations/stripes-components/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"advancedSearch.match.exactPhrase": "Exact phrase",
"advancedSearch.match.containsAll": "Contains all",
"advancedSearch.match.startsWith": "Starts with",
"advancedSearch.match.containsAny": "Contains any",
"advancedSearch.footer.search": "Search",
"advancedSearch.footer.cancel": "Cancel",
"advancedSearch.boolean.label": "Operator",
Expand Down

0 comments on commit d27151a

Please sign in to comment.