Skip to content

Commit

Permalink
Merge pull request #946 from CBIIT/expand_active_filter_items_in_quer…
Browse files Browse the repository at this point in the history
…y_bar

Default Expand feature.
  • Loading branch information
iksheth authored Mar 11, 2024
2 parents 6112157 + e28dd42 commit 38a1917
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 44 deletions.
21 changes: 7 additions & 14 deletions packages/query-bar/src/components/CheckboxFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import clsx from 'clsx';
export default ({
index, data, classes, maxItems,
onSectionClick, onItemClick,
displayAllActiveFilters,
}) => {
const { items, section } = data;
const [expand, setExpand] = useState(false);
const [expand, setExpand] = useState(true);
const noOfItems = expand ? items.length : maxItems;

useEffect(() => {
Expand Down Expand Up @@ -51,18 +50,12 @@ export default ({
))}
{items.length > maxItems && (
<>
{
displayAllActiveFilters
? (
<span
className={classes.expandBtn}
onClick={() => setExpand(!expand)}
>
...
</span>
)
: '...'
}
<span
className={classes.expandBtn}
onClick={() => setExpand(!expand)}
>
...
</span>
</>
)}
{(expand && items.length > maxItems) && (
Expand Down
38 changes: 8 additions & 30 deletions packages/query-bar/src/generators/QueryBarGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ export const QueryBarGenerator = (uiConfig = DEFAULT_CONFIG) => {
? config.maxItems
: DEFAULT_CONFIG.config.maxItems;

const displayAllActiveFilters = config && typeof config.displayAllActiveFilters === 'boolean'
? config.displayAllActiveFilters
: DEFAULT_CONFIG.config.displayAllActiveFilters;

const clearAll = functions && typeof functions.clearAll === 'function'
? functions.clearAll
: DEFAULT_CONFIG.functions.clearAll;
Expand Down Expand Up @@ -63,7 +59,7 @@ export const QueryBarGenerator = (uiConfig = DEFAULT_CONFIG) => {

const { autocomplete, upload } = localFind;

const [expand, setExpand] = useState(false);
const [expand, setExpand] = useState(true);
const noOfItems = expand ? autocomplete.length : maxItems;

useEffect(() => {
Expand All @@ -77,22 +73,11 @@ export const QueryBarGenerator = (uiConfig = DEFAULT_CONFIG) => {
.map((facet) => {
if (facet.type !== CHECKBOX) { return facet; }

const { data, items } = facet;
const { items } = facet;
const itemKeys = Object.keys(items);
itemKeys.sort((a, b) => a.localeCompare(b));

/* Find any SELECTED CHECKBOXES that do NOT have any data
* and remove them from the list of selected checkboxes artificially */
if (!displayAllActiveFilters) {
itemKeys.forEach((item) => {
if (data.findIndex((d) => d.group === item) < 0) {
itemKeys.splice(itemKeys.indexOf(item), 1);
}
});
}

/**
* Set displayAllActiveFilters to True
* to display all the active filters in the query bar
* ICDC-3287
*/
Expand Down Expand Up @@ -177,18 +162,12 @@ export const QueryBarGenerator = (uiConfig = DEFAULT_CONFIG) => {
))}
{autocomplete.length > maxItems && (
<>
{
displayAllActiveFilters
? (
<span
className={classes.expandBtn}
onClick={() => setExpand(!expand)}
>
...
</span>
)
: '...'
}
<span
className={classes.expandBtn}
onClick={() => setExpand(!expand)}
>
...
</span>
</>
)}
{(expand && autocomplete.length > maxItems) && (
Expand Down Expand Up @@ -217,7 +196,6 @@ export const QueryBarGenerator = (uiConfig = DEFAULT_CONFIG) => {
type={filter.type}
data={filter}
maxItems={maxItems}
displayAllActiveFilters={displayAllActiveFilters}
classes={classes}
onSectionClick={filter.type === CHECKBOX
? resetFacetSection
Expand Down

0 comments on commit 38a1917

Please sign in to comment.