@databiosphere/findable-ui 2.0.0 → 2.0.1

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.
Files changed (28) hide show
  1. package/lib/components/Table/table.js +1 -1
  2. package/lib/components/common/AnchorLink/anchorLink.styles.js +1 -0
  3. package/lib/config/entities.d.ts +10 -3
  4. package/lib/hooks/useEntityList.js +1 -1
  5. package/lib/hooks/useSessionTimeout.js +9 -2
  6. package/lib/providers/exploreState/entities.d.ts +19 -0
  7. package/lib/providers/exploreState/entities.js +2 -0
  8. package/lib/providers/exploreState/initializer/constants.d.ts +5 -0
  9. package/lib/providers/exploreState/initializer/constants.js +32 -0
  10. package/lib/providers/exploreState/initializer/utils.d.ts +12 -0
  11. package/lib/providers/exploreState/initializer/utils.js +116 -0
  12. package/lib/providers/exploreState/utils.d.ts +37 -22
  13. package/lib/providers/exploreState/utils.js +64 -65
  14. package/lib/providers/exploreState.d.ts +4 -21
  15. package/lib/providers/exploreState.js +23 -22
  16. package/lib/views/ExploreView/exploreView.js +6 -6
  17. package/package.json +1 -1
  18. package/src/components/Table/table.tsx +1 -1
  19. package/src/components/common/AnchorLink/anchorLink.styles.ts +1 -0
  20. package/src/config/entities.ts +11 -3
  21. package/src/hooks/useEntityList.ts +1 -1
  22. package/src/hooks/useSessionTimeout.ts +9 -3
  23. package/src/providers/exploreState/entities.ts +32 -0
  24. package/src/providers/exploreState/{constants.ts → initializer/constants.ts} +8 -3
  25. package/src/providers/exploreState/initializer/utils.ts +183 -0
  26. package/src/providers/exploreState/utils.ts +103 -92
  27. package/src/providers/exploreState.tsx +50 -81
  28. package/src/views/ExploreView/exploreView.tsx +8 -8
@@ -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");
@@ -11,6 +11,7 @@ exports.AnchorLink = (0, styled_1.default)(link_1.default) `
11
11
  color: ${colors_1.inkLight};
12
12
  margin-left: 4px;
13
13
  opacity: 0;
14
+ position: absolute;
14
15
  transition: opacity 0.2s ease-in-out;
15
16
 
16
17
  svg {
@@ -46,9 +46,16 @@ export interface BackPageTabConfig extends TabConfig {
46
46
  sideColumn?: ComponentsConfig;
47
47
  }
48
48
  /**
49
- * Model of grouped configured categories in site config.
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
- categoryGroupConfigs?: CategoryGroupConfig[];
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
- categoryGroupConfigs?: CategoryGroupConfig[];
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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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 { SiteConfig } from "../../config/entities";
3
- import { EntityPageStateMapper, ExploreState, PaginationState } from "../exploreState";
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 filter count.
6
- * @param filterState - Filter state.
7
- * @returns filter count.
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 getFilterCount(filterState: SelectedFilter[]): number;
11
+ export declare function getEntityCategoryGroupConfigKey(entityPath: string, entityPageState: EntityPageStateMapper): CategoryGroupConfigKey;
10
12
  /**
11
- * Returns the initial explore state.
12
- * @param config - Site config.
13
- * @param entityListType - Entity list type.
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 initExploreState(config: SiteConfig, entityListType: string, decodedFilterParam: string, decodedCatalogParam?: string, decodedFeatureFlagParam?: string): ExploreState;
17
+ export declare function getEntityCategoryConfigs(state: ExploreState): CategoryConfig[] | undefined;
20
18
  /**
21
- * Initializes filter state from URL "filter" parameter.
22
- * @param decodedFilterParam - Decoded filter parameter.
23
- * @returns filter state.
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 initFilterState(decodedFilterParam: string): SelectedFilter[];
24
+ export declare function getEntityState(categoryGroupConfigKey: CategoryGroupConfigKey, state: ExploreState): EntityState;
26
25
  /**
27
- * Initializes entity page state.
28
- * @param config - Site config.
29
- * @returns entity page state.
26
+ * Returns the filter count.
27
+ * @param filterState - Filter state.
28
+ * @returns filter count.
30
29
  */
31
- export declare function initEntityPageState(config: SiteConfig): EntityPageStateMapper;
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.initEntityPageState = exports.initFilterState = exports.initExploreState = exports.getFilterCount = void 0;
4
- const utils_1 = require("../../components/Table/common/utils");
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 filter count.
10
- * @param filterState - Filter state.
11
- * @returns filter count.
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 initExploreState(config, entityListType, decodedFilterParam, decodedCatalogParam, decodedFeatureFlagParam) {
27
- const entityPageState = initEntityPageState(config);
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.initExploreState = initExploreState;
14
+ exports.getEntityCategoryGroupConfigKey = getEntityCategoryGroupConfigKey;
34
15
  /**
35
- * Returns configured grouped configured categories as a list of configured categories.
36
- * @param categoryGroupConfigs - Configured category groups.
37
- * @returns a list of configured categories.
16
+ * Returns the category configs for the current entity.
17
+ * @param state - Explore state.
18
+ * @returns category configs.
38
19
  */
39
- function flattenCategoryGroupConfigs(categoryGroupConfigs) {
40
- return categoryGroupConfigs === null || categoryGroupConfigs === void 0 ? void 0 : categoryGroupConfigs.flatMap(({ categoryConfigs }) => categoryConfigs);
20
+ function getEntityCategoryConfigs(state) {
21
+ return getEntityState(getEntityCategoryGroupConfigKey(state.tabValue, state.entityPageState), state).categoryConfigs;
41
22
  }
23
+ exports.getEntityCategoryConfigs = getEntityCategoryConfigs;
42
24
  /**
43
- * Initializes filter state from URL "filter" parameter.
44
- * @param decodedFilterParam - Decoded filter parameter.
45
- * @returns filter state.
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 initFilterState(decodedFilterParam) {
48
- // Define filter state, from URL "filter" parameter, if present and valid.
49
- let filterState = [];
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.initFilterState = initFilterState;
34
+ exports.getEntityState = getEntityState;
59
35
  /**
60
- * Initializes entity page state.
61
- * @param config - Site config.
62
- * @returns entity page state.
36
+ * Returns the filter count.
37
+ * @param filterState - Filter state.
38
+ * @returns filter count.
63
39
  */
64
- function initEntityPageState(config) {
65
- const { categoryGroupConfigs } = config;
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.initEntityPageState = initEntityPageState;
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;
@@ -1,8 +1,8 @@
1
- import { ColumnSort } from "@tanstack/react-table";
2
1
  import React, { Dispatch, ReactNode } from "react";
3
2
  import { AzulSearchIndex } from "../apis/azul/common/entities";
4
3
  import { SelectCategory, SelectedFilter } from "../common/entities";
5
- import { CategoryConfig, CategoryGroupConfig, EntityPath, SiteConfig } from "../config/entities";
4
+ import { CategoryGroup, SiteConfig } from "../config/entities";
5
+ import { EntityPageStateMapper, EntityStateByCategoryGroupConfigKey } from "./exploreState/entities";
6
6
  import { PaginateTablePayload, ProcessExploreResponsePayload, ProcessRelatedResponsePayload, ResetExploreResponsePayload, ToggleEntityViewPayload, UpdateColumnVisibilityPayload, UpdateFilterPayload, UpdateSortingPayload } from "./exploreState/payloads/entities";
7
7
  export declare type CatalogState = string | undefined;
8
8
  /**
@@ -19,32 +19,15 @@ export interface ExploreContext {
19
19
  config: SiteConfig;
20
20
  entityList: string;
21
21
  }
22
- /**
23
- * State for each entity.
24
- */
25
- export interface EntityPageState {
26
- categoryConfigs?: CategoryConfig[];
27
- categoryGroupConfigs?: CategoryGroupConfig[];
28
- categoryViews: SelectCategory[];
29
- columnsVisibility: Record<string, boolean>;
30
- filterCount: number;
31
- filterState: SelectedFilter[];
32
- sorting: ColumnSort[];
33
- }
34
- /**
35
- * State for all entities.
36
- */
37
- export interface EntityPageStateMapper {
38
- [key: EntityPath]: EntityPageState;
39
- }
40
22
  /**
41
23
  * Explore state.
42
24
  */
43
25
  export declare type ExploreState = {
44
26
  catalogState: CatalogState;
45
- categoryGroupConfigs?: CategoryGroupConfig[];
27
+ categoryGroups?: CategoryGroup[];
46
28
  categoryViews: SelectCategory[];
47
29
  entityPageState: EntityPageStateMapper;
30
+ entityStateByCategoryGroupConfigKey: EntityStateByCategoryGroupConfigKey;
48
31
  featureFlagState: FeatureFlagState;
49
32
  filterCount: number;
50
33
  filterState: SelectedFilter[];