@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.
- package/lib/components/Links/components/Link/components/ExploreViewLink/exploreViewLink.js +13 -1
- package/lib/components/Table/table.js +1 -1
- package/lib/config/entities.d.ts +1 -1
- package/lib/providers/exploreState/initializer/utils.js +1 -2
- package/lib/providers/exploreState/payloads/entities.d.ts +1 -0
- package/lib/providers/exploreState.js +3 -2
- package/package.json +1 -1
- package/src/components/Links/components/Link/components/ExploreViewLink/exploreViewLink.tsx +17 -1
- package/src/components/Table/table.tsx +1 -1
- package/src/config/entities.ts +1 -1
- package/src/providers/exploreState/initializer/utils.ts +1 -2
- package/src/providers/exploreState/payloads/entities.ts +1 -0
- package/src/providers/exploreState.tsx +8 -2
|
@@ -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:
|
|
113
|
+
enableMultiSort: clientFiltering,
|
|
114
114
|
enableRowSelection,
|
|
115
115
|
enableSorting: true,
|
|
116
116
|
enableSortingRemoval: false,
|
package/lib/config/entities.d.ts
CHANGED
|
@@ -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
|
-
|
|
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,
|
|
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;
|
|
@@ -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,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:
|
|
156
|
+
enableMultiSort: clientFiltering,
|
|
157
157
|
enableRowSelection,
|
|
158
158
|
enableSorting: true, // client-side filtering.
|
|
159
159
|
enableSortingRemoval: false, // client-side filtering.
|
package/src/config/entities.ts
CHANGED
|
@@ -73,8 +73,7 @@ function buildSavedFilterByCategoryValueKey(
|
|
|
73
73
|
if (!savedFilters) return;
|
|
74
74
|
const savedFilterByCategoryValueKey: SavedFilterByCategoryValueKey =
|
|
75
75
|
new Map();
|
|
76
|
-
for (const { filters,
|
|
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;
|
|
@@ -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:
|
|
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
|
/**
|