@trackunit/filters-filter-bar 0.0.421 → 0.0.423
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 +8 -7
- package/index.esm.js +8 -7
- package/package.json +1 -1
package/index.cjs.js
CHANGED
|
@@ -1006,13 +1006,14 @@ const useFilterBar = ({ name, onValuesChange, filterBarDefinition, initialState,
|
|
|
1006
1006
|
};
|
|
1007
1007
|
});
|
|
1008
1008
|
}, []);
|
|
1009
|
+
const filterDefinitionsValues = react.useMemo(() => sharedUtils.objectValues(filterBarDefinition), [filterBarDefinition]);
|
|
1009
1010
|
const [filterBarConfig, setFilterBarConfig] = react.useState(() => {
|
|
1010
1011
|
let initialFilterBarConfig;
|
|
1011
1012
|
const storedFilters = localStorage.getItem(`filter-${name}`);
|
|
1012
1013
|
if (storedFilters && storedFilters !== "undefined") {
|
|
1013
1014
|
const loadedFilterBarConfig = JSON.parse(storedFilters);
|
|
1014
|
-
if (validateFilter(loadedFilterBarConfig,
|
|
1015
|
-
initialFilterBarConfig = loadedFilterBarConfig;
|
|
1015
|
+
if (validateFilter(loadedFilterBarConfig, filterDefinitionsValues)) {
|
|
1016
|
+
initialFilterBarConfig = createInitialState(loadedFilterBarConfig.name, filterDefinitionsValues, initialState || loadedFilterBarConfig.initialState, setValue);
|
|
1016
1017
|
}
|
|
1017
1018
|
}
|
|
1018
1019
|
//WHY WE NEED THIS?
|
|
@@ -1020,7 +1021,7 @@ const useFilterBar = ({ name, onValuesChange, filterBarDefinition, initialState,
|
|
|
1020
1021
|
//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.
|
|
1021
1022
|
//This mean that filterbars that have this functionality wouldn't be able to save the state of the filterbar.
|
|
1022
1023
|
//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.
|
|
1023
|
-
const hasNonVisibleDefaultValues =
|
|
1024
|
+
const hasNonVisibleDefaultValues = filterDefinitionsValues.some(value => {
|
|
1024
1025
|
var _a;
|
|
1025
1026
|
return value.showInStarredMenu &&
|
|
1026
1027
|
!value.showInStarredMenu() &&
|
|
@@ -1030,7 +1031,7 @@ const useFilterBar = ({ name, onValuesChange, filterBarDefinition, initialState,
|
|
|
1030
1031
|
value.defaultValue.toString().length > 0;
|
|
1031
1032
|
});
|
|
1032
1033
|
if (initialFilterBarConfig === undefined || hasNonVisibleDefaultValues) {
|
|
1033
|
-
initialFilterBarConfig = createInitialState(name,
|
|
1034
|
+
initialFilterBarConfig = createInitialState(name, filterDefinitionsValues, initialState || {}, setValue);
|
|
1034
1035
|
}
|
|
1035
1036
|
// eslint-disable-next-line no-autofix/local-rules/prefer-custom-object-keys
|
|
1036
1037
|
Object.keys(initialFilterBarConfig.values).forEach(key => {
|
|
@@ -1092,7 +1093,7 @@ const useFilterBar = ({ name, onValuesChange, filterBarDefinition, initialState,
|
|
|
1092
1093
|
const filterMapActions = react.useMemo(() => {
|
|
1093
1094
|
// Reset an individual filter to its initial state
|
|
1094
1095
|
const resetIndividualFilterToInitialState = (key) => {
|
|
1095
|
-
const tmpInitialState = createInitialState(name,
|
|
1096
|
+
const tmpInitialState = createInitialState(name, filterDefinitionsValues, initialState || {}, setValue);
|
|
1096
1097
|
setFilterBarConfig(prevState => {
|
|
1097
1098
|
return {
|
|
1098
1099
|
...prevState,
|
|
@@ -1294,13 +1295,13 @@ const useFilterBar = ({ name, onValuesChange, filterBarDefinition, initialState,
|
|
|
1294
1295
|
setFilterBarConfig(prevState => {
|
|
1295
1296
|
return {
|
|
1296
1297
|
...prevState,
|
|
1297
|
-
values: createInitialState(name,
|
|
1298
|
+
values: createInitialState(name, filterDefinitionsValues, initialState || {}, setValue).values,
|
|
1298
1299
|
};
|
|
1299
1300
|
});
|
|
1300
1301
|
},
|
|
1301
1302
|
resetIndividualFilterToInitialState,
|
|
1302
1303
|
};
|
|
1303
|
-
}, [
|
|
1304
|
+
}, [filterDefinitionsValues, initialState, name, setValue]);
|
|
1304
1305
|
return react.useMemo(() => {
|
|
1305
1306
|
return {
|
|
1306
1307
|
filterBarConfig: { ...filterBarConfig, ...filterMapActions, ...filterMapGetter },
|
package/index.esm.js
CHANGED
|
@@ -1004,13 +1004,14 @@ const useFilterBar = ({ name, onValuesChange, filterBarDefinition, initialState,
|
|
|
1004
1004
|
};
|
|
1005
1005
|
});
|
|
1006
1006
|
}, []);
|
|
1007
|
+
const filterDefinitionsValues = useMemo(() => objectValues(filterBarDefinition), [filterBarDefinition]);
|
|
1007
1008
|
const [filterBarConfig, setFilterBarConfig] = useState(() => {
|
|
1008
1009
|
let initialFilterBarConfig;
|
|
1009
1010
|
const storedFilters = localStorage.getItem(`filter-${name}`);
|
|
1010
1011
|
if (storedFilters && storedFilters !== "undefined") {
|
|
1011
1012
|
const loadedFilterBarConfig = JSON.parse(storedFilters);
|
|
1012
|
-
if (validateFilter(loadedFilterBarConfig,
|
|
1013
|
-
initialFilterBarConfig = loadedFilterBarConfig;
|
|
1013
|
+
if (validateFilter(loadedFilterBarConfig, filterDefinitionsValues)) {
|
|
1014
|
+
initialFilterBarConfig = createInitialState(loadedFilterBarConfig.name, filterDefinitionsValues, initialState || loadedFilterBarConfig.initialState, setValue);
|
|
1014
1015
|
}
|
|
1015
1016
|
}
|
|
1016
1017
|
//WHY WE NEED THIS?
|
|
@@ -1018,7 +1019,7 @@ const useFilterBar = ({ name, onValuesChange, filterBarDefinition, initialState,
|
|
|
1018
1019
|
//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.
|
|
1019
1020
|
//This mean that filterbars that have this functionality wouldn't be able to save the state of the filterbar.
|
|
1020
1021
|
//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.
|
|
1021
|
-
const hasNonVisibleDefaultValues =
|
|
1022
|
+
const hasNonVisibleDefaultValues = filterDefinitionsValues.some(value => {
|
|
1022
1023
|
var _a;
|
|
1023
1024
|
return value.showInStarredMenu &&
|
|
1024
1025
|
!value.showInStarredMenu() &&
|
|
@@ -1028,7 +1029,7 @@ const useFilterBar = ({ name, onValuesChange, filterBarDefinition, initialState,
|
|
|
1028
1029
|
value.defaultValue.toString().length > 0;
|
|
1029
1030
|
});
|
|
1030
1031
|
if (initialFilterBarConfig === undefined || hasNonVisibleDefaultValues) {
|
|
1031
|
-
initialFilterBarConfig = createInitialState(name,
|
|
1032
|
+
initialFilterBarConfig = createInitialState(name, filterDefinitionsValues, initialState || {}, setValue);
|
|
1032
1033
|
}
|
|
1033
1034
|
// eslint-disable-next-line no-autofix/local-rules/prefer-custom-object-keys
|
|
1034
1035
|
Object.keys(initialFilterBarConfig.values).forEach(key => {
|
|
@@ -1090,7 +1091,7 @@ const useFilterBar = ({ name, onValuesChange, filterBarDefinition, initialState,
|
|
|
1090
1091
|
const filterMapActions = useMemo(() => {
|
|
1091
1092
|
// Reset an individual filter to its initial state
|
|
1092
1093
|
const resetIndividualFilterToInitialState = (key) => {
|
|
1093
|
-
const tmpInitialState = createInitialState(name,
|
|
1094
|
+
const tmpInitialState = createInitialState(name, filterDefinitionsValues, initialState || {}, setValue);
|
|
1094
1095
|
setFilterBarConfig(prevState => {
|
|
1095
1096
|
return {
|
|
1096
1097
|
...prevState,
|
|
@@ -1292,13 +1293,13 @@ const useFilterBar = ({ name, onValuesChange, filterBarDefinition, initialState,
|
|
|
1292
1293
|
setFilterBarConfig(prevState => {
|
|
1293
1294
|
return {
|
|
1294
1295
|
...prevState,
|
|
1295
|
-
values: createInitialState(name,
|
|
1296
|
+
values: createInitialState(name, filterDefinitionsValues, initialState || {}, setValue).values,
|
|
1296
1297
|
};
|
|
1297
1298
|
});
|
|
1298
1299
|
},
|
|
1299
1300
|
resetIndividualFilterToInitialState,
|
|
1300
1301
|
};
|
|
1301
|
-
}, [
|
|
1302
|
+
}, [filterDefinitionsValues, initialState, name, setValue]);
|
|
1302
1303
|
return useMemo(() => {
|
|
1303
1304
|
return {
|
|
1304
1305
|
filterBarConfig: { ...filterBarConfig, ...filterMapActions, ...filterMapGetter },
|