diff --git a/src/custom/CatalogFilterSection/CatalogFilterSidebar.tsx b/src/custom/CatalogFilterSection/CatalogFilterSidebar.tsx index 965af08b6..c3e36e9ce 100644 --- a/src/custom/CatalogFilterSection/CatalogFilterSidebar.tsx +++ b/src/custom/CatalogFilterSection/CatalogFilterSidebar.tsx @@ -29,14 +29,24 @@ export interface FilterOption { export interface FilterList { filterKey: string; sectionDisplayName?: string; - options: FilterOption[]; defaultOpen?: boolean; isMultiSelect?: boolean; + options?: FilterOption[]; + customComponent?: React.ComponentType; } +type FilterListWithOptions = FilterList & { options: FilterOption[]; customComponent?: never }; + +type FilterListWithCustomComponent = FilterList & { + customComponent: React.ComponentType; + options?: never; +}; + +export type FilterListType = FilterListWithOptions | FilterListWithCustomComponent; + export interface CatalogFilterSidebarProps { setData: (callback: (prevFilters: FilterValues) => FilterValues) => void; - lists: FilterList[]; + lists: FilterListType[]; value?: FilterValues; styleProps?: StyleProps; } diff --git a/src/custom/CatalogFilterSection/CatalogFilterSidebarState.tsx b/src/custom/CatalogFilterSection/CatalogFilterSidebarState.tsx index 76b0d72d3..1d2bb51ba 100644 --- a/src/custom/CatalogFilterSection/CatalogFilterSidebarState.tsx +++ b/src/custom/CatalogFilterSection/CatalogFilterSidebarState.tsx @@ -1,7 +1,7 @@ import { useCallback, useState } from 'react'; import { CatalogFilterSidebarProps, - FilterList, + FilterListType, FilterValues, StyleProps } from './CatalogFilterSidebar'; @@ -16,7 +16,7 @@ import FilterSection from './FilterSection'; * @param {Object} styleProps - The style properties for the component. */ const CatalogFilterSidebarState: React.FC<{ - lists: FilterList[]; + lists: FilterListType[]; onApplyFilters: CatalogFilterSidebarProps['setData']; value: FilterValues; styleProps: StyleProps; @@ -78,19 +78,36 @@ const CatalogFilterSidebarState: React.FC<{ return ( <> - {lists.map((list) => ( - - ))} + {lists.map((list) => { + if (list.customComponent) { + return ( + + ); + } + + return ( + + ); + })} ); }; diff --git a/src/custom/CatalogFilterSection/FilterSection.tsx b/src/custom/CatalogFilterSection/FilterSection.tsx index 0696a6ed1..4be5eddbd 100644 --- a/src/custom/CatalogFilterSection/FilterSection.tsx +++ b/src/custom/CatalogFilterSection/FilterSection.tsx @@ -10,12 +10,13 @@ import { EndAdornmentText, FilterTitleButton } from './style'; interface FilterSectionProps { filterKey: string; sectionDisplayName?: string; - options: FilterOption[]; + options?: FilterOption[]; filters: FilterValues; openSections: Record; - onCheckboxChange: (filterKey: string, value: string, checked: boolean) => void; + onCheckboxChange?: (filterKey: string, value: string, checked: boolean) => void; onSectionToggle: (filterKey: string) => void; styleProps: StyleProps; + customComponent?: React.ComponentType; } /** @@ -33,12 +34,13 @@ interface FilterSectionProps { const FilterSection: React.FC = ({ filterKey, sectionDisplayName, - options, + options = [], filters, openSections, onCheckboxChange, onSectionToggle, - styleProps + styleProps, + customComponent: CustomComponent }) => { const [searchQuery, setSearchQuery] = useState(''); @@ -47,9 +49,10 @@ const FilterSection: React.FC = ({ }, []); const showSearch = options.length > 10; - const searchedOptions = searchQuery - ? options.filter((option) => option.label.toLowerCase().includes(searchQuery.toLowerCase())) - : options; + const searchedOptions = + searchQuery && options.length + ? options.filter((option) => option.label.toLowerCase().includes(searchQuery.toLowerCase())) + : options; return ( <> @@ -65,59 +68,66 @@ const FilterSection: React.FC = ({ {openSections[filterKey] ? : } - - {showSearch && ( - - Total : {searchedOptions.length ?? 0} - } - /> - - )} - {searchedOptions.map((option, index) => ( - - - + ) : ( + + {showSearch && ( + + Total : {searchedOptions.length ?? 0} } - onChange={(e) => onCheckboxChange(filterKey, option.value, e.target.checked)} - value={option.value} /> + + )} + {searchedOptions.map((option, index) => ( + + + + onCheckboxChange && + onCheckboxChange(filterKey, option.value, e.target.checked) + } + value={option.value} + /> - {option.Icon && } + {option.Icon && } - {option.label} + {option.label} + + + {option.totalCount !== undefined && `(${option.totalCount || 0})`} + {option.description && ( + + )} + - - {option.totalCount !== undefined && `(${option.totalCount || 0})`} - {option.description && ( - - )} - - - ))} - + ))} + + )} ); diff --git a/src/custom/CatalogFilterSection/index.tsx b/src/custom/CatalogFilterSection/index.tsx index a79660b97..5fb7338c4 100644 --- a/src/custom/CatalogFilterSection/index.tsx +++ b/src/custom/CatalogFilterSection/index.tsx @@ -1,4 +1,4 @@ -import CatalogFilterSidebar, { FilterList } from './CatalogFilterSidebar'; +import CatalogFilterSidebar, { FilterListType } from './CatalogFilterSidebar'; export { CatalogFilterSidebar }; -export type { FilterList }; +export type { FilterListType }; diff --git a/src/custom/index.tsx b/src/custom/index.tsx index 14e2b14ab..8442e7f30 100644 --- a/src/custom/index.tsx +++ b/src/custom/index.tsx @@ -45,7 +45,7 @@ import { TransferListProps } from './TransferModal/TransferList/TransferList'; import UniversalFilter, { UniversalFilterProps } from './UniversalFilter'; export { CatalogCard } from './CatalogCard'; export { CatalogFilterSidebar } from './CatalogFilterSection'; -export type { FilterList } from './CatalogFilterSection'; +export type { FilterListType } from './CatalogFilterSection'; export { StyledChartDialog } from './ChartDialog'; export { LearningContent } from './LearningContent'; export { NavigationNavbar } from './NavigationNavbar';