-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(filters): dynamic filter components
- Loading branch information
Showing
18 changed files
with
111 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from 'react' | ||
import { ConfigurableFilterKey } from './../../../lib' | ||
import { | ||
AggregationTypeFilter, | ||
DomainTypeSelectionFilter, | ||
ValueTypeSelectionFilter, | ||
} from './filterSelectors' | ||
import { useFilterKeys } from './useFilterKeys' | ||
|
||
type FilterKeyToComponentMap = Partial<Record<ConfigurableFilterKey, React.FC>> | ||
|
||
const filterKeyToComponentMap: FilterKeyToComponentMap = { | ||
domainType: DomainTypeSelectionFilter, | ||
valueType: ValueTypeSelectionFilter, | ||
aggregationType: AggregationTypeFilter, | ||
} | ||
|
||
export const DynamicFilters = () => { | ||
const filterKeys = useFilterKeys() | ||
|
||
return ( | ||
<> | ||
{filterKeys.map((filterKey) => { | ||
const FilterComponent = filterKeyToComponentMap[filterKey] | ||
return FilterComponent ? ( | ||
<FilterComponent key={filterKey} /> | ||
) : null | ||
})} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.filterWrapper { | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: 4px; | ||
align-items: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './ConstantFilters' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './ConstantSelectionFilter' | ||
export * from './IdentifiableFilter' | ||
export * from './ConstantFilters' | ||
export * from './filterSelectors/ConstantSelectionFilter' | ||
export * from './filterSelectors/IdentifiableFilter' | ||
export * from './filterSelectors/ConstantFilters' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { useMemo } from 'react' | ||
import { | ||
useSectionListFilters, | ||
ParsedFilterParams, | ||
ConfigurableFilterKey, | ||
IDENTIFIABLE_KEY, | ||
} from '../../../lib' | ||
import { useModelListView } from '../listView' | ||
|
||
export type FiltersWithValue = { | ||
[FilterKey in ConfigurableFilterKey]: { | ||
value: ParsedFilterParams[FilterKey] | ||
label: string | ||
filterKey: FilterKey | ||
} | ||
} | ||
|
||
export const useFilterKeys = () => { | ||
const [filters] = useSectionListFilters() | ||
const views = useModelListView() | ||
const viewFilters = views.filters | ||
// combine filters and views, since filters in URL might not be selected for view | ||
// but we should show them when they have a value | ||
const filterKeys = useMemo(() => { | ||
const viewFilterKeys = viewFilters.map(({ filterKey }) => filterKey) | ||
const selectedFiltersNotInView = Object.entries(filters) | ||
.filter( | ||
([filterKey, value]) => | ||
value !== undefined && | ||
filterKey !== IDENTIFIABLE_KEY && | ||
!viewFilterKeys.includes(filterKey as ConfigurableFilterKey) | ||
) | ||
.map(([filterKey]) => filterKey) as ConfigurableFilterKey[] | ||
|
||
return viewFilterKeys.concat(selectedFiltersNotInView) | ||
}, [filters, viewFilters]) | ||
return filterKeys | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
export * from './sections' | ||
export * from './translatedModelConstants' | ||
export * from './translatedModelProperties' | ||
export * from './sectionListView' | ||
|
||
export const IDENTIFIABLE_KEY = 'identifiable' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...sectionListView/sectionListViewsConfig.ts → ...nList/listViews/sectionListViewsConfig.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters