@databiosphere/findable-ui 3.0.0 → 3.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.
package/lib/config/entities.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TabProps as MTabProps, Theme, ThemeOptions } from "@mui/material";
|
|
2
2
|
import { ColumnSort } from "@tanstack/react-table";
|
|
3
3
|
import { JSXElementConstructor, ReactNode } from "react";
|
|
4
|
-
import { CategoryKey, SelectedFilter, SelectedFilterValue } from "../common/entities";
|
|
4
|
+
import { CategoryKey, SelectCategoryValueView, SelectedFilter, SelectedFilterValue } from "../common/entities";
|
|
5
5
|
import { HeroTitle } from "../components/common/Title/title";
|
|
6
6
|
import { FooterProps } from "../components/Layout/components/Footer/footer";
|
|
7
7
|
import { HeaderProps } from "../components/Layout/components/Header/header";
|
|
@@ -66,6 +66,7 @@ export interface CategoryGroup {
|
|
|
66
66
|
export interface CategoryConfig {
|
|
67
67
|
key: string;
|
|
68
68
|
label: string;
|
|
69
|
+
mapSelectCategoryValue?: (selectCategoryValue: SelectCategoryValueView) => SelectCategoryValueView;
|
|
69
70
|
}
|
|
70
71
|
/**
|
|
71
72
|
* Column configuration.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CategoryKey, CategoryValueKey, Filters, SelectCategory, SelectCategoryView } from "../common/entities";
|
|
1
|
+
import { CategoryKey, CategoryValueKey, Filters, SelectCategory, SelectCategoryValue, SelectCategoryView } from "../common/entities";
|
|
2
2
|
import { CategoryConfig } from "../config/entities";
|
|
3
3
|
/**
|
|
4
4
|
* State backing filter functionality and calculations. Converted to view model for display.
|
|
@@ -33,3 +33,9 @@ export declare function buildCategoryViews(categories: SelectCategory[], categor
|
|
|
33
33
|
* @returns New filter state generated from the current set of selected values and the newly selected value.
|
|
34
34
|
*/
|
|
35
35
|
export declare function buildNextFilterState(filterState: FilterState, categoryKey: CategoryKey, selectedValue: CategoryValueKey, selected: boolean): FilterState;
|
|
36
|
+
/**
|
|
37
|
+
* Default function returning select category value, unmodified.
|
|
38
|
+
* @param selectCategoryValue - Select category value.
|
|
39
|
+
* @returns original select category value.
|
|
40
|
+
*/
|
|
41
|
+
export declare function getSelectCategoryValue(selectCategoryValue: SelectCategoryValue): SelectCategoryValue;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildNextFilterState = exports.buildCategoryViews = void 0;
|
|
3
|
+
exports.getSelectCategoryValue = exports.buildNextFilterState = exports.buildCategoryViews = void 0;
|
|
4
4
|
const constants_1 = require("../common/constants");
|
|
5
5
|
/**
|
|
6
6
|
* Build the view-specific model of the given category value.
|
|
@@ -27,11 +27,13 @@ function buildCategoryValueView(categoryValue, categorySelectedFilter) {
|
|
|
27
27
|
* @returns Full built category value view, ready for display.
|
|
28
28
|
*/
|
|
29
29
|
function buildCategoryView(category, categoryValueViews, categoryConfigs) {
|
|
30
|
+
const categoryConfig = findCategoryConfig(category.key, categoryConfigs);
|
|
31
|
+
const mapSelectCategoryValue = (categoryConfig === null || categoryConfig === void 0 ? void 0 : categoryConfig.mapSelectCategoryValue) || getSelectCategoryValue;
|
|
30
32
|
return {
|
|
31
33
|
isDisabled: false,
|
|
32
34
|
key: category.key,
|
|
33
|
-
label: getCategoryLabel(category.key,
|
|
34
|
-
values: categoryValueViews,
|
|
35
|
+
label: getCategoryLabel(category.key, categoryConfig),
|
|
36
|
+
values: categoryValueViews.map(mapSelectCategoryValue),
|
|
35
37
|
};
|
|
36
38
|
}
|
|
37
39
|
/**
|
|
@@ -107,16 +109,33 @@ function getCategorySelectedFilter(categoryKey, filterState) {
|
|
|
107
109
|
/**
|
|
108
110
|
* Get the label for the given category key as per the config.
|
|
109
111
|
* @param key - Key of category to find label of.
|
|
110
|
-
* @param
|
|
112
|
+
* @param categoryConfig - Category.
|
|
111
113
|
* @returns the display value for the given category.
|
|
112
114
|
*/
|
|
113
|
-
function getCategoryLabel(key,
|
|
114
|
-
const categoryConfig = categoryConfigs.find((categoryConfig) => categoryConfig.key === key);
|
|
115
|
+
function getCategoryLabel(key, categoryConfig) {
|
|
115
116
|
if (!categoryConfig) {
|
|
116
117
|
return key;
|
|
117
118
|
}
|
|
118
119
|
return categoryConfig.label;
|
|
119
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Default function returning select category value, unmodified.
|
|
123
|
+
* @param selectCategoryValue - Select category value.
|
|
124
|
+
* @returns original select category value.
|
|
125
|
+
*/
|
|
126
|
+
function getSelectCategoryValue(selectCategoryValue) {
|
|
127
|
+
return selectCategoryValue;
|
|
128
|
+
}
|
|
129
|
+
exports.getSelectCategoryValue = getSelectCategoryValue;
|
|
130
|
+
/**
|
|
131
|
+
* Returns the category config for the given category config key.
|
|
132
|
+
* @param key - Category config key.
|
|
133
|
+
* @param categoryConfigs - Category configs.
|
|
134
|
+
* @returns category config.
|
|
135
|
+
*/
|
|
136
|
+
function findCategoryConfig(key, categoryConfigs) {
|
|
137
|
+
return categoryConfigs.find((categoryConfig) => categoryConfig.key === key);
|
|
138
|
+
}
|
|
120
139
|
/**
|
|
121
140
|
* Determine if given category value is selected.
|
|
122
141
|
* @param categoryValueKey - The key of the category value to check if selected in the filter state.
|
package/package.json
CHANGED
package/src/config/entities.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { ColumnSort } from "@tanstack/react-table";
|
|
|
3
3
|
import { JSXElementConstructor, ReactNode } from "react";
|
|
4
4
|
import {
|
|
5
5
|
CategoryKey,
|
|
6
|
+
SelectCategoryValueView,
|
|
6
7
|
SelectedFilter,
|
|
7
8
|
SelectedFilterValue,
|
|
8
9
|
} from "../common/entities";
|
|
@@ -77,6 +78,9 @@ export interface CategoryGroup {
|
|
|
77
78
|
export interface CategoryConfig {
|
|
78
79
|
key: string;
|
|
79
80
|
label: string;
|
|
81
|
+
mapSelectCategoryValue?: (
|
|
82
|
+
selectCategoryValue: SelectCategoryValueView
|
|
83
|
+
) => SelectCategoryValueView;
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
/**
|
|
@@ -73,11 +73,14 @@ function buildCategoryView(
|
|
|
73
73
|
categoryValueViews: SelectCategoryValueView[],
|
|
74
74
|
categoryConfigs: CategoryConfig[]
|
|
75
75
|
): SelectCategoryView {
|
|
76
|
+
const categoryConfig = findCategoryConfig(category.key, categoryConfigs);
|
|
77
|
+
const mapSelectCategoryValue =
|
|
78
|
+
categoryConfig?.mapSelectCategoryValue || getSelectCategoryValue;
|
|
76
79
|
return {
|
|
77
80
|
isDisabled: false,
|
|
78
81
|
key: category.key,
|
|
79
|
-
label: getCategoryLabel(category.key,
|
|
80
|
-
values: categoryValueViews,
|
|
82
|
+
label: getCategoryLabel(category.key, categoryConfig),
|
|
83
|
+
values: categoryValueViews.map(mapSelectCategoryValue),
|
|
81
84
|
};
|
|
82
85
|
}
|
|
83
86
|
|
|
@@ -192,22 +195,43 @@ function getCategorySelectedFilter(
|
|
|
192
195
|
/**
|
|
193
196
|
* Get the label for the given category key as per the config.
|
|
194
197
|
* @param key - Key of category to find label of.
|
|
195
|
-
* @param
|
|
198
|
+
* @param categoryConfig - Category.
|
|
196
199
|
* @returns the display value for the given category.
|
|
197
200
|
*/
|
|
198
201
|
function getCategoryLabel(
|
|
199
202
|
key: string,
|
|
200
|
-
|
|
203
|
+
categoryConfig?: CategoryConfig
|
|
201
204
|
): string {
|
|
202
|
-
const categoryConfig = categoryConfigs.find(
|
|
203
|
-
(categoryConfig) => categoryConfig.key === key
|
|
204
|
-
);
|
|
205
205
|
if (!categoryConfig) {
|
|
206
206
|
return key;
|
|
207
207
|
}
|
|
208
208
|
return categoryConfig.label;
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Default function returning select category value, unmodified.
|
|
213
|
+
* @param selectCategoryValue - Select category value.
|
|
214
|
+
* @returns original select category value.
|
|
215
|
+
*/
|
|
216
|
+
export function getSelectCategoryValue(
|
|
217
|
+
selectCategoryValue: SelectCategoryValue
|
|
218
|
+
): SelectCategoryValue {
|
|
219
|
+
return selectCategoryValue;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Returns the category config for the given category config key.
|
|
224
|
+
* @param key - Category config key.
|
|
225
|
+
* @param categoryConfigs - Category configs.
|
|
226
|
+
* @returns category config.
|
|
227
|
+
*/
|
|
228
|
+
function findCategoryConfig(
|
|
229
|
+
key: string,
|
|
230
|
+
categoryConfigs: CategoryConfig[]
|
|
231
|
+
): CategoryConfig | undefined {
|
|
232
|
+
return categoryConfigs.find((categoryConfig) => categoryConfig.key === key);
|
|
233
|
+
}
|
|
234
|
+
|
|
211
235
|
/**
|
|
212
236
|
* Determine if given category value is selected.
|
|
213
237
|
* @param categoryValueKey - The key of the category value to check if selected in the filter state.
|