@databiosphere/findable-ui 4.0.0 → 5.0.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.
@@ -33,6 +33,7 @@ const useExploreState_1 = require("../../../../../../hooks/useExploreState");
33
33
  const exploreState_1 = require("../../../../../../providers/exploreState");
34
34
  const entities_1 = require("../../../../common/entities");
35
35
  const PARAM_FILTER = "filter";
36
+ const PARAM_SORTING = "sorting";
36
37
  const ExploreViewLink = ({ className, label, onClick, target = entities_1.ANCHOR_TARGET.SELF, url, }) => {
37
38
  const { exploreDispatch, exploreState } = (0, useExploreState_1.useExploreState)();
38
39
  if (!isValidExploreURL(url, exploreState)) {
@@ -41,8 +42,9 @@ const ExploreViewLink = ({ className, label, onClick, target = entities_1.ANCHOR
41
42
  const onNavigate = (0, react_1.useCallback)(() => {
42
43
  const entityListType = getEntityListType(url.href);
43
44
  const filters = getSelectedFilters(url.query);
45
+ const sorting = getSorting(url.query);
44
46
  exploreDispatch({
45
- payload: { entityListType, filters },
47
+ payload: { entityListType, filters, sorting },
46
48
  type: exploreState_1.ExploreActionKind.UpdateEntityFilters,
47
49
  });
48
50
  onClick === null || onClick === void 0 ? void 0 : onClick();
@@ -68,6 +70,16 @@ function getSelectedFilters(query) {
68
70
  const parsedQuery = JSON.parse(decodedQuery);
69
71
  return parsedQuery[PARAM_FILTER];
70
72
  }
73
+ /**
74
+ * Returns the sorting from the given query.
75
+ * @param query - Query.
76
+ * @returns sorting.
77
+ */
78
+ function getSorting(query) {
79
+ const decodedQuery = decodeURIComponent(query);
80
+ const parsedQuery = JSON.parse(decodedQuery);
81
+ return parsedQuery[PARAM_SORTING];
82
+ }
71
83
  /**
72
84
  * Returns true if the given value is a SelectedFilter.
73
85
  * @param value - Value.
@@ -110,7 +110,7 @@ const TableComponent = ({ columns, getRowId, initialState, items, listView, tota
110
110
  data: items,
111
111
  enableColumnFilters: true,
112
112
  enableFilters: true,
113
- enableMultiSort: false,
113
+ enableMultiSort: clientFiltering,
114
114
  enableRowSelection,
115
115
  enableSorting: true,
116
116
  enableSortingRemoval: false,
@@ -250,7 +250,7 @@ export interface Override {
250
250
  declare type RelatedSearchFunction = (searchKey: CategoryKey | undefined, resultKey: CategoryKey | undefined, selectedCategoryValues: SelectedFilterValue | undefined) => Promise<RelatedSearchResult | undefined>;
251
251
  export interface SavedFilter {
252
252
  filters: SelectedFilter[];
253
- sort?: ColumnSort;
253
+ sorting?: ColumnSort[];
254
254
  title: string;
255
255
  }
256
256
  /**
@@ -48,8 +48,7 @@ function buildSavedFilterByCategoryValueKey(savedFilters) {
48
48
  if (!savedFilters)
49
49
  return;
50
50
  const savedFilterByCategoryValueKey = new Map();
51
- for (const { filters, sort, title } of savedFilters) {
52
- const sorting = sort ? [sort] : undefined;
51
+ for (const { filters, sorting, title } of savedFilters) {
53
52
  savedFilterByCategoryValueKey.set(title, { filters, sorting, title });
54
53
  }
55
54
  return savedFilterByCategoryValueKey;
@@ -54,6 +54,7 @@ export declare type UpdateColumnVisibilityPayload = VisibilityState;
54
54
  export interface UpdateEntityFiltersPayload {
55
55
  entityListType: string;
56
56
  filters: SelectedFilter[];
57
+ sorting?: ColumnSort[];
57
58
  }
58
59
  /**
59
60
  * Update entity view access payload.
@@ -229,13 +229,14 @@ function exploreReducer(state, action, exploreContext) {
229
229
  * Update entity filters.
230
230
  */
231
231
  case ExploreActionKind.UpdateEntityFilters: {
232
- const { entityListType, filters: filterState } = payload;
232
+ const { entityListType, filters: filterState, sorting } = payload;
233
233
  const categoryGroupConfigKey = (0, utils_2.getEntityCategoryGroupConfigKey)(entityListType, state.entityPageState);
234
234
  (0, utils_2.updateEntityStateByCategoryGroupConfigKey)(state, {
235
235
  filterState,
236
236
  savedFilterState: [], // Clear saved filter state.
237
237
  }, categoryGroupConfigKey);
238
- return Object.assign(Object.assign({}, state), { entityPageState: (0, utils_2.resetRowSelection)(state, categoryGroupConfigKey) });
238
+ return Object.assign(Object.assign({}, state), { entityPageState: (0, utils_2.updateEntityPageState)(entityListType, Object.assign({}, (0, utils_2.resetRowSelection)(state, categoryGroupConfigKey)), { sorting } // Update sorting for the entity.
239
+ ) });
239
240
  }
240
241
  /**
241
242
  * Update entity view access
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@databiosphere/findable-ui",
3
- "version": "4.0.0",
3
+ "version": "5.0.0",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -1,3 +1,4 @@
1
+ import { ColumnSort } from "@tanstack/react-table";
1
2
  import Link from "next/link";
2
3
  import React, { useCallback } from "react";
3
4
  import { UrlObject } from "url";
@@ -14,6 +15,7 @@ import {
14
15
  import { LinkProps } from "../../link";
15
16
 
16
17
  const PARAM_FILTER = "filter";
18
+ const PARAM_SORTING = "sorting";
17
19
 
18
20
  export interface ExploreViewLinkProps
19
21
  extends Omit<LinkProps, "copyable" | "noWrap" | "url"> {
@@ -36,8 +38,9 @@ export const ExploreViewLink = ({
36
38
  const onNavigate = useCallback(() => {
37
39
  const entityListType = getEntityListType(url.href);
38
40
  const filters = getSelectedFilters(url.query);
41
+ const sorting = getSorting(url.query);
39
42
  exploreDispatch({
40
- payload: { entityListType, filters },
43
+ payload: { entityListType, filters, sorting },
41
44
  type: ExploreActionKind.UpdateEntityFilters,
42
45
  });
43
46
  onClick?.();
@@ -78,6 +81,19 @@ function getSelectedFilters(
78
81
  return parsedQuery[PARAM_FILTER];
79
82
  }
80
83
 
84
+ /**
85
+ * Returns the sorting from the given query.
86
+ * @param query - Query.
87
+ * @returns sorting.
88
+ */
89
+ function getSorting(
90
+ query: UrlObjectWithHrefAndQuery["query"]
91
+ ): ColumnSort[] | undefined {
92
+ const decodedQuery = decodeURIComponent(query);
93
+ const parsedQuery = JSON.parse(decodedQuery);
94
+ return parsedQuery[PARAM_SORTING];
95
+ }
96
+
81
97
  /**
82
98
  * Returns true if the given value is a SelectedFilter.
83
99
  * @param value - Value.
@@ -153,7 +153,7 @@ TableProps<T>): JSX.Element => {
153
153
  data: items,
154
154
  enableColumnFilters: true, // client-side filtering.
155
155
  enableFilters: true, // client-side filtering.
156
- enableMultiSort: false,
156
+ enableMultiSort: clientFiltering,
157
157
  enableRowSelection,
158
158
  enableSorting: true, // client-side filtering.
159
159
  enableSortingRemoval: false, // client-side filtering.
@@ -315,7 +315,7 @@ type RelatedSearchFunction = (
315
315
 
316
316
  export interface SavedFilter {
317
317
  filters: SelectedFilter[];
318
- sort?: ColumnSort;
318
+ sorting?: ColumnSort[];
319
319
  title: string;
320
320
  }
321
321
  /**
@@ -73,8 +73,7 @@ function buildSavedFilterByCategoryValueKey(
73
73
  if (!savedFilters) return;
74
74
  const savedFilterByCategoryValueKey: SavedFilterByCategoryValueKey =
75
75
  new Map();
76
- for (const { filters, sort, title } of savedFilters) {
77
- const sorting = sort ? [sort] : undefined;
76
+ for (const { filters, sorting, title } of savedFilters) {
78
77
  savedFilterByCategoryValueKey.set(title, { filters, sorting, title });
79
78
  }
80
79
  return savedFilterByCategoryValueKey;
@@ -78,6 +78,7 @@ export type UpdateColumnVisibilityPayload = VisibilityState;
78
78
  export interface UpdateEntityFiltersPayload {
79
79
  entityListType: string;
80
80
  filters: SelectedFilter[];
81
+ sorting?: ColumnSort[];
81
82
  }
82
83
  /**
83
84
  * Update entity view access payload.
@@ -601,7 +601,7 @@ function exploreReducer(
601
601
  * Update entity filters.
602
602
  */
603
603
  case ExploreActionKind.UpdateEntityFilters: {
604
- const { entityListType, filters: filterState } = payload;
604
+ const { entityListType, filters: filterState, sorting } = payload;
605
605
  const categoryGroupConfigKey = getEntityCategoryGroupConfigKey(
606
606
  entityListType,
607
607
  state.entityPageState
@@ -616,7 +616,13 @@ function exploreReducer(
616
616
  );
617
617
  return {
618
618
  ...state,
619
- entityPageState: resetRowSelection(state, categoryGroupConfigKey),
619
+ entityPageState: updateEntityPageState(
620
+ entityListType,
621
+ {
622
+ ...resetRowSelection(state, categoryGroupConfigKey), // Reset row selection for all entities with the same category group config key.
623
+ },
624
+ { sorting } // Update sorting for the entity.
625
+ ),
620
626
  };
621
627
  }
622
628
  /**