@databiosphere/findable-ui 2.0.1 → 2.2.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/lib/components/Filter/components/FilterLabel/filterLabel.styles.js +1 -2
- package/lib/components/Filter/components/Filters/filters.d.ts +1 -1
- package/lib/components/Filter/components/Filters/filters.js +11 -1
- package/lib/components/Filter/components/Filters/filters.styles.d.ts +5 -0
- package/lib/components/Filter/components/Filters/filters.styles.js +15 -2
- package/lib/components/Filter/components/VariableSizeListItem/variableSizeListItem.js +2 -1
- package/lib/config/entities.d.ts +7 -1
- package/lib/providers/exploreState/constants.d.ts +3 -3
- package/lib/providers/exploreState/constants.js +3 -26
- package/lib/providers/exploreState/entities.d.ts +10 -3
- package/lib/providers/exploreState/initializer/constants.js +2 -0
- package/lib/providers/exploreState/initializer/utils.js +63 -4
- package/lib/providers/exploreState/payloads/entities.d.ts +8 -0
- package/lib/providers/exploreState/utils.d.ts +42 -10
- package/lib/providers/exploreState/utils.js +75 -13
- package/lib/providers/exploreState.d.ts +12 -4
- package/lib/providers/exploreState.js +30 -4
- package/lib/views/ExploreView/exploreView.js +14 -8
- package/package.json +1 -1
- package/src/components/Filter/components/FilterLabel/filterLabel.styles.ts +1 -2
- package/src/components/Filter/components/Filters/filters.styles.ts +19 -1
- package/src/components/Filter/components/Filters/filters.tsx +23 -4
- package/src/components/Filter/components/VariableSizeListItem/variableSizeListItem.tsx +6 -3
- package/src/config/entities.ts +11 -1
- package/src/providers/exploreState/constants.ts +3 -0
- package/src/providers/exploreState/entities.ts +20 -2
- package/src/providers/exploreState/initializer/constants.ts +2 -0
- package/src/providers/exploreState/initializer/utils.ts +73 -2
- package/src/providers/exploreState/payloads/entities.ts +9 -0
- package/src/providers/exploreState/utils.ts +104 -20
- package/src/providers/exploreState.tsx +67 -10
- package/src/views/ExploreView/exploreView.tsx +16 -8
|
@@ -8,7 +8,7 @@ const styled_1 = __importDefault(require("@emotion/styled"));
|
|
|
8
8
|
const material_1 = require("@mui/material");
|
|
9
9
|
const breakpoints_1 = require("../../../../styles/common/mixins/breakpoints");
|
|
10
10
|
exports.FilterLabel = (0, styled_1.default)(material_1.Button) `
|
|
11
|
-
|
|
11
|
+
font-weight: inherit;
|
|
12
12
|
gap: 0;
|
|
13
13
|
justify-content: space-between;
|
|
14
14
|
padding: 10px 16px;
|
|
@@ -20,7 +20,6 @@ exports.FilterLabel = (0, styled_1.default)(material_1.Button) `
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
&.Mui-disabled {
|
|
23
|
-
color: ${({ theme }) => theme.palette.ink.main};
|
|
24
23
|
opacity: 0.3;
|
|
25
24
|
}
|
|
26
25
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { TrackFilterOpenedFunction } from "config/entities";
|
|
3
2
|
import { SelectCategoryView } from "../../../../common/entities";
|
|
3
|
+
import { TrackFilterOpenedFunction } from "../../../../config/entities";
|
|
4
4
|
import { OnFilterFn } from "../../../../hooks/useCategoryFilter";
|
|
5
5
|
export interface CategoryFilter {
|
|
6
6
|
categoryViews: SelectCategoryView[];
|
|
@@ -65,11 +65,13 @@ const Filters = ({ categoryFilters, closeAncestor, disabled = false, onFilter, t
|
|
|
65
65
|
const { height: windowHeight } = (0, useWindowResize_1.useWindowResize)();
|
|
66
66
|
const filterListRef = (0, react_1.useRef)(null);
|
|
67
67
|
const [height, setHeight] = (0, react_1.useState)(0);
|
|
68
|
+
const isLabeled = (0, react_1.useMemo)(() => isCategoryViewsLabeled(categoryFilters), [categoryFilters]);
|
|
68
69
|
(0, react_1.useEffect)(() => {
|
|
69
70
|
setHeight(calculateListHeight(windowHeight, filterListRef.current));
|
|
70
71
|
}, [windowHeight]);
|
|
71
|
-
return (react_1.default.createElement(filters_styles_1.Filters, { disabled: disabled, height: height, ref: filterListRef }, categoryFilters.map(({ categoryViews, label }, i) => (react_1.default.createElement(react_1.Fragment, { key: i },
|
|
72
|
+
return (react_1.default.createElement(filters_styles_1.Filters, { disabled: disabled, height: height, isBaseStyle: !isLabeled, ref: filterListRef }, categoryFilters.map(({ categoryViews, label }, i) => (react_1.default.createElement(react_1.Fragment, { key: i },
|
|
72
73
|
i !== 0 && react_1.default.createElement(material_1.Divider, null),
|
|
74
|
+
label && react_1.default.createElement(filters_styles_1.CategoryViewsLabel, null, label),
|
|
73
75
|
categoryViews.map((categoryView) => (react_1.default.createElement(filter_1.Filter, { key: categoryView.key, categorySection: label, categoryView: categoryView, closeAncestor: closeAncestor, isFilterDrawer: isFilterDrawer, onFilter: onFilter, trackFilterOpened: trackFilterOpened, tags: renderFilterTags(categoryView, onFilter) }))))))));
|
|
74
76
|
};
|
|
75
77
|
exports.Filters = Filters;
|
|
@@ -83,3 +85,11 @@ function calculateListHeight(windowHeight, filterListEl) {
|
|
|
83
85
|
var _a, _b;
|
|
84
86
|
return windowHeight - ((_b = (_a = filterListEl === null || filterListEl === void 0 ? void 0 : filterListEl.getBoundingClientRect()) === null || _a === void 0 ? void 0 : _a.top) !== null && _b !== void 0 ? _b : 0);
|
|
85
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Returns true if any category views are labelled.
|
|
90
|
+
* @param categoryFilters - Category filters.
|
|
91
|
+
* @returns true if any category views are labelled.
|
|
92
|
+
*/
|
|
93
|
+
function isCategoryViewsLabeled(categoryFilters) {
|
|
94
|
+
return categoryFilters.some(({ label }) => label);
|
|
95
|
+
}
|
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
interface Props {
|
|
3
3
|
disabled: boolean;
|
|
4
4
|
height: number;
|
|
5
|
+
isBaseStyle: boolean;
|
|
5
6
|
}
|
|
6
7
|
export declare const Filters: import("@emotion/styled").StyledComponent<{
|
|
7
8
|
theme?: import("@emotion/react").Theme | undefined;
|
|
8
9
|
as?: import("react").ElementType<any> | undefined;
|
|
9
10
|
} & Props, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
11
|
+
export declare const CategoryViewsLabel: import("@emotion/styled").StyledComponent<{
|
|
12
|
+
theme?: import("@emotion/react").Theme | undefined;
|
|
13
|
+
as?: import("react").ElementType<any> | undefined;
|
|
14
|
+
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
10
15
|
export {};
|
|
@@ -3,13 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Filters = void 0;
|
|
6
|
+
exports.CategoryViewsLabel = exports.Filters = void 0;
|
|
7
7
|
const react_1 = require("@emotion/react");
|
|
8
8
|
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
9
9
|
const breakpoints_1 = require("../../../../styles/common/mixins/breakpoints");
|
|
10
|
+
const colors_1 = require("../../../../styles/common/mixins/colors");
|
|
11
|
+
const fonts_1 = require("../../../../styles/common/mixins/fonts");
|
|
10
12
|
exports.Filters = (0, styled_1.default)("div", {
|
|
11
|
-
shouldForwardProp: (prop) => prop !== "height",
|
|
13
|
+
shouldForwardProp: (prop) => prop !== "height" && prop !== "isBaseStyle",
|
|
12
14
|
}) `
|
|
15
|
+
${(props) => (props.isBaseStyle ? (0, fonts_1.textBody500)(props) : (0, fonts_1.textBody400)(props))};
|
|
16
|
+
color: ${(props) => (props.isBaseStyle ? (0, colors_1.inkMain)(props) : (0, colors_1.inkLight)(props))};
|
|
13
17
|
height: ${({ height }) => height}px;
|
|
14
18
|
margin: 8px 0;
|
|
15
19
|
overflow: auto;
|
|
@@ -31,3 +35,12 @@ exports.Filters = (0, styled_1.default)("div", {
|
|
|
31
35
|
padding: 0 12px 0 16px;
|
|
32
36
|
}
|
|
33
37
|
`;
|
|
38
|
+
exports.CategoryViewsLabel = (0, styled_1.default)("div") `
|
|
39
|
+
${fonts_1.textBody500};
|
|
40
|
+
color: ${colors_1.inkMain};
|
|
41
|
+
padding: 8px 16px;
|
|
42
|
+
|
|
43
|
+
${breakpoints_1.mediaDesktopSmallUp} {
|
|
44
|
+
padding: 8px 0;
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
@@ -25,6 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
const material_1 = require("@mui/material");
|
|
27
27
|
const react_1 = __importStar(require("react"));
|
|
28
|
+
const constants_1 = require("../../../../providers/exploreState/constants");
|
|
28
29
|
const typography_1 = require("../../../../theme/common/typography");
|
|
29
30
|
const checkedIcon_1 = require("../../../common/CustomIcon/components/CheckedIcon/checkedIcon");
|
|
30
31
|
const uncheckedIcon_1 = require("../../../common/CustomIcon/components/UncheckedIcon/uncheckedIcon");
|
|
@@ -43,6 +44,6 @@ function VariableSizeListItem({ categoryKey, categorySection, matchedItem, onFil
|
|
|
43
44
|
};
|
|
44
45
|
return (react_1.default.createElement(material_1.ListItemButton, { ref: listItemRef, onClick: handleItemClicked, selected: selected, style: style },
|
|
45
46
|
react_1.default.createElement(material_1.Checkbox, { checked: selected, checkedIcon: react_1.default.createElement(checkedIcon_1.CheckedIcon, null), icon: react_1.default.createElement(uncheckedIcon_1.UncheckedIcon, null) }),
|
|
46
|
-
react_1.default.createElement(material_1.ListItemText, { disableTypography: true, primary: react_1.default.createElement(highlightedLabel_1.HighlightedLabel, { label: label, ranges: labelRanges }), secondary: react_1.default.createElement(material_1.Typography, { color: "ink.light", variant: typography_1.TEXT_BODY_SMALL_400 }, count) })));
|
|
47
|
+
react_1.default.createElement(material_1.ListItemText, { disableTypography: true, primary: react_1.default.createElement(highlightedLabel_1.HighlightedLabel, { label: label, ranges: labelRanges }), secondary: categoryKey !== constants_1.SELECT_CATEGORY_KEY.SAVED_FILTERS && (react_1.default.createElement(material_1.Typography, { color: "ink.light", variant: typography_1.TEXT_BODY_SMALL_400 }, count)) })));
|
|
47
48
|
}
|
|
48
49
|
exports.default = VariableSizeListItem;
|
package/lib/config/entities.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TabProps as MTabProps, Theme, ThemeOptions } from "@mui/material";
|
|
2
2
|
import { ColumnSort } from "@tanstack/react-table";
|
|
3
3
|
import { JSXElementConstructor, ReactNode } from "react";
|
|
4
|
-
import { CategoryKey, SelectedFilterValue } from "../common/entities";
|
|
4
|
+
import { CategoryKey, SelectedFilter, SelectedFilterValue } from "../common/entities";
|
|
5
5
|
import { HeroTitle } from "../components/common/Title/title";
|
|
6
6
|
import { FooterProps } from "../components/Layout/components/Footer/footer";
|
|
7
7
|
import { HeaderProps } from "../components/Layout/components/Header/header";
|
|
@@ -51,6 +51,7 @@ export interface BackPageTabConfig extends TabConfig {
|
|
|
51
51
|
export interface CategoryGroupConfig {
|
|
52
52
|
categoryGroups: CategoryGroup[];
|
|
53
53
|
key: string;
|
|
54
|
+
savedFilters?: SavedFilter[];
|
|
54
55
|
}
|
|
55
56
|
/**
|
|
56
57
|
* Model of grouped configured categories in site config.
|
|
@@ -244,6 +245,11 @@ export interface Override {
|
|
|
244
245
|
* Related search function.
|
|
245
246
|
*/
|
|
246
247
|
declare type RelatedSearchFunction = (searchKey: CategoryKey | undefined, resultKey: CategoryKey | undefined, selectedCategoryValues: SelectedFilterValue | undefined) => Promise<RelatedSearchResult | undefined>;
|
|
248
|
+
export interface SavedFilter {
|
|
249
|
+
filters: SelectedFilter[];
|
|
250
|
+
sort?: ColumnSort;
|
|
251
|
+
title: string;
|
|
252
|
+
}
|
|
247
253
|
/**
|
|
248
254
|
* Filter applied tracking payload
|
|
249
255
|
*/
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export declare const SELECT_CATEGORY_KEY: {
|
|
2
|
+
SAVED_FILTERS: string;
|
|
3
|
+
};
|
|
@@ -1,29 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
currentPage: 1,
|
|
7
|
-
index: null,
|
|
8
|
-
nextIndex: null,
|
|
9
|
-
pageSize: 25,
|
|
10
|
-
pages: 1,
|
|
11
|
-
previousIndex: null,
|
|
12
|
-
rows: 0,
|
|
13
|
-
};
|
|
14
|
-
// Initial state
|
|
15
|
-
exports.INITIAL_STATE = {
|
|
16
|
-
catalogState: undefined,
|
|
17
|
-
categoryViews: [],
|
|
18
|
-
entityPageState: {},
|
|
19
|
-
featureFlagState: undefined,
|
|
20
|
-
filterCount: 0,
|
|
21
|
-
filterState: [],
|
|
22
|
-
isRelatedView: false,
|
|
23
|
-
listItems: [],
|
|
24
|
-
listView: undefined,
|
|
25
|
-
loading: true,
|
|
26
|
-
paginationState: exports.DEFAULT_PAGINATION_STATE,
|
|
27
|
-
relatedListItems: undefined,
|
|
28
|
-
tabValue: "",
|
|
3
|
+
exports.SELECT_CATEGORY_KEY = void 0;
|
|
4
|
+
exports.SELECT_CATEGORY_KEY = {
|
|
5
|
+
SAVED_FILTERS: "savedFilters",
|
|
29
6
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ColumnSort } from "@tanstack/react-table";
|
|
2
|
-
import { SelectCategory, SelectedFilter } from "../../common/entities";
|
|
3
|
-
import { CategoryConfig, CategoryGroup, CategoryGroupConfig, EntityPath } from "../../config/entities";
|
|
2
|
+
import { CategoryValueKey, SelectCategory, SelectCategoryView, SelectedFilter } from "../../common/entities";
|
|
3
|
+
import { CategoryConfig, CategoryGroup, CategoryGroupConfig, EntityPath, SavedFilter } from "../../config/entities";
|
|
4
4
|
export interface EntityPageState {
|
|
5
5
|
categoryGroupConfigKey: CategoryGroupConfigKey;
|
|
6
6
|
columnsVisibility: Record<string, boolean>;
|
|
@@ -12,8 +12,15 @@ export interface EntityPageStateMapper {
|
|
|
12
12
|
export interface EntityState {
|
|
13
13
|
categoryConfigs?: CategoryConfig[];
|
|
14
14
|
categoryGroups?: CategoryGroup[];
|
|
15
|
-
categoryViews:
|
|
15
|
+
categoryViews: SelectCategoryView[];
|
|
16
16
|
filterState: SelectedFilter[];
|
|
17
|
+
savedFilterByCategoryValueKey?: SavedFilterByCategoryValueKey;
|
|
18
|
+
savedFilterState: SelectedFilter[];
|
|
19
|
+
savedSelectCategories: SelectCategory[];
|
|
17
20
|
}
|
|
18
21
|
export declare type EntityStateByCategoryGroupConfigKey = Map<CategoryGroupConfigKey, EntityState>;
|
|
19
22
|
export declare type CategoryGroupConfigKey = CategoryGroupConfig["key"];
|
|
23
|
+
export interface EntityStateSavedFilter extends Omit<SavedFilter, "sort"> {
|
|
24
|
+
sorting?: ColumnSort[];
|
|
25
|
+
}
|
|
26
|
+
export declare type SavedFilterByCategoryValueKey = Map<CategoryValueKey, EntityStateSavedFilter>;
|
|
@@ -4,6 +4,8 @@ exports.INITIAL_STATE = exports.DEFAULT_PAGINATION_STATE = exports.DEFAULT_ENTIT
|
|
|
4
4
|
exports.DEFAULT_ENTITY_STATE = {
|
|
5
5
|
categoryViews: [],
|
|
6
6
|
filterState: [],
|
|
7
|
+
savedFilterState: [],
|
|
8
|
+
savedSelectCategories: [],
|
|
7
9
|
};
|
|
8
10
|
exports.DEFAULT_PAGINATION_STATE = {
|
|
9
11
|
currentPage: 1,
|
|
@@ -3,8 +3,63 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.initReducerArguments = void 0;
|
|
4
4
|
const utils_1 = require("../../../components/Table/common/utils");
|
|
5
5
|
const utils_2 = require("../../../config/utils");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
6
7
|
const utils_3 = require("../utils");
|
|
7
|
-
const
|
|
8
|
+
const constants_2 = require("./constants");
|
|
9
|
+
/**
|
|
10
|
+
* Builds category groups from the given category group config (adds the saved filters category to the category groups).
|
|
11
|
+
* @param categoryGroupConfig - Category group config.
|
|
12
|
+
* @returns category groups with saved filters category.
|
|
13
|
+
*/
|
|
14
|
+
function buildCategoryGroups(categoryGroupConfig) {
|
|
15
|
+
const { categoryGroups, savedFilters } = categoryGroupConfig;
|
|
16
|
+
if (!savedFilters)
|
|
17
|
+
return categoryGroups;
|
|
18
|
+
const clonedCategoryGroups = [...categoryGroups];
|
|
19
|
+
const savedFiltersCategoryGroup = {
|
|
20
|
+
categoryConfigs: [
|
|
21
|
+
{ key: constants_1.SELECT_CATEGORY_KEY.SAVED_FILTERS, label: "Saved Filters" },
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
clonedCategoryGroups.unshift(savedFiltersCategoryGroup);
|
|
25
|
+
return clonedCategoryGroups;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Returns the saved filters as select categories.
|
|
29
|
+
* @param savedFilters - Saved filters.
|
|
30
|
+
* @returns select categories.
|
|
31
|
+
*/
|
|
32
|
+
function buildSavedSelectCategories(savedFilters) {
|
|
33
|
+
if (!savedFilters)
|
|
34
|
+
return [];
|
|
35
|
+
return [
|
|
36
|
+
{
|
|
37
|
+
key: constants_1.SELECT_CATEGORY_KEY.SAVED_FILTERS,
|
|
38
|
+
label: "",
|
|
39
|
+
values: savedFilters.map(({ title }) => ({
|
|
40
|
+
count: 1,
|
|
41
|
+
key: title,
|
|
42
|
+
label: title,
|
|
43
|
+
selected: false, // Selected state updated in filter hook.
|
|
44
|
+
})),
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Builds saved filter by category value key.
|
|
50
|
+
* @param savedFilters - Saved filters.
|
|
51
|
+
* @returns saved filter by category value key.
|
|
52
|
+
*/
|
|
53
|
+
function buildSavedFilterByCategoryValueKey(savedFilters) {
|
|
54
|
+
if (!savedFilters)
|
|
55
|
+
return;
|
|
56
|
+
const savedFilterByCategoryValueKey = new Map();
|
|
57
|
+
for (const { filters, sort, title } of savedFilters) {
|
|
58
|
+
const sorting = sort ? [sort] : undefined;
|
|
59
|
+
savedFilterByCategoryValueKey.set(title, { filters, sorting, title });
|
|
60
|
+
}
|
|
61
|
+
return savedFilterByCategoryValueKey;
|
|
62
|
+
}
|
|
8
63
|
/**
|
|
9
64
|
* Returns entity related configured category group config where entity config takes precedence over site config.
|
|
10
65
|
* @param siteConfig - Site config.
|
|
@@ -71,10 +126,14 @@ function initEntityStateByCategoryGroupConfigKey(config, categoryGroupConfigKey,
|
|
|
71
126
|
const categoryGroupConfig = getEntityCategoryGroupConfig(config, entity);
|
|
72
127
|
if (!categoryGroupConfig)
|
|
73
128
|
continue;
|
|
74
|
-
const {
|
|
129
|
+
const { key, savedFilters } = categoryGroupConfig;
|
|
75
130
|
if (entityStateByCategoryGroupConfigKey.has(key))
|
|
76
131
|
continue;
|
|
77
|
-
|
|
132
|
+
const categoryGroups = buildCategoryGroups(categoryGroupConfig);
|
|
133
|
+
const savedSelectCategories = buildSavedSelectCategories(savedFilters);
|
|
134
|
+
const savedFilterByCategoryValueKey = buildSavedFilterByCategoryValueKey(savedFilters);
|
|
135
|
+
entityStateByCategoryGroupConfigKey.set(key, Object.assign(Object.assign({}, constants_2.DEFAULT_ENTITY_STATE), { categoryConfigs: flattenCategoryGroups(categoryGroups), categoryGroups, filterState: key === categoryGroupConfigKey ? filterState : [], savedFilterByCategoryValueKey,
|
|
136
|
+
savedSelectCategories }));
|
|
78
137
|
}
|
|
79
138
|
return entityStateByCategoryGroupConfigKey;
|
|
80
139
|
}
|
|
@@ -109,7 +168,7 @@ function initReducerArguments(config, entityListType, decodedFilterParam, decode
|
|
|
109
168
|
const categoryGroupConfigKey = (0, utils_3.getEntityCategoryGroupConfigKey)(entityListType, entityPageState);
|
|
110
169
|
const entityStateByCategoryGroupConfigKey = initEntityStateByCategoryGroupConfigKey(config, categoryGroupConfigKey, filterState);
|
|
111
170
|
const categoryGroups = initCategoryGroups(entityStateByCategoryGroupConfigKey, categoryGroupConfigKey);
|
|
112
|
-
return Object.assign(Object.assign({},
|
|
171
|
+
return Object.assign(Object.assign({}, constants_2.INITIAL_STATE), { catalogState: decodedCatalogParam, categoryGroups,
|
|
113
172
|
entityPageState,
|
|
114
173
|
entityStateByCategoryGroupConfigKey, featureFlagState: decodedFeatureFlagParam, filterCount: (0, utils_3.getFilterCount)(filterState), filterState, tabValue: entityListType });
|
|
115
174
|
}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { ColumnSort } from "@tanstack/react-table";
|
|
2
2
|
import { CategoryKey, CategoryValueKey, PaginationDirectionType, SelectCategory } from "../../../common/entities";
|
|
3
3
|
import { ENTITY_VIEW, ListItems, PaginationResponse, RelatedListItems } from "../../exploreState";
|
|
4
|
+
/**
|
|
5
|
+
* Apply saved filter payload.
|
|
6
|
+
*/
|
|
7
|
+
export interface ApplySavedFilterPayload {
|
|
8
|
+
categoryKey: CategoryKey;
|
|
9
|
+
selected: boolean;
|
|
10
|
+
selectedValue: CategoryValueKey;
|
|
11
|
+
}
|
|
4
12
|
/**
|
|
5
13
|
* Process explore response payload.
|
|
6
14
|
*/
|
|
@@ -1,7 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ColumnSort } from "@tanstack/react-table";
|
|
2
|
+
import { CategoryKey, CategoryValueKey, SelectedFilter } from "../../common/entities";
|
|
3
3
|
import { ExploreState, PaginationState } from "../exploreState";
|
|
4
|
-
import { CategoryGroupConfigKey, EntityPageState, EntityPageStateMapper, EntityState } from "./entities";
|
|
4
|
+
import { CategoryGroupConfigKey, EntityPageState, EntityPageStateMapper, EntityState, EntityStateSavedFilter } from "./entities";
|
|
5
|
+
/**
|
|
6
|
+
* Returns the entity state saved filter state for the given category key.
|
|
7
|
+
* @param categoryKey - Category key.
|
|
8
|
+
* @param selectedValue - Key of category value that has been de/selected.
|
|
9
|
+
* @param selected - True if value is selected, false if de-selected.
|
|
10
|
+
* @returns entity state saved filter state.
|
|
11
|
+
*/
|
|
12
|
+
export declare function buildEntityStateSavedFilterState(categoryKey: CategoryKey, selectedValue: CategoryValueKey, selected: boolean): SelectedFilter[];
|
|
13
|
+
/**
|
|
14
|
+
* Build new set of selected filters on de/select of a "saved filter" filter.
|
|
15
|
+
* @param state - Explore state.
|
|
16
|
+
* @param selectedValue - Key of category value that has been de/selected.
|
|
17
|
+
* @param selected - True if value is selected, false if de-selected.
|
|
18
|
+
* @returns new selected filters.
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildNextSavedFilterState(state: ExploreState, selectedValue: CategoryValueKey, selected: boolean): SelectedFilter[];
|
|
5
21
|
/**
|
|
6
22
|
* Returns the category group config key for the current entity.
|
|
7
23
|
* @param entityPath - Entity path.
|
|
@@ -10,18 +26,27 @@ import { CategoryGroupConfigKey, EntityPageState, EntityPageStateMapper, EntityS
|
|
|
10
26
|
*/
|
|
11
27
|
export declare function getEntityCategoryGroupConfigKey(entityPath: string, entityPageState: EntityPageStateMapper): CategoryGroupConfigKey;
|
|
12
28
|
/**
|
|
13
|
-
* Returns the
|
|
29
|
+
* Returns the entity state for the current entity.
|
|
14
30
|
* @param state - Explore state.
|
|
15
|
-
* @
|
|
31
|
+
* @param categoryGroupConfigKey - Category group config key.
|
|
32
|
+
* @returns entity state.
|
|
16
33
|
*/
|
|
17
|
-
export declare function
|
|
34
|
+
export declare function getEntityState(state: ExploreState, categoryGroupConfigKey?: string): EntityState;
|
|
18
35
|
/**
|
|
19
|
-
* Returns the
|
|
20
|
-
* @param categoryGroupConfigKey - Category group config key.
|
|
36
|
+
* Returns the saved filter/sorting for the given category key.
|
|
21
37
|
* @param state - Explore state.
|
|
22
|
-
* @
|
|
38
|
+
* @param categoryValueKey - Category key.
|
|
39
|
+
* @returns saved filter/sorting for the category key.
|
|
40
|
+
*/
|
|
41
|
+
export declare function getEntityStateSavedFilter(state: ExploreState, categoryValueKey: CategoryValueKey): EntityStateSavedFilter | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Returns entity state "saved filter" sorting for the given category value key.
|
|
44
|
+
* @param state - Explore state.
|
|
45
|
+
* @param selectedValue - Key of category value that has been de/selected.
|
|
46
|
+
* @param selected - True if value is selected, false if de-selected.
|
|
47
|
+
* @returns sorting.
|
|
23
48
|
*/
|
|
24
|
-
export declare function
|
|
49
|
+
export declare function getEntityStateSavedSorting(state: ExploreState, selectedValue: CategoryValueKey, selected: boolean): ColumnSort[] | undefined;
|
|
25
50
|
/**
|
|
26
51
|
* Returns the filter count.
|
|
27
52
|
* @param filterState - Filter state.
|
|
@@ -43,6 +68,13 @@ export declare function resetPage(paginationState: PaginationState): PaginationS
|
|
|
43
68
|
*/
|
|
44
69
|
export declare function updateEntityPageState(entityPath: string, // entityListType.
|
|
45
70
|
entityPageState: EntityPageStateMapper, nextEntityPageState: Partial<EntityPageState>): EntityPageStateMapper;
|
|
71
|
+
/**
|
|
72
|
+
* Updates entity page state sorting for all entities with the same category group config key.
|
|
73
|
+
* @param state - Explore state.
|
|
74
|
+
* @param sorting - Sorting.
|
|
75
|
+
* @returns entity page state.
|
|
76
|
+
*/
|
|
77
|
+
export declare function updateEntityPageStateSorting(state: ExploreState, sorting?: EntityPageState["sorting"]): EntityPageStateMapper;
|
|
46
78
|
/**
|
|
47
79
|
* Updates entity state by category group config key.
|
|
48
80
|
* @param state - Explore state.
|
|
@@ -1,7 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateEntityStateByCategoryGroupConfigKey = exports.updateEntityPageState = exports.resetPage = exports.getFilterCount = exports.
|
|
3
|
+
exports.updateEntityStateByCategoryGroupConfigKey = exports.updateEntityPageStateSorting = exports.updateEntityPageState = exports.resetPage = exports.getFilterCount = exports.getEntityStateSavedSorting = exports.getEntityStateSavedFilter = exports.getEntityState = exports.getEntityCategoryGroupConfigKey = exports.buildNextSavedFilterState = exports.buildEntityStateSavedFilterState = void 0;
|
|
4
4
|
const constants_1 = require("./initializer/constants");
|
|
5
|
+
/**
|
|
6
|
+
* Returns the entity state saved filter state for the given category key.
|
|
7
|
+
* @param categoryKey - Category key.
|
|
8
|
+
* @param selectedValue - Key of category value that has been de/selected.
|
|
9
|
+
* @param selected - True if value is selected, false if de-selected.
|
|
10
|
+
* @returns entity state saved filter state.
|
|
11
|
+
*/
|
|
12
|
+
function buildEntityStateSavedFilterState(categoryKey, selectedValue, selected) {
|
|
13
|
+
if (!selected)
|
|
14
|
+
return [];
|
|
15
|
+
return [{ categoryKey, value: [selectedValue] }];
|
|
16
|
+
}
|
|
17
|
+
exports.buildEntityStateSavedFilterState = buildEntityStateSavedFilterState;
|
|
18
|
+
/**
|
|
19
|
+
* Build new set of selected filters on de/select of a "saved filter" filter.
|
|
20
|
+
* @param state - Explore state.
|
|
21
|
+
* @param selectedValue - Key of category value that has been de/selected.
|
|
22
|
+
* @param selected - True if value is selected, false if de-selected.
|
|
23
|
+
* @returns new selected filters.
|
|
24
|
+
*/
|
|
25
|
+
function buildNextSavedFilterState(state, selectedValue, selected) {
|
|
26
|
+
if (!selected)
|
|
27
|
+
return []; // Clears all filters on de-select of saved filter.
|
|
28
|
+
const savedFilter = getEntityStateSavedFilter(state, selectedValue);
|
|
29
|
+
return (savedFilter === null || savedFilter === void 0 ? void 0 : savedFilter.filters) || [];
|
|
30
|
+
}
|
|
31
|
+
exports.buildNextSavedFilterState = buildNextSavedFilterState;
|
|
5
32
|
/**
|
|
6
33
|
* Returns the category group config key for the current entity.
|
|
7
34
|
* @param entityPath - Entity path.
|
|
@@ -13,25 +40,42 @@ function getEntityCategoryGroupConfigKey(entityPath, entityPageState) {
|
|
|
13
40
|
}
|
|
14
41
|
exports.getEntityCategoryGroupConfigKey = getEntityCategoryGroupConfigKey;
|
|
15
42
|
/**
|
|
16
|
-
* Returns the
|
|
43
|
+
* Returns the entity state for the current entity.
|
|
17
44
|
* @param state - Explore state.
|
|
18
|
-
* @returns category configs.
|
|
19
|
-
*/
|
|
20
|
-
function getEntityCategoryConfigs(state) {
|
|
21
|
-
return getEntityState(getEntityCategoryGroupConfigKey(state.tabValue, state.entityPageState), state).categoryConfigs;
|
|
22
|
-
}
|
|
23
|
-
exports.getEntityCategoryConfigs = getEntityCategoryConfigs;
|
|
24
|
-
/**
|
|
25
|
-
* Returns the entity state for the given category group config key.
|
|
26
45
|
* @param categoryGroupConfigKey - Category group config key.
|
|
27
|
-
* @param state - Explore state.
|
|
28
46
|
* @returns entity state.
|
|
29
47
|
*/
|
|
30
|
-
function getEntityState(categoryGroupConfigKey, state) {
|
|
48
|
+
function getEntityState(state, categoryGroupConfigKey = getEntityCategoryGroupConfigKey(state.tabValue, state.entityPageState)) {
|
|
31
49
|
return (state.entityStateByCategoryGroupConfigKey.get(categoryGroupConfigKey) ||
|
|
32
50
|
constants_1.DEFAULT_ENTITY_STATE);
|
|
33
51
|
}
|
|
34
52
|
exports.getEntityState = getEntityState;
|
|
53
|
+
/**
|
|
54
|
+
* Returns the saved filter/sorting for the given category key.
|
|
55
|
+
* @param state - Explore state.
|
|
56
|
+
* @param categoryValueKey - Category key.
|
|
57
|
+
* @returns saved filter/sorting for the category key.
|
|
58
|
+
*/
|
|
59
|
+
function getEntityStateSavedFilter(state, categoryValueKey) {
|
|
60
|
+
var _a;
|
|
61
|
+
const entityState = getEntityState(state);
|
|
62
|
+
return (_a = entityState.savedFilterByCategoryValueKey) === null || _a === void 0 ? void 0 : _a.get(categoryValueKey);
|
|
63
|
+
}
|
|
64
|
+
exports.getEntityStateSavedFilter = getEntityStateSavedFilter;
|
|
65
|
+
/**
|
|
66
|
+
* Returns entity state "saved filter" sorting for the given category value key.
|
|
67
|
+
* @param state - Explore state.
|
|
68
|
+
* @param selectedValue - Key of category value that has been de/selected.
|
|
69
|
+
* @param selected - True if value is selected, false if de-selected.
|
|
70
|
+
* @returns sorting.
|
|
71
|
+
*/
|
|
72
|
+
function getEntityStateSavedSorting(state, selectedValue, selected) {
|
|
73
|
+
if (!selected)
|
|
74
|
+
return;
|
|
75
|
+
const savedFilter = getEntityStateSavedFilter(state, selectedValue);
|
|
76
|
+
return savedFilter === null || savedFilter === void 0 ? void 0 : savedFilter.sorting;
|
|
77
|
+
}
|
|
78
|
+
exports.getEntityStateSavedSorting = getEntityStateSavedSorting;
|
|
35
79
|
/**
|
|
36
80
|
* Returns the filter count.
|
|
37
81
|
* @param filterState - Filter state.
|
|
@@ -74,6 +118,24 @@ entityPageState, nextEntityPageState) {
|
|
|
74
118
|
return Object.assign(Object.assign({}, entityPageState), { [entityPath]: Object.assign(Object.assign({}, entityPageState[entityPath]), nextEntityPageState) });
|
|
75
119
|
}
|
|
76
120
|
exports.updateEntityPageState = updateEntityPageState;
|
|
121
|
+
/**
|
|
122
|
+
* Updates entity page state sorting for all entities with the same category group config key.
|
|
123
|
+
* @param state - Explore state.
|
|
124
|
+
* @param sorting - Sorting.
|
|
125
|
+
* @returns entity page state.
|
|
126
|
+
*/
|
|
127
|
+
function updateEntityPageStateSorting(state, sorting) {
|
|
128
|
+
if (!sorting)
|
|
129
|
+
return state.entityPageState;
|
|
130
|
+
const categoryGroupConfigKey = getEntityCategoryGroupConfigKey(state.tabValue, state.entityPageState);
|
|
131
|
+
return Object.entries(state.entityPageState).reduce((acc, [entityPath, entityPageState]) => {
|
|
132
|
+
if (entityPageState.categoryGroupConfigKey === categoryGroupConfigKey) {
|
|
133
|
+
return Object.assign(Object.assign({}, acc), { [entityPath]: Object.assign(Object.assign({}, entityPageState), { sorting }) });
|
|
134
|
+
}
|
|
135
|
+
return Object.assign(Object.assign({}, acc), { [entityPath]: entityPageState });
|
|
136
|
+
}, {});
|
|
137
|
+
}
|
|
138
|
+
exports.updateEntityPageStateSorting = updateEntityPageStateSorting;
|
|
77
139
|
/**
|
|
78
140
|
* Updates entity state by category group config key.
|
|
79
141
|
* @param state - Explore state.
|
|
@@ -82,7 +144,7 @@ exports.updateEntityPageState = updateEntityPageState;
|
|
|
82
144
|
*/
|
|
83
145
|
function updateEntityStateByCategoryGroupConfigKey(state, nextEntityState) {
|
|
84
146
|
const categoryGroupConfigKey = getEntityCategoryGroupConfigKey(state.tabValue, state.entityPageState);
|
|
85
|
-
const entityState = getEntityState(
|
|
147
|
+
const entityState = getEntityState(state, categoryGroupConfigKey);
|
|
86
148
|
if (entityState) {
|
|
87
149
|
setEntityStateByCategoryGroupConfigKey(categoryGroupConfigKey, state, Object.assign(Object.assign({}, entityState), nextEntityState));
|
|
88
150
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React, { Dispatch, ReactNode } from "react";
|
|
2
2
|
import { AzulSearchIndex } from "../apis/azul/common/entities";
|
|
3
|
-
import {
|
|
3
|
+
import { SelectCategoryView, SelectedFilter } from "../common/entities";
|
|
4
4
|
import { CategoryGroup, SiteConfig } from "../config/entities";
|
|
5
5
|
import { EntityPageStateMapper, EntityStateByCategoryGroupConfigKey } from "./exploreState/entities";
|
|
6
|
-
import { PaginateTablePayload, ProcessExploreResponsePayload, ProcessRelatedResponsePayload, ResetExploreResponsePayload, ToggleEntityViewPayload, UpdateColumnVisibilityPayload, UpdateFilterPayload, UpdateSortingPayload } from "./exploreState/payloads/entities";
|
|
6
|
+
import { ApplySavedFilterPayload, PaginateTablePayload, ProcessExploreResponsePayload, ProcessRelatedResponsePayload, ResetExploreResponsePayload, ToggleEntityViewPayload, UpdateColumnVisibilityPayload, UpdateFilterPayload, UpdateSortingPayload } from "./exploreState/payloads/entities";
|
|
7
7
|
export declare type CatalogState = string | undefined;
|
|
8
8
|
/**
|
|
9
9
|
* Entity view.
|
|
@@ -25,7 +25,7 @@ export interface ExploreContext {
|
|
|
25
25
|
export declare type ExploreState = {
|
|
26
26
|
catalogState: CatalogState;
|
|
27
27
|
categoryGroups?: CategoryGroup[];
|
|
28
|
-
categoryViews:
|
|
28
|
+
categoryViews: SelectCategoryView[];
|
|
29
29
|
entityPageState: EntityPageStateMapper;
|
|
30
30
|
entityStateByCategoryGroupConfigKey: EntityStateByCategoryGroupConfigKey;
|
|
31
31
|
featureFlagState: FeatureFlagState;
|
|
@@ -103,6 +103,7 @@ export declare function ExploreStateProvider({ children, entityListType, }: {
|
|
|
103
103
|
* Explore action kind.
|
|
104
104
|
*/
|
|
105
105
|
export declare enum ExploreActionKind {
|
|
106
|
+
ApplySavedFilter = "APPLY_SAVED_FILTER",
|
|
106
107
|
ClearFilters = "CLEAR_FILTERS",
|
|
107
108
|
PaginateTable = "PAGINATE_TABLE",
|
|
108
109
|
ProcessExploreResponse = "PROCESS_EXPLORE_RESPONSE",
|
|
@@ -118,7 +119,14 @@ export declare enum ExploreActionKind {
|
|
|
118
119
|
/**
|
|
119
120
|
* Explore action.
|
|
120
121
|
*/
|
|
121
|
-
export declare type ExploreAction = ClearFiltersAction | PaginateTableAction | ProcessExploreResponseAction | ProcessRelatedResponseAction | ResetExploreResponseAction | ResetStateAction | SelectEntityTypeAction | ToggleEntityViewAction | UpdateColumnVisibilityAction | UpdateFilterAction | UpdateSortingAction;
|
|
122
|
+
export declare type ExploreAction = ApplySavedFilterAction | ClearFiltersAction | PaginateTableAction | ProcessExploreResponseAction | ProcessRelatedResponseAction | ResetExploreResponseAction | ResetStateAction | SelectEntityTypeAction | ToggleEntityViewAction | UpdateColumnVisibilityAction | UpdateFilterAction | UpdateSortingAction;
|
|
123
|
+
/**
|
|
124
|
+
* Apply saved filter action.
|
|
125
|
+
*/
|
|
126
|
+
declare type ApplySavedFilterAction = {
|
|
127
|
+
payload: ApplySavedFilterPayload;
|
|
128
|
+
type: ExploreActionKind.ApplySavedFilter;
|
|
129
|
+
};
|
|
122
130
|
/**
|
|
123
131
|
* Clear filters action.
|
|
124
132
|
*/
|