@databiosphere/findable-ui 2.0.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/lib/components/Filter/components/FilterLabel/filterLabel.styles.js +1 -2
  2. package/lib/components/Filter/components/Filters/filters.d.ts +1 -1
  3. package/lib/components/Filter/components/Filters/filters.js +11 -1
  4. package/lib/components/Filter/components/Filters/filters.styles.d.ts +5 -0
  5. package/lib/components/Filter/components/Filters/filters.styles.js +15 -2
  6. package/lib/components/Filter/components/VariableSizeListItem/variableSizeListItem.js +2 -1
  7. package/lib/config/entities.d.ts +7 -1
  8. package/lib/providers/exploreState/constants.d.ts +3 -3
  9. package/lib/providers/exploreState/constants.js +3 -26
  10. package/lib/providers/exploreState/entities.d.ts +10 -3
  11. package/lib/providers/exploreState/initializer/constants.js +2 -0
  12. package/lib/providers/exploreState/initializer/utils.js +63 -4
  13. package/lib/providers/exploreState/payloads/entities.d.ts +8 -0
  14. package/lib/providers/exploreState/utils.d.ts +42 -10
  15. package/lib/providers/exploreState/utils.js +75 -13
  16. package/lib/providers/exploreState.d.ts +12 -4
  17. package/lib/providers/exploreState.js +30 -4
  18. package/lib/views/ExploreView/exploreView.js +14 -8
  19. package/package.json +1 -1
  20. package/src/components/Filter/components/FilterLabel/filterLabel.styles.ts +1 -2
  21. package/src/components/Filter/components/Filters/filters.styles.ts +19 -1
  22. package/src/components/Filter/components/Filters/filters.tsx +23 -4
  23. package/src/components/Filter/components/VariableSizeListItem/variableSizeListItem.tsx +6 -3
  24. package/src/config/entities.ts +11 -1
  25. package/src/providers/exploreState/constants.ts +3 -0
  26. package/src/providers/exploreState/entities.ts +20 -2
  27. package/src/providers/exploreState/initializer/constants.ts +2 -0
  28. package/src/providers/exploreState/initializer/utils.ts +73 -2
  29. package/src/providers/exploreState/payloads/entities.ts +9 -0
  30. package/src/providers/exploreState/utils.ts +104 -20
  31. package/src/providers/exploreState.tsx +67 -10
  32. package/src/views/ExploreView/exploreView.tsx +16 -8
@@ -8,7 +8,7 @@ import React, {
8
8
  useState,
9
9
  } from "react";
10
10
  import { AzulSearchIndex } from "../apis/azul/common/entities";
11
- import { SelectCategory, SelectedFilter } from "../common/entities";
11
+ import { SelectCategoryView, SelectedFilter } from "../common/entities";
12
12
  import { CategoryGroup, SiteConfig } from "../config/entities";
13
13
  import { useAuthentication } from "../hooks/useAuthentication/useAuthentication";
14
14
  import {
@@ -27,6 +27,7 @@ import {
27
27
  } from "./exploreState/initializer/constants";
28
28
  import { initReducerArguments } from "./exploreState/initializer/utils";
29
29
  import {
30
+ ApplySavedFilterPayload,
30
31
  PaginateTablePayload,
31
32
  ProcessExploreResponsePayload,
32
33
  ProcessRelatedResponsePayload,
@@ -37,12 +38,15 @@ import {
37
38
  UpdateSortingPayload,
38
39
  } from "./exploreState/payloads/entities";
39
40
  import {
40
- getEntityCategoryConfigs,
41
+ buildEntityStateSavedFilterState,
42
+ buildNextSavedFilterState,
41
43
  getEntityCategoryGroupConfigKey,
42
44
  getEntityState,
45
+ getEntityStateSavedSorting,
43
46
  getFilterCount,
44
47
  resetPage,
45
48
  updateEntityPageState,
49
+ updateEntityPageStateSorting,
46
50
  updateEntityStateByCategoryGroupConfigKey,
47
51
  } from "./exploreState/utils";
48
52
 
@@ -70,7 +74,7 @@ export interface ExploreContext {
70
74
  export type ExploreState = {
71
75
  catalogState: CatalogState;
72
76
  categoryGroups?: CategoryGroup[];
73
- categoryViews: SelectCategory[];
77
+ categoryViews: SelectCategoryView[];
74
78
  entityPageState: EntityPageStateMapper;
75
79
  entityStateByCategoryGroupConfigKey: EntityStateByCategoryGroupConfigKey;
76
80
  featureFlagState: FeatureFlagState;
@@ -218,6 +222,7 @@ export function ExploreStateProvider({
218
222
  * Explore action kind.
219
223
  */
220
224
  export enum ExploreActionKind {
225
+ ApplySavedFilter = "APPLY_SAVED_FILTER",
221
226
  ClearFilters = "CLEAR_FILTERS",
222
227
  PaginateTable = "PAGINATE_TABLE",
223
228
  ProcessExploreResponse = "PROCESS_EXPLORE_RESPONSE",
@@ -235,6 +240,7 @@ export enum ExploreActionKind {
235
240
  * Explore action.
236
241
  */
237
242
  export type ExploreAction =
243
+ | ApplySavedFilterAction
238
244
  | ClearFiltersAction
239
245
  | PaginateTableAction
240
246
  | ProcessExploreResponseAction
@@ -247,6 +253,14 @@ export type ExploreAction =
247
253
  | UpdateFilterAction
248
254
  | UpdateSortingAction;
249
255
 
256
+ /**
257
+ * Apply saved filter action.
258
+ */
259
+ type ApplySavedFilterAction = {
260
+ payload: ApplySavedFilterPayload;
261
+ type: ExploreActionKind.ApplySavedFilter;
262
+ };
263
+
250
264
  /**
251
265
  * Clear filters action.
252
266
  */
@@ -351,13 +365,48 @@ function exploreReducer(
351
365
  const { config, entityList } = exploreContext;
352
366
 
353
367
  switch (type) {
368
+ /**
369
+ * Apply saved filter
370
+ **/
371
+ case ExploreActionKind.ApplySavedFilter: {
372
+ const filterState = buildNextSavedFilterState(
373
+ state,
374
+ payload.selectedValue,
375
+ payload.selected
376
+ );
377
+ const savedFilterState = buildEntityStateSavedFilterState(
378
+ payload.categoryKey,
379
+ payload.selectedValue,
380
+ payload.selected
381
+ );
382
+ const savedSorting = getEntityStateSavedSorting(
383
+ state,
384
+ payload.selectedValue,
385
+ payload.selected
386
+ );
387
+ updateEntityStateByCategoryGroupConfigKey(state, {
388
+ filterState,
389
+ savedFilterState,
390
+ });
391
+ return {
392
+ ...state,
393
+ entityPageState: updateEntityPageStateSorting(state, savedSorting),
394
+ filterCount: getFilterCount(filterState),
395
+ filterState,
396
+ paginationState: resetPage(state.paginationState),
397
+ };
398
+ }
354
399
  /**
355
400
  * Clear all filters
356
401
  **/
357
402
  case ExploreActionKind.ClearFilters: {
358
403
  const filterCount = 0;
359
404
  const filterState: SelectedFilter[] = [];
360
- updateEntityStateByCategoryGroupConfigKey(state, { filterState });
405
+ const savedFilterState: SelectedFilter[] = [];
406
+ updateEntityStateByCategoryGroupConfigKey(state, {
407
+ filterState,
408
+ savedFilterState,
409
+ });
361
410
  return {
362
411
  ...state,
363
412
  filterCount,
@@ -386,11 +435,15 @@ function exploreReducer(
386
435
  * Process explore response
387
436
  **/
388
437
  case ExploreActionKind.ProcessExploreResponse: {
438
+ const entityState = getEntityState(state);
389
439
  const nextCategoryViews = payload.selectCategories
390
440
  ? buildCategoryViews(
391
- payload.selectCategories,
392
- getEntityCategoryConfigs(state),
393
- state.filterState
441
+ [
442
+ ...payload.selectCategories,
443
+ ...entityState.savedSelectCategories, // "savedFilter" select categories are built from config at reducer initialization.
444
+ ],
445
+ entityState.categoryConfigs,
446
+ [...state.filterState, ...entityState.savedFilterState]
394
447
  )
395
448
  : state.categoryViews;
396
449
  updateEntityStateByCategoryGroupConfigKey(state, {
@@ -441,8 +494,8 @@ function exploreReducer(
441
494
  return state;
442
495
  }
443
496
  const entityState = getEntityState(
444
- getEntityCategoryGroupConfigKey(payload, state.entityPageState),
445
- state
497
+ state,
498
+ getEntityCategoryGroupConfigKey(payload, state.entityPageState)
446
499
  );
447
500
  return {
448
501
  ...state,
@@ -476,7 +529,11 @@ function exploreReducer(
476
529
  payload.selectedValue,
477
530
  payload.selected
478
531
  );
479
- updateEntityStateByCategoryGroupConfigKey(state, { filterState });
532
+ const savedFilterState: SelectedFilter[] = []; // Clear saved filter state.
533
+ updateEntityStateByCategoryGroupConfigKey(state, {
534
+ filterState,
535
+ savedFilterState,
536
+ });
480
537
  return {
481
538
  ...state,
482
539
  filterCount: getFilterCount(filterState),
@@ -41,6 +41,7 @@ import { useEntityListRelatedView } from "../../hooks/useEntityListRelatedView";
41
41
  import { useExploreState } from "../../hooks/useExploreState";
42
42
  import { useSummary } from "../../hooks/useSummary";
43
43
  import { ExploreActionKind, ExploreState } from "../../providers/exploreState";
44
+ import { SELECT_CATEGORY_KEY } from "../../providers/exploreState/constants";
44
45
  import { DESKTOP_SM } from "../../theme/common/breakpoints";
45
46
 
46
47
  export type ExploreViewProps = AzulEntitiesStaticResponse;
@@ -111,13 +112,18 @@ export const ExploreView = (props: ExploreViewProps): JSX.Element => {
111
112
  categorySection?: string,
112
113
  searchTerm?: string
113
114
  ): void => {
115
+ const dispatchType =
116
+ categoryKey === SELECT_CATEGORY_KEY.SAVED_FILTERS
117
+ ? ExploreActionKind.ApplySavedFilter
118
+ : ExploreActionKind.UpdateFilter;
119
+
114
120
  exploreDispatch({
115
121
  payload: {
116
122
  categoryKey,
117
123
  selected,
118
124
  selectedValue: selectedCategoryValue,
119
125
  },
120
- type: ExploreActionKind.UpdateFilter,
126
+ type: dispatchType,
121
127
  });
122
128
 
123
129
  trackingConfig?.trackFilterApplied?.({
@@ -226,23 +232,25 @@ function buildCategoryFilters(
226
232
  if (!categoryGroups) {
227
233
  return [{ categoryViews: selectCategoryViews }];
228
234
  }
229
- return categoryGroups.map(({ categoryConfigs, label }) => {
235
+ return categoryGroups.reduce((accGroups, { categoryConfigs, label }) => {
230
236
  // Grab the category views for the configured grouped categories.
231
237
  const categoryViews = categoryConfigs.reduce(
232
- (acc, { key: categoryKey }) => {
238
+ (accViews, { key: categoryKey }) => {
233
239
  const categoryView = selectCategoryViews.find(
234
240
  ({ key }) => key === categoryKey
235
241
  );
236
242
  if (categoryView) {
237
- acc.push(categoryView);
243
+ accViews.push(categoryView);
238
244
  }
239
- return acc;
245
+ return accViews;
240
246
  },
241
247
  [] as SelectCategoryView[]
242
248
  );
243
- // Return the configured label and category views.
244
- return { categoryViews, label };
245
- });
249
+ if (categoryViews.length > 0) {
250
+ accGroups.push({ categoryViews, label });
251
+ }
252
+ return accGroups;
253
+ }, [] as CategoryFilter[]);
246
254
  }
247
255
 
248
256
  /**