@trackunit/filters-filter-bar 0.0.238 → 0.0.241
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/index.cjs.js +20 -5
- package/index.esm.js +21 -6
- package/package.json +1 -1
package/index.cjs.js
CHANGED
|
@@ -1038,13 +1038,28 @@ const useFilterBar = ({ name, onValuesChange, filterBarDefinition, initialState,
|
|
|
1038
1038
|
const storedFilters = localStorage.getItem(`filter-${name}`);
|
|
1039
1039
|
if (storedFilters && storedFilters !== "undefined") {
|
|
1040
1040
|
const loadedFilterBarConfig = JSON.parse(storedFilters);
|
|
1041
|
-
if (validateFilter(loadedFilterBarConfig,
|
|
1041
|
+
if (validateFilter(loadedFilterBarConfig, sharedUtils.objectValues(filterBarDefinition))) {
|
|
1042
1042
|
initialFilterBarConfig = loadedFilterBarConfig;
|
|
1043
1043
|
}
|
|
1044
1044
|
}
|
|
1045
|
-
|
|
1046
|
-
|
|
1045
|
+
//WHY WE NEED THIS?
|
|
1046
|
+
//For filters that are not visible and we want to set the default value to the initial state.
|
|
1047
|
+
//To do this for a changing default value as in customers and sites we would need to recreate the initialFilterBarConfig every time the default value changes.
|
|
1048
|
+
//This mean that filterbars that have this functionality wouldn't be able to save the state of the filterbar.
|
|
1049
|
+
//Another option would be to create a new filterbar for each customer or site. This also has its drawbacks. Would raise it with the frontend community.
|
|
1050
|
+
const hasNonVisibleDefaultValues = sharedUtils.objectValues(filterBarDefinition).some(key => {
|
|
1051
|
+
var _a;
|
|
1052
|
+
return key.showInStarredMenu &&
|
|
1053
|
+
!key.showInStarredMenu() &&
|
|
1054
|
+
key.showInFilterBar &&
|
|
1055
|
+
!key.showInFilterBar() &&
|
|
1056
|
+
((_a = key.defaultValue) === null || _a === void 0 ? void 0 : _a.toString) &&
|
|
1057
|
+
key.defaultValue.toString().length > 0;
|
|
1058
|
+
});
|
|
1059
|
+
if (initialFilterBarConfig === undefined || hasNonVisibleDefaultValues) {
|
|
1060
|
+
initialFilterBarConfig = createInitialState(name, sharedUtils.objectValues(filterBarDefinition), initialState || {}, setValue);
|
|
1047
1061
|
}
|
|
1062
|
+
// eslint-disable-next-line local-rules/prefer-custom-object-keys
|
|
1048
1063
|
Object.keys(initialFilterBarConfig.values).forEach(key => {
|
|
1049
1064
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1050
1065
|
initialFilterBarConfig.setters[`set${capitalize(key)}`] = (callback) => setValue(key, callback);
|
|
@@ -1104,7 +1119,7 @@ const useFilterBar = ({ name, onValuesChange, filterBarDefinition, initialState,
|
|
|
1104
1119
|
const filterMapActions = react.useMemo(() => {
|
|
1105
1120
|
// Reset an individual filter to its initial state
|
|
1106
1121
|
const resetIndividualFilterToInitialState = (key) => {
|
|
1107
|
-
const tmpInitialState = createInitialState(name,
|
|
1122
|
+
const tmpInitialState = createInitialState(name, sharedUtils.objectValues(filterBarDefinition), initialState || {}, setValue);
|
|
1108
1123
|
setFilterBarConfig(prevState => {
|
|
1109
1124
|
return Object.assign(Object.assign({}, prevState), { values: Object.assign(Object.assign({}, prevState.values), { [key]: tmpInitialState.values[key] }) });
|
|
1110
1125
|
});
|
|
@@ -1226,7 +1241,7 @@ const useFilterBar = ({ name, onValuesChange, filterBarDefinition, initialState,
|
|
|
1226
1241
|
// Reset filters to initial state
|
|
1227
1242
|
resetFiltersToInitialState() {
|
|
1228
1243
|
setFilterBarConfig(prevState => {
|
|
1229
|
-
return Object.assign(Object.assign({}, prevState), { values: createInitialState(name,
|
|
1244
|
+
return Object.assign(Object.assign({}, prevState), { values: createInitialState(name, sharedUtils.objectValues(filterBarDefinition), initialState || {}, setValue).values });
|
|
1230
1245
|
});
|
|
1231
1246
|
},
|
|
1232
1247
|
resetIndividualFilterToInitialState,
|
package/index.esm.js
CHANGED
|
@@ -3,7 +3,7 @@ import { registerTranslations, useNamespaceTranslation } from '@trackunit/i18n-l
|
|
|
3
3
|
import { twMerge } from 'tailwind-merge';
|
|
4
4
|
import { cvaMerge } from '@trackunit/css-class-variance-utilities';
|
|
5
5
|
import { Button, Popover, PopoverTrigger, IconButton, Icon, PopoverContent, MenuList, Text, StarButton, useResize, Collapse, DayRangePicker } from '@trackunit/react-components';
|
|
6
|
-
import { truthy, capitalize as capitalize$1, nonNullable } from '@trackunit/shared-utils';
|
|
6
|
+
import { truthy, capitalize as capitalize$1, nonNullable, objectValues } from '@trackunit/shared-utils';
|
|
7
7
|
import { useMemo, useState, Fragment as Fragment$1, useCallback, useEffect, useRef } from 'react';
|
|
8
8
|
import { Filter as Filter$1, FilterBody, RadioFilterItem, CheckBoxFilterItem, FilterHeader as FilterHeader$1, FilterFooter } from '@trackunit/react-filter-components';
|
|
9
9
|
import { useAnalytics, useTextSearch } from '@trackunit/react-core-hooks';
|
|
@@ -1030,13 +1030,28 @@ const useFilterBar = ({ name, onValuesChange, filterBarDefinition, initialState,
|
|
|
1030
1030
|
const storedFilters = localStorage.getItem(`filter-${name}`);
|
|
1031
1031
|
if (storedFilters && storedFilters !== "undefined") {
|
|
1032
1032
|
const loadedFilterBarConfig = JSON.parse(storedFilters);
|
|
1033
|
-
if (validateFilter(loadedFilterBarConfig,
|
|
1033
|
+
if (validateFilter(loadedFilterBarConfig, objectValues(filterBarDefinition))) {
|
|
1034
1034
|
initialFilterBarConfig = loadedFilterBarConfig;
|
|
1035
1035
|
}
|
|
1036
1036
|
}
|
|
1037
|
-
|
|
1038
|
-
|
|
1037
|
+
//WHY WE NEED THIS?
|
|
1038
|
+
//For filters that are not visible and we want to set the default value to the initial state.
|
|
1039
|
+
//To do this for a changing default value as in customers and sites we would need to recreate the initialFilterBarConfig every time the default value changes.
|
|
1040
|
+
//This mean that filterbars that have this functionality wouldn't be able to save the state of the filterbar.
|
|
1041
|
+
//Another option would be to create a new filterbar for each customer or site. This also has its drawbacks. Would raise it with the frontend community.
|
|
1042
|
+
const hasNonVisibleDefaultValues = objectValues(filterBarDefinition).some(key => {
|
|
1043
|
+
var _a;
|
|
1044
|
+
return key.showInStarredMenu &&
|
|
1045
|
+
!key.showInStarredMenu() &&
|
|
1046
|
+
key.showInFilterBar &&
|
|
1047
|
+
!key.showInFilterBar() &&
|
|
1048
|
+
((_a = key.defaultValue) === null || _a === void 0 ? void 0 : _a.toString) &&
|
|
1049
|
+
key.defaultValue.toString().length > 0;
|
|
1050
|
+
});
|
|
1051
|
+
if (initialFilterBarConfig === undefined || hasNonVisibleDefaultValues) {
|
|
1052
|
+
initialFilterBarConfig = createInitialState(name, objectValues(filterBarDefinition), initialState || {}, setValue);
|
|
1039
1053
|
}
|
|
1054
|
+
// eslint-disable-next-line local-rules/prefer-custom-object-keys
|
|
1040
1055
|
Object.keys(initialFilterBarConfig.values).forEach(key => {
|
|
1041
1056
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1042
1057
|
initialFilterBarConfig.setters[`set${capitalize(key)}`] = (callback) => setValue(key, callback);
|
|
@@ -1096,7 +1111,7 @@ const useFilterBar = ({ name, onValuesChange, filterBarDefinition, initialState,
|
|
|
1096
1111
|
const filterMapActions = useMemo(() => {
|
|
1097
1112
|
// Reset an individual filter to its initial state
|
|
1098
1113
|
const resetIndividualFilterToInitialState = (key) => {
|
|
1099
|
-
const tmpInitialState = createInitialState(name,
|
|
1114
|
+
const tmpInitialState = createInitialState(name, objectValues(filterBarDefinition), initialState || {}, setValue);
|
|
1100
1115
|
setFilterBarConfig(prevState => {
|
|
1101
1116
|
return Object.assign(Object.assign({}, prevState), { values: Object.assign(Object.assign({}, prevState.values), { [key]: tmpInitialState.values[key] }) });
|
|
1102
1117
|
});
|
|
@@ -1218,7 +1233,7 @@ const useFilterBar = ({ name, onValuesChange, filterBarDefinition, initialState,
|
|
|
1218
1233
|
// Reset filters to initial state
|
|
1219
1234
|
resetFiltersToInitialState() {
|
|
1220
1235
|
setFilterBarConfig(prevState => {
|
|
1221
|
-
return Object.assign(Object.assign({}, prevState), { values: createInitialState(name,
|
|
1236
|
+
return Object.assign(Object.assign({}, prevState), { values: createInitialState(name, objectValues(filterBarDefinition), initialState || {}, setValue).values });
|
|
1222
1237
|
});
|
|
1223
1238
|
},
|
|
1224
1239
|
resetIndividualFilterToInitialState,
|