@databiosphere/findable-ui 29.0.2 → 31.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +35 -0
- package/lib/common/categories/config/types.d.ts +28 -0
- package/lib/common/categories/config/utils.d.ts +31 -0
- package/lib/common/categories/config/utils.js +29 -0
- package/lib/common/categories/models/range/typeGuards.d.ts +14 -0
- package/lib/common/categories/models/range/typeGuards.js +18 -0
- package/lib/common/categories/models/range/types.d.ts +15 -0
- package/lib/common/categories/models/range/types.js +1 -0
- package/lib/common/categories/models/range/utils.d.ts +23 -0
- package/lib/common/categories/models/range/utils.js +41 -0
- package/lib/common/categories/models/select/utils.d.ts +8 -0
- package/lib/common/categories/models/select/utils.js +16 -0
- package/lib/common/categories/models/types.d.ts +6 -0
- package/lib/common/categories/models/types.js +1 -0
- package/lib/common/categories/views/common/types.d.ts +10 -0
- package/lib/common/categories/views/common/types.js +1 -0
- package/lib/common/categories/views/range/typeGuards.d.ts +8 -0
- package/lib/common/categories/views/range/typeGuards.js +8 -0
- package/lib/common/categories/views/range/types.d.ts +19 -0
- package/lib/common/categories/views/range/types.js +1 -0
- package/lib/common/categories/views/range/utils.d.ts +12 -0
- package/lib/common/categories/views/range/utils.js +24 -0
- package/lib/common/categories/views/select/typeGuards.d.ts +8 -0
- package/lib/common/categories/views/select/typeGuards.js +8 -0
- package/lib/common/categories/views/select/types.d.ts +7 -0
- package/lib/common/categories/views/select/types.js +1 -0
- package/lib/common/categories/views/types.d.ts +13 -0
- package/lib/common/categories/views/types.js +8 -0
- package/lib/common/entities.d.ts +8 -23
- package/lib/components/DataDictionary/components/Entities/entities.d.ts +3 -1
- package/lib/components/DataDictionary/components/Entities/entities.js +1 -1
- package/lib/components/DataDictionary/components/Entities/types.d.ts +5 -5
- package/lib/components/DataDictionary/components/Entity/entity.d.ts +3 -1
- package/lib/components/DataDictionary/components/Entity/entity.js +6 -6
- package/lib/components/DataDictionary/components/Entity/types.d.ts +5 -5
- package/lib/components/DataDictionary/components/Outline/utils.d.ts +3 -2
- package/lib/components/DataDictionary/components/Table/components/BasicCell/basicCell.d.ts +3 -2
- package/lib/components/DataDictionary/components/Table/components/BasicCell/basicCell.js +6 -2
- package/lib/components/DataDictionary/components/Table/components/BasicCell/utils.d.ts +9 -0
- package/lib/components/DataDictionary/components/Table/components/BasicCell/utils.js +12 -0
- package/lib/components/DataDictionary/components/Table/hook.d.ts +3 -3
- package/lib/components/DataDictionary/components/Table/hook.js +3 -1
- package/lib/components/DataDictionary/components/Table/options/core/constants.d.ts +2 -3
- package/lib/components/DataDictionary/components/Table/options/hook.d.ts +2 -2
- package/lib/components/DataDictionary/components/Table/options/sorting/constants.d.ts +2 -3
- package/lib/components/DataDictionary/components/Table/table.d.ts +2 -1
- package/lib/components/DataDictionary/components/Table/table.js +1 -1
- package/lib/components/DataDictionary/components/Table/types.d.ts +3 -4
- package/lib/components/DataDictionary/dataDictionary.d.ts +3 -1
- package/lib/components/DataDictionary/dataDictionary.styles.js +2 -3
- package/lib/components/DataDictionary/hooks/UseDataDictionary/hook.d.ts +3 -1
- package/lib/components/DataDictionary/hooks/UseDataDictionary/types.d.ts +5 -5
- package/lib/components/Filter/components/Filter/filter.d.ts +2 -2
- package/lib/components/Filter/components/Filter/filter.js +11 -3
- package/lib/components/Filter/components/Filter/stories/args.d.ts +5 -0
- package/lib/components/Filter/components/Filter/stories/args.js +19 -0
- package/lib/components/Filter/components/Filter/stories/filter.stories.d.ts +8 -0
- package/lib/components/Filter/components/Filter/stories/filter.stories.js +21 -0
- package/lib/components/Filter/components/FilterMenu/filterMenu.js +2 -2
- package/lib/components/Filter/components/FilterMenu/filterMenu.styles.d.ts +1 -1
- package/lib/components/Filter/components/FilterMenu/filterMenu.styles.js +1 -1
- package/lib/components/Filter/components/FilterRange/constants.d.ts +0 -2
- package/lib/components/Filter/components/FilterRange/constants.js +0 -5
- package/lib/components/Filter/components/FilterRange/filterRange.d.ts +1 -1
- package/lib/components/Filter/components/FilterRange/filterRange.js +50 -21
- package/lib/components/Filter/components/FilterRange/filterRange.styles.js +58 -10
- package/lib/components/Filter/components/FilterRange/hooks/UseFilterRange/constants.d.ts +5 -0
- package/lib/components/Filter/components/FilterRange/hooks/UseFilterRange/constants.js +5 -0
- package/lib/components/Filter/components/FilterRange/hooks/UseFilterRange/hook.d.ts +2 -2
- package/lib/components/Filter/components/FilterRange/hooks/UseFilterRange/hook.js +32 -7
- package/lib/components/Filter/components/FilterRange/hooks/UseFilterRange/schema.d.ts +6 -0
- package/lib/components/Filter/components/FilterRange/hooks/UseFilterRange/schema.js +50 -0
- package/lib/components/Filter/components/FilterRange/hooks/UseFilterRange/types.d.ts +26 -3
- package/lib/components/Filter/components/FilterRange/hooks/UseFilterRange/types.js +6 -1
- package/lib/components/Filter/components/FilterRange/hooks/UseFilterRange/utils.d.ts +15 -0
- package/lib/components/Filter/components/FilterRange/hooks/UseFilterRange/utils.js +25 -0
- package/lib/components/Filter/components/FilterRange/stories/args.d.ts +3 -0
- package/lib/components/Filter/components/FilterRange/stories/args.js +13 -0
- package/lib/components/Filter/components/FilterRange/stories/filterRange.stories.js +2 -2
- package/lib/components/Filter/components/FilterRange/types.d.ts +10 -6
- package/lib/components/Filter/components/FilterRange/types.js +1 -6
- package/lib/components/Filter/components/FilterRange/utils.d.ts +8 -0
- package/lib/components/Filter/components/FilterRange/utils.js +15 -0
- package/lib/components/Filter/components/FilterTag/stories/args.d.ts +5 -0
- package/lib/components/Filter/components/FilterTag/stories/args.js +17 -0
- package/lib/components/Filter/components/FilterTag/stories/filterTag.stories.d.ts +8 -0
- package/lib/components/Filter/components/FilterTag/stories/filterTag.stories.js +21 -0
- package/lib/components/Filter/components/FilterTag/utils.d.ts +10 -0
- package/lib/components/Filter/components/FilterTag/utils.js +40 -0
- package/lib/components/Filter/components/Filters/filters.d.ts +2 -2
- package/lib/components/Filter/components/Filters/filters.js +15 -8
- package/lib/components/Filter/components/Filters/stories/args.d.ts +3 -0
- package/lib/components/Filter/components/Filters/stories/args.js +15 -0
- package/lib/components/Filter/components/Filters/stories/constants.d.ts +22 -0
- package/lib/components/Filter/components/Filters/stories/constants.js +134 -0
- package/lib/components/Filter/components/Filters/stories/filters.stories.d.ts +6 -0
- package/lib/components/Filter/components/Filters/stories/filters.stories.js +15 -0
- package/lib/components/Filter/components/SearchAllFilters/components/VariableSizeList/VariableSizeList.d.ts +1 -1
- package/lib/components/Filter/components/SearchAllFilters/components/VariableSizeList/VariableSizeList.js +5 -5
- package/lib/components/Filter/components/SearchAllFilters/components/VariableSizeListItem/variableSizeListItem.js +2 -1
- package/lib/components/Filter/components/SearchAllFilters/searchAllFilters.d.ts +3 -2
- package/lib/components/Filter/components/SearchAllFilters/searchAllFilters.js +6 -4
- package/lib/components/Filter/components/VariableSizeListItem/variableSizeListItem.js +2 -1
- package/lib/components/Index/components/EntitiesView/components/ChartView/utils.js +2 -0
- package/lib/components/Index/table/hook.js +4 -0
- package/lib/components/MarkdownRenderer/components/Anchor/anchor.d.ts +19 -0
- package/lib/components/MarkdownRenderer/components/Anchor/anchor.js +21 -0
- package/lib/components/MarkdownRenderer/components/Table/table.d.ts +3 -0
- package/lib/components/MarkdownRenderer/components/Table/table.js +5 -0
- package/lib/components/MarkdownRenderer/components/Table/table.styles.d.ts +4 -0
- package/lib/components/MarkdownRenderer/components/Table/table.styles.js +40 -0
- package/lib/components/MarkdownRenderer/constants.d.ts +2 -0
- package/lib/components/MarkdownRenderer/constants.js +6 -0
- package/lib/components/MarkdownRenderer/markdownRenderer.d.ts +2 -0
- package/lib/components/MarkdownRenderer/markdownRenderer.js +45 -0
- package/lib/components/MarkdownRenderer/markdownRenderer.styles.d.ts +4 -0
- package/lib/components/MarkdownRenderer/markdownRenderer.styles.js +13 -0
- package/lib/components/MarkdownRenderer/types.d.ts +6 -0
- package/lib/components/MarkdownRenderer/types.js +1 -0
- package/lib/components/Table/columnDef/accessorFn/typeGuards.d.ts +9 -0
- package/lib/components/Table/columnDef/accessorFn/typeGuards.js +10 -0
- package/lib/components/Table/common/utils.d.ts +2 -2
- package/lib/components/Table/common/utils.js +28 -13
- package/lib/components/Table/components/TableCell/components/ChipCell/chipCell.d.ts +4 -0
- package/lib/components/Table/components/TableCell/components/ChipCell/chipCell.js +8 -0
- package/lib/components/Table/components/TableCell/components/LinkCell/linkCell.d.ts +4 -0
- package/lib/components/Table/components/TableCell/components/LinkCell/linkCell.js +21 -0
- package/lib/components/Table/components/TableCell/components/LinkCell/stories/args.d.ts +6 -0
- package/lib/components/Table/components/TableCell/components/LinkCell/stories/args.js +27 -0
- package/lib/components/Table/components/TableCell/components/LinkCell/stories/linkCell.stories.d.ts +9 -0
- package/lib/components/Table/components/TableCell/components/LinkCell/stories/linkCell.stories.js +18 -0
- package/lib/components/Table/components/TableCell/components/LinkCell/stories/types.d.ts +3 -0
- package/lib/components/Table/components/TableCell/components/LinkCell/stories/types.js +1 -0
- package/lib/components/Table/components/TableCell/components/LinkCell/utils.d.ts +22 -0
- package/lib/components/Table/components/TableCell/components/LinkCell/utils.js +45 -0
- package/lib/components/Table/components/TableCell/components/MarkdownCell/markdownCell.d.ts +4 -0
- package/lib/components/Table/components/TableCell/components/MarkdownCell/markdownCell.js +13 -0
- package/lib/components/Table/components/TableCell/components/MarkdownCell/markdownCell.styles.d.ts +3 -0
- package/lib/components/Table/components/TableCell/components/MarkdownCell/markdownCell.styles.js +30 -0
- package/lib/components/Table/components/TableCell/components/MarkdownCell/stories/args.d.ts +4 -0
- package/lib/components/Table/components/TableCell/components/MarkdownCell/stories/args.js +10 -0
- package/lib/components/Table/components/TableCell/components/MarkdownCell/stories/constants.d.ts +5 -0
- package/lib/components/Table/components/TableCell/components/MarkdownCell/stories/constants.js +9 -0
- package/lib/components/Table/components/TableCell/components/MarkdownCell/stories/markdownCell.stories.d.ts +7 -0
- package/lib/components/Table/components/TableCell/components/MarkdownCell/stories/markdownCell.stories.js +25 -0
- package/lib/components/Table/components/TableCell/components/MarkdownCell/stories/types.d.ts +3 -0
- package/lib/components/Table/components/TableCell/components/MarkdownCell/stories/types.js +1 -0
- package/lib/components/Table/components/TableCell/components/MarkdownCell/types.d.ts +3 -0
- package/lib/components/Table/components/TableCell/components/MarkdownCell/types.js +1 -0
- package/lib/components/Table/featureOptions/facetedColumn/getFacetedMinMaxValues.d.ts +8 -0
- package/lib/components/Table/featureOptions/facetedColumn/getFacetedMinMaxValues.js +46 -0
- package/lib/components/common/Link/typeGuards.d.ts +13 -0
- package/lib/components/common/Link/typeGuards.js +21 -0
- package/lib/config/entities.d.ts +2 -11
- package/lib/hooks/useCategoryFilter.d.ts +8 -13
- package/lib/hooks/useCategoryFilter.js +31 -28
- package/lib/providers/exploreState/entities.d.ts +5 -3
- package/lib/providers/exploreState/payloads/entities.d.ts +6 -2
- package/lib/providers/exploreState.d.ts +3 -2
- package/lib/providers/exploreState.js +1 -1
- package/lib/styles/common/mui/typography.js +1 -0
- package/lib/tests/utils.d.ts +24 -0
- package/lib/tests/utils.js +34 -0
- package/lib/theme/common/components.js +19 -1
- package/lib/views/ExploreView/exploreView.js +10 -8
- package/package.json +7 -1
- package/src/common/categories/config/types.ts +42 -0
- package/src/common/categories/config/utils.ts +47 -0
- package/src/common/categories/models/range/typeGuards.ts +24 -0
- package/src/common/categories/models/range/types.ts +17 -0
- package/src/common/categories/models/range/utils.ts +51 -0
- package/src/common/categories/models/select/utils.ts +23 -0
- package/src/common/categories/models/types.ts +7 -0
- package/src/common/categories/views/common/types.ts +11 -0
- package/src/common/categories/views/range/typeGuards.ts +13 -0
- package/src/common/categories/views/range/types.ts +21 -0
- package/src/common/categories/views/range/utils.ts +35 -0
- package/src/common/categories/views/select/typeGuards.ts +13 -0
- package/src/common/categories/views/select/types.ts +8 -0
- package/src/common/categories/views/types.ts +15 -0
- package/src/common/entities.ts +8 -26
- package/src/components/DataDictionary/components/Entities/entities.tsx +7 -5
- package/src/components/DataDictionary/components/Entities/types.ts +5 -9
- package/src/components/DataDictionary/components/Entity/entity.tsx +9 -7
- package/src/components/DataDictionary/components/Entity/types.ts +5 -9
- package/src/components/DataDictionary/components/Outline/utils.ts +5 -2
- package/src/components/DataDictionary/components/Table/components/BasicCell/basicCell.tsx +12 -4
- package/src/components/DataDictionary/components/Table/components/BasicCell/utils.ts +13 -0
- package/src/components/DataDictionary/components/Table/hook.ts +16 -8
- package/src/components/DataDictionary/components/Table/options/core/constants.ts +2 -3
- package/src/components/DataDictionary/components/Table/options/hook.ts +3 -3
- package/src/components/DataDictionary/components/Table/options/sorting/constants.ts +2 -6
- package/src/components/DataDictionary/components/Table/table.tsx +4 -1
- package/src/components/DataDictionary/components/Table/types.ts +3 -4
- package/src/components/DataDictionary/dataDictionary.styles.ts +2 -3
- package/src/components/DataDictionary/dataDictionary.tsx +4 -2
- package/src/components/DataDictionary/hooks/UseDataDictionary/hook.ts +9 -2
- package/src/components/DataDictionary/hooks/UseDataDictionary/types.ts +5 -9
- package/src/components/Filter/components/Filter/filter.tsx +38 -13
- package/src/components/Filter/components/Filter/stories/args.ts +24 -0
- package/src/components/Filter/components/Filter/stories/filter.stories.tsx +32 -0
- package/src/components/Filter/components/FilterMenu/filterMenu.styles.ts +1 -1
- package/src/components/Filter/components/FilterMenu/filterMenu.tsx +7 -3
- package/src/components/Filter/components/FilterRange/constants.ts +0 -7
- package/src/components/Filter/components/FilterRange/filterRange.styles.ts +58 -14
- package/src/components/Filter/components/FilterRange/filterRange.tsx +112 -40
- package/src/components/Filter/components/FilterRange/hooks/UseFilterRange/constants.ts +5 -0
- package/src/components/Filter/components/FilterRange/hooks/UseFilterRange/hook.ts +51 -10
- package/src/components/Filter/components/FilterRange/hooks/UseFilterRange/schema.ts +60 -0
- package/src/components/Filter/components/FilterRange/hooks/UseFilterRange/types.ts +34 -3
- package/src/components/Filter/components/FilterRange/hooks/UseFilterRange/utils.ts +32 -0
- package/src/components/Filter/components/FilterRange/stories/args.ts +16 -0
- package/src/components/Filter/components/FilterRange/stories/filterRange.stories.tsx +2 -2
- package/src/components/Filter/components/FilterRange/types.ts +12 -6
- package/src/components/Filter/components/FilterRange/utils.ts +16 -0
- package/src/components/Filter/components/FilterTag/stories/args.ts +22 -0
- package/src/components/Filter/components/FilterTag/stories/filterTag.stories.tsx +32 -0
- package/src/components/Filter/components/FilterTag/utils.ts +57 -0
- package/src/components/Filter/components/Filters/filters.tsx +21 -12
- package/src/components/Filter/components/Filters/stories/args.ts +24 -0
- package/src/components/Filter/components/Filters/stories/constants.ts +151 -0
- package/src/components/Filter/components/Filters/stories/filters.stories.tsx +24 -0
- package/src/components/Filter/components/SearchAllFilters/components/VariableSizeList/VariableSizeList.tsx +32 -29
- package/src/components/Filter/components/SearchAllFilters/components/VariableSizeListItem/variableSizeListItem.tsx +9 -1
- package/src/components/Filter/components/SearchAllFilters/searchAllFilters.tsx +12 -6
- package/src/components/Filter/components/VariableSizeListItem/variableSizeListItem.tsx +2 -1
- package/src/components/Index/components/EntitiesView/components/ChartView/utils.ts +2 -0
- package/src/components/Index/table/hook.ts +4 -0
- package/src/components/MarkdownRenderer/components/Anchor/anchor.tsx +34 -0
- package/src/components/MarkdownRenderer/components/Table/table.styles.ts +41 -0
- package/src/components/MarkdownRenderer/components/Table/table.tsx +13 -0
- package/src/components/MarkdownRenderer/constants.ts +8 -0
- package/src/components/MarkdownRenderer/markdownRenderer.styles.ts +16 -0
- package/src/components/MarkdownRenderer/markdownRenderer.tsx +62 -0
- package/src/components/MarkdownRenderer/types.ts +7 -0
- package/src/components/Table/columnDef/accessorFn/typeGuards.ts +15 -0
- package/src/components/Table/common/utils.ts +37 -16
- package/src/components/Table/components/TableCell/components/ChipCell/chipCell.tsx +16 -0
- package/src/components/Table/components/TableCell/components/LinkCell/linkCell.tsx +64 -0
- package/src/components/Table/components/TableCell/components/LinkCell/stories/args.ts +35 -0
- package/src/components/Table/components/TableCell/components/LinkCell/stories/linkCell.stories.tsx +32 -0
- package/src/components/Table/components/TableCell/components/LinkCell/stories/types.ts +4 -0
- package/src/components/Table/components/TableCell/components/LinkCell/utils.ts +59 -0
- package/src/components/Table/components/TableCell/components/MarkdownCell/markdownCell.styles.ts +31 -0
- package/src/components/Table/components/TableCell/components/MarkdownCell/markdownCell.tsx +29 -0
- package/src/components/Table/components/TableCell/components/MarkdownCell/stories/args.ts +17 -0
- package/src/components/Table/components/TableCell/components/MarkdownCell/stories/constants.ts +11 -0
- package/src/components/Table/components/TableCell/components/MarkdownCell/stories/markdownCell.stories.tsx +37 -0
- package/src/components/Table/components/TableCell/components/MarkdownCell/stories/types.ts +4 -0
- package/src/components/Table/components/TableCell/components/MarkdownCell/types.ts +3 -0
- package/src/components/Table/featureOptions/facetedColumn/getFacetedMinMaxValues.ts +64 -0
- package/src/components/common/Link/typeGuards.ts +35 -0
- package/src/config/entities.ts +1 -14
- package/src/hooks/useCategoryFilter.ts +56 -53
- package/src/providers/exploreState/entities.ts +3 -3
- package/src/providers/exploreState/initializer/utils.ts +1 -1
- package/src/providers/exploreState/payloads/entities.ts +5 -2
- package/src/providers/exploreState.tsx +5 -3
- package/src/styles/common/mui/typography.ts +1 -0
- package/src/tests/utils.ts +44 -0
- package/src/theme/common/components.ts +19 -1
- package/src/views/ExploreView/exploreView.tsx +17 -22
- package/tests/filter.test.tsx +100 -0
- package/tests/filterRange.test.tsx +331 -46
- package/tests/filters.test.tsx +61 -0
- package/tests/getFacetedMinMaxValues.test.ts +166 -0
- package/tests/linkCell.test.tsx +89 -0
- package/tests/markdownCell.test.tsx +53 -0
- package/types/data-explorer-ui.d.ts +2 -0
- package/lib/components/DataDictionary/components/Table/components/BasicCell/types.d.ts +0 -3
- package/lib/components/Filter/components/Filter/filter.stories.d.ts +0 -25
- package/lib/components/Filter/components/Filter/filter.stories.js +0 -42
- package/lib/components/Filter/components/FilterTag/filterTag.stories.d.ts +0 -16
- package/lib/components/Filter/components/FilterTag/filterTag.stories.js +0 -17
- package/lib/components/Filter/components/Filters/filters.stories.d.ts +0 -6
- package/lib/components/Filter/components/Filters/filters.stories.js +0 -91
- package/src/components/DataDictionary/components/Table/components/BasicCell/types.ts +0 -7
- package/src/components/Filter/components/Filter/filter.stories.tsx +0 -52
- package/src/components/Filter/components/FilterTag/filterTag.stories.tsx +0 -23
- package/src/components/Filter/components/Filters/filters.stories.tsx +0 -101
- package/tests/filterRangeMock.test.tsx +0 -38
- /package/lib/{components/DataDictionary/components/Table/components/BasicCell → common/categories/config}/types.js +0 -0
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
Button,
|
|
3
3
|
Divider,
|
|
4
4
|
FormControl,
|
|
5
|
+
FormHelperText,
|
|
5
6
|
Grid,
|
|
6
7
|
InputLabel,
|
|
7
8
|
OutlinedInput,
|
|
@@ -10,62 +11,133 @@ import {
|
|
|
10
11
|
} from "@mui/material";
|
|
11
12
|
import React, { Fragment } from "react";
|
|
12
13
|
import { TEST_IDS } from "../../../../tests/testIds";
|
|
14
|
+
import { SouthIcon } from "../../../common/CustomIcon/components/SouthIcon/southIcon";
|
|
15
|
+
import {
|
|
16
|
+
FilterViewTools,
|
|
17
|
+
StyledButtonBase,
|
|
18
|
+
} from "../FilterMenu/filterMenu.styles";
|
|
13
19
|
import {
|
|
14
20
|
BUTTON_PROPS,
|
|
15
21
|
DIVIDER_PROPS,
|
|
16
22
|
INPUT_LABEL_PROPS,
|
|
17
23
|
INPUT_PROPS,
|
|
18
|
-
RANGE_OPERATOR_DISPLAY,
|
|
19
24
|
TOGGLE_BUTTON_GROUP_PROPS,
|
|
20
25
|
} from "./constants";
|
|
21
26
|
import { StyledForm } from "./filterRange.styles";
|
|
27
|
+
import { FIELD_NAME } from "./hooks/UseFilterRange/constants";
|
|
22
28
|
import { useFilterRange } from "./hooks/UseFilterRange/hook";
|
|
23
|
-
import {
|
|
29
|
+
import { RANGE_OPERATOR } from "./hooks/UseFilterRange/types";
|
|
30
|
+
import { FilterRangeProps } from "./types";
|
|
31
|
+
import { getRangeOperator } from "./utils";
|
|
24
32
|
|
|
25
|
-
export const FilterRange = ({
|
|
26
|
-
|
|
33
|
+
export const FilterRange = ({
|
|
34
|
+
categoryKey,
|
|
35
|
+
categoryLabel,
|
|
36
|
+
categorySection,
|
|
37
|
+
className,
|
|
38
|
+
isFilterDrawer,
|
|
39
|
+
max,
|
|
40
|
+
min,
|
|
41
|
+
onCloseFilter,
|
|
42
|
+
onFilter,
|
|
43
|
+
selectedMax,
|
|
44
|
+
selectedMin,
|
|
45
|
+
unit,
|
|
46
|
+
}: FilterRangeProps): JSX.Element => {
|
|
47
|
+
const rangeOperator = getRangeOperator({ selectedMax, selectedMin });
|
|
48
|
+
const {
|
|
49
|
+
clearErrors,
|
|
50
|
+
formState: { errors },
|
|
51
|
+
handleSubmit,
|
|
52
|
+
onChange,
|
|
53
|
+
value,
|
|
54
|
+
} = useFilterRange(rangeOperator);
|
|
27
55
|
return (
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
56
|
+
<Fragment>
|
|
57
|
+
{isFilterDrawer && (
|
|
58
|
+
<FilterViewTools>
|
|
59
|
+
<StyledButtonBase onClick={onCloseFilter}>
|
|
60
|
+
<SouthIcon fontSize="small" />
|
|
61
|
+
{categoryLabel}
|
|
62
|
+
</StyledButtonBase>
|
|
63
|
+
</FilterViewTools>
|
|
64
|
+
)}
|
|
65
|
+
<StyledForm
|
|
66
|
+
className={className}
|
|
67
|
+
data-testid={TEST_IDS.FILTER_RANGE}
|
|
68
|
+
onSubmit={handleSubmit(onFilter, {
|
|
69
|
+
categoryKey,
|
|
70
|
+
categorySection,
|
|
71
|
+
})}
|
|
37
72
|
>
|
|
38
|
-
<
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
<
|
|
48
|
-
|
|
49
|
-
</
|
|
50
|
-
<
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
73
|
+
<ToggleButtonGroup
|
|
74
|
+
{...TOGGLE_BUTTON_GROUP_PROPS}
|
|
75
|
+
onChange={(e, value) => {
|
|
76
|
+
clearErrors();
|
|
77
|
+
onChange?.(e, value);
|
|
78
|
+
}}
|
|
79
|
+
value={value}
|
|
80
|
+
>
|
|
81
|
+
<ToggleButton value={RANGE_OPERATOR.BETWEEN}>Between</ToggleButton>
|
|
82
|
+
<ToggleButton value={RANGE_OPERATOR.LESS_THAN}>
|
|
83
|
+
Less Than
|
|
84
|
+
</ToggleButton>
|
|
85
|
+
<Divider {...DIVIDER_PROPS} />
|
|
86
|
+
<ToggleButton value={RANGE_OPERATOR.GREATER_THAN}>
|
|
87
|
+
Greater Than
|
|
88
|
+
</ToggleButton>
|
|
89
|
+
</ToggleButtonGroup>
|
|
90
|
+
<Grid>
|
|
91
|
+
{value !== RANGE_OPERATOR.LESS_THAN && (
|
|
92
|
+
<FormControl error={!!errors[FIELD_NAME.MIN]}>
|
|
93
|
+
<InputLabel {...INPUT_LABEL_PROPS} htmlFor={FIELD_NAME.MIN}>
|
|
94
|
+
{value === RANGE_OPERATOR.BETWEEN ? "Min" : "Greater Than"}
|
|
95
|
+
{unit && ` (${unit})`}
|
|
96
|
+
</InputLabel>
|
|
97
|
+
<OutlinedInput
|
|
98
|
+
{...INPUT_PROPS}
|
|
99
|
+
defaultValue={selectedMin}
|
|
100
|
+
id={FIELD_NAME.MIN}
|
|
101
|
+
name={FIELD_NAME.MIN}
|
|
102
|
+
onFocus={clearErrors}
|
|
103
|
+
placeholder="eg. 1"
|
|
104
|
+
/>
|
|
105
|
+
<FormHelperText>
|
|
106
|
+
{errors[FIELD_NAME.MIN]
|
|
107
|
+
? errors[FIELD_NAME.MIN]
|
|
108
|
+
: value === RANGE_OPERATOR.BETWEEN
|
|
109
|
+
? `Min allowed: ${min}`
|
|
110
|
+
: `Allowed values: \u2265 ${min} and \u2264 ${max}`}
|
|
111
|
+
</FormHelperText>
|
|
112
|
+
</FormControl>
|
|
113
|
+
)}
|
|
114
|
+
{value === RANGE_OPERATOR.BETWEEN && <Divider />}
|
|
115
|
+
{value !== RANGE_OPERATOR.GREATER_THAN && (
|
|
116
|
+
<FormControl error={!!errors[FIELD_NAME.MAX]}>
|
|
117
|
+
<InputLabel {...INPUT_LABEL_PROPS} htmlFor={FIELD_NAME.MAX}>
|
|
118
|
+
{value === RANGE_OPERATOR.BETWEEN ? "Max" : "Less Than"}
|
|
119
|
+
{unit && ` (${unit})`}
|
|
58
120
|
</InputLabel>
|
|
59
121
|
<OutlinedInput
|
|
60
122
|
{...INPUT_PROPS}
|
|
61
|
-
|
|
62
|
-
|
|
123
|
+
defaultValue={selectedMax}
|
|
124
|
+
id={FIELD_NAME.MAX}
|
|
125
|
+
name={FIELD_NAME.MAX}
|
|
126
|
+
onFocus={clearErrors}
|
|
127
|
+
placeholder="eg. 20"
|
|
63
128
|
/>
|
|
129
|
+
<FormHelperText color="inkLight">
|
|
130
|
+
{errors[FIELD_NAME.MAX]
|
|
131
|
+
? errors[FIELD_NAME.MAX]
|
|
132
|
+
: value === RANGE_OPERATOR.BETWEEN
|
|
133
|
+
? `Max allowed: ${max}`
|
|
134
|
+
: `Allowed values: \u2265 ${min} and \u2264 ${max}`}
|
|
135
|
+
</FormHelperText>
|
|
64
136
|
</FormControl>
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
</
|
|
137
|
+
)}
|
|
138
|
+
</Grid>
|
|
139
|
+
<Button {...BUTTON_PROPS}>Filter</Button>
|
|
140
|
+
</StyledForm>
|
|
141
|
+
</Fragment>
|
|
70
142
|
);
|
|
71
143
|
};
|
|
@@ -1,20 +1,61 @@
|
|
|
1
|
-
import { FormEvent, useCallback } from "react";
|
|
1
|
+
import { FormEvent, useCallback, useState } from "react";
|
|
2
|
+
import { ValidationError } from "yup";
|
|
3
|
+
import { VIEW_KIND } from "../../../../../../common/categories/views/types";
|
|
2
4
|
import { useToggleButtonGroup } from "../../../../../common/ToggleButtonGroup/hooks/UseToggleButtonGroup/hook";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
+
import { SCHEMA } from "./schema";
|
|
6
|
+
import {
|
|
7
|
+
FieldErrors,
|
|
8
|
+
OnSubmitFn,
|
|
9
|
+
RANGE_OPERATOR,
|
|
10
|
+
SubmitParams,
|
|
11
|
+
UseFilterRange,
|
|
12
|
+
} from "./types";
|
|
13
|
+
import { getFormValues } from "./utils";
|
|
5
14
|
|
|
6
|
-
export const useFilterRange = (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
);
|
|
15
|
+
export const useFilterRange = (
|
|
16
|
+
initialValue: RANGE_OPERATOR = RANGE_OPERATOR.BETWEEN
|
|
17
|
+
): UseFilterRange => {
|
|
18
|
+
const [errors, setErrors] = useState<FieldErrors>({});
|
|
19
|
+
const { onChange, value } =
|
|
20
|
+
useToggleButtonGroup<RANGE_OPERATOR>(initialValue);
|
|
10
21
|
|
|
11
|
-
const
|
|
12
|
-
|
|
22
|
+
const clearErrors = useCallback(() => {
|
|
23
|
+
setErrors({});
|
|
13
24
|
}, []);
|
|
14
25
|
|
|
26
|
+
const handleSubmit = useCallback(
|
|
27
|
+
(onSubmit: OnSubmitFn, parameters: SubmitParams) => {
|
|
28
|
+
return (e: FormEvent<HTMLFormElement>): void => {
|
|
29
|
+
e.preventDefault();
|
|
30
|
+
const fieldValues = getFormValues(e.currentTarget, value); // `value` is current range operator.
|
|
31
|
+
SCHEMA.validate(fieldValues, { abortEarly: false })
|
|
32
|
+
.then((result) => {
|
|
33
|
+
setErrors({});
|
|
34
|
+
onSubmit(
|
|
35
|
+
parameters.categoryKey,
|
|
36
|
+
[result.min, result.max],
|
|
37
|
+
true,
|
|
38
|
+
parameters.categorySection,
|
|
39
|
+
VIEW_KIND.RANGE
|
|
40
|
+
);
|
|
41
|
+
})
|
|
42
|
+
.catch((validationError: ValidationError) => {
|
|
43
|
+
const fieldErrors: FieldErrors = {};
|
|
44
|
+
for (const error of validationError.inner) {
|
|
45
|
+
if (error.path) fieldErrors[error.path] = error.message;
|
|
46
|
+
}
|
|
47
|
+
setErrors(fieldErrors);
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
[value]
|
|
52
|
+
);
|
|
53
|
+
|
|
15
54
|
return {
|
|
55
|
+
clearErrors,
|
|
56
|
+
formState: { errors },
|
|
57
|
+
handleSubmit,
|
|
16
58
|
onChange,
|
|
17
|
-
onSubmit,
|
|
18
59
|
value,
|
|
19
60
|
};
|
|
20
61
|
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { mixed, number, object } from "yup";
|
|
2
|
+
import { FIELD_NAME } from "./constants";
|
|
3
|
+
import { RANGE_OPERATOR } from "./types";
|
|
4
|
+
|
|
5
|
+
export const SCHEMA = object({
|
|
6
|
+
[FIELD_NAME.MAX]: number()
|
|
7
|
+
.typeError("Value must be a number")
|
|
8
|
+
.when(FIELD_NAME.RANGE_OPERATOR, {
|
|
9
|
+
is: RANGE_OPERATOR.BETWEEN,
|
|
10
|
+
then: (schema) => schema.notRequired(),
|
|
11
|
+
})
|
|
12
|
+
.when(FIELD_NAME.RANGE_OPERATOR, {
|
|
13
|
+
is: RANGE_OPERATOR.LESS_THAN,
|
|
14
|
+
then: (schema) => schema.required("Value is required"),
|
|
15
|
+
})
|
|
16
|
+
.when(FIELD_NAME.RANGE_OPERATOR, {
|
|
17
|
+
is: RANGE_OPERATOR.GREATER_THAN,
|
|
18
|
+
then: (schema) => schema.notRequired(),
|
|
19
|
+
}),
|
|
20
|
+
[FIELD_NAME.MIN]: number()
|
|
21
|
+
.typeError("Value must be a number")
|
|
22
|
+
.when(FIELD_NAME.RANGE_OPERATOR, {
|
|
23
|
+
is: RANGE_OPERATOR.BETWEEN,
|
|
24
|
+
then: (schema) =>
|
|
25
|
+
schema
|
|
26
|
+
.notRequired()
|
|
27
|
+
.test(
|
|
28
|
+
"min-less-than-max",
|
|
29
|
+
"Min must be less than max",
|
|
30
|
+
function (min) {
|
|
31
|
+
const max = this.parent[FIELD_NAME.MAX];
|
|
32
|
+
// If either value is not a number, skip validation.
|
|
33
|
+
if (!min || !max) return true;
|
|
34
|
+
if (Number.isNaN(min) || Number.isNaN(max)) return true;
|
|
35
|
+
return min < max;
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
.test(
|
|
39
|
+
"at-least-min-or-max",
|
|
40
|
+
"Min or Max is required",
|
|
41
|
+
function (min) {
|
|
42
|
+
const max = this.parent[FIELD_NAME.MAX];
|
|
43
|
+
// If both values are null, validation fails.
|
|
44
|
+
return !(min === null && max === null);
|
|
45
|
+
}
|
|
46
|
+
),
|
|
47
|
+
})
|
|
48
|
+
.when(FIELD_NAME.RANGE_OPERATOR, {
|
|
49
|
+
is: RANGE_OPERATOR.LESS_THAN,
|
|
50
|
+
then: (schema) => schema.notRequired(),
|
|
51
|
+
})
|
|
52
|
+
.when(FIELD_NAME.RANGE_OPERATOR, {
|
|
53
|
+
is: RANGE_OPERATOR.GREATER_THAN,
|
|
54
|
+
otherwise: (schema) => schema.notRequired(),
|
|
55
|
+
then: (schema) => schema.required("Value is required"),
|
|
56
|
+
}),
|
|
57
|
+
[FIELD_NAME.RANGE_OPERATOR]: mixed<RANGE_OPERATOR>().default(
|
|
58
|
+
RANGE_OPERATOR.BETWEEN
|
|
59
|
+
),
|
|
60
|
+
});
|
|
@@ -1,9 +1,40 @@
|
|
|
1
1
|
import { ToggleButtonGroupProps } from "@mui/material";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { OnFilterFn } from "hooks/useCategoryFilter";
|
|
3
|
+
import { FormEventHandler } from "react";
|
|
4
|
+
import { FIELD_NAME } from "./constants";
|
|
5
|
+
|
|
6
|
+
export type FieldErrors = Partial<Record<FieldName, string>>;
|
|
7
|
+
|
|
8
|
+
export type FieldName = (typeof FIELD_NAME)[keyof typeof FIELD_NAME];
|
|
9
|
+
|
|
10
|
+
export interface FieldValues {
|
|
11
|
+
max: FormDataEntryValue | null;
|
|
12
|
+
min: FormDataEntryValue | null;
|
|
13
|
+
rangeOperator: RANGE_OPERATOR;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type OnSubmitFn = OnFilterFn;
|
|
17
|
+
|
|
18
|
+
export type OnSubmitParams = Parameters<OnSubmitFn>;
|
|
19
|
+
|
|
20
|
+
export enum RANGE_OPERATOR {
|
|
21
|
+
BETWEEN = "between",
|
|
22
|
+
GREATER_THAN = "greaterThan",
|
|
23
|
+
LESS_THAN = "lessThan",
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type SubmitParams = {
|
|
27
|
+
categoryKey: OnSubmitParams[0];
|
|
28
|
+
categorySection?: OnSubmitParams[3];
|
|
29
|
+
};
|
|
4
30
|
|
|
5
31
|
export interface UseFilterRange {
|
|
32
|
+
clearErrors: () => void;
|
|
33
|
+
formState: { errors: FieldErrors };
|
|
34
|
+
handleSubmit: (
|
|
35
|
+
onSubmit: OnSubmitFn,
|
|
36
|
+
parameters: SubmitParams
|
|
37
|
+
) => FormEventHandler;
|
|
6
38
|
onChange: ToggleButtonGroupProps["onChange"];
|
|
7
|
-
onSubmit: (e: FormEvent) => void;
|
|
8
39
|
value: RANGE_OPERATOR;
|
|
9
40
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { FieldValues, RANGE_OPERATOR } from "./types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves the min and max field values from a form.
|
|
5
|
+
* @param e - The form element to retrieve values from.
|
|
6
|
+
* @param rangeOperator - The range operator value in use.
|
|
7
|
+
* @returns The values from the form.
|
|
8
|
+
*/
|
|
9
|
+
export function getFormValues(
|
|
10
|
+
e: HTMLFormElement,
|
|
11
|
+
rangeOperator: RANGE_OPERATOR
|
|
12
|
+
): FieldValues {
|
|
13
|
+
const formData = new FormData(e);
|
|
14
|
+
const fieldValues = {} as FieldValues;
|
|
15
|
+
fieldValues.max = parseMinMaxValue(formData.get("max"));
|
|
16
|
+
fieldValues.min = parseMinMaxValue(formData.get("min"));
|
|
17
|
+
fieldValues.rangeOperator = rangeOperator;
|
|
18
|
+
return fieldValues;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Parses a form data value null or empty string to null.
|
|
23
|
+
* Schema validation will handle the rest.
|
|
24
|
+
* @param value - The value to parse.
|
|
25
|
+
* @returns The parsed value, or null if the value is null or empty string.
|
|
26
|
+
*/
|
|
27
|
+
export function parseMinMaxValue(
|
|
28
|
+
value: FormDataEntryValue | null
|
|
29
|
+
): FormDataEntryValue | null {
|
|
30
|
+
if (value === null || value === "") return null;
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { fn } from "@storybook/test";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
import { FilterRange } from "../filterRange";
|
|
4
|
+
|
|
5
|
+
export const DEFAULT_ARGS: ComponentProps<typeof FilterRange> = {
|
|
6
|
+
categoryKey: "Weight",
|
|
7
|
+
categoryLabel: "Weight",
|
|
8
|
+
isFilterDrawer: false,
|
|
9
|
+
max: 2100,
|
|
10
|
+
min: 100,
|
|
11
|
+
onCloseFilter: fn(),
|
|
12
|
+
onFilter: fn(),
|
|
13
|
+
selectedMax: null,
|
|
14
|
+
selectedMin: null,
|
|
15
|
+
unit: "kg",
|
|
16
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import { FilterRange } from "../filterRange";
|
|
3
|
+
import { DEFAULT_ARGS } from "./args";
|
|
3
4
|
|
|
4
5
|
const meta: Meta<typeof FilterRange> = {
|
|
5
|
-
args: {},
|
|
6
6
|
component: FilterRange,
|
|
7
7
|
};
|
|
8
8
|
|
|
@@ -11,5 +11,5 @@ export default meta;
|
|
|
11
11
|
type Story = StoryObj<typeof meta>;
|
|
12
12
|
|
|
13
13
|
export const Default: Story = {
|
|
14
|
-
args:
|
|
14
|
+
args: DEFAULT_ARGS,
|
|
15
15
|
};
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import { RangeCategoryView } from "../../../../common/categories/views/range/types";
|
|
2
|
+
import { CategoryKey } from "../../../../common/entities";
|
|
3
|
+
import { OnFilterFn } from "../../../../hooks/useCategoryFilter";
|
|
1
4
|
import { BaseComponentProps } from "../../../types";
|
|
2
5
|
|
|
3
|
-
export interface FilterRangeProps
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
export interface FilterRangeProps
|
|
7
|
+
extends Omit<RangeCategoryView, "key" | "label">,
|
|
8
|
+
BaseComponentProps {
|
|
9
|
+
categoryKey: CategoryKey;
|
|
10
|
+
categoryLabel: string;
|
|
11
|
+
categorySection?: string;
|
|
12
|
+
isFilterDrawer: boolean;
|
|
13
|
+
onCloseFilter: () => void;
|
|
14
|
+
onFilter: OnFilterFn;
|
|
9
15
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RangeCategoryView } from "../../../../common/categories/views/range/types";
|
|
2
|
+
import { RANGE_OPERATOR } from "./hooks/UseFilterRange/types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns the range operator based on the selected values.
|
|
6
|
+
* @param categoryView - View model of range category.
|
|
7
|
+
* @returns The range operator or undefined if no valid range is selected.
|
|
8
|
+
*/
|
|
9
|
+
export function getRangeOperator(
|
|
10
|
+
categoryView: Pick<RangeCategoryView, "selectedMax" | "selectedMin">
|
|
11
|
+
): RANGE_OPERATOR | undefined {
|
|
12
|
+
const { selectedMax, selectedMin } = categoryView;
|
|
13
|
+
if (selectedMin && selectedMax) return RANGE_OPERATOR.BETWEEN;
|
|
14
|
+
if (selectedMin) return RANGE_OPERATOR.GREATER_THAN;
|
|
15
|
+
if (selectedMax) return RANGE_OPERATOR.LESS_THAN;
|
|
16
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { fn } from "@storybook/test";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
import { LOREM_IPSUM } from "storybook/loremIpsum";
|
|
4
|
+
import { FilterTag } from "../filterTag";
|
|
5
|
+
|
|
6
|
+
export const DEFAULT_ARGS: ComponentProps<typeof FilterTag> = {
|
|
7
|
+
label: "male",
|
|
8
|
+
onRemove: fn(),
|
|
9
|
+
superseded: false,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const WITH_ELLIPSIS_ARGS: ComponentProps<typeof FilterTag> = {
|
|
13
|
+
label: LOREM_IPSUM.LONG,
|
|
14
|
+
onRemove: fn(),
|
|
15
|
+
superseded: false,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const WITH_RANGE_ARGS: ComponentProps<typeof FilterTag> = {
|
|
19
|
+
label: "10 - 34",
|
|
20
|
+
onRemove: fn(),
|
|
21
|
+
superseded: false,
|
|
22
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Box } from "@mui/material";
|
|
2
|
+
import { Meta, StoryObj } from "@storybook/react";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { FilterTag } from "../filterTag";
|
|
5
|
+
import { DEFAULT_ARGS, WITH_ELLIPSIS_ARGS, WITH_RANGE_ARGS } from "./args";
|
|
6
|
+
|
|
7
|
+
const meta: Meta<typeof FilterTag> = {
|
|
8
|
+
component: FilterTag,
|
|
9
|
+
decorators: [
|
|
10
|
+
(Story): JSX.Element => (
|
|
11
|
+
<Box sx={{ width: 232 }}>
|
|
12
|
+
<Story />
|
|
13
|
+
</Box>
|
|
14
|
+
),
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default meta;
|
|
19
|
+
|
|
20
|
+
type Story = StoryObj<typeof meta>;
|
|
21
|
+
|
|
22
|
+
export const Default: Story = {
|
|
23
|
+
args: DEFAULT_ARGS,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const WithEllipsis: Story = {
|
|
27
|
+
args: WITH_ELLIPSIS_ARGS,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const WithRange: Story = {
|
|
31
|
+
args: WITH_RANGE_ARGS,
|
|
32
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { RangeCategoryView } from "../../../../common/categories/views/range/types";
|
|
2
|
+
import { VIEW_KIND } from "../../../../common/categories/views/types";
|
|
3
|
+
import { CategoryTag } from "../../../../common/entities";
|
|
4
|
+
import { OnFilterFn } from "../../../../hooks/useCategoryFilter";
|
|
5
|
+
import { RANGE_OPERATOR } from "../FilterRange/hooks/UseFilterRange/types";
|
|
6
|
+
import { getRangeOperator } from "../FilterRange/utils";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Returns set of filter tags with tag label (the selected range values) and corresponding Tag onRemove function.
|
|
10
|
+
* @param categoryView - View model of range category.
|
|
11
|
+
* @param onFilter - Function to execute on selection or removal of category value.
|
|
12
|
+
* @returns Array of selected filter tags.
|
|
13
|
+
*/
|
|
14
|
+
export function buildRangeTag(
|
|
15
|
+
categoryView: RangeCategoryView,
|
|
16
|
+
onFilter: OnFilterFn
|
|
17
|
+
): CategoryTag[] {
|
|
18
|
+
const rangeOperator = getRangeOperator(categoryView);
|
|
19
|
+
if (!rangeOperator) return [];
|
|
20
|
+
return [
|
|
21
|
+
{
|
|
22
|
+
label: buildRangeTagLabel(categoryView, rangeOperator),
|
|
23
|
+
onRemove: () =>
|
|
24
|
+
onFilter(
|
|
25
|
+
categoryView.key,
|
|
26
|
+
undefined,
|
|
27
|
+
false,
|
|
28
|
+
undefined,
|
|
29
|
+
VIEW_KIND.RANGE
|
|
30
|
+
),
|
|
31
|
+
superseded: false,
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Returns the label for the range tag based on the selected values.
|
|
38
|
+
* @param categoryView - View model of range category.
|
|
39
|
+
* @param rangeOperator - The range operator.
|
|
40
|
+
* @returns The label for the range tag.
|
|
41
|
+
*/
|
|
42
|
+
function buildRangeTagLabel(
|
|
43
|
+
categoryView: RangeCategoryView,
|
|
44
|
+
rangeOperator: RANGE_OPERATOR
|
|
45
|
+
): string {
|
|
46
|
+
const { selectedMax, selectedMin } = categoryView;
|
|
47
|
+
switch (rangeOperator) {
|
|
48
|
+
case RANGE_OPERATOR.BETWEEN:
|
|
49
|
+
return `${selectedMin} - ${selectedMax}`;
|
|
50
|
+
case RANGE_OPERATOR.GREATER_THAN:
|
|
51
|
+
return `> ${selectedMin}`;
|
|
52
|
+
case RANGE_OPERATOR.LESS_THAN:
|
|
53
|
+
return `< ${selectedMax}`;
|
|
54
|
+
default:
|
|
55
|
+
return "";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Divider } from "@mui/material";
|
|
2
2
|
import React, { Fragment, useEffect, useRef, useState } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { isRangeCategoryView } from "../../../../common/categories/views/range/typeGuards";
|
|
4
|
+
import { CategoryView } from "../../../../common/categories/views/types";
|
|
5
|
+
import { CategoryTag } from "../../../../common/entities";
|
|
4
6
|
import { TrackFilterOpenedFunction } from "../../../../config/entities";
|
|
5
7
|
import {
|
|
6
8
|
BREAKPOINT_FN_NAME,
|
|
@@ -11,11 +13,12 @@ import { useWindowResize } from "../../../../hooks/useWindowResize";
|
|
|
11
13
|
import { TEST_IDS } from "../../../../tests/testIds";
|
|
12
14
|
import { DESKTOP_SM } from "../../../../theme/common/breakpoints";
|
|
13
15
|
import { Filter } from "../Filter/filter";
|
|
16
|
+
import { buildRangeTag } from "../FilterTag/utils";
|
|
14
17
|
import { FilterTags } from "../FilterTags/filterTags";
|
|
15
18
|
import { CategoryViewsLabel, Filters as FilterList } from "./filters.styles";
|
|
16
19
|
|
|
17
20
|
export interface CategoryFilter {
|
|
18
|
-
categoryViews:
|
|
21
|
+
categoryViews: CategoryView[];
|
|
19
22
|
label?: string;
|
|
20
23
|
}
|
|
21
24
|
|
|
@@ -28,15 +31,21 @@ export interface FiltersProps {
|
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
/**
|
|
31
|
-
* Returns
|
|
34
|
+
* Returns filter tags for the given category view.
|
|
32
35
|
* @param categoryView - View model of category to display.
|
|
33
|
-
* @param onFilter - Function to execute on
|
|
34
|
-
* @returns Array of
|
|
36
|
+
* @param onFilter - Function to execute on selection or removal of category value.
|
|
37
|
+
* @returns Array of filter tags.
|
|
35
38
|
*/
|
|
36
|
-
function
|
|
37
|
-
categoryView:
|
|
39
|
+
function buildFilterTags(
|
|
40
|
+
categoryView: CategoryView,
|
|
38
41
|
onFilter: OnFilterFn
|
|
39
42
|
): CategoryTag[] {
|
|
43
|
+
// Handle range category views
|
|
44
|
+
if (isRangeCategoryView(categoryView)) {
|
|
45
|
+
return buildRangeTag(categoryView, onFilter);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Handle select category views.
|
|
40
49
|
const { key: categoryKey, values } = categoryView;
|
|
41
50
|
return values
|
|
42
51
|
.filter(({ selected }) => selected)
|
|
@@ -50,16 +59,16 @@ function buildSelectCategoryTags(
|
|
|
50
59
|
}
|
|
51
60
|
|
|
52
61
|
/**
|
|
53
|
-
*
|
|
62
|
+
* Returns filter tags element for the given category view.
|
|
54
63
|
* @param categoryView - View model of category to display.
|
|
55
|
-
* @param onFilter - Function to execute on
|
|
56
|
-
* @returns Filter tags element
|
|
64
|
+
* @param onFilter - Function to execute on selection or removal of category value.
|
|
65
|
+
* @returns Filter tags element.
|
|
57
66
|
*/
|
|
58
67
|
function renderFilterTags(
|
|
59
|
-
categoryView:
|
|
68
|
+
categoryView: CategoryView,
|
|
60
69
|
onFilter: OnFilterFn
|
|
61
70
|
): JSX.Element {
|
|
62
|
-
const tags =
|
|
71
|
+
const tags = buildFilterTags(categoryView, onFilter);
|
|
63
72
|
return <FilterTags tags={tags} />;
|
|
64
73
|
}
|
|
65
74
|
|