@databiosphere/findable-ui 34.0.0 → 34.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.
Files changed (36) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +7 -0
  3. package/lib/providers/exploreState/entities.d.ts +1 -1
  4. package/lib/providers/exploreState.js +10 -10
  5. package/lib/providers/exploreStateSync/hooks/UseMetaCommands/handlers.d.ts +10 -0
  6. package/lib/providers/exploreStateSync/hooks/UseMetaCommands/handlers.js +18 -0
  7. package/lib/providers/exploreStateSync/hooks/UseMetaCommands/hook.d.ts +1 -0
  8. package/lib/providers/exploreStateSync/hooks/UseMetaCommands/hook.js +33 -0
  9. package/lib/providers/exploreStateSync/hooks/UseMetaCommands/types.d.ts +11 -0
  10. package/lib/providers/exploreStateSync/hooks/UseMetaCommands/types.js +5 -0
  11. package/lib/providers/exploreStateSync/hooks/UseMetaCommands/utils.d.ts +34 -0
  12. package/lib/providers/exploreStateSync/hooks/UseMetaCommands/utils.js +59 -0
  13. package/lib/providers/exploreStateSync/provider.d.ts +19 -0
  14. package/lib/providers/exploreStateSync/provider.js +22 -0
  15. package/lib/views/ExploreView/exploreView.js +2 -1
  16. package/package.json +1 -1
  17. package/src/providers/exploreState/entities.ts +1 -1
  18. package/src/providers/exploreState.tsx +10 -11
  19. package/src/providers/exploreStateSync/hooks/UseMetaCommands/handlers.ts +25 -0
  20. package/src/providers/exploreStateSync/hooks/UseMetaCommands/hook.ts +38 -0
  21. package/src/providers/exploreStateSync/hooks/UseMetaCommands/types.ts +13 -0
  22. package/src/providers/exploreStateSync/hooks/UseMetaCommands/utils.ts +69 -0
  23. package/src/providers/exploreStateSync/provider.tsx +29 -0
  24. package/src/views/ExploreView/exploreView.tsx +3 -2
  25. package/lib/providers/exploreState/hooks/UseMetaCommands/actions.d.ts +0 -13
  26. package/lib/providers/exploreState/hooks/UseMetaCommands/actions.js +0 -24
  27. package/lib/providers/exploreState/hooks/UseMetaCommands/types.d.ts +0 -4
  28. package/lib/providers/exploreState/hooks/UseMetaCommands/types.js +0 -5
  29. package/lib/providers/exploreState/hooks/UseMetaCommands/useMetaCommands.d.ts +0 -2
  30. package/lib/providers/exploreState/hooks/UseMetaCommands/useMetaCommands.js +0 -21
  31. package/lib/providers/exploreState/hooks/UseMetaCommands/utils.d.ts +0 -9
  32. package/lib/providers/exploreState/hooks/UseMetaCommands/utils.js +0 -25
  33. package/src/providers/exploreState/hooks/UseMetaCommands/actions.ts +0 -29
  34. package/src/providers/exploreState/hooks/UseMetaCommands/types.ts +0 -4
  35. package/src/providers/exploreState/hooks/UseMetaCommands/useMetaCommands.ts +0 -27
  36. package/src/providers/exploreState/hooks/UseMetaCommands/utils.ts +0 -33
@@ -1,3 +1,3 @@
1
1
  {
2
- ".": "34.0.0"
2
+ ".": "34.1.0"
3
3
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [34.1.0](https://github.com/DataBiosphere/findable-ui/compare/v34.0.0...v34.1.0) (2025-05-29)
4
+
5
+
6
+ ### Features
7
+
8
+ * entity lists do not load when page refreshes ([#506](https://github.com/DataBiosphere/findable-ui/issues/506)) ([#507](https://github.com/DataBiosphere/findable-ui/issues/507)) ([05ba8a1](https://github.com/DataBiosphere/findable-ui/commit/05ba8a17d5c94b35e35056a51d06066f337a276a))
9
+
3
10
  ## [34.0.0](https://github.com/DataBiosphere/findable-ui/compare/v33.0.0...v34.0.0) (2025-05-27)
4
11
 
5
12
 
@@ -4,7 +4,7 @@ import { CategoryView } from "../../common/categories/views/types";
4
4
  import { CategoryValueKey, SelectCategory, SelectedFilter } from "../../common/entities";
5
5
  import { RowPreviewState } from "../../components/Table/features/RowPreview/entities";
6
6
  import { CategoryGroup, CategoryGroupConfig, EntityPath, SavedFilter } from "../../config/entities";
7
- import { META_COMMAND } from "./hooks/UseMetaCommands/types";
7
+ import { META_COMMAND } from "../exploreStateSync/hooks/UseMetaCommands/types";
8
8
  export interface EntityPageState {
9
9
  categoryGroupConfigKey: CategoryGroupConfigKey;
10
10
  columnVisibility: VisibilityState;
@@ -8,11 +8,10 @@ import { syncStateFromUrlAction } from "./exploreState/actions/syncStateFromUrl/
8
8
  import { updateGroupingAction } from "./exploreState/actions/updateGrouping/action";
9
9
  import { updateColumnVisibilityAction } from "./exploreState/actions/updateVisibility/action";
10
10
  import { useBeforePopState } from "./exploreState/hooks/UseBeforePopState/useBeforePopState";
11
- import { META_COMMAND } from "./exploreState/hooks/UseMetaCommands/types";
12
- import { useMetaCommands } from "./exploreState/hooks/UseMetaCommands/useMetaCommands";
13
11
  import { DEFAULT_PAGINATION_STATE, INITIAL_STATE, } from "./exploreState/initializer/constants";
14
12
  import { initReducerArguments } from "./exploreState/initializer/utils";
15
13
  import { buildEntityStateSavedFilterState, buildNextSavedFilterState, closeRowPreview, getEntityCategoryGroupConfigKey, getEntityState, getEntityStateSavedProperty, getFilterCount, patchEntityListItems, resetPage, updateEntityPageState, updateEntityPageStateWithCommonCategoryGroupConfigKey, updateEntityStateByCategoryGroupConfigKey, updateSelectColumnVisibility, } from "./exploreState/utils";
14
+ import { META_COMMAND } from "./exploreStateSync/hooks/UseMetaCommands/types";
16
15
  /**
17
16
  * Explore state context for storing and using filter-related and explore state.
18
17
  */
@@ -56,8 +55,6 @@ export function ExploreStateProvider({ children, entityListType, }) {
56
55
  type: ExploreActionKind.ResetExploreResponse,
57
56
  });
58
57
  }, [exploreDispatch, token]);
59
- // Meta-command related side effects.
60
- useMetaCommands({ exploreDispatch, exploreState });
61
58
  // Before pop state related side effects (forward / backward navigation by browser buttons).
62
59
  useBeforePopState({ exploreDispatch, exploreState });
63
60
  return (React.createElement(ExploreStateContext.Provider, { value: exploreContextValue }, children));
@@ -118,7 +115,7 @@ function exploreReducer(state, action, exploreContext) {
118
115
  entityPageState: updateEntityPageStateWithCommonCategoryGroupConfigKey(state, { grouping, rowPreview, rowSelection, sorting }),
119
116
  filterCount: getFilterCount(filterState),
120
117
  filterState,
121
- meta: { command: META_COMMAND.NAVIGATE_TO_FILTERS },
118
+ meta: { command: META_COMMAND.STATE_TO_URL_PUSH },
122
119
  paginationState: resetPage(state.paginationState),
123
120
  rowPreview,
124
121
  };
@@ -141,7 +138,7 @@ function exploreReducer(state, action, exploreContext) {
141
138
  entityPageState: updateEntityPageStateWithCommonCategoryGroupConfigKey(state, { rowPreview, rowSelection }),
142
139
  filterCount,
143
140
  filterState,
144
- meta: { command: META_COMMAND.NAVIGATE_TO_FILTERS },
141
+ meta: { command: META_COMMAND.STATE_TO_URL_PUSH },
145
142
  paginationState: resetPage(state.paginationState),
146
143
  rowPreview,
147
144
  };
@@ -233,8 +230,11 @@ function exploreReducer(state, action, exploreContext) {
233
230
  **/
234
231
  case ExploreActionKind.SelectEntityType: {
235
232
  if (payload === state.tabValue) {
236
- // Update meta to match command "REPLACE_TO_FILTERS" - facilitates navigation to filters on return back to entity from elsewhere.
237
- return { ...state, meta: { command: META_COMMAND.REPLACE_TO_FILTERS } };
233
+ // Update meta to match command "STATE_TO_URL_REPLACE" - facilitates navigation to filters on return back to entity from elsewhere.
234
+ return {
235
+ ...state,
236
+ meta: { command: META_COMMAND.STATE_TO_URL_REPLACE },
237
+ };
238
238
  }
239
239
  const entityState = getEntityState(state, getEntityCategoryGroupConfigKey(payload, state.entityPageState));
240
240
  const rowPreview = closeRowPreview(state.rowPreview); // Close row preview, without updating the entity page state row preview.
@@ -246,7 +246,7 @@ function exploreReducer(state, action, exploreContext) {
246
246
  filterState: entityState.filterState,
247
247
  listItems: [],
248
248
  loading: true,
249
- meta: { command: META_COMMAND.REPLACE_TO_FILTERS },
249
+ meta: { command: META_COMMAND.STATE_TO_URL_REPLACE },
250
250
  paginationState: { ...resetPage(state.paginationState), rows: 0 },
251
251
  rowPreview,
252
252
  tabValue: payload,
@@ -324,7 +324,7 @@ function exploreReducer(state, action, exploreContext) {
324
324
  entityPageState: updateEntityPageStateWithCommonCategoryGroupConfigKey(state, { rowPreview, rowSelection }),
325
325
  filterCount: getFilterCount(filterState),
326
326
  filterState,
327
- meta: { command: META_COMMAND.NAVIGATE_TO_FILTERS },
327
+ meta: { command: META_COMMAND.STATE_TO_URL_PUSH },
328
328
  paginationState: resetPage(state.paginationState),
329
329
  rowPreview,
330
330
  };
@@ -0,0 +1,10 @@
1
+ import { NextRouter } from "next/router";
2
+ import { ExploreQueryState } from "./types";
3
+ /**
4
+ * Updates the URL query parameters based on state.
5
+ * Pushes or replaces the query to the router.
6
+ * @param state - State -- partial explore state.
7
+ * @param currentQuery - Query -- current.
8
+ * @param method - "push" or "replace".
9
+ */
10
+ export declare function updateUrlFromState(state: ExploreQueryState, currentQuery: NextRouter["query"], method?: "push" | "replace"): void;
@@ -0,0 +1,18 @@
1
+ import Router from "next/router";
2
+ import { buildQuery, stringifyQuery } from "./utils";
3
+ /**
4
+ * Updates the URL query parameters based on state.
5
+ * Pushes or replaces the query to the router.
6
+ * @param state - State -- partial explore state.
7
+ * @param currentQuery - Query -- current.
8
+ * @param method - "push" or "replace".
9
+ */
10
+ export function updateUrlFromState(state, currentQuery, method = "push") {
11
+ // Build the next query.
12
+ const query = buildQuery(state);
13
+ // Do nothing if the next query is the same as the current query.
14
+ if (stringifyQuery(query) === stringifyQuery(currentQuery))
15
+ return;
16
+ // Push or replace the query to the router.
17
+ Router[method]({ query }, undefined, { shallow: true });
18
+ }
@@ -0,0 +1 @@
1
+ export declare const useMetaCommands: () => void;
@@ -0,0 +1,33 @@
1
+ import { useRouter } from "next/router";
2
+ import { useEffect, useMemo } from "react";
3
+ import { useExploreState } from "../../../../hooks/useExploreState";
4
+ import { clearMeta } from "../../../exploreState/actions/clearMeta/dispatch";
5
+ import { updateUrlFromState } from "./handlers";
6
+ import { META_COMMAND } from "./types";
7
+ import { getQueryState } from "./utils";
8
+ export const useMetaCommands = () => {
9
+ const { exploreDispatch, exploreState } = useExploreState();
10
+ // Router must be ready before executing any meta-command side effects.
11
+ const { isReady, query } = useRouter();
12
+ // Command.
13
+ const command = exploreState.meta?.command;
14
+ // Extract relevant state to update URL.
15
+ const state = useMemo(() => getQueryState(exploreState), [exploreState]);
16
+ useEffect(() => {
17
+ // Do nothing if the router is not ready.
18
+ if (!isReady)
19
+ return;
20
+ switch (command) {
21
+ case META_COMMAND.STATE_TO_URL_PUSH:
22
+ updateUrlFromState(state, query);
23
+ exploreDispatch(clearMeta());
24
+ break;
25
+ case META_COMMAND.STATE_TO_URL_REPLACE:
26
+ updateUrlFromState(state, query, "replace");
27
+ exploreDispatch(clearMeta());
28
+ break;
29
+ default:
30
+ break;
31
+ }
32
+ }, [command, exploreDispatch, isReady, query, state]);
33
+ };
@@ -0,0 +1,11 @@
1
+ import { ExploreState } from "../../../exploreState";
2
+ export interface ExploreQueryState {
3
+ catalog: ExploreState["catalogState"];
4
+ entityListType: ExploreState["tabValue"];
5
+ ff: ExploreState["featureFlagState"];
6
+ filter: ExploreState["filterState"];
7
+ }
8
+ export declare enum META_COMMAND {
9
+ STATE_TO_URL_PUSH = "STATE_TO_URL_PUSH",
10
+ STATE_TO_URL_REPLACE = "STATE_TO_URL_REPLACE"
11
+ }
@@ -0,0 +1,5 @@
1
+ export var META_COMMAND;
2
+ (function (META_COMMAND) {
3
+ META_COMMAND["STATE_TO_URL_PUSH"] = "STATE_TO_URL_PUSH";
4
+ META_COMMAND["STATE_TO_URL_REPLACE"] = "STATE_TO_URL_REPLACE";
5
+ })(META_COMMAND || (META_COMMAND = {}));
@@ -0,0 +1,34 @@
1
+ import { NextRouter } from "next/router";
2
+ import { ExploreState } from "../../../exploreState";
3
+ import { ExploreQueryState } from "./types";
4
+ /**
5
+ * Builds a query object from state.
6
+ * State values are expected to be undefined, string, or an array.
7
+ * Undefined values and empty arrays are not included in the query.
8
+ * @param state - State -- partial explore state.
9
+ * @returns A query object.
10
+ */
11
+ export declare function buildQuery(state: ExploreQueryState): NextRouter["query"];
12
+ /**
13
+ * Extracts URL-relevant values from the ExploreState for query parameter synchronization.
14
+ *
15
+ * This function maps specific properties from the full ExploreState to the
16
+ * ExploreQueryState interface, which contains only the subset of state that
17
+ * should be synchronized with the URL.
18
+ *
19
+ * The extracted properties are:
20
+ * - catalog: Current catalog selection (string | undefined)
21
+ * - entityListType: Current active tab value (string)
22
+ * - ff: Feature flag state (string | undefined)
23
+ * - filter: Applied filters (SelectedFilter[])
24
+ *
25
+ * @param exploreState - Explore state.
26
+ * @returns Subset of state used for URL query parameters.
27
+ */
28
+ export declare function getQueryState(exploreState: ExploreState): ExploreQueryState;
29
+ /**
30
+ * Returns a sorted string representation of a query object.
31
+ * @param query - Query object.
32
+ * @returns Sorted string representation of the query object.
33
+ */
34
+ export declare function stringifyQuery(query: NextRouter["query"]): string;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Builds a query object from state.
3
+ * State values are expected to be undefined, string, or an array.
4
+ * Undefined values and empty arrays are not included in the query.
5
+ * @param state - State -- partial explore state.
6
+ * @returns A query object.
7
+ */
8
+ export function buildQuery(state) {
9
+ const query = {};
10
+ for (const [key, value] of Object.entries(state)) {
11
+ // Handle the undefined case.
12
+ if (value === undefined)
13
+ continue;
14
+ // Handle the string case.
15
+ if (typeof value === "string") {
16
+ query[key] = value;
17
+ continue;
18
+ }
19
+ // Handle the array case.
20
+ if (value.length === 0)
21
+ continue;
22
+ query[key] = JSON.stringify(value);
23
+ }
24
+ return query;
25
+ }
26
+ /**
27
+ * Extracts URL-relevant values from the ExploreState for query parameter synchronization.
28
+ *
29
+ * This function maps specific properties from the full ExploreState to the
30
+ * ExploreQueryState interface, which contains only the subset of state that
31
+ * should be synchronized with the URL.
32
+ *
33
+ * The extracted properties are:
34
+ * - catalog: Current catalog selection (string | undefined)
35
+ * - entityListType: Current active tab value (string)
36
+ * - ff: Feature flag state (string | undefined)
37
+ * - filter: Applied filters (SelectedFilter[])
38
+ *
39
+ * @param exploreState - Explore state.
40
+ * @returns Subset of state used for URL query parameters.
41
+ */
42
+ export function getQueryState(exploreState) {
43
+ return {
44
+ catalog: exploreState.catalogState,
45
+ entityListType: exploreState.tabValue,
46
+ ff: exploreState.featureFlagState,
47
+ filter: exploreState.filterState,
48
+ };
49
+ }
50
+ /**
51
+ * Returns a sorted string representation of a query object.
52
+ * @param query - Query object.
53
+ * @returns Sorted string representation of the query object.
54
+ */
55
+ export function stringifyQuery(query) {
56
+ return JSON.stringify(Object.keys(query)
57
+ .sort()
58
+ .reduce((acc, key) => ({ ...acc, [key]: query[key] }), {}));
59
+ }
@@ -0,0 +1,19 @@
1
+ import { ReactNode } from "react";
2
+ /**
3
+ * Synchronizes the ExploreView component's state with the Next.js URL.
4
+ *
5
+ * Listens for reducer meta-commands (`STATE_TO_URL_PUSH`/`STATE_TO_URL_REPLACE`)
6
+ * and updates the URL accordingly using router methods.
7
+ *
8
+ * Usage:
9
+ * ```tsx
10
+ * <ExploreStateProvider>
11
+ * <ExploreStateSyncProvider>
12
+ * <ExploreView />
13
+ * </ExploreStateSyncProvider>
14
+ * </ExploreStateProvider>
15
+ * ```
16
+ */
17
+ export declare function ExploreStateSyncProvider({ children, }: {
18
+ children: ReactNode;
19
+ }): JSX.Element;
@@ -0,0 +1,22 @@
1
+ import React from "react";
2
+ import { useMetaCommands } from "./hooks/UseMetaCommands/hook";
3
+ /**
4
+ * Synchronizes the ExploreView component's state with the Next.js URL.
5
+ *
6
+ * Listens for reducer meta-commands (`STATE_TO_URL_PUSH`/`STATE_TO_URL_REPLACE`)
7
+ * and updates the URL accordingly using router methods.
8
+ *
9
+ * Usage:
10
+ * ```tsx
11
+ * <ExploreStateProvider>
12
+ * <ExploreStateSyncProvider>
13
+ * <ExploreView />
14
+ * </ExploreStateSyncProvider>
15
+ * </ExploreStateProvider>
16
+ * ```
17
+ */
18
+ export function ExploreStateSyncProvider({ children, }) {
19
+ // Meta-command related side effects.
20
+ useMetaCommands();
21
+ return React.createElement(React.Fragment, null, children);
22
+ }
@@ -18,6 +18,7 @@ import { useExploreState } from "../../hooks/useExploreState";
18
18
  import { useSummary } from "../../hooks/useSummary";
19
19
  import { ExploreActionKind } from "../../providers/exploreState";
20
20
  import { SELECT_CATEGORY_KEY } from "../../providers/exploreState/constants";
21
+ import { ExploreStateSyncProvider } from "../../providers/exploreStateSync/provider";
21
22
  import { TEST_IDS } from "../../tests/testIds";
22
23
  import { DESKTOP_SM } from "../../theme/common/breakpoints";
23
24
  export const ExploreView = (props) => {
@@ -98,7 +99,7 @@ export const ExploreView = (props) => {
98
99
  });
99
100
  }
100
101
  }, [entityListType, exploreDispatch]);
101
- return (React.createElement(React.Fragment, null,
102
+ return (React.createElement(ExploreStateSyncProvider, null,
102
103
  categoryViews && !!categoryViews.length && (React.createElement(Sidebar, { drawerOpen: isDrawerOpen, onDrawerClose: onCloseDrawer },
103
104
  React.createElement(SidebarTools, { "data-testid": TEST_IDS.FILTER_CONTROLS },
104
105
  React.createElement(SidebarLabel, { label: "Filters" }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@databiosphere/findable-ui",
3
- "version": "34.0.0",
3
+ "version": "34.1.0",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
@@ -18,7 +18,7 @@ import {
18
18
  EntityPath,
19
19
  SavedFilter,
20
20
  } from "../../config/entities";
21
- import { META_COMMAND } from "./hooks/UseMetaCommands/types";
21
+ import { META_COMMAND } from "../exploreStateSync/hooks/UseMetaCommands/types";
22
22
 
23
23
  export interface EntityPageState {
24
24
  categoryGroupConfigKey: CategoryGroupConfigKey;
@@ -35,8 +35,6 @@ import {
35
35
  Meta,
36
36
  } from "./exploreState/entities";
37
37
  import { useBeforePopState } from "./exploreState/hooks/UseBeforePopState/useBeforePopState";
38
- import { META_COMMAND } from "./exploreState/hooks/UseMetaCommands/types";
39
- import { useMetaCommands } from "./exploreState/hooks/UseMetaCommands/useMetaCommands";
40
38
  import {
41
39
  DEFAULT_PAGINATION_STATE,
42
40
  INITIAL_STATE,
@@ -70,6 +68,7 @@ import {
70
68
  updateEntityStateByCategoryGroupConfigKey,
71
69
  updateSelectColumnVisibility,
72
70
  } from "./exploreState/utils";
71
+ import { META_COMMAND } from "./exploreStateSync/hooks/UseMetaCommands/types";
73
72
 
74
73
  export type CatalogState = string | undefined;
75
74
 
@@ -215,9 +214,6 @@ export function ExploreStateProvider({
215
214
  });
216
215
  }, [exploreDispatch, token]);
217
216
 
218
- // Meta-command related side effects.
219
- useMetaCommands({ exploreDispatch, exploreState });
220
-
221
217
  // Before pop state related side effects (forward / backward navigation by browser buttons).
222
218
  useBeforePopState({ exploreDispatch, exploreState });
223
219
 
@@ -445,7 +441,7 @@ function exploreReducer(
445
441
  ),
446
442
  filterCount: getFilterCount(filterState),
447
443
  filterState,
448
- meta: { command: META_COMMAND.NAVIGATE_TO_FILTERS },
444
+ meta: { command: META_COMMAND.STATE_TO_URL_PUSH },
449
445
  paginationState: resetPage(state.paginationState),
450
446
  rowPreview,
451
447
  };
@@ -471,7 +467,7 @@ function exploreReducer(
471
467
  ),
472
468
  filterCount,
473
469
  filterState,
474
- meta: { command: META_COMMAND.NAVIGATE_TO_FILTERS },
470
+ meta: { command: META_COMMAND.STATE_TO_URL_PUSH },
475
471
  paginationState: resetPage(state.paginationState),
476
472
  rowPreview,
477
473
  };
@@ -578,8 +574,11 @@ function exploreReducer(
578
574
  **/
579
575
  case ExploreActionKind.SelectEntityType: {
580
576
  if (payload === state.tabValue) {
581
- // Update meta to match command "REPLACE_TO_FILTERS" - facilitates navigation to filters on return back to entity from elsewhere.
582
- return { ...state, meta: { command: META_COMMAND.REPLACE_TO_FILTERS } };
577
+ // Update meta to match command "STATE_TO_URL_REPLACE" - facilitates navigation to filters on return back to entity from elsewhere.
578
+ return {
579
+ ...state,
580
+ meta: { command: META_COMMAND.STATE_TO_URL_REPLACE },
581
+ };
583
582
  }
584
583
  const entityState = getEntityState(
585
584
  state,
@@ -594,7 +593,7 @@ function exploreReducer(
594
593
  filterState: entityState.filterState,
595
594
  listItems: [],
596
595
  loading: true,
597
- meta: { command: META_COMMAND.REPLACE_TO_FILTERS },
596
+ meta: { command: META_COMMAND.STATE_TO_URL_REPLACE },
598
597
  paginationState: { ...resetPage(state.paginationState), rows: 0 },
599
598
  rowPreview,
600
599
  tabValue: payload,
@@ -699,7 +698,7 @@ function exploreReducer(
699
698
  ),
700
699
  filterCount: getFilterCount(filterState),
701
700
  filterState,
702
- meta: { command: META_COMMAND.NAVIGATE_TO_FILTERS },
701
+ meta: { command: META_COMMAND.STATE_TO_URL_PUSH },
703
702
  paginationState: resetPage(state.paginationState),
704
703
  rowPreview,
705
704
  };
@@ -0,0 +1,25 @@
1
+ import Router, { NextRouter } from "next/router";
2
+ import { ExploreQueryState } from "./types";
3
+ import { buildQuery, stringifyQuery } from "./utils";
4
+
5
+ /**
6
+ * Updates the URL query parameters based on state.
7
+ * Pushes or replaces the query to the router.
8
+ * @param state - State -- partial explore state.
9
+ * @param currentQuery - Query -- current.
10
+ * @param method - "push" or "replace".
11
+ */
12
+ export function updateUrlFromState(
13
+ state: ExploreQueryState,
14
+ currentQuery: NextRouter["query"],
15
+ method: "push" | "replace" = "push"
16
+ ): void {
17
+ // Build the next query.
18
+ const query = buildQuery(state);
19
+
20
+ // Do nothing if the next query is the same as the current query.
21
+ if (stringifyQuery(query) === stringifyQuery(currentQuery)) return;
22
+
23
+ // Push or replace the query to the router.
24
+ Router[method]({ query }, undefined, { shallow: true });
25
+ }
@@ -0,0 +1,38 @@
1
+ import { useRouter } from "next/router";
2
+ import { useEffect, useMemo } from "react";
3
+ import { useExploreState } from "../../../../hooks/useExploreState";
4
+ import { clearMeta } from "../../../exploreState/actions/clearMeta/dispatch";
5
+ import { updateUrlFromState } from "./handlers";
6
+ import { META_COMMAND } from "./types";
7
+ import { getQueryState } from "./utils";
8
+
9
+ export const useMetaCommands = (): void => {
10
+ const { exploreDispatch, exploreState } = useExploreState();
11
+
12
+ // Router must be ready before executing any meta-command side effects.
13
+ const { isReady, query } = useRouter();
14
+
15
+ // Command.
16
+ const command = exploreState.meta?.command;
17
+
18
+ // Extract relevant state to update URL.
19
+ const state = useMemo(() => getQueryState(exploreState), [exploreState]);
20
+
21
+ useEffect(() => {
22
+ // Do nothing if the router is not ready.
23
+ if (!isReady) return;
24
+
25
+ switch (command) {
26
+ case META_COMMAND.STATE_TO_URL_PUSH:
27
+ updateUrlFromState(state, query);
28
+ exploreDispatch(clearMeta());
29
+ break;
30
+ case META_COMMAND.STATE_TO_URL_REPLACE:
31
+ updateUrlFromState(state, query, "replace");
32
+ exploreDispatch(clearMeta());
33
+ break;
34
+ default:
35
+ break;
36
+ }
37
+ }, [command, exploreDispatch, isReady, query, state]);
38
+ };
@@ -0,0 +1,13 @@
1
+ import { ExploreState } from "../../../exploreState";
2
+
3
+ export interface ExploreQueryState {
4
+ catalog: ExploreState["catalogState"];
5
+ entityListType: ExploreState["tabValue"];
6
+ ff: ExploreState["featureFlagState"];
7
+ filter: ExploreState["filterState"];
8
+ }
9
+
10
+ export enum META_COMMAND {
11
+ STATE_TO_URL_PUSH = "STATE_TO_URL_PUSH",
12
+ STATE_TO_URL_REPLACE = "STATE_TO_URL_REPLACE",
13
+ }
@@ -0,0 +1,69 @@
1
+ import { NextRouter } from "next/router";
2
+ import { ExploreState } from "../../../exploreState";
3
+ import { ExploreQueryState } from "./types";
4
+
5
+ /**
6
+ * Builds a query object from state.
7
+ * State values are expected to be undefined, string, or an array.
8
+ * Undefined values and empty arrays are not included in the query.
9
+ * @param state - State -- partial explore state.
10
+ * @returns A query object.
11
+ */
12
+ export function buildQuery(state: ExploreQueryState): NextRouter["query"] {
13
+ const query: NextRouter["query"] = {};
14
+
15
+ for (const [key, value] of Object.entries(state)) {
16
+ // Handle the undefined case.
17
+ if (value === undefined) continue;
18
+
19
+ // Handle the string case.
20
+ if (typeof value === "string") {
21
+ query[key] = value;
22
+ continue;
23
+ }
24
+
25
+ // Handle the array case.
26
+ if (value.length === 0) continue;
27
+ query[key] = JSON.stringify(value);
28
+ }
29
+
30
+ return query;
31
+ }
32
+
33
+ /**
34
+ * Extracts URL-relevant values from the ExploreState for query parameter synchronization.
35
+ *
36
+ * This function maps specific properties from the full ExploreState to the
37
+ * ExploreQueryState interface, which contains only the subset of state that
38
+ * should be synchronized with the URL.
39
+ *
40
+ * The extracted properties are:
41
+ * - catalog: Current catalog selection (string | undefined)
42
+ * - entityListType: Current active tab value (string)
43
+ * - ff: Feature flag state (string | undefined)
44
+ * - filter: Applied filters (SelectedFilter[])
45
+ *
46
+ * @param exploreState - Explore state.
47
+ * @returns Subset of state used for URL query parameters.
48
+ */
49
+ export function getQueryState(exploreState: ExploreState): ExploreQueryState {
50
+ return {
51
+ catalog: exploreState.catalogState,
52
+ entityListType: exploreState.tabValue,
53
+ ff: exploreState.featureFlagState,
54
+ filter: exploreState.filterState,
55
+ };
56
+ }
57
+
58
+ /**
59
+ * Returns a sorted string representation of a query object.
60
+ * @param query - Query object.
61
+ * @returns Sorted string representation of the query object.
62
+ */
63
+ export function stringifyQuery(query: NextRouter["query"]): string {
64
+ return JSON.stringify(
65
+ Object.keys(query)
66
+ .sort()
67
+ .reduce((acc, key) => ({ ...acc, [key]: query[key] }), {})
68
+ );
69
+ }
@@ -0,0 +1,29 @@
1
+ import React, { ReactNode } from "react";
2
+ import { useMetaCommands } from "./hooks/UseMetaCommands/hook";
3
+
4
+ /**
5
+ * Synchronizes the ExploreView component's state with the Next.js URL.
6
+ *
7
+ * Listens for reducer meta-commands (`STATE_TO_URL_PUSH`/`STATE_TO_URL_REPLACE`)
8
+ * and updates the URL accordingly using router methods.
9
+ *
10
+ * Usage:
11
+ * ```tsx
12
+ * <ExploreStateProvider>
13
+ * <ExploreStateSyncProvider>
14
+ * <ExploreView />
15
+ * </ExploreStateSyncProvider>
16
+ * </ExploreStateProvider>
17
+ * ```
18
+ */
19
+
20
+ export function ExploreStateSyncProvider({
21
+ children,
22
+ }: {
23
+ children: ReactNode;
24
+ }): JSX.Element {
25
+ // Meta-command related side effects.
26
+ useMetaCommands();
27
+
28
+ return <>{children}</>;
29
+ }
@@ -35,6 +35,7 @@ import { useExploreState } from "../../hooks/useExploreState";
35
35
  import { useSummary } from "../../hooks/useSummary";
36
36
  import { ExploreActionKind } from "../../providers/exploreState";
37
37
  import { SELECT_CATEGORY_KEY } from "../../providers/exploreState/constants";
38
+ import { ExploreStateSyncProvider } from "../../providers/exploreStateSync/provider";
38
39
  import { TEST_IDS } from "../../tests/testIds";
39
40
  import { DESKTOP_SM } from "../../theme/common/breakpoints";
40
41
 
@@ -141,7 +142,7 @@ export const ExploreView = (props: ExploreViewProps): JSX.Element => {
141
142
  }, [entityListType, exploreDispatch]);
142
143
 
143
144
  return (
144
- <>
145
+ <ExploreStateSyncProvider>
145
146
  {categoryViews && !!categoryViews.length && (
146
147
  <Sidebar drawerOpen={isDrawerOpen} onDrawerClose={onCloseDrawer}>
147
148
  <SidebarTools data-testid={TEST_IDS.FILTER_CONTROLS}>
@@ -182,7 +183,7 @@ export const ExploreView = (props: ExploreViewProps): JSX.Element => {
182
183
  Tabs={<Tabs />}
183
184
  title={entityConfig.explorerTitle || explorerTitle}
184
185
  />
185
- </>
186
+ </ExploreStateSyncProvider>
186
187
  );
187
188
  };
188
189
 
@@ -1,13 +0,0 @@
1
- import { ExploreState } from "../../../exploreState";
2
- /**
3
- * Updates the URL query parameters for the entity list page based on the current explore state.
4
- * Pushes the query to the router.
5
- * @param exploreState - The current explore state.
6
- */
7
- export declare function navigateToFilters(exploreState: ExploreState): void;
8
- /**
9
- * Updates the URL query parameters for the entity list page based on the current explore state.
10
- * Replaces the query to the router.
11
- * @param exploreState - The current explore state.
12
- */
13
- export declare function replaceToFilters(exploreState: ExploreState): void;
@@ -1,24 +0,0 @@
1
- import Router from "next/router";
2
- import { buildQuery } from "./utils";
3
- /**
4
- * Updates the URL query parameters for the entity list page based on the current explore state.
5
- * Pushes the query to the router.
6
- * @param exploreState - The current explore state.
7
- */
8
- export function navigateToFilters(exploreState) {
9
- // Build the query object.
10
- const query = buildQuery(exploreState);
11
- // Push the query to the router.
12
- Router.push({ query }, undefined, { shallow: true });
13
- }
14
- /**
15
- * Updates the URL query parameters for the entity list page based on the current explore state.
16
- * Replaces the query to the router.
17
- * @param exploreState - The current explore state.
18
- */
19
- export function replaceToFilters(exploreState) {
20
- // Build the query object.
21
- const query = buildQuery(exploreState);
22
- // Replace the query to the router.
23
- Router.replace({ query }, undefined, { shallow: true });
24
- }
@@ -1,4 +0,0 @@
1
- export declare enum META_COMMAND {
2
- NAVIGATE_TO_FILTERS = "NAVIGATE_TO_FILTERS",
3
- REPLACE_TO_FILTERS = "REPLACE_TO_FILTERS"
4
- }
@@ -1,5 +0,0 @@
1
- export var META_COMMAND;
2
- (function (META_COMMAND) {
3
- META_COMMAND["NAVIGATE_TO_FILTERS"] = "NAVIGATE_TO_FILTERS";
4
- META_COMMAND["REPLACE_TO_FILTERS"] = "REPLACE_TO_FILTERS";
5
- })(META_COMMAND || (META_COMMAND = {}));
@@ -1,2 +0,0 @@
1
- import { ExploreStateContextProps } from "../../../exploreState";
2
- export declare const useMetaCommands: ({ exploreDispatch, exploreState, }: ExploreStateContextProps) => void;
@@ -1,21 +0,0 @@
1
- import { useEffect } from "react";
2
- import { clearMeta } from "../../actions/clearMeta/dispatch";
3
- import { navigateToFilters, replaceToFilters } from "./actions";
4
- import { META_COMMAND } from "./types";
5
- export const useMetaCommands = ({ exploreDispatch, exploreState, }) => {
6
- useEffect(() => {
7
- const command = exploreState.meta?.command;
8
- switch (command) {
9
- case META_COMMAND.NAVIGATE_TO_FILTERS:
10
- navigateToFilters(exploreState);
11
- exploreDispatch(clearMeta());
12
- break;
13
- case META_COMMAND.REPLACE_TO_FILTERS:
14
- replaceToFilters(exploreState);
15
- exploreDispatch(clearMeta());
16
- break;
17
- default:
18
- break;
19
- }
20
- }, [exploreDispatch, exploreState]);
21
- };
@@ -1,9 +0,0 @@
1
- import { UrlObject } from "url";
2
- import { ExploreState } from "../../../exploreState";
3
- /**
4
- * Builds a query object from the current explore state.
5
- * Contains catalog, feature flag, filter, and entity list type.
6
- * @param exploreState - The current explore state.
7
- * @returns A query object.
8
- */
9
- export declare function buildQuery(exploreState: ExploreState): UrlObject["query"];
@@ -1,25 +0,0 @@
1
- import { EXPLORE_URL_PARAMS } from "../../../exploreState/constants";
2
- /**
3
- * Builds a query object from the current explore state.
4
- * Contains catalog, feature flag, filter, and entity list type.
5
- * @param exploreState - The current explore state.
6
- * @returns A query object.
7
- */
8
- export function buildQuery(exploreState) {
9
- const query = {};
10
- // Entity list type.
11
- query["entityListType"] = exploreState.tabValue;
12
- // Filter state.
13
- if (exploreState.filterState.length > 0) {
14
- query[EXPLORE_URL_PARAMS.FILTER] = JSON.stringify(exploreState.filterState);
15
- }
16
- // Catalog state.
17
- if (exploreState.catalogState) {
18
- query[EXPLORE_URL_PARAMS.CATALOG] = exploreState.catalogState;
19
- }
20
- // Feature flag state.
21
- if (exploreState.featureFlagState) {
22
- query[EXPLORE_URL_PARAMS.FEATURE_FLAG] = exploreState.featureFlagState;
23
- }
24
- return query;
25
- }
@@ -1,29 +0,0 @@
1
- import Router from "next/router";
2
- import { ExploreState } from "../../../exploreState";
3
- import { buildQuery } from "./utils";
4
-
5
- /**
6
- * Updates the URL query parameters for the entity list page based on the current explore state.
7
- * Pushes the query to the router.
8
- * @param exploreState - The current explore state.
9
- */
10
- export function navigateToFilters(exploreState: ExploreState): void {
11
- // Build the query object.
12
- const query = buildQuery(exploreState);
13
-
14
- // Push the query to the router.
15
- Router.push({ query }, undefined, { shallow: true });
16
- }
17
-
18
- /**
19
- * Updates the URL query parameters for the entity list page based on the current explore state.
20
- * Replaces the query to the router.
21
- * @param exploreState - The current explore state.
22
- */
23
- export function replaceToFilters(exploreState: ExploreState): void {
24
- // Build the query object.
25
- const query = buildQuery(exploreState);
26
-
27
- // Replace the query to the router.
28
- Router.replace({ query }, undefined, { shallow: true });
29
- }
@@ -1,4 +0,0 @@
1
- export enum META_COMMAND {
2
- NAVIGATE_TO_FILTERS = "NAVIGATE_TO_FILTERS",
3
- REPLACE_TO_FILTERS = "REPLACE_TO_FILTERS",
4
- }
@@ -1,27 +0,0 @@
1
- import { useEffect } from "react";
2
- import { ExploreStateContextProps } from "../../../exploreState";
3
- import { clearMeta } from "../../actions/clearMeta/dispatch";
4
- import { navigateToFilters, replaceToFilters } from "./actions";
5
- import { META_COMMAND } from "./types";
6
-
7
- export const useMetaCommands = ({
8
- exploreDispatch,
9
- exploreState,
10
- }: ExploreStateContextProps): void => {
11
- useEffect(() => {
12
- const command = exploreState.meta?.command;
13
-
14
- switch (command) {
15
- case META_COMMAND.NAVIGATE_TO_FILTERS:
16
- navigateToFilters(exploreState);
17
- exploreDispatch(clearMeta());
18
- break;
19
- case META_COMMAND.REPLACE_TO_FILTERS:
20
- replaceToFilters(exploreState);
21
- exploreDispatch(clearMeta());
22
- break;
23
- default:
24
- break;
25
- }
26
- }, [exploreDispatch, exploreState]);
27
- };
@@ -1,33 +0,0 @@
1
- import { UrlObject } from "url";
2
- import { ExploreState } from "../../../exploreState";
3
- import { EXPLORE_URL_PARAMS } from "../../../exploreState/constants";
4
-
5
- /**
6
- * Builds a query object from the current explore state.
7
- * Contains catalog, feature flag, filter, and entity list type.
8
- * @param exploreState - The current explore state.
9
- * @returns A query object.
10
- */
11
- export function buildQuery(exploreState: ExploreState): UrlObject["query"] {
12
- const query: UrlObject["query"] = {};
13
-
14
- // Entity list type.
15
- query["entityListType"] = exploreState.tabValue;
16
-
17
- // Filter state.
18
- if (exploreState.filterState.length > 0) {
19
- query[EXPLORE_URL_PARAMS.FILTER] = JSON.stringify(exploreState.filterState);
20
- }
21
-
22
- // Catalog state.
23
- if (exploreState.catalogState) {
24
- query[EXPLORE_URL_PARAMS.CATALOG] = exploreState.catalogState;
25
- }
26
-
27
- // Feature flag state.
28
- if (exploreState.featureFlagState) {
29
- query[EXPLORE_URL_PARAMS.FEATURE_FLAG] = exploreState.featureFlagState;
30
- }
31
-
32
- return query;
33
- }