Skip to content

Commit

Permalink
fix catalog filter group getting removed on keyword change
Browse files Browse the repository at this point in the history
  • Loading branch information
invincibleJai committed May 19, 2022
1 parent e799218 commit 62e0e60
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 18 deletions.
Expand Up @@ -19,7 +19,6 @@ type CatalogFiltersProps = {
filterGroupCounts: CatalogFilterCounts;
filterGroupMap: { [key: string]: CatalogItemAttribute };
filterGroupsShowAll: { [key: string]: boolean };
catalogItemsCount: number;
onFilterChange: (filterType: string, id: string, value: boolean) => void;
onShowAllToggle: (groupName: string) => void;
};
Expand All @@ -29,7 +28,6 @@ const CatalogFilters: React.FC<CatalogFiltersProps> = ({
filterGroupCounts,
filterGroupMap,
filterGroupsShowAll,
catalogItemsCount,
onFilterChange,
onShowAllToggle,
}) => {
Expand All @@ -40,19 +38,6 @@ const CatalogFilters: React.FC<CatalogFiltersProps> = ({
return acc;
}, {});

const getFilterGroup = (filterGroup: CatalogFilter, groupName: string): CatalogFilter => {
const filterGroupKeys = Object.keys(filterGroup);

return filterGroupKeys.length > 0
? _.omitBy(filterGroup, (filter, filterName) => {
const { label, active } = filter;
const count = filterGroupCounts[groupName]?.[filterName] ?? 0;
const showFilter = label && (active || (count > 0 && catalogItemsCount !== count));
return !showFilter;
})
: {};
};

const renderFilterItem = (filter: CatalogFilterItem, filterName: string, groupName: string) => {
const { label, active } = filter;
const count = filterGroupCounts[groupName]?.[filterName] ?? 0;
Expand All @@ -75,8 +60,7 @@ const CatalogFilters: React.FC<CatalogFiltersProps> = ({
};

const renderFilterGroup = (filterGroup: CatalogFilter, groupName: string) => {
const fg = getFilterGroup(filterGroup, groupName);
const filterGroupKeys = Object.keys(fg);
const filterGroupKeys = Object.keys(filterGroup);
if (filterGroupKeys.length > 0) {
const sortedFilterGroup = filterGroupKeys.sort().reduce<CatalogFilter>((acc, filterName) => {
acc[filterName] = filterGroup[filterName];
Expand Down
Expand Up @@ -246,7 +246,6 @@ const CatalogView: React.FC<CatalogViewProps> = ({
filterGroupCounts={filterGroupCounts}
filterGroupMap={filterGroupMap}
filterGroupsShowAll={filterGroupsShowAll}
catalogItemsCount={items.length}
onShowAllToggle={handleShowAllToggle}
onFilterChange={handleFilterChange}
/>
Expand Down

0 comments on commit 62e0e60

Please sign in to comment.