@trackunit/filters-filter-bar 1.15.15 → 1.16.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/index.cjs.js +24 -26
- package/index.esm.js +24 -26
- package/package.json +7 -7
- package/src/lib/types/FilterTypes.d.ts +1 -1
package/index.cjs.js
CHANGED
|
@@ -348,9 +348,9 @@ const reduceFilterText = (input) => {
|
|
|
348
348
|
*/
|
|
349
349
|
const FilterComponent = ({ filter, filterBarActions, filterState, readOnly = false, visualStyle = "button", className, asIcon, size, }) => {
|
|
350
350
|
const values = filterBarActions.getValuesByKey(filter.filterKey);
|
|
351
|
-
const valuesLength = values && Array.isArray(values) ? values.length : undefined;
|
|
351
|
+
const valuesLength = values !== undefined && Array.isArray(values) ? values.length : undefined;
|
|
352
352
|
const getFilterText = () => {
|
|
353
|
-
if (
|
|
353
|
+
if (values === undefined) {
|
|
354
354
|
return undefined;
|
|
355
355
|
}
|
|
356
356
|
if (filter.valueAsText) {
|
|
@@ -362,7 +362,7 @@ const FilterComponent = ({ filter, filterBarActions, filterState, readOnly = fal
|
|
|
362
362
|
else if (filter.type === "valueName") {
|
|
363
363
|
return values.name;
|
|
364
364
|
}
|
|
365
|
-
return values
|
|
365
|
+
return values?.toString();
|
|
366
366
|
};
|
|
367
367
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
368
368
|
const setValue = (callback) => {
|
|
@@ -763,7 +763,9 @@ const DefaultMinMaxFilter = ({ filterDefinition, filterName, value, setValue, fi
|
|
|
763
763
|
value: JSON.stringify({ min: realMinValue, max: realMaxValue }),
|
|
764
764
|
});
|
|
765
765
|
setValue(() => {
|
|
766
|
-
return realMinValue
|
|
766
|
+
return realMinValue !== undefined || realMaxValue !== undefined
|
|
767
|
+
? { min: realMinValue, max: realMaxValue }
|
|
768
|
+
: {};
|
|
767
769
|
});
|
|
768
770
|
};
|
|
769
771
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(reactFilterComponents.FilterHeader, { onReset: () => filterBarActions.resetIndividualFilterToInitialState(filterDefinition.filterKey), resetLabel: t("filtersBar.resetFilter"), showReset: filterBarActions.appliedFilterKeys().includes(filterDefinition.filterKey), title: filterDefinition.title }), jsxRuntime.jsxs(reactFilterComponents.FilterBody, { children: [jsxRuntime.jsxs("div", { className: "flex gap-1 px-1 pb-0.5 pt-1", children: [jsxRuntime.jsx(reactFormComponents.NumberField, { addonAfter: unit, className: "w-40", label: t("filtersBar.defaultMinMaxFilters.min"), max: filterDefinition.type === "minMax" ? filterDefinition.maximumNumber : undefined, min: filterDefinition.type === "minMax" ? filterDefinition.minimumNumber : undefined, onChange: e => setMinValue(e.target.value === "" ? undefined : Number(e.target.value)), value: minValue ?? "" }), jsxRuntime.jsx(reactFormComponents.NumberField, { addonAfter: unit, className: "w-40", label: t("filtersBar.defaultMinMaxFilters.max"), max: filterDefinition.type === "minMax" ? filterDefinition.maximumNumber : undefined, min: filterDefinition.type === "minMax" ? filterDefinition.minimumNumber : undefined, onChange: e => setMaxValue(e.target.value === "" ? undefined : Number(e.target.value)), value: maxValue ?? "" })] }), jsxRuntime.jsx(reactFilterComponents.FilterFooter, { children: jsxRuntime.jsx(reactComponents.Button, { onClick: handleApply, size: "small", variant: "primary", children: t("filtersBar.defaultMinMaxFilters.apply") }) })] })] }));
|
|
@@ -1134,7 +1136,7 @@ const FilterTableComponent = ({ filterKey, filterBarDefinition, filterBarConfig,
|
|
|
1134
1136
|
if (Array.isArray(filterValues)) {
|
|
1135
1137
|
return total + filterValues.length;
|
|
1136
1138
|
}
|
|
1137
|
-
return total + (filterValues ? 1 : 0);
|
|
1139
|
+
return total + (filterValues !== undefined ? 1 : 0);
|
|
1138
1140
|
}, 0);
|
|
1139
1141
|
}, [filterBarConfig]);
|
|
1140
1142
|
if (Array.isArray(filterKey)) {
|
|
@@ -1578,17 +1580,13 @@ const isNotRightType = (filterDefinition, foundFilter) => {
|
|
|
1578
1580
|
*
|
|
1579
1581
|
*/
|
|
1580
1582
|
const isMinMaxFilterValue = (value) => {
|
|
1581
|
-
return value
|
|
1582
|
-
? typeof value === "object" && (Object.keys(value).includes("min") || Object.keys(value).includes("max"))
|
|
1583
|
-
: false;
|
|
1583
|
+
return typeof value === "object" && value !== null && (Object.keys(value).includes("min") || Object.keys(value).includes("max"));
|
|
1584
1584
|
};
|
|
1585
1585
|
/**
|
|
1586
1586
|
*
|
|
1587
1587
|
*/
|
|
1588
1588
|
const isDateRangeValue = (value) => {
|
|
1589
|
-
return value
|
|
1590
|
-
? typeof value === "object" && (Object.keys(value).includes("from") || Object.keys(value).includes("to"))
|
|
1591
|
-
: false;
|
|
1589
|
+
return typeof value === "object" && value !== null && (Object.keys(value).includes("from") || Object.keys(value).includes("to"));
|
|
1592
1590
|
};
|
|
1593
1591
|
/**
|
|
1594
1592
|
* {
|
|
@@ -1615,7 +1613,7 @@ const isStringArrayFilterValue = (value) => {
|
|
|
1615
1613
|
*
|
|
1616
1614
|
*/
|
|
1617
1615
|
const isBooleanValue = (value) => {
|
|
1618
|
-
return
|
|
1616
|
+
return typeof value === "object" && value !== null && Object.keys(value).includes("booleanValue");
|
|
1619
1617
|
};
|
|
1620
1618
|
/**
|
|
1621
1619
|
* Type guard to check if a value is a single ValueName object
|
|
@@ -1655,7 +1653,7 @@ const validateFilter = ({ values, filterDefinitions, }) => {
|
|
|
1655
1653
|
filterDefinitions.forEach(filterDefinition => {
|
|
1656
1654
|
const foundFilter = values[filterDefinition.filterKey];
|
|
1657
1655
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1658
|
-
if (foundFilter && hasValue(foundFilter) && isNotRightType(filterDefinition, foundFilter)) {
|
|
1656
|
+
if (foundFilter !== undefined && foundFilter !== null && hasValue(foundFilter) && isNotRightType(filterDefinition, foundFilter)) {
|
|
1659
1657
|
inBadState = true;
|
|
1660
1658
|
}
|
|
1661
1659
|
});
|
|
@@ -1681,7 +1679,7 @@ const useIsDefaultValue = () => {
|
|
|
1681
1679
|
dequal.dequal(filterValue, filterDefinition?.defaultValue)) {
|
|
1682
1680
|
return true;
|
|
1683
1681
|
}
|
|
1684
|
-
if (
|
|
1682
|
+
if (filterValue === undefined || filterValue === null || filterValue === "" || filterValue === 0) {
|
|
1685
1683
|
return true;
|
|
1686
1684
|
}
|
|
1687
1685
|
if (Array.isArray(filterValue)) {
|
|
@@ -2003,7 +2001,7 @@ const useFilterUrlSync = () => {
|
|
|
2003
2001
|
return filterValue;
|
|
2004
2002
|
}
|
|
2005
2003
|
if (zodSchema._def.typeName === "ZodString") {
|
|
2006
|
-
return filterValue ? filterValue + "" : filterValue;
|
|
2004
|
+
return filterValue !== undefined && filterValue !== null ? filterValue + "" : filterValue;
|
|
2007
2005
|
}
|
|
2008
2006
|
if (typeof filterValue === "string") {
|
|
2009
2007
|
try {
|
|
@@ -2019,11 +2017,11 @@ const useFilterUrlSync = () => {
|
|
|
2019
2017
|
const loadedValues = {};
|
|
2020
2018
|
definitions.forEach(filter => {
|
|
2021
2019
|
const filterValue = search[filter.filterKey];
|
|
2022
|
-
if (filterValue) {
|
|
2023
|
-
const zodSchema = filter.zodSchema
|
|
2020
|
+
if (filterValue !== undefined && filterValue !== null) {
|
|
2021
|
+
const zodSchema = filter.zodSchema ?? getZodSchema(filter.type);
|
|
2024
2022
|
const jsonParsed = getJsonParsedVal(filterValue, zodSchema);
|
|
2025
2023
|
const zodParsed = zodSchema.safeParse(jsonParsed);
|
|
2026
|
-
if (zodParsed.success) {
|
|
2024
|
+
if (zodParsed.success === true) {
|
|
2027
2025
|
loadedValues[filter.filterKey] = zodParsed.data;
|
|
2028
2026
|
}
|
|
2029
2027
|
}
|
|
@@ -2034,7 +2032,7 @@ const useFilterUrlSync = () => {
|
|
|
2034
2032
|
const urlObject = {};
|
|
2035
2033
|
definitions.forEach(filter => {
|
|
2036
2034
|
const value = values?.[filter.filterKey];
|
|
2037
|
-
if (value) {
|
|
2035
|
+
if (Boolean(value)) {
|
|
2038
2036
|
if (setEmptyAndDefaultValues) {
|
|
2039
2037
|
urlObject[filter.filterKey] = value;
|
|
2040
2038
|
}
|
|
@@ -2111,7 +2109,7 @@ const useFilterBarPersistence = ({ name, setValue, refreshData, isDefaultValue,
|
|
|
2111
2109
|
(typeof searchParams[name] === "string" &&
|
|
2112
2110
|
!dequal.dequal(decode(searchParams[name]), typeof search[name] === "string" ? decode(search[name]) : search[name]))) {
|
|
2113
2111
|
return requestAnimationFrame(async () => {
|
|
2114
|
-
const replace =
|
|
2112
|
+
const replace = search[name] === undefined || search[name] === null;
|
|
2115
2113
|
await navigate({
|
|
2116
2114
|
to: ".",
|
|
2117
2115
|
search: (prev) => {
|
|
@@ -2152,7 +2150,7 @@ const useFilterBarPersistence = ({ name, setValue, refreshData, isDefaultValue,
|
|
|
2152
2150
|
let currentSearchValueParsed;
|
|
2153
2151
|
let lastSearchUpdateRefParsed;
|
|
2154
2152
|
try {
|
|
2155
|
-
currentSearchValueParsed = currentSearchValue ? decode(currentSearchValue) : undefined;
|
|
2153
|
+
currentSearchValueParsed = currentSearchValue !== undefined && currentSearchValue !== null ? decode(currentSearchValue) : undefined;
|
|
2156
2154
|
}
|
|
2157
2155
|
catch (_) {
|
|
2158
2156
|
// Invalid compressed data, treat as undefined
|
|
@@ -2222,7 +2220,7 @@ const useFilterBarPersistence = ({ name, setValue, refreshData, isDefaultValue,
|
|
|
2222
2220
|
if (storedFilters && storedFilters !== "undefined") {
|
|
2223
2221
|
try {
|
|
2224
2222
|
const loadedFilterBarConfigValues = JSON.parse(storedFilters);
|
|
2225
|
-
return loadedFilterBarConfigValues?.values
|
|
2223
|
+
return loadedFilterBarConfigValues?.values ?? {};
|
|
2226
2224
|
}
|
|
2227
2225
|
catch (error) {
|
|
2228
2226
|
return {};
|
|
@@ -2231,9 +2229,9 @@ const useFilterBarPersistence = ({ name, setValue, refreshData, isDefaultValue,
|
|
|
2231
2229
|
return {};
|
|
2232
2230
|
}, [clientSideUserId, name, initialStoredFilters, lastName]);
|
|
2233
2231
|
const loadFromSearchURL = react.useCallback(() => {
|
|
2234
|
-
let searchParams = search
|
|
2232
|
+
let searchParams = search ?? {};
|
|
2235
2233
|
const searchParamValue = searchParams[name];
|
|
2236
|
-
if (searchParamValue) {
|
|
2234
|
+
if (searchParamValue !== undefined && searchParamValue !== null) {
|
|
2237
2235
|
try {
|
|
2238
2236
|
searchParams = decode(searchParamValue);
|
|
2239
2237
|
}
|
|
@@ -2251,7 +2249,7 @@ const useFilterBarPersistence = ({ name, setValue, refreshData, isDefaultValue,
|
|
|
2251
2249
|
else {
|
|
2252
2250
|
const values = loadFromLocalStorage() || {};
|
|
2253
2251
|
const searchParams = loadFromSearchURL();
|
|
2254
|
-
if (searchParams && sharedUtils.objectKeys(searchParams).length > 0) {
|
|
2252
|
+
if (searchParams !== null && sharedUtils.objectKeys(searchParams).length > 0) {
|
|
2255
2253
|
const valuesFromUrl = getFilterValuesFromUrl(filterDefinitions, searchParams);
|
|
2256
2254
|
if (sharedUtils.objectKeys(valuesFromUrl).length > 0) {
|
|
2257
2255
|
// if there are values from the URL, update ALL filters values based on the searchParams or their defaults
|
|
@@ -2549,7 +2547,7 @@ const useSearchParamAsFilter = ({ filterName, search, zodSchema, errorHandler, }
|
|
|
2549
2547
|
try {
|
|
2550
2548
|
const getJsonParsedVal = () => {
|
|
2551
2549
|
if (zodSchema._def.typeName === "ZodString") {
|
|
2552
|
-
return foundParam ? foundParam + "" : foundParam;
|
|
2550
|
+
return foundParam !== undefined && foundParam !== null ? foundParam + "" : foundParam;
|
|
2553
2551
|
}
|
|
2554
2552
|
if (typeof search === "string" && typeof foundParam === "string") {
|
|
2555
2553
|
return JSON.parse(foundParam);
|
package/index.esm.js
CHANGED
|
@@ -346,9 +346,9 @@ const reduceFilterText = (input) => {
|
|
|
346
346
|
*/
|
|
347
347
|
const FilterComponent = ({ filter, filterBarActions, filterState, readOnly = false, visualStyle = "button", className, asIcon, size, }) => {
|
|
348
348
|
const values = filterBarActions.getValuesByKey(filter.filterKey);
|
|
349
|
-
const valuesLength = values && Array.isArray(values) ? values.length : undefined;
|
|
349
|
+
const valuesLength = values !== undefined && Array.isArray(values) ? values.length : undefined;
|
|
350
350
|
const getFilterText = () => {
|
|
351
|
-
if (
|
|
351
|
+
if (values === undefined) {
|
|
352
352
|
return undefined;
|
|
353
353
|
}
|
|
354
354
|
if (filter.valueAsText) {
|
|
@@ -360,7 +360,7 @@ const FilterComponent = ({ filter, filterBarActions, filterState, readOnly = fal
|
|
|
360
360
|
else if (filter.type === "valueName") {
|
|
361
361
|
return values.name;
|
|
362
362
|
}
|
|
363
|
-
return values
|
|
363
|
+
return values?.toString();
|
|
364
364
|
};
|
|
365
365
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
366
366
|
const setValue = (callback) => {
|
|
@@ -761,7 +761,9 @@ const DefaultMinMaxFilter = ({ filterDefinition, filterName, value, setValue, fi
|
|
|
761
761
|
value: JSON.stringify({ min: realMinValue, max: realMaxValue }),
|
|
762
762
|
});
|
|
763
763
|
setValue(() => {
|
|
764
|
-
return realMinValue
|
|
764
|
+
return realMinValue !== undefined || realMaxValue !== undefined
|
|
765
|
+
? { min: realMinValue, max: realMaxValue }
|
|
766
|
+
: {};
|
|
765
767
|
});
|
|
766
768
|
};
|
|
767
769
|
return (jsxs(Fragment, { children: [jsx(FilterHeader$1, { onReset: () => filterBarActions.resetIndividualFilterToInitialState(filterDefinition.filterKey), resetLabel: t("filtersBar.resetFilter"), showReset: filterBarActions.appliedFilterKeys().includes(filterDefinition.filterKey), title: filterDefinition.title }), jsxs(FilterBody, { children: [jsxs("div", { className: "flex gap-1 px-1 pb-0.5 pt-1", children: [jsx(NumberField, { addonAfter: unit, className: "w-40", label: t("filtersBar.defaultMinMaxFilters.min"), max: filterDefinition.type === "minMax" ? filterDefinition.maximumNumber : undefined, min: filterDefinition.type === "minMax" ? filterDefinition.minimumNumber : undefined, onChange: e => setMinValue(e.target.value === "" ? undefined : Number(e.target.value)), value: minValue ?? "" }), jsx(NumberField, { addonAfter: unit, className: "w-40", label: t("filtersBar.defaultMinMaxFilters.max"), max: filterDefinition.type === "minMax" ? filterDefinition.maximumNumber : undefined, min: filterDefinition.type === "minMax" ? filterDefinition.minimumNumber : undefined, onChange: e => setMaxValue(e.target.value === "" ? undefined : Number(e.target.value)), value: maxValue ?? "" })] }), jsx(FilterFooter, { children: jsx(Button, { onClick: handleApply, size: "small", variant: "primary", children: t("filtersBar.defaultMinMaxFilters.apply") }) })] })] }));
|
|
@@ -1132,7 +1134,7 @@ const FilterTableComponent = ({ filterKey, filterBarDefinition, filterBarConfig,
|
|
|
1132
1134
|
if (Array.isArray(filterValues)) {
|
|
1133
1135
|
return total + filterValues.length;
|
|
1134
1136
|
}
|
|
1135
|
-
return total + (filterValues ? 1 : 0);
|
|
1137
|
+
return total + (filterValues !== undefined ? 1 : 0);
|
|
1136
1138
|
}, 0);
|
|
1137
1139
|
}, [filterBarConfig]);
|
|
1138
1140
|
if (Array.isArray(filterKey)) {
|
|
@@ -1576,17 +1578,13 @@ const isNotRightType = (filterDefinition, foundFilter) => {
|
|
|
1576
1578
|
*
|
|
1577
1579
|
*/
|
|
1578
1580
|
const isMinMaxFilterValue = (value) => {
|
|
1579
|
-
return value
|
|
1580
|
-
? typeof value === "object" && (Object.keys(value).includes("min") || Object.keys(value).includes("max"))
|
|
1581
|
-
: false;
|
|
1581
|
+
return typeof value === "object" && value !== null && (Object.keys(value).includes("min") || Object.keys(value).includes("max"));
|
|
1582
1582
|
};
|
|
1583
1583
|
/**
|
|
1584
1584
|
*
|
|
1585
1585
|
*/
|
|
1586
1586
|
const isDateRangeValue = (value) => {
|
|
1587
|
-
return value
|
|
1588
|
-
? typeof value === "object" && (Object.keys(value).includes("from") || Object.keys(value).includes("to"))
|
|
1589
|
-
: false;
|
|
1587
|
+
return typeof value === "object" && value !== null && (Object.keys(value).includes("from") || Object.keys(value).includes("to"));
|
|
1590
1588
|
};
|
|
1591
1589
|
/**
|
|
1592
1590
|
* {
|
|
@@ -1613,7 +1611,7 @@ const isStringArrayFilterValue = (value) => {
|
|
|
1613
1611
|
*
|
|
1614
1612
|
*/
|
|
1615
1613
|
const isBooleanValue = (value) => {
|
|
1616
|
-
return
|
|
1614
|
+
return typeof value === "object" && value !== null && Object.keys(value).includes("booleanValue");
|
|
1617
1615
|
};
|
|
1618
1616
|
/**
|
|
1619
1617
|
* Type guard to check if a value is a single ValueName object
|
|
@@ -1653,7 +1651,7 @@ const validateFilter = ({ values, filterDefinitions, }) => {
|
|
|
1653
1651
|
filterDefinitions.forEach(filterDefinition => {
|
|
1654
1652
|
const foundFilter = values[filterDefinition.filterKey];
|
|
1655
1653
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1656
|
-
if (foundFilter && hasValue(foundFilter) && isNotRightType(filterDefinition, foundFilter)) {
|
|
1654
|
+
if (foundFilter !== undefined && foundFilter !== null && hasValue(foundFilter) && isNotRightType(filterDefinition, foundFilter)) {
|
|
1657
1655
|
inBadState = true;
|
|
1658
1656
|
}
|
|
1659
1657
|
});
|
|
@@ -1679,7 +1677,7 @@ const useIsDefaultValue = () => {
|
|
|
1679
1677
|
dequal(filterValue, filterDefinition?.defaultValue)) {
|
|
1680
1678
|
return true;
|
|
1681
1679
|
}
|
|
1682
|
-
if (
|
|
1680
|
+
if (filterValue === undefined || filterValue === null || filterValue === "" || filterValue === 0) {
|
|
1683
1681
|
return true;
|
|
1684
1682
|
}
|
|
1685
1683
|
if (Array.isArray(filterValue)) {
|
|
@@ -2001,7 +1999,7 @@ const useFilterUrlSync = () => {
|
|
|
2001
1999
|
return filterValue;
|
|
2002
2000
|
}
|
|
2003
2001
|
if (zodSchema._def.typeName === "ZodString") {
|
|
2004
|
-
return filterValue ? filterValue + "" : filterValue;
|
|
2002
|
+
return filterValue !== undefined && filterValue !== null ? filterValue + "" : filterValue;
|
|
2005
2003
|
}
|
|
2006
2004
|
if (typeof filterValue === "string") {
|
|
2007
2005
|
try {
|
|
@@ -2017,11 +2015,11 @@ const useFilterUrlSync = () => {
|
|
|
2017
2015
|
const loadedValues = {};
|
|
2018
2016
|
definitions.forEach(filter => {
|
|
2019
2017
|
const filterValue = search[filter.filterKey];
|
|
2020
|
-
if (filterValue) {
|
|
2021
|
-
const zodSchema = filter.zodSchema
|
|
2018
|
+
if (filterValue !== undefined && filterValue !== null) {
|
|
2019
|
+
const zodSchema = filter.zodSchema ?? getZodSchema(filter.type);
|
|
2022
2020
|
const jsonParsed = getJsonParsedVal(filterValue, zodSchema);
|
|
2023
2021
|
const zodParsed = zodSchema.safeParse(jsonParsed);
|
|
2024
|
-
if (zodParsed.success) {
|
|
2022
|
+
if (zodParsed.success === true) {
|
|
2025
2023
|
loadedValues[filter.filterKey] = zodParsed.data;
|
|
2026
2024
|
}
|
|
2027
2025
|
}
|
|
@@ -2032,7 +2030,7 @@ const useFilterUrlSync = () => {
|
|
|
2032
2030
|
const urlObject = {};
|
|
2033
2031
|
definitions.forEach(filter => {
|
|
2034
2032
|
const value = values?.[filter.filterKey];
|
|
2035
|
-
if (value) {
|
|
2033
|
+
if (Boolean(value)) {
|
|
2036
2034
|
if (setEmptyAndDefaultValues) {
|
|
2037
2035
|
urlObject[filter.filterKey] = value;
|
|
2038
2036
|
}
|
|
@@ -2109,7 +2107,7 @@ const useFilterBarPersistence = ({ name, setValue, refreshData, isDefaultValue,
|
|
|
2109
2107
|
(typeof searchParams[name] === "string" &&
|
|
2110
2108
|
!dequal(decode(searchParams[name]), typeof search[name] === "string" ? decode(search[name]) : search[name]))) {
|
|
2111
2109
|
return requestAnimationFrame(async () => {
|
|
2112
|
-
const replace =
|
|
2110
|
+
const replace = search[name] === undefined || search[name] === null;
|
|
2113
2111
|
await navigate({
|
|
2114
2112
|
to: ".",
|
|
2115
2113
|
search: (prev) => {
|
|
@@ -2150,7 +2148,7 @@ const useFilterBarPersistence = ({ name, setValue, refreshData, isDefaultValue,
|
|
|
2150
2148
|
let currentSearchValueParsed;
|
|
2151
2149
|
let lastSearchUpdateRefParsed;
|
|
2152
2150
|
try {
|
|
2153
|
-
currentSearchValueParsed = currentSearchValue ? decode(currentSearchValue) : undefined;
|
|
2151
|
+
currentSearchValueParsed = currentSearchValue !== undefined && currentSearchValue !== null ? decode(currentSearchValue) : undefined;
|
|
2154
2152
|
}
|
|
2155
2153
|
catch (_) {
|
|
2156
2154
|
// Invalid compressed data, treat as undefined
|
|
@@ -2220,7 +2218,7 @@ const useFilterBarPersistence = ({ name, setValue, refreshData, isDefaultValue,
|
|
|
2220
2218
|
if (storedFilters && storedFilters !== "undefined") {
|
|
2221
2219
|
try {
|
|
2222
2220
|
const loadedFilterBarConfigValues = JSON.parse(storedFilters);
|
|
2223
|
-
return loadedFilterBarConfigValues?.values
|
|
2221
|
+
return loadedFilterBarConfigValues?.values ?? {};
|
|
2224
2222
|
}
|
|
2225
2223
|
catch (error) {
|
|
2226
2224
|
return {};
|
|
@@ -2229,9 +2227,9 @@ const useFilterBarPersistence = ({ name, setValue, refreshData, isDefaultValue,
|
|
|
2229
2227
|
return {};
|
|
2230
2228
|
}, [clientSideUserId, name, initialStoredFilters, lastName]);
|
|
2231
2229
|
const loadFromSearchURL = useCallback(() => {
|
|
2232
|
-
let searchParams = search
|
|
2230
|
+
let searchParams = search ?? {};
|
|
2233
2231
|
const searchParamValue = searchParams[name];
|
|
2234
|
-
if (searchParamValue) {
|
|
2232
|
+
if (searchParamValue !== undefined && searchParamValue !== null) {
|
|
2235
2233
|
try {
|
|
2236
2234
|
searchParams = decode(searchParamValue);
|
|
2237
2235
|
}
|
|
@@ -2249,7 +2247,7 @@ const useFilterBarPersistence = ({ name, setValue, refreshData, isDefaultValue,
|
|
|
2249
2247
|
else {
|
|
2250
2248
|
const values = loadFromLocalStorage() || {};
|
|
2251
2249
|
const searchParams = loadFromSearchURL();
|
|
2252
|
-
if (searchParams && objectKeys(searchParams).length > 0) {
|
|
2250
|
+
if (searchParams !== null && objectKeys(searchParams).length > 0) {
|
|
2253
2251
|
const valuesFromUrl = getFilterValuesFromUrl(filterDefinitions, searchParams);
|
|
2254
2252
|
if (objectKeys(valuesFromUrl).length > 0) {
|
|
2255
2253
|
// if there are values from the URL, update ALL filters values based on the searchParams or their defaults
|
|
@@ -2547,7 +2545,7 @@ const useSearchParamAsFilter = ({ filterName, search, zodSchema, errorHandler, }
|
|
|
2547
2545
|
try {
|
|
2548
2546
|
const getJsonParsedVal = () => {
|
|
2549
2547
|
if (zodSchema._def.typeName === "ZodString") {
|
|
2550
|
-
return foundParam ? foundParam + "" : foundParam;
|
|
2548
|
+
return foundParam !== undefined && foundParam !== null ? foundParam + "" : foundParam;
|
|
2551
2549
|
}
|
|
2552
2550
|
if (typeof search === "string" && typeof foundParam === "string") {
|
|
2553
2551
|
return JSON.parse(foundParam);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/filters-filter-bar",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.0",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -12,15 +12,15 @@
|
|
|
12
12
|
"tailwind-merge": "^2.0.0",
|
|
13
13
|
"string-ts": "^2.0.0",
|
|
14
14
|
"zod": "^3.23.8",
|
|
15
|
-
"@trackunit/iris-app-api": "1.
|
|
16
|
-
"@trackunit/react-core-hooks": "1.12.
|
|
17
|
-
"@trackunit/react-filter-components": "1.
|
|
18
|
-
"@trackunit/react-date-and-time-components": "1.
|
|
15
|
+
"@trackunit/iris-app-api": "1.15.0",
|
|
16
|
+
"@trackunit/react-core-hooks": "1.12.57",
|
|
17
|
+
"@trackunit/react-filter-components": "1.15.0",
|
|
18
|
+
"@trackunit/react-date-and-time-components": "1.18.0",
|
|
19
19
|
"@trackunit/shared-utils": "1.13.68",
|
|
20
|
-
"@trackunit/react-form-components": "1.
|
|
20
|
+
"@trackunit/react-form-components": "1.16.0",
|
|
21
21
|
"@trackunit/iris-app-runtime-core-api": "1.12.51",
|
|
22
22
|
"@trackunit/geo-json-utils": "1.11.69",
|
|
23
|
-
"@trackunit/i18n-library-translation": "1.
|
|
23
|
+
"@trackunit/i18n-library-translation": "1.13.0",
|
|
24
24
|
"@trackunit/css-class-variance-utilities": "1.11.68",
|
|
25
25
|
"@trackunit/react-components": "1.18.9",
|
|
26
26
|
"@tanstack/react-router": "1.114.29"
|
|
@@ -15,7 +15,7 @@ export type MinMaxFilterValue = {
|
|
|
15
15
|
min?: number;
|
|
16
16
|
max?: number;
|
|
17
17
|
};
|
|
18
|
-
export type FilterValueType = Array<string> | Array<ValueName> | ValueName | DateRangeValue | MinMaxFilterValue | AreaFilterGeoJsonGeometry | string | number | BooleanValue | undefined;
|
|
18
|
+
export type FilterValueType = Array<string> | Array<ValueName> | ValueName | DateRangeValue | MinMaxFilterValue | AreaFilterGeoJsonGeometry | string | number | BooleanValue | undefined | null;
|
|
19
19
|
export declare type FilterTypes = "boolean" | "string" | "number" | "dateRange" | "area" | "valueNameArray" | "valueName" | "stringArray" | "minMax";
|
|
20
20
|
export type FilterMapActions = {
|
|
21
21
|
toggleArrayValue: (key: string, value: string) => void;
|