@databiosphere/findable-ui 2.0.0 → 2.1.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.js +11 -1
- package/lib/components/Filter/components/Filters/filters.styles.d.ts +5 -0
- package/lib/components/Filter/components/Filters/filters.styles.js +14 -1
- package/lib/components/Table/table.js +1 -1
- package/lib/components/common/AnchorLink/anchorLink.styles.js +1 -0
- package/lib/config/entities.d.ts +10 -3
- package/lib/hooks/useEntityList.js +1 -1
- package/lib/hooks/useSessionTimeout.js +9 -2
- package/lib/providers/exploreState/entities.d.ts +19 -0
- package/lib/providers/exploreState/entities.js +2 -0
- package/lib/providers/exploreState/initializer/constants.d.ts +5 -0
- package/lib/providers/exploreState/initializer/constants.js +32 -0
- package/lib/providers/exploreState/initializer/utils.d.ts +12 -0
- package/lib/providers/exploreState/initializer/utils.js +116 -0
- package/lib/providers/exploreState/utils.d.ts +37 -22
- package/lib/providers/exploreState/utils.js +64 -65
- package/lib/providers/exploreState.d.ts +4 -21
- package/lib/providers/exploreState.js +23 -22
- package/lib/views/ExploreView/exploreView.js +6 -6
- 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 +18 -0
- package/src/components/Filter/components/Filters/filters.tsx +22 -3
- package/src/components/Table/table.tsx +1 -1
- package/src/components/common/AnchorLink/anchorLink.styles.ts +1 -0
- package/src/config/entities.ts +11 -3
- package/src/hooks/useEntityList.ts +1 -1
- package/src/hooks/useSessionTimeout.ts +9 -3
- package/src/providers/exploreState/entities.ts +32 -0
- package/src/providers/exploreState/{constants.ts → initializer/constants.ts} +8 -3
- package/src/providers/exploreState/initializer/utils.ts +183 -0
- package/src/providers/exploreState/utils.ts +103 -92
- package/src/providers/exploreState.tsx +50 -81
- package/src/views/ExploreView/exploreView.tsx +8 -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
|
|
|
@@ -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
13
|
shouldForwardProp: (prop) => prop !== "height",
|
|
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
|
+
`;
|
|
@@ -34,7 +34,7 @@ const useExploreMode_1 = require("../../hooks/useExploreMode");
|
|
|
34
34
|
const useExploreState_1 = require("../../hooks/useExploreState");
|
|
35
35
|
const useScroll_1 = require("../../hooks/useScroll");
|
|
36
36
|
const exploreState_1 = require("../../providers/exploreState");
|
|
37
|
-
const constants_1 = require("../../providers/exploreState/constants");
|
|
37
|
+
const constants_1 = require("../../providers/exploreState/initializer/constants");
|
|
38
38
|
const breakpoints_1 = require("../../theme/common/breakpoints");
|
|
39
39
|
const paper_styles_1 = require("../common/Paper/paper.styles");
|
|
40
40
|
const noResults_1 = require("../NoResults/noResults");
|
package/lib/config/entities.d.ts
CHANGED
|
@@ -46,9 +46,16 @@ export interface BackPageTabConfig extends TabConfig {
|
|
|
46
46
|
sideColumn?: ComponentsConfig;
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
|
-
* Model of
|
|
49
|
+
* Model of category group config in site config.
|
|
50
50
|
*/
|
|
51
51
|
export interface CategoryGroupConfig {
|
|
52
|
+
categoryGroups: CategoryGroup[];
|
|
53
|
+
key: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Model of grouped configured categories in site config.
|
|
57
|
+
*/
|
|
58
|
+
export interface CategoryGroup {
|
|
52
59
|
categoryConfigs: CategoryConfig[];
|
|
53
60
|
label?: string;
|
|
54
61
|
}
|
|
@@ -115,7 +122,7 @@ export declare type EntityPath = string;
|
|
|
115
122
|
*/
|
|
116
123
|
export interface EntityConfig<T = any, I = any> extends TabConfig {
|
|
117
124
|
apiPath?: EntityPath;
|
|
118
|
-
|
|
125
|
+
categoryGroupConfig?: CategoryGroupConfig;
|
|
119
126
|
detail: BackPageConfig;
|
|
120
127
|
entityMapper?: EntityMapper<T, I>;
|
|
121
128
|
exploreMode: ExploreMode;
|
|
@@ -290,7 +297,7 @@ export interface SiteConfig {
|
|
|
290
297
|
appTitle: string;
|
|
291
298
|
authentication?: AuthenticationConfig;
|
|
292
299
|
browserURL: string;
|
|
293
|
-
|
|
300
|
+
categoryGroupConfig?: CategoryGroupConfig;
|
|
294
301
|
contentDir?: string;
|
|
295
302
|
contentThemeOptionsFn?: ThemeOptionsFn;
|
|
296
303
|
dataSource: DataSourceConfig;
|
|
@@ -5,7 +5,7 @@ const react_1 = require("react");
|
|
|
5
5
|
const filterTransformer_1 = require("../apis/azul/common/filterTransformer");
|
|
6
6
|
const utils_1 = require("../config/utils");
|
|
7
7
|
const exploreState_1 = require("../providers/exploreState");
|
|
8
|
-
const constants_1 = require("../providers/exploreState/constants");
|
|
8
|
+
const constants_1 = require("../providers/exploreState/initializer/constants");
|
|
9
9
|
const useAsync_1 = require("./useAsync");
|
|
10
10
|
const useAuthentication_1 = require("./useAuthentication/useAuthentication");
|
|
11
11
|
const useConfig_1 = require("./useConfig");
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.useSessionTimeout = exports.INACTIVITY_PARAM = void 0;
|
|
7
|
+
const router_1 = __importDefault(require("next/router"));
|
|
4
8
|
const react_1 = require("react");
|
|
9
|
+
const useConfig_1 = require("./useConfig");
|
|
5
10
|
const useLocation_1 = require("./useLocation");
|
|
6
11
|
exports.INACTIVITY_PARAM = "inactivityTimeout";
|
|
7
12
|
/**
|
|
@@ -9,14 +14,16 @@ exports.INACTIVITY_PARAM = "inactivityTimeout";
|
|
|
9
14
|
* @returns flag indicating if the session has timed out.
|
|
10
15
|
*/
|
|
11
16
|
const useSessionTimeout = () => {
|
|
17
|
+
const { config: { redirectRootToPath }, } = (0, useConfig_1.useConfig)();
|
|
12
18
|
const [isSessionTimeout, setIsSessionTimeout] = (0, react_1.useState)(false);
|
|
13
19
|
// Get the session timeout from URL parameters.
|
|
14
20
|
const { search } = (0, useLocation_1.useLocation)() || {};
|
|
15
21
|
const sessionTimeout = search === null || search === void 0 ? void 0 : search.get(exports.INACTIVITY_PARAM);
|
|
16
22
|
// Clears session timeout state.
|
|
17
|
-
const clearSessionTimeout = () => {
|
|
23
|
+
const clearSessionTimeout = (0, react_1.useCallback)(() => {
|
|
18
24
|
setIsSessionTimeout(false);
|
|
19
|
-
|
|
25
|
+
router_1.default.replace(redirectRootToPath);
|
|
26
|
+
}, [redirectRootToPath]);
|
|
20
27
|
(0, react_1.useEffect)(() => {
|
|
21
28
|
setIsSessionTimeout(sessionTimeout === "true");
|
|
22
29
|
}, [sessionTimeout]);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ColumnSort } from "@tanstack/react-table";
|
|
2
|
+
import { SelectCategory, SelectedFilter } from "../../common/entities";
|
|
3
|
+
import { CategoryConfig, CategoryGroup, CategoryGroupConfig, EntityPath } from "../../config/entities";
|
|
4
|
+
export interface EntityPageState {
|
|
5
|
+
categoryGroupConfigKey: CategoryGroupConfigKey;
|
|
6
|
+
columnsVisibility: Record<string, boolean>;
|
|
7
|
+
sorting: ColumnSort[];
|
|
8
|
+
}
|
|
9
|
+
export interface EntityPageStateMapper {
|
|
10
|
+
[key: EntityPath]: EntityPageState;
|
|
11
|
+
}
|
|
12
|
+
export interface EntityState {
|
|
13
|
+
categoryConfigs?: CategoryConfig[];
|
|
14
|
+
categoryGroups?: CategoryGroup[];
|
|
15
|
+
categoryViews: SelectCategory[];
|
|
16
|
+
filterState: SelectedFilter[];
|
|
17
|
+
}
|
|
18
|
+
export declare type EntityStateByCategoryGroupConfigKey = Map<CategoryGroupConfigKey, EntityState>;
|
|
19
|
+
export declare type CategoryGroupConfigKey = CategoryGroupConfig["key"];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ExploreState, PaginationState } from "../../exploreState";
|
|
2
|
+
import { EntityState } from "../entities";
|
|
3
|
+
export declare const DEFAULT_ENTITY_STATE: EntityState;
|
|
4
|
+
export declare const DEFAULT_PAGINATION_STATE: PaginationState;
|
|
5
|
+
export declare const INITIAL_STATE: ExploreState;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.INITIAL_STATE = exports.DEFAULT_PAGINATION_STATE = exports.DEFAULT_ENTITY_STATE = void 0;
|
|
4
|
+
exports.DEFAULT_ENTITY_STATE = {
|
|
5
|
+
categoryViews: [],
|
|
6
|
+
filterState: [],
|
|
7
|
+
};
|
|
8
|
+
exports.DEFAULT_PAGINATION_STATE = {
|
|
9
|
+
currentPage: 1,
|
|
10
|
+
index: null,
|
|
11
|
+
nextIndex: null,
|
|
12
|
+
pageSize: 25,
|
|
13
|
+
pages: 1,
|
|
14
|
+
previousIndex: null,
|
|
15
|
+
rows: 0,
|
|
16
|
+
};
|
|
17
|
+
exports.INITIAL_STATE = {
|
|
18
|
+
catalogState: undefined,
|
|
19
|
+
categoryViews: [],
|
|
20
|
+
entityPageState: {},
|
|
21
|
+
entityStateByCategoryGroupConfigKey: new Map(),
|
|
22
|
+
featureFlagState: undefined,
|
|
23
|
+
filterCount: 0,
|
|
24
|
+
filterState: [],
|
|
25
|
+
isRelatedView: false,
|
|
26
|
+
listItems: [],
|
|
27
|
+
listView: undefined,
|
|
28
|
+
loading: true,
|
|
29
|
+
paginationState: exports.DEFAULT_PAGINATION_STATE,
|
|
30
|
+
relatedListItems: undefined,
|
|
31
|
+
tabValue: "",
|
|
32
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SiteConfig } from "../../../config/entities";
|
|
2
|
+
import { ExploreState } from "../../exploreState";
|
|
3
|
+
/**
|
|
4
|
+
* Returns the explore state reducer initial arguments.
|
|
5
|
+
* @param config - Site config.
|
|
6
|
+
* @param entityListType - Entity list type.
|
|
7
|
+
* @param decodedFilterParam - Decoded filter parameter.
|
|
8
|
+
* @param decodedCatalogParam - Decoded catalog parameter.
|
|
9
|
+
* @param decodedFeatureFlagParam - Decoded feature flag parameter.
|
|
10
|
+
* @returns explore state reducer initial arguments.
|
|
11
|
+
*/
|
|
12
|
+
export declare function initReducerArguments(config: SiteConfig, entityListType: string, decodedFilterParam: string, decodedCatalogParam?: string, decodedFeatureFlagParam?: string): ExploreState;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initReducerArguments = void 0;
|
|
4
|
+
const utils_1 = require("../../../components/Table/common/utils");
|
|
5
|
+
const utils_2 = require("../../../config/utils");
|
|
6
|
+
const utils_3 = require("../utils");
|
|
7
|
+
const constants_1 = require("./constants");
|
|
8
|
+
/**
|
|
9
|
+
* Returns entity related configured category group config where entity config takes precedence over site config.
|
|
10
|
+
* @param siteConfig - Site config.
|
|
11
|
+
* @param entityConfig - Entity config.
|
|
12
|
+
* @returns entity related category group config.
|
|
13
|
+
*/
|
|
14
|
+
function getEntityCategoryGroupConfig(siteConfig, entityConfig) {
|
|
15
|
+
const siteCategoryGroupConfig = siteConfig.categoryGroupConfig;
|
|
16
|
+
const entityCategoryGroupConfig = entityConfig.categoryGroupConfig;
|
|
17
|
+
return entityCategoryGroupConfig !== null && entityCategoryGroupConfig !== void 0 ? entityCategoryGroupConfig : siteCategoryGroupConfig;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Returns configured category groups as a list of configured categories.
|
|
21
|
+
* @param categoryGroups - Configured category groups.
|
|
22
|
+
* @returns a list of configured categories.
|
|
23
|
+
*/
|
|
24
|
+
function flattenCategoryGroups(categoryGroups) {
|
|
25
|
+
return categoryGroups === null || categoryGroups === void 0 ? void 0 : categoryGroups.flatMap(({ categoryConfigs }) => categoryConfigs);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Initializes category group config key for the entity.
|
|
29
|
+
* @param siteConfig - Site config.
|
|
30
|
+
* @param entityConfig - Entity config.
|
|
31
|
+
* @returns category group config key.
|
|
32
|
+
*/
|
|
33
|
+
function initCategoryGroupConfigKey(siteConfig, entityConfig) {
|
|
34
|
+
const categoryGroupConfig = getEntityCategoryGroupConfig(siteConfig, entityConfig);
|
|
35
|
+
return (categoryGroupConfig === null || categoryGroupConfig === void 0 ? void 0 : categoryGroupConfig.key) || entityConfig.route;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Initializes category groups for the current entity.
|
|
39
|
+
* @param entityStateByCategoryGroupConfigKey - Entity state by category group config key.
|
|
40
|
+
* @param categoryGroupConfigKey - Category group config key.
|
|
41
|
+
* @returns category groups.
|
|
42
|
+
*/
|
|
43
|
+
function initCategoryGroups(entityStateByCategoryGroupConfigKey, categoryGroupConfigKey) {
|
|
44
|
+
var _a;
|
|
45
|
+
return (_a = entityStateByCategoryGroupConfigKey.get(categoryGroupConfigKey)) === null || _a === void 0 ? void 0 : _a.categoryGroups;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Initializes entity page state.
|
|
49
|
+
* @param config - Site config.
|
|
50
|
+
* @returns entity page state.
|
|
51
|
+
*/
|
|
52
|
+
function initEntityPageState(config) {
|
|
53
|
+
return config.entities.reduce((acc, entity) => {
|
|
54
|
+
return Object.assign(Object.assign({}, acc), { [entity.route]: {
|
|
55
|
+
categoryGroupConfigKey: initCategoryGroupConfigKey(config, entity),
|
|
56
|
+
columnsVisibility: (0, utils_1.getInitialTableColumnVisibility)(entity.list.columns),
|
|
57
|
+
sorting: (0, utils_2.getDefaultSorting)(entity),
|
|
58
|
+
} });
|
|
59
|
+
}, {});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Initializes entity state by category group config key.
|
|
63
|
+
* @param config - Site config.
|
|
64
|
+
* @param categoryGroupConfigKey - Category group config key.
|
|
65
|
+
* @param filterState - Filter state.
|
|
66
|
+
* @returns entity state by category group config key.
|
|
67
|
+
*/
|
|
68
|
+
function initEntityStateByCategoryGroupConfigKey(config, categoryGroupConfigKey, filterState) {
|
|
69
|
+
const entityStateByCategoryGroupConfigKey = new Map();
|
|
70
|
+
for (const entity of config.entities) {
|
|
71
|
+
const categoryGroupConfig = getEntityCategoryGroupConfig(config, entity);
|
|
72
|
+
if (!categoryGroupConfig)
|
|
73
|
+
continue;
|
|
74
|
+
const { categoryGroups, key } = categoryGroupConfig;
|
|
75
|
+
if (entityStateByCategoryGroupConfigKey.has(key))
|
|
76
|
+
continue;
|
|
77
|
+
entityStateByCategoryGroupConfigKey.set(key, Object.assign(Object.assign({}, constants_1.DEFAULT_ENTITY_STATE), { categoryConfigs: flattenCategoryGroups(categoryGroups), categoryGroups, filterState: key === categoryGroupConfigKey ? filterState : [] }));
|
|
78
|
+
}
|
|
79
|
+
return entityStateByCategoryGroupConfigKey;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Initializes filter state from URL "filter" parameter.
|
|
83
|
+
* @param decodedFilterParam - Decoded filter parameter.
|
|
84
|
+
* @returns filter state.
|
|
85
|
+
*/
|
|
86
|
+
function initFilterState(decodedFilterParam) {
|
|
87
|
+
// Define filter state, from URL "filter" parameter, if present and valid.
|
|
88
|
+
let filterState = [];
|
|
89
|
+
try {
|
|
90
|
+
filterState = JSON.parse(decodedFilterParam);
|
|
91
|
+
}
|
|
92
|
+
catch (_a) {
|
|
93
|
+
// do nothing
|
|
94
|
+
}
|
|
95
|
+
return filterState;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Returns the explore state reducer initial arguments.
|
|
99
|
+
* @param config - Site config.
|
|
100
|
+
* @param entityListType - Entity list type.
|
|
101
|
+
* @param decodedFilterParam - Decoded filter parameter.
|
|
102
|
+
* @param decodedCatalogParam - Decoded catalog parameter.
|
|
103
|
+
* @param decodedFeatureFlagParam - Decoded feature flag parameter.
|
|
104
|
+
* @returns explore state reducer initial arguments.
|
|
105
|
+
*/
|
|
106
|
+
function initReducerArguments(config, entityListType, decodedFilterParam, decodedCatalogParam, decodedFeatureFlagParam) {
|
|
107
|
+
const filterState = initFilterState(decodedFilterParam);
|
|
108
|
+
const entityPageState = initEntityPageState(config);
|
|
109
|
+
const categoryGroupConfigKey = (0, utils_3.getEntityCategoryGroupConfigKey)(entityListType, entityPageState);
|
|
110
|
+
const entityStateByCategoryGroupConfigKey = initEntityStateByCategoryGroupConfigKey(config, categoryGroupConfigKey, filterState);
|
|
111
|
+
const categoryGroups = initCategoryGroups(entityStateByCategoryGroupConfigKey, categoryGroupConfigKey);
|
|
112
|
+
return Object.assign(Object.assign({}, constants_1.INITIAL_STATE), { catalogState: decodedCatalogParam, categoryGroups,
|
|
113
|
+
entityPageState,
|
|
114
|
+
entityStateByCategoryGroupConfigKey, featureFlagState: decodedFeatureFlagParam, filterCount: (0, utils_3.getFilterCount)(filterState), filterState, tabValue: entityListType });
|
|
115
|
+
}
|
|
116
|
+
exports.initReducerArguments = initReducerArguments;
|
|
@@ -1,37 +1,52 @@
|
|
|
1
1
|
import { SelectedFilter } from "../../common/entities";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { CategoryConfig } from "../../config/entities";
|
|
3
|
+
import { ExploreState, PaginationState } from "../exploreState";
|
|
4
|
+
import { CategoryGroupConfigKey, EntityPageState, EntityPageStateMapper, EntityState } from "./entities";
|
|
4
5
|
/**
|
|
5
|
-
* Returns the
|
|
6
|
-
* @param
|
|
7
|
-
* @
|
|
6
|
+
* Returns the category group config key for the current entity.
|
|
7
|
+
* @param entityPath - Entity path.
|
|
8
|
+
* @param entityPageState - Entity page state mapper.
|
|
9
|
+
* @returns category group config key.
|
|
8
10
|
*/
|
|
9
|
-
export declare function
|
|
11
|
+
export declare function getEntityCategoryGroupConfigKey(entityPath: string, entityPageState: EntityPageStateMapper): CategoryGroupConfigKey;
|
|
10
12
|
/**
|
|
11
|
-
* Returns the
|
|
12
|
-
* @param
|
|
13
|
-
* @
|
|
14
|
-
* @param decodedFilterParam - Decoded filter parameter.
|
|
15
|
-
* @param decodedCatalogParam - Decoded catalog parameter.
|
|
16
|
-
* @param decodedFeatureFlagParam - Decoded feature flag parameter.
|
|
17
|
-
* @returns explore state.
|
|
13
|
+
* Returns the category configs for the current entity.
|
|
14
|
+
* @param state - Explore state.
|
|
15
|
+
* @returns category configs.
|
|
18
16
|
*/
|
|
19
|
-
export declare function
|
|
17
|
+
export declare function getEntityCategoryConfigs(state: ExploreState): CategoryConfig[] | undefined;
|
|
20
18
|
/**
|
|
21
|
-
*
|
|
22
|
-
* @param
|
|
23
|
-
* @
|
|
19
|
+
* Returns the entity state for the given category group config key.
|
|
20
|
+
* @param categoryGroupConfigKey - Category group config key.
|
|
21
|
+
* @param state - Explore state.
|
|
22
|
+
* @returns entity state.
|
|
24
23
|
*/
|
|
25
|
-
export declare function
|
|
24
|
+
export declare function getEntityState(categoryGroupConfigKey: CategoryGroupConfigKey, state: ExploreState): EntityState;
|
|
26
25
|
/**
|
|
27
|
-
*
|
|
28
|
-
* @param
|
|
29
|
-
* @returns
|
|
26
|
+
* Returns the filter count.
|
|
27
|
+
* @param filterState - Filter state.
|
|
28
|
+
* @returns filter count.
|
|
30
29
|
*/
|
|
31
|
-
export declare function
|
|
30
|
+
export declare function getFilterCount(filterState: SelectedFilter[]): number;
|
|
32
31
|
/**
|
|
33
32
|
* Resets pagination.
|
|
34
33
|
* @param paginationState - Pagination state.
|
|
35
34
|
* @returns a reset pagination state.
|
|
36
35
|
*/
|
|
37
36
|
export declare function resetPage(paginationState: PaginationState): PaginationState;
|
|
37
|
+
/**
|
|
38
|
+
* Updates entity page state for the given entity path.
|
|
39
|
+
* @param entityPath - Entity path.
|
|
40
|
+
* @param entityPageState - Entity page state.
|
|
41
|
+
* @param nextEntityPageState - Partial next entity page state.
|
|
42
|
+
* @returns updated entity page state.
|
|
43
|
+
*/
|
|
44
|
+
export declare function updateEntityPageState(entityPath: string, // entityListType.
|
|
45
|
+
entityPageState: EntityPageStateMapper, nextEntityPageState: Partial<EntityPageState>): EntityPageStateMapper;
|
|
46
|
+
/**
|
|
47
|
+
* Updates entity state by category group config key.
|
|
48
|
+
* @param state - Explore state.
|
|
49
|
+
* @param nextEntityState - Partial next entity state.
|
|
50
|
+
* @returns updated entity state by category group config key.
|
|
51
|
+
*/
|
|
52
|
+
export declare function updateEntityStateByCategoryGroupConfigKey(state: ExploreState, nextEntityState: Partial<EntityState>): void;
|
|
@@ -1,82 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resetPage = exports.
|
|
4
|
-
const
|
|
5
|
-
const utils_2 = require("../../config/utils");
|
|
6
|
-
const exploreState_1 = require("../exploreState");
|
|
7
|
-
const constants_1 = require("./constants");
|
|
3
|
+
exports.updateEntityStateByCategoryGroupConfigKey = exports.updateEntityPageState = exports.resetPage = exports.getFilterCount = exports.getEntityState = exports.getEntityCategoryConfigs = exports.getEntityCategoryGroupConfigKey = void 0;
|
|
4
|
+
const constants_1 = require("./initializer/constants");
|
|
8
5
|
/**
|
|
9
|
-
* Returns the
|
|
10
|
-
* @param
|
|
11
|
-
* @
|
|
12
|
-
|
|
13
|
-
function getFilterCount(filterState) {
|
|
14
|
-
return filterState.reduce((acc, filter) => acc + filter.value.length, 0);
|
|
15
|
-
}
|
|
16
|
-
exports.getFilterCount = getFilterCount;
|
|
17
|
-
/**
|
|
18
|
-
* Returns the initial explore state.
|
|
19
|
-
* @param config - Site config.
|
|
20
|
-
* @param entityListType - Entity list type.
|
|
21
|
-
* @param decodedFilterParam - Decoded filter parameter.
|
|
22
|
-
* @param decodedCatalogParam - Decoded catalog parameter.
|
|
23
|
-
* @param decodedFeatureFlagParam - Decoded feature flag parameter.
|
|
24
|
-
* @returns explore state.
|
|
6
|
+
* Returns the category group config key for the current entity.
|
|
7
|
+
* @param entityPath - Entity path.
|
|
8
|
+
* @param entityPageState - Entity page state mapper.
|
|
9
|
+
* @returns category group config key.
|
|
25
10
|
*/
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
const filterState = initFilterState(decodedFilterParam);
|
|
29
|
-
const filterCount = getFilterCount(filterState);
|
|
30
|
-
return Object.assign(Object.assign({}, constants_1.INITIAL_STATE), { catalogState: decodedCatalogParam, categoryGroupConfigs: entityPageState[entityListType].categoryGroupConfigs, entityPageState: initEntityPageState(config), featureFlagState: decodedFeatureFlagParam, filterCount,
|
|
31
|
-
filterState, listView: exploreState_1.ENTITY_VIEW.EXACT, tabValue: entityListType });
|
|
11
|
+
function getEntityCategoryGroupConfigKey(entityPath, entityPageState) {
|
|
12
|
+
return entityPageState[entityPath].categoryGroupConfigKey;
|
|
32
13
|
}
|
|
33
|
-
exports.
|
|
14
|
+
exports.getEntityCategoryGroupConfigKey = getEntityCategoryGroupConfigKey;
|
|
34
15
|
/**
|
|
35
|
-
* Returns
|
|
36
|
-
* @param
|
|
37
|
-
* @returns
|
|
16
|
+
* Returns the category configs for the current entity.
|
|
17
|
+
* @param state - Explore state.
|
|
18
|
+
* @returns category configs.
|
|
38
19
|
*/
|
|
39
|
-
function
|
|
40
|
-
return
|
|
20
|
+
function getEntityCategoryConfigs(state) {
|
|
21
|
+
return getEntityState(getEntityCategoryGroupConfigKey(state.tabValue, state.entityPageState), state).categoryConfigs;
|
|
41
22
|
}
|
|
23
|
+
exports.getEntityCategoryConfigs = getEntityCategoryConfigs;
|
|
42
24
|
/**
|
|
43
|
-
*
|
|
44
|
-
* @param
|
|
45
|
-
* @
|
|
25
|
+
* Returns the entity state for the given category group config key.
|
|
26
|
+
* @param categoryGroupConfigKey - Category group config key.
|
|
27
|
+
* @param state - Explore state.
|
|
28
|
+
* @returns entity state.
|
|
46
29
|
*/
|
|
47
|
-
function
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
try {
|
|
51
|
-
filterState = JSON.parse(decodedFilterParam);
|
|
52
|
-
}
|
|
53
|
-
catch (_a) {
|
|
54
|
-
// do nothing
|
|
55
|
-
}
|
|
56
|
-
return filterState;
|
|
30
|
+
function getEntityState(categoryGroupConfigKey, state) {
|
|
31
|
+
return (state.entityStateByCategoryGroupConfigKey.get(categoryGroupConfigKey) ||
|
|
32
|
+
constants_1.DEFAULT_ENTITY_STATE);
|
|
57
33
|
}
|
|
58
|
-
exports.
|
|
34
|
+
exports.getEntityState = getEntityState;
|
|
59
35
|
/**
|
|
60
|
-
*
|
|
61
|
-
* @param
|
|
62
|
-
* @returns
|
|
36
|
+
* Returns the filter count.
|
|
37
|
+
* @param filterState - Filter state.
|
|
38
|
+
* @returns filter count.
|
|
63
39
|
*/
|
|
64
|
-
function
|
|
65
|
-
|
|
66
|
-
return config.entities.reduce((acc, entity) => {
|
|
67
|
-
var _a, _b;
|
|
68
|
-
return (Object.assign(Object.assign({}, acc), { [entity.route]: {
|
|
69
|
-
categoryConfigs: flattenCategoryGroupConfigs((_a = entity.categoryGroupConfigs) !== null && _a !== void 0 ? _a : categoryGroupConfigs),
|
|
70
|
-
categoryGroupConfigs: (_b = entity.categoryGroupConfigs) !== null && _b !== void 0 ? _b : categoryGroupConfigs,
|
|
71
|
-
categoryViews: [],
|
|
72
|
-
columnsVisibility: (0, utils_1.getInitialTableColumnVisibility)(entity.list.columns),
|
|
73
|
-
filterCount: 0,
|
|
74
|
-
filterState: [],
|
|
75
|
-
sorting: (0, utils_2.getDefaultSorting)(entity),
|
|
76
|
-
} }));
|
|
77
|
-
}, {});
|
|
40
|
+
function getFilterCount(filterState) {
|
|
41
|
+
return filterState.reduce((acc, filter) => acc + filter.value.length, 0);
|
|
78
42
|
}
|
|
79
|
-
exports.
|
|
43
|
+
exports.getFilterCount = getFilterCount;
|
|
80
44
|
/**
|
|
81
45
|
* Resets pagination.
|
|
82
46
|
* @param paginationState - Pagination state.
|
|
@@ -89,3 +53,38 @@ function resetPage(paginationState) {
|
|
|
89
53
|
return nextPaginationState;
|
|
90
54
|
}
|
|
91
55
|
exports.resetPage = resetPage;
|
|
56
|
+
/**
|
|
57
|
+
* Sets entity state for the given category group config key.
|
|
58
|
+
* @param categoryGroupConfigKey - Category group config key.
|
|
59
|
+
* @param state - Explore state.
|
|
60
|
+
* @param nextEntityState - Next entity state.
|
|
61
|
+
*/
|
|
62
|
+
function setEntityStateByCategoryGroupConfigKey(categoryGroupConfigKey, state, nextEntityState) {
|
|
63
|
+
state.entityStateByCategoryGroupConfigKey.set(categoryGroupConfigKey, nextEntityState);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Updates entity page state for the given entity path.
|
|
67
|
+
* @param entityPath - Entity path.
|
|
68
|
+
* @param entityPageState - Entity page state.
|
|
69
|
+
* @param nextEntityPageState - Partial next entity page state.
|
|
70
|
+
* @returns updated entity page state.
|
|
71
|
+
*/
|
|
72
|
+
function updateEntityPageState(entityPath, // entityListType.
|
|
73
|
+
entityPageState, nextEntityPageState) {
|
|
74
|
+
return Object.assign(Object.assign({}, entityPageState), { [entityPath]: Object.assign(Object.assign({}, entityPageState[entityPath]), nextEntityPageState) });
|
|
75
|
+
}
|
|
76
|
+
exports.updateEntityPageState = updateEntityPageState;
|
|
77
|
+
/**
|
|
78
|
+
* Updates entity state by category group config key.
|
|
79
|
+
* @param state - Explore state.
|
|
80
|
+
* @param nextEntityState - Partial next entity state.
|
|
81
|
+
* @returns updated entity state by category group config key.
|
|
82
|
+
*/
|
|
83
|
+
function updateEntityStateByCategoryGroupConfigKey(state, nextEntityState) {
|
|
84
|
+
const categoryGroupConfigKey = getEntityCategoryGroupConfigKey(state.tabValue, state.entityPageState);
|
|
85
|
+
const entityState = getEntityState(categoryGroupConfigKey, state);
|
|
86
|
+
if (entityState) {
|
|
87
|
+
setEntityStateByCategoryGroupConfigKey(categoryGroupConfigKey, state, Object.assign(Object.assign({}, entityState), nextEntityState));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.updateEntityStateByCategoryGroupConfigKey = updateEntityStateByCategoryGroupConfigKey;
|