@databiosphere/findable-ui 32.0.0 → 32.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 (67) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +16 -0
  3. package/lib/components/Index/index.js +1 -1
  4. package/lib/components/Index/table/hook.d.ts +2 -2
  5. package/lib/components/Index/table/hook.js +5 -2
  6. package/lib/components/Index/table/types.d.ts +3 -0
  7. package/lib/hooks/useEntityList.js +1 -7
  8. package/lib/hooks/useURLFilterParams.d.ts +1 -0
  9. package/lib/hooks/useURLFilterParams.js +1 -0
  10. package/lib/hooks/useUpdateURLSearchParams.d.ts +1 -0
  11. package/lib/hooks/useUpdateURLSearchParams.js +1 -0
  12. package/lib/providers/exploreState/actions/clearMeta/action.d.ts +9 -0
  13. package/lib/providers/exploreState/actions/clearMeta/action.js +12 -0
  14. package/lib/providers/exploreState/actions/clearMeta/dispatch.d.ts +6 -0
  15. package/lib/providers/exploreState/actions/clearMeta/dispatch.js +11 -0
  16. package/lib/providers/exploreState/actions/clearMeta/types.d.ts +6 -0
  17. package/lib/providers/exploreState/actions/clearMeta/types.js +1 -0
  18. package/lib/providers/exploreState/actions/syncStateFromUrl/action.d.ts +10 -0
  19. package/lib/providers/exploreState/actions/syncStateFromUrl/action.js +25 -0
  20. package/lib/providers/exploreState/actions/syncStateFromUrl/dispatch.d.ts +7 -0
  21. package/lib/providers/exploreState/actions/syncStateFromUrl/dispatch.js +12 -0
  22. package/lib/providers/exploreState/actions/syncStateFromUrl/types.d.ts +8 -0
  23. package/lib/providers/exploreState/actions/syncStateFromUrl/types.js +1 -0
  24. package/lib/providers/exploreState/actions/syncStateFromUrl/utils.d.ts +9 -0
  25. package/lib/providers/exploreState/actions/syncStateFromUrl/utils.js +23 -0
  26. package/lib/providers/exploreState/constants.d.ts +5 -0
  27. package/lib/providers/exploreState/constants.js +5 -0
  28. package/lib/providers/exploreState/entities.d.ts +4 -0
  29. package/lib/providers/exploreState/hooks/UseBeforePopState/useBeforePopState.d.ts +18 -0
  30. package/lib/providers/exploreState/hooks/UseBeforePopState/useBeforePopState.js +41 -0
  31. package/lib/providers/exploreState/hooks/UseBeforePopState/utils.d.ts +23 -0
  32. package/lib/providers/exploreState/hooks/UseBeforePopState/utils.js +68 -0
  33. package/lib/providers/exploreState/hooks/UseMetaCommands/actions.d.ts +13 -0
  34. package/lib/providers/exploreState/hooks/UseMetaCommands/actions.js +24 -0
  35. package/lib/providers/exploreState/hooks/UseMetaCommands/types.d.ts +4 -0
  36. package/lib/providers/exploreState/hooks/UseMetaCommands/types.js +5 -0
  37. package/lib/providers/exploreState/hooks/UseMetaCommands/useMetaCommands.d.ts +2 -0
  38. package/lib/providers/exploreState/hooks/UseMetaCommands/useMetaCommands.js +21 -0
  39. package/lib/providers/exploreState/hooks/UseMetaCommands/utils.d.ts +9 -0
  40. package/lib/providers/exploreState/hooks/UseMetaCommands/utils.js +25 -0
  41. package/lib/providers/exploreState/initializer/constants.js +1 -0
  42. package/lib/providers/exploreState.d.ts +7 -2
  43. package/lib/providers/exploreState.js +36 -1
  44. package/package.json +1 -1
  45. package/src/components/Index/index.tsx +1 -1
  46. package/src/components/Index/table/hook.ts +8 -3
  47. package/src/components/Index/table/types.ts +4 -0
  48. package/src/hooks/useEntityList.ts +1 -14
  49. package/src/hooks/useURLFilterParams.ts +1 -0
  50. package/src/hooks/useUpdateURLSearchParams.ts +1 -0
  51. package/src/providers/exploreState/actions/clearMeta/action.ts +18 -0
  52. package/src/providers/exploreState/actions/clearMeta/dispatch.ts +13 -0
  53. package/src/providers/exploreState/actions/clearMeta/types.ts +8 -0
  54. package/src/providers/exploreState/actions/syncStateFromUrl/action.ts +44 -0
  55. package/src/providers/exploreState/actions/syncStateFromUrl/dispatch.ts +16 -0
  56. package/src/providers/exploreState/actions/syncStateFromUrl/types.ts +13 -0
  57. package/src/providers/exploreState/actions/syncStateFromUrl/utils.ts +31 -0
  58. package/src/providers/exploreState/constants.ts +6 -0
  59. package/src/providers/exploreState/entities.ts +5 -0
  60. package/src/providers/exploreState/hooks/UseBeforePopState/useBeforePopState.ts +46 -0
  61. package/src/providers/exploreState/hooks/UseBeforePopState/utils.ts +93 -0
  62. package/src/providers/exploreState/hooks/UseMetaCommands/actions.ts +29 -0
  63. package/src/providers/exploreState/hooks/UseMetaCommands/types.ts +4 -0
  64. package/src/providers/exploreState/hooks/UseMetaCommands/useMetaCommands.ts +27 -0
  65. package/src/providers/exploreState/hooks/UseMetaCommands/utils.ts +33 -0
  66. package/src/providers/exploreState/initializer/constants.ts +1 -0
  67. package/src/providers/exploreState.tsx +44 -1
@@ -0,0 +1,27 @@
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
+ };
@@ -0,0 +1,33 @@
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
+ }
@@ -36,6 +36,7 @@ export const INITIAL_STATE: ExploreState = {
36
36
  filterState: [],
37
37
  listItems: [],
38
38
  loading: true,
39
+ meta: null,
39
40
  paginationState: DEFAULT_PAGINATION_STATE,
40
41
  rowPreview: undefined,
41
42
  tabValue: "",
@@ -20,6 +20,10 @@ import {
20
20
  } from "../hooks/useCategoryFilter";
21
21
  import { useConfig } from "../hooks/useConfig";
22
22
  import { useURLFilterParams } from "../hooks/useURLFilterParams";
23
+ import { clearMetaAction } from "./exploreState/actions/clearMeta/action";
24
+ import { ClearMetaAction } from "./exploreState/actions/clearMeta/types";
25
+ import { syncStateFromUrlAction } from "./exploreState/actions/syncStateFromUrl/action";
26
+ import { SyncStateFromUrlAction } from "./exploreState/actions/syncStateFromUrl/types";
23
27
  import { updateGroupingAction } from "./exploreState/actions/updateGrouping/action";
24
28
  import { UpdateGroupingAction } from "./exploreState/actions/updateGrouping/types";
25
29
  import { updateColumnVisibilityAction } from "./exploreState/actions/updateVisibility/action";
@@ -28,7 +32,11 @@ import {
28
32
  EntityPageStateMapper,
29
33
  EntityStateByCategoryGroupConfigKey,
30
34
  ListItem,
35
+ Meta,
31
36
  } from "./exploreState/entities";
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";
32
40
  import {
33
41
  DEFAULT_PAGINATION_STATE,
34
42
  INITIAL_STATE,
@@ -87,6 +95,7 @@ export type ExploreState = {
87
95
  filterState: SelectedFilter[];
88
96
  listItems: ListItems;
89
97
  loading: boolean;
98
+ meta: Meta | null;
90
99
  paginationState: PaginationState;
91
100
  rowPreview: RowPreviewState;
92
101
  tabValue: string;
@@ -206,6 +215,12 @@ export function ExploreStateProvider({
206
215
  });
207
216
  }, [exploreDispatch, token]);
208
217
 
218
+ // Meta-command related side effects.
219
+ useMetaCommands({ exploreDispatch, exploreState });
220
+
221
+ // Before pop state related side effects (forward / backward navigation by browser buttons).
222
+ useBeforePopState({ exploreDispatch, exploreState });
223
+
209
224
  return (
210
225
  <ExploreStateContext.Provider value={exploreContextValue}>
211
226
  {children}
@@ -219,12 +234,14 @@ export function ExploreStateProvider({
219
234
  export enum ExploreActionKind {
220
235
  ApplySavedFilter = "APPLY_SAVED_FILTER",
221
236
  ClearFilters = "CLEAR_FILTERS",
237
+ ClearMeta = "CLEAR_META",
222
238
  PaginateTable = "PAGINATE_TABLE",
223
239
  PatchExploreResponse = "PATCH_EXPLORE_RESPONSE",
224
240
  ProcessExploreResponse = "PROCESS_EXPLORE_RESPONSE",
225
241
  ResetExploreResponse = "RESET_EXPLORE_RESPONSE",
226
242
  ResetState = "RESET_STATE",
227
243
  SelectEntityType = "SELECT_ENTITY_TYPE",
244
+ SyncStateFromUrl = "SYNC_STATE_FROM_URL",
228
245
  UpdateColumnVisibility = "UPDATE_COLUMN_VISIBILITY",
229
246
  UpdateEntityFilters = "UPDATE_ENTITY_FILTERS",
230
247
  UpdateEntityViewAccess = "UPDATE_ENTITY_VIEW_ACCESS",
@@ -241,12 +258,14 @@ export enum ExploreActionKind {
241
258
  export type ExploreAction =
242
259
  | ApplySavedFilterAction
243
260
  | ClearFiltersAction
261
+ | ClearMetaAction
244
262
  | PaginateTableAction
245
263
  | PatchExploreResponseAction
246
264
  | ProcessExploreResponseAction
247
265
  | ResetExploreResponseAction
248
266
  | ResetStateAction
249
267
  | SelectEntityTypeAction
268
+ | SyncStateFromUrlAction
250
269
  | UpdateColumnVisibilityAction
251
270
  | UpdateEntityFiltersAction
252
271
  | UpdateEntityViewAccessAction
@@ -426,6 +445,7 @@ function exploreReducer(
426
445
  ),
427
446
  filterCount: getFilterCount(filterState),
428
447
  filterState,
448
+ meta: { command: META_COMMAND.NAVIGATE_TO_FILTERS },
429
449
  paginationState: resetPage(state.paginationState),
430
450
  rowPreview,
431
451
  };
@@ -451,10 +471,17 @@ function exploreReducer(
451
471
  ),
452
472
  filterCount,
453
473
  filterState,
474
+ meta: { command: META_COMMAND.NAVIGATE_TO_FILTERS },
454
475
  paginationState: resetPage(state.paginationState),
455
476
  rowPreview,
456
477
  };
457
478
  }
479
+ /**
480
+ * Clear meta
481
+ */
482
+ case ExploreActionKind.ClearMeta: {
483
+ return clearMetaAction(state, payload);
484
+ }
458
485
  /**
459
486
  * Paginate table
460
487
  **/
@@ -551,7 +578,8 @@ function exploreReducer(
551
578
  **/
552
579
  case ExploreActionKind.SelectEntityType: {
553
580
  if (payload === state.tabValue) {
554
- return state;
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 } };
555
583
  }
556
584
  const entityState = getEntityState(
557
585
  state,
@@ -566,11 +594,18 @@ function exploreReducer(
566
594
  filterState: entityState.filterState,
567
595
  listItems: [],
568
596
  loading: true,
597
+ meta: { command: META_COMMAND.REPLACE_TO_FILTERS },
569
598
  paginationState: { ...resetPage(state.paginationState), rows: 0 },
570
599
  rowPreview,
571
600
  tabValue: payload,
572
601
  };
573
602
  }
603
+ /**
604
+ * Sync state from URL.
605
+ */
606
+ case ExploreActionKind.SyncStateFromUrl: {
607
+ return syncStateFromUrlAction(state, payload);
608
+ }
574
609
  /**
575
610
  * Update column visibility
576
611
  **/
@@ -620,6 +655,13 @@ function exploreReducer(
620
655
  categoryGroupConfigKey
621
656
  ),
622
657
  rowPreview: closeRowPreview(state.rowPreview),
658
+ ...(payload.entityListType === state.tabValue
659
+ ? {
660
+ filterCount: getFilterCount(filterState),
661
+ filterState,
662
+ paginationState: { ...resetPage(state.paginationState), rows: 0 },
663
+ }
664
+ : {}),
623
665
  };
624
666
  }
625
667
  /**
@@ -657,6 +699,7 @@ function exploreReducer(
657
699
  ),
658
700
  filterCount: getFilterCount(filterState),
659
701
  filterState,
702
+ meta: { command: META_COMMAND.NAVIGATE_TO_FILTERS },
660
703
  paginationState: resetPage(state.paginationState),
661
704
  rowPreview,
662
705
  };