fastapi-rtk 0.1.35 → 0.1.36
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/dist/core/cjs/Tables/NextGenDataGrid/hooks/useColumns/ColumnHeaderFilter.cjs +4 -0
- package/dist/core/cjs/Tables/NextGenDataGrid/hooks/useColumns/ColumnHeaderFilterInput/ColumnHeaderFilterInput.cjs +42 -15
- package/dist/core/cjs/Tables/NextGenDataGrid/hooks/useColumns/useColumns.cjs +4 -0
- package/dist/core/esm/Tables/NextGenDataGrid/hooks/useColumns/ColumnHeaderFilter.mjs +4 -0
- package/dist/core/esm/Tables/NextGenDataGrid/hooks/useColumns/ColumnHeaderFilterInput/ColumnHeaderFilterInput.mjs +42 -15
- package/dist/core/esm/Tables/NextGenDataGrid/hooks/useColumns/useColumns.mjs +4 -0
- package/dist/core/lib/Tables/NextGenDataGrid/NextGenDataGrid.d.ts +8 -0
- package/dist/core/lib/Tables/NextGenDataGrid/hooks/useColumns/ColumnHeaderFilter.d.ts +3 -1
- package/dist/core/lib/Tables/NextGenDataGrid/hooks/useColumns/ColumnHeaderFilterInput/ColumnHeaderFilterInput.d.ts +3 -1
- package/package.json +1 -1
|
@@ -21,6 +21,8 @@ const ColumnHeaderFilter = ({
|
|
|
21
21
|
filterMenu,
|
|
22
22
|
filterModeDescription,
|
|
23
23
|
updateQueryParams,
|
|
24
|
+
withLocalStorage,
|
|
25
|
+
localStorageKey,
|
|
24
26
|
mrtProps
|
|
25
27
|
}) => {
|
|
26
28
|
var _a;
|
|
@@ -49,6 +51,8 @@ const ColumnHeaderFilter = ({
|
|
|
49
51
|
filterState,
|
|
50
52
|
filterSync,
|
|
51
53
|
updateQueryParams,
|
|
54
|
+
withLocalStorage,
|
|
55
|
+
localStorageKey,
|
|
52
56
|
filters,
|
|
53
57
|
actionIconProps,
|
|
54
58
|
filterProps,
|
|
@@ -13,6 +13,29 @@ const useApi = require("../../../../../hooks/api/useApi.cjs");
|
|
|
13
13
|
const utils$2 = require("../../../utils.cjs");
|
|
14
14
|
const utils$1 = require("../utils.cjs");
|
|
15
15
|
const HeaderInput = require("./HeaderInput.cjs");
|
|
16
|
+
const getLocalStorageValue = (key, defaultValue) => {
|
|
17
|
+
const value = localStorage.getItem(key);
|
|
18
|
+
if (value === null) {
|
|
19
|
+
return defaultValue;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(value);
|
|
23
|
+
} catch (e) {
|
|
24
|
+
console.error(`Error parsing localStorage value for key "${key}":`, e);
|
|
25
|
+
return defaultValue;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const setLocalStorageValue = (key, value) => {
|
|
29
|
+
if (value === void 0) {
|
|
30
|
+
localStorage.removeItem(key);
|
|
31
|
+
} else {
|
|
32
|
+
try {
|
|
33
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
34
|
+
} catch (e) {
|
|
35
|
+
console.error(`Error setting localStorage value for key "${key}":`, e);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
16
39
|
const FilterIconWrapper = React.forwardRef(({ label, disabled, children, ...props }, ref) => {
|
|
17
40
|
if (disabled) {
|
|
18
41
|
return React.cloneElement(children, { ref });
|
|
@@ -40,13 +63,15 @@ function ColumnHeaderFilterInput({
|
|
|
40
63
|
filterState,
|
|
41
64
|
filterSync,
|
|
42
65
|
updateQueryParams,
|
|
66
|
+
withLocalStorage,
|
|
67
|
+
localStorageKey,
|
|
43
68
|
actionIconProps,
|
|
44
69
|
functionProps,
|
|
45
70
|
mrtProps
|
|
46
71
|
}) {
|
|
47
72
|
var _a, _b;
|
|
48
73
|
const { column } = mrtProps;
|
|
49
|
-
const { info, queryParams, setQueryParams } = useApi.useApi();
|
|
74
|
+
const { path, info, queryParams, setQueryParams } = useApi.useApi();
|
|
50
75
|
const schema = React.useMemo(() => {
|
|
51
76
|
var _a2, _b2;
|
|
52
77
|
return (_b2 = (_a2 = info == null ? void 0 : info.filters) == null ? void 0 : _a2[column.id]) == null ? void 0 : _b2.schema;
|
|
@@ -56,27 +81,29 @@ function ColumnHeaderFilterInput({
|
|
|
56
81
|
[
|
|
57
82
|
{ value: field.getValue(), onChange: field.getInputProps().onChange },
|
|
58
83
|
{ value: column.getFilterValue(), onChange: column.setFilterValue },
|
|
84
|
+
...withLocalStorage ? [
|
|
85
|
+
{
|
|
86
|
+
value: getLocalStorageValue(localStorageKey ?? `nextgen-datagrid-${path}-${column}`),
|
|
87
|
+
onChange: (value) => setLocalStorageValue(localStorageKey ?? `nextgen-datagrid-${path}-${column}`, value)
|
|
88
|
+
}
|
|
89
|
+
] : [],
|
|
59
90
|
...filterState ? [filterState] : [],
|
|
60
91
|
...updateQueryParams ? [
|
|
61
92
|
{
|
|
62
93
|
value: (_b = (_a = queryParams == null ? void 0 : queryParams.filters) == null ? void 0 : _a.find((qpFilter) => qpFilter.id === column.id)) == null ? void 0 : _b.value,
|
|
63
94
|
onChange: (value) => {
|
|
64
95
|
setQueryParams((prev) => {
|
|
65
|
-
|
|
66
|
-
const newFilter = {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
opr,
|
|
70
|
-
value
|
|
71
|
-
};
|
|
72
|
-
if (value === void 0) {
|
|
73
|
-
return { ...prev, filters: newFilters.filter((qpFilter) => qpFilter.id !== newFilter.id) };
|
|
74
|
-
}
|
|
75
|
-
const existingFilterIndex = newFilters.findIndex((qpFilter) => qpFilter.id === newFilter.id);
|
|
76
|
-
if (existingFilterIndex > -1) {
|
|
77
|
-
newFilters[existingFilterIndex] = newFilter;
|
|
96
|
+
let newFilters = [...(prev == null ? void 0 : prev.filters) ?? []];
|
|
97
|
+
const newFilter = { id: column.id, col: column.id, opr, value };
|
|
98
|
+
if (newFilter.value === void 0) {
|
|
99
|
+
newFilters = newFilters.filter((qpFilter) => qpFilter.id !== newFilter.id);
|
|
78
100
|
} else {
|
|
79
|
-
newFilters.
|
|
101
|
+
const existingFilterIndex = newFilters.findIndex((qpFilter) => qpFilter.id === newFilter.id);
|
|
102
|
+
if (existingFilterIndex > -1) {
|
|
103
|
+
newFilters[existingFilterIndex] = newFilter;
|
|
104
|
+
} else {
|
|
105
|
+
newFilters.push(newFilter);
|
|
106
|
+
}
|
|
80
107
|
}
|
|
81
108
|
return { ...prev, filters: newFilters };
|
|
82
109
|
});
|
|
@@ -36,6 +36,8 @@ function useColumns(columnProps, header, body, textFilterSeparator, enableAdvanc
|
|
|
36
36
|
filterMenu,
|
|
37
37
|
filterModeDescription,
|
|
38
38
|
updateQueryParams = true,
|
|
39
|
+
withLocalStorage,
|
|
40
|
+
localStorageKey,
|
|
39
41
|
defaultOpr = ((_d = (_c = (_b = (_a = info == null ? void 0 : info.filters) == null ? void 0 : _a[col]) == null ? void 0 : _b.filters) == null ? void 0 : _c[0]) == null ? void 0 : _d.operator) || ""
|
|
40
42
|
} = utils.getProps(header, specialKey.all, col);
|
|
41
43
|
const filterFn = utils.fromFilterToFilterFn(col, defaultOpr);
|
|
@@ -68,6 +70,8 @@ function useColumns(columnProps, header, body, textFilterSeparator, enableAdvanc
|
|
|
68
70
|
filterMenu,
|
|
69
71
|
filterModeDescription,
|
|
70
72
|
updateQueryParams,
|
|
73
|
+
withLocalStorage,
|
|
74
|
+
localStorageKey,
|
|
71
75
|
mrtProps: props,
|
|
72
76
|
children: filterComponent
|
|
73
77
|
}
|
|
@@ -19,6 +19,8 @@ const ColumnHeaderFilter = ({
|
|
|
19
19
|
filterMenu,
|
|
20
20
|
filterModeDescription,
|
|
21
21
|
updateQueryParams,
|
|
22
|
+
withLocalStorage,
|
|
23
|
+
localStorageKey,
|
|
22
24
|
mrtProps
|
|
23
25
|
}) => {
|
|
24
26
|
var _a;
|
|
@@ -47,6 +49,8 @@ const ColumnHeaderFilter = ({
|
|
|
47
49
|
filterState,
|
|
48
50
|
filterSync,
|
|
49
51
|
updateQueryParams,
|
|
52
|
+
withLocalStorage,
|
|
53
|
+
localStorageKey,
|
|
50
54
|
filters,
|
|
51
55
|
actionIconProps,
|
|
52
56
|
filterProps,
|
|
@@ -11,6 +11,29 @@ import { useApi } from "../../../../../hooks/api/useApi.mjs";
|
|
|
11
11
|
import { getProps } from "../../../utils.mjs";
|
|
12
12
|
import { getBasicInput } from "../utils.mjs";
|
|
13
13
|
import { HeaderInput } from "./HeaderInput.mjs";
|
|
14
|
+
const getLocalStorageValue = (key, defaultValue) => {
|
|
15
|
+
const value = localStorage.getItem(key);
|
|
16
|
+
if (value === null) {
|
|
17
|
+
return defaultValue;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(value);
|
|
21
|
+
} catch (e) {
|
|
22
|
+
console.error(`Error parsing localStorage value for key "${key}":`, e);
|
|
23
|
+
return defaultValue;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const setLocalStorageValue = (key, value) => {
|
|
27
|
+
if (value === void 0) {
|
|
28
|
+
localStorage.removeItem(key);
|
|
29
|
+
} else {
|
|
30
|
+
try {
|
|
31
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
console.error(`Error setting localStorage value for key "${key}":`, e);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
14
37
|
const FilterIconWrapper = forwardRef(({ label, disabled, children, ...props }, ref) => {
|
|
15
38
|
if (disabled) {
|
|
16
39
|
return cloneElement(children, { ref });
|
|
@@ -38,13 +61,15 @@ function ColumnHeaderFilterInput({
|
|
|
38
61
|
filterState,
|
|
39
62
|
filterSync,
|
|
40
63
|
updateQueryParams,
|
|
64
|
+
withLocalStorage,
|
|
65
|
+
localStorageKey,
|
|
41
66
|
actionIconProps,
|
|
42
67
|
functionProps,
|
|
43
68
|
mrtProps
|
|
44
69
|
}) {
|
|
45
70
|
var _a, _b;
|
|
46
71
|
const { column } = mrtProps;
|
|
47
|
-
const { info, queryParams, setQueryParams } = useApi();
|
|
72
|
+
const { path, info, queryParams, setQueryParams } = useApi();
|
|
48
73
|
const schema = useMemo(() => {
|
|
49
74
|
var _a2, _b2;
|
|
50
75
|
return (_b2 = (_a2 = info == null ? void 0 : info.filters) == null ? void 0 : _a2[column.id]) == null ? void 0 : _b2.schema;
|
|
@@ -54,27 +79,29 @@ function ColumnHeaderFilterInput({
|
|
|
54
79
|
[
|
|
55
80
|
{ value: field.getValue(), onChange: field.getInputProps().onChange },
|
|
56
81
|
{ value: column.getFilterValue(), onChange: column.setFilterValue },
|
|
82
|
+
...withLocalStorage ? [
|
|
83
|
+
{
|
|
84
|
+
value: getLocalStorageValue(localStorageKey ?? `nextgen-datagrid-${path}-${column}`),
|
|
85
|
+
onChange: (value) => setLocalStorageValue(localStorageKey ?? `nextgen-datagrid-${path}-${column}`, value)
|
|
86
|
+
}
|
|
87
|
+
] : [],
|
|
57
88
|
...filterState ? [filterState] : [],
|
|
58
89
|
...updateQueryParams ? [
|
|
59
90
|
{
|
|
60
91
|
value: (_b = (_a = queryParams == null ? void 0 : queryParams.filters) == null ? void 0 : _a.find((qpFilter) => qpFilter.id === column.id)) == null ? void 0 : _b.value,
|
|
61
92
|
onChange: (value) => {
|
|
62
93
|
setQueryParams((prev) => {
|
|
63
|
-
|
|
64
|
-
const newFilter = {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
opr,
|
|
68
|
-
value
|
|
69
|
-
};
|
|
70
|
-
if (value === void 0) {
|
|
71
|
-
return { ...prev, filters: newFilters.filter((qpFilter) => qpFilter.id !== newFilter.id) };
|
|
72
|
-
}
|
|
73
|
-
const existingFilterIndex = newFilters.findIndex((qpFilter) => qpFilter.id === newFilter.id);
|
|
74
|
-
if (existingFilterIndex > -1) {
|
|
75
|
-
newFilters[existingFilterIndex] = newFilter;
|
|
94
|
+
let newFilters = [...(prev == null ? void 0 : prev.filters) ?? []];
|
|
95
|
+
const newFilter = { id: column.id, col: column.id, opr, value };
|
|
96
|
+
if (newFilter.value === void 0) {
|
|
97
|
+
newFilters = newFilters.filter((qpFilter) => qpFilter.id !== newFilter.id);
|
|
76
98
|
} else {
|
|
77
|
-
newFilters.
|
|
99
|
+
const existingFilterIndex = newFilters.findIndex((qpFilter) => qpFilter.id === newFilter.id);
|
|
100
|
+
if (existingFilterIndex > -1) {
|
|
101
|
+
newFilters[existingFilterIndex] = newFilter;
|
|
102
|
+
} else {
|
|
103
|
+
newFilters.push(newFilter);
|
|
104
|
+
}
|
|
78
105
|
}
|
|
79
106
|
return { ...prev, filters: newFilters };
|
|
80
107
|
});
|
|
@@ -34,6 +34,8 @@ function useColumns(columnProps, header, body, textFilterSeparator, enableAdvanc
|
|
|
34
34
|
filterMenu,
|
|
35
35
|
filterModeDescription,
|
|
36
36
|
updateQueryParams = true,
|
|
37
|
+
withLocalStorage,
|
|
38
|
+
localStorageKey,
|
|
37
39
|
defaultOpr = ((_d = (_c = (_b = (_a = info == null ? void 0 : info.filters) == null ? void 0 : _a[col]) == null ? void 0 : _b.filters) == null ? void 0 : _c[0]) == null ? void 0 : _d.operator) || ""
|
|
38
40
|
} = getProps(header, specialKey.all, col);
|
|
39
41
|
const filterFn = fromFilterToFilterFn(col, defaultOpr);
|
|
@@ -66,6 +68,8 @@ function useColumns(columnProps, header, body, textFilterSeparator, enableAdvanc
|
|
|
66
68
|
filterMenu,
|
|
67
69
|
filterModeDescription,
|
|
68
70
|
updateQueryParams,
|
|
71
|
+
withLocalStorage,
|
|
72
|
+
localStorageKey,
|
|
69
73
|
mrtProps: props,
|
|
70
74
|
children: filterComponent
|
|
71
75
|
}
|
|
@@ -71,6 +71,14 @@ export type NextGenDataGridHeaderProps = {
|
|
|
71
71
|
* - Whether to update the query params when the filter is applied. Default is true
|
|
72
72
|
*/
|
|
73
73
|
updateQueryParams?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* - Whether to store the filter state in local storage. Defaults to false
|
|
76
|
+
*/
|
|
77
|
+
withLocalStorage?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* - The key to use for local storage when `withLocalStorage` is enabled. Defaults to `nextgen-datagrid-${path}-${column}` where `path` is the API path and `column` is the column name
|
|
80
|
+
*/
|
|
81
|
+
localStorageKey?: string;
|
|
74
82
|
/**
|
|
75
83
|
* - Sets the default operator for the filter. The filter componenet may change based on the operator
|
|
76
84
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function ColumnHeaderFilter({ children, enableFilterModes, filters, filterFn, filterProps, filterState, filterSync, filterMenu, filterModeDescription, updateQueryParams, mrtProps, }: {
|
|
1
|
+
export function ColumnHeaderFilter({ children, enableFilterModes, filters, filterFn, filterProps, filterState, filterSync, filterMenu, filterModeDescription, updateQueryParams, withLocalStorage, localStorageKey, mrtProps, }: {
|
|
2
2
|
children: any;
|
|
3
3
|
enableFilterModes: any;
|
|
4
4
|
filters: any;
|
|
@@ -9,5 +9,7 @@ export function ColumnHeaderFilter({ children, enableFilterModes, filters, filte
|
|
|
9
9
|
filterMenu: any;
|
|
10
10
|
filterModeDescription: any;
|
|
11
11
|
updateQueryParams: any;
|
|
12
|
+
withLocalStorage: any;
|
|
13
|
+
localStorageKey: any;
|
|
12
14
|
mrtProps: any;
|
|
13
15
|
}): import("react").JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function ColumnHeaderFilterInput({ children, opr, enableFilterModes, filters, filterProps, filterState, filterSync, updateQueryParams, actionIconProps, functionProps, mrtProps, }: {
|
|
1
|
+
export function ColumnHeaderFilterInput({ children, opr, enableFilterModes, filters, filterProps, filterState, filterSync, updateQueryParams, withLocalStorage, localStorageKey, actionIconProps, functionProps, mrtProps, }: {
|
|
2
2
|
children: any;
|
|
3
3
|
opr: any;
|
|
4
4
|
enableFilterModes: any;
|
|
@@ -7,6 +7,8 @@ export function ColumnHeaderFilterInput({ children, opr, enableFilterModes, filt
|
|
|
7
7
|
filterState: any;
|
|
8
8
|
filterSync: any;
|
|
9
9
|
updateQueryParams: any;
|
|
10
|
+
withLocalStorage: any;
|
|
11
|
+
localStorageKey: any;
|
|
10
12
|
actionIconProps: any;
|
|
11
13
|
functionProps: any;
|
|
12
14
|
mrtProps: any;
|
package/package.json
CHANGED