@trackunit/filters-filter-bar 0.0.446 → 0.0.448
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 +15 -34
- package/index.esm.js +20 -39
- package/package.json +3 -2
- package/src/lib/components/DefaultCheckboxFilter.d.ts +1 -1
- package/src/lib/components/DefaultFilterTypes.d.ts +0 -4
- package/src/lib/components/DefaultRadioFilter.d.ts +1 -1
- package/src/lib/components/DynamicFilterList.d.ts +1 -13
- package/src/lib/types/FilterTypes.d.ts +0 -2
- package/src/lib/utils/createInitialState.d.ts +1 -1
package/index.cjs.js
CHANGED
|
@@ -13,6 +13,7 @@ var reactCoreContextsApi = require('@trackunit/react-core-contexts-api');
|
|
|
13
13
|
var reactFormComponents = require('@trackunit/react-form-components');
|
|
14
14
|
var reactDateAndTimeComponents = require('@trackunit/react-date-and-time-components');
|
|
15
15
|
var dequal = require('dequal');
|
|
16
|
+
var stringTs = require('string-ts');
|
|
16
17
|
var isEqual = require('lodash/isEqual');
|
|
17
18
|
|
|
18
19
|
var defaultTranslations = {
|
|
@@ -556,14 +557,14 @@ const toggleFilterValue = (value) => {
|
|
|
556
557
|
*
|
|
557
558
|
* @returns {JSX.Element} - Returns the DynamicFilterList component.
|
|
558
559
|
*/
|
|
559
|
-
const DynamicFilterList = ({ rowCount, keyMapper, labelMapper,
|
|
560
|
+
const DynamicFilterList = ({ rowCount, keyMapper, labelMapper, onChange, checked, count, showRequestMoreUseSearch = false, type, }) => {
|
|
560
561
|
const [t] = useTranslation();
|
|
561
562
|
const parentRef = react.useRef(null);
|
|
562
563
|
const updatedRowCount = react.useMemo(() => (showRequestMoreUseSearch ? rowCount + 1 : rowCount), [rowCount, showRequestMoreUseSearch]);
|
|
563
|
-
return (jsxRuntime.jsx(reactFilterComponents.FilterBody, { limitSize: true, ref: parentRef, children: jsxRuntime.jsx(reactComponents.VirtualizedList, { count: updatedRowCount, rowHeight: 40, separator: "space", children: index => {
|
|
564
|
-
return (jsxRuntime.jsx("div", { children: showRequestMoreUseSearch && index === rowCount ? (jsxRuntime.jsxs("div", { className: "p-3 pt-2", children: [jsxRuntime.jsx("span", { className: "text-sm text-gray-600", children: t("filter.more.options.if.you.search.title", { count: rowCount }) }), jsxRuntime.jsx("br", {}), jsxRuntime.jsx("span", { className: "text-sm italic text-gray-400", children: t("filter.more.options.if.you.search.description") })] })) : type === "Radio" ? (jsxRuntime.jsx(reactFilterComponents.RadioFilterItem, { dataTestId: "dynamic-filter-radio-" + keyMapper(index), itemCount: count(index), label: labelMapper(index),
|
|
564
|
+
return (jsxRuntime.jsx(reactFilterComponents.FilterBody, { dataTestId: "FUUUCK", limitSize: true, ref: parentRef, children: jsxRuntime.jsx(reactComponents.VirtualizedList, { count: updatedRowCount, rowHeight: 40, separator: "space", children: index => {
|
|
565
|
+
return (jsxRuntime.jsx("div", { children: showRequestMoreUseSearch && index === rowCount ? (jsxRuntime.jsxs("div", { className: "p-3 pt-2", children: [jsxRuntime.jsx("span", { className: "text-sm text-gray-600", children: t("filter.more.options.if.you.search.title", { count: rowCount }) }), jsxRuntime.jsx("br", {}), jsxRuntime.jsx("span", { className: "text-sm italic text-gray-400", children: t("filter.more.options.if.you.search.description") })] })) : type === "Radio" ? (jsxRuntime.jsx(reactFilterComponents.RadioFilterItem, { dataTestId: "dynamic-filter-radio-" + keyMapper(index), itemCount: count(index), label: labelMapper(index), selected: checked(index), value: keyMapper(index) }, keyMapper(index))) : (jsxRuntime.jsx(reactFilterComponents.CheckBoxFilterItem, { checked: checked(index), dataTestId: "dynamic-filter-check-box-" + keyMapper(index), itemCount: count(index), label: labelMapper(index), name: keyMapper(index), onChange: () => {
|
|
565
566
|
onChange === null || onChange === void 0 ? void 0 : onChange(index);
|
|
566
|
-
}
|
|
567
|
+
} }, keyMapper(index))) }));
|
|
567
568
|
} }) }));
|
|
568
569
|
};
|
|
569
570
|
|
|
@@ -578,7 +579,7 @@ const FilterHeader = ({ filterKey, title, searchEnabled, searchProps, filterHasC
|
|
|
578
579
|
resetIndividualFilterToInitialState(filterKey);
|
|
579
580
|
onResetFilter === null || onResetFilter === void 0 ? void 0 : onResetFilter();
|
|
580
581
|
};
|
|
581
|
-
return (jsxRuntime.jsx(reactFilterComponents.FilterHeader, { dataTestId: `${filterKey}-filter-header`, loading: loading, onReset: handleResetFilter, resetLabel: t("filtersBar.resetFilter"), showReset: filterHasChanged(filterKey), title: title, children: searchEnabled ? (jsxRuntime.jsx(reactFormComponents.Search, { autoFocus: true, fieldSize: "small", onChange: e => searchProps.onChange(e.currentTarget.value), placeholder: t("assetFilters.searchPlaceholder"), suffix: jsxRuntime.jsx(reactComponents.Text, { size: "small", subtle: true, children: searchProps.count }), value: searchProps.value })) : null }));
|
|
582
|
+
return (jsxRuntime.jsx(reactFilterComponents.FilterHeader, { dataTestId: `${filterKey}-filter-header`, loading: loading, onReset: handleResetFilter, resetLabel: t("filtersBar.resetFilter"), showReset: filterHasChanged(filterKey), title: title, children: searchEnabled ? (jsxRuntime.jsx(reactFormComponents.Search, { autoFocus: true, fieldSize: "small", id: `${filterKey}-search`, onChange: e => searchProps.onChange(e.currentTarget.value), placeholder: t("assetFilters.searchPlaceholder"), suffix: jsxRuntime.jsx(reactComponents.Text, { size: "small", subtle: true, children: searchProps.count }), value: searchProps.value })) : null }));
|
|
582
583
|
};
|
|
583
584
|
|
|
584
585
|
/**
|
|
@@ -606,7 +607,7 @@ const EmptyResults = ({ loading }) => {
|
|
|
606
607
|
*
|
|
607
608
|
* @param {DefaultFilterProps<string[]>} props - The properties required for the `DefaultCheckboxFilter` component.
|
|
608
609
|
*/
|
|
609
|
-
const DefaultCheckboxFilter = ({ filterDefinition, filterBarActions, options, loading, setValue, filterName, customSearch, showRequestMoreUseSearch = false, showUndefinedOptionWithCountAtBottom = true,
|
|
610
|
+
const DefaultCheckboxFilter = ({ filterDefinition, filterBarActions, options, loading, setValue, filterName, customSearch, showRequestMoreUseSearch = false, showUndefinedOptionWithCountAtBottom = true, }) => {
|
|
610
611
|
var _a, _b, _c, _d, _e;
|
|
611
612
|
const [undefinedCount, setUndefinedCount] = react.useState(null);
|
|
612
613
|
const { logEvent } = reactCoreHooks.useAnalytics(FilterEvents);
|
|
@@ -674,9 +675,9 @@ const DefaultCheckboxFilter = ({ filterDefinition, filterBarActions, options, lo
|
|
|
674
675
|
if (result) {
|
|
675
676
|
handleSetValue(result);
|
|
676
677
|
}
|
|
677
|
-
},
|
|
678
|
+
}, rowCount: undefinedCount ? res.length - 1 : res.length, showRequestMoreUseSearch: showRequestMoreUseSearch, type: "CheckBox" })) }), showUndefinedOptionWithCountAtBottom && undefinedCount ? (jsxRuntime.jsx(reactFilterComponents.CheckBoxFilterItem, { checked: filterDefinition.type === "valueName"
|
|
678
679
|
? filterBarActions.objectArrayIncludesValue(filterDefinition.filterKey, ((_c = results[undefinedCount.index]) === null || _c === void 0 ? void 0 : _c.key) || "")
|
|
679
|
-
: filterBarActions.arrayIncludesValue(filterDefinition.filterKey, ((_d = results[undefinedCount.index]) === null || _d === void 0 ? void 0 : _d.key) || ""), className: "border-t-2", dataTestId: "dynamic-filter-check-box-undefined", itemCount: undefinedCount.count, label: (_e = results[undefinedCount.index]) === null || _e === void 0 ? void 0 : _e.label, name: "dynamic-filter-check-box-undefined", onChange: () => {
|
|
680
|
+
: filterBarActions.arrayIncludesValue(filterDefinition.filterKey, ((_d = results[undefinedCount.index]) === null || _d === void 0 ? void 0 : _d.key) || ""), className: "rounded-none border-t-2", dataTestId: "dynamic-filter-check-box-undefined", itemCount: undefinedCount.count, label: (_e = results[undefinedCount.index]) === null || _e === void 0 ? void 0 : _e.label, name: "dynamic-filter-check-box-undefined", onChange: () => {
|
|
680
681
|
const result = results[undefinedCount.index];
|
|
681
682
|
if (result) {
|
|
682
683
|
handleSetValue(result);
|
|
@@ -768,7 +769,7 @@ const DefaultMinMaxFilter = ({ filterDefinition, filterName, value, setValue, fi
|
|
|
768
769
|
*
|
|
769
770
|
* @returns {JSX.Element} - Returns the DefaultRadioFilter component.
|
|
770
771
|
*/
|
|
771
|
-
const DefaultRadioFilter = ({ filterDefinition, filterBarActions, options, loading, filterName, customSearch, showRequestMoreUseSearch = false,
|
|
772
|
+
const DefaultRadioFilter = ({ filterDefinition, filterBarActions, options, loading, filterName, customSearch, showRequestMoreUseSearch = false, }) => {
|
|
772
773
|
var _a, _b, _c;
|
|
773
774
|
const { logEvent } = reactCoreHooks.useAnalytics(FilterEvents);
|
|
774
775
|
const [filteredOptions, searchText, setSearchText] = reactCoreHooks.useTextSearch(options, item => [item.label]);
|
|
@@ -790,20 +791,7 @@ const DefaultRadioFilter = ({ filterDefinition, filterBarActions, options, loadi
|
|
|
790
791
|
count: filteredOptions.length,
|
|
791
792
|
} }), jsxRuntime.jsx(FilterResults, { loading: loading, results: customSearch ? options : filteredOptions, children: res => (jsxRuntime.jsx(reactFormComponents.RadioGroup, { id: "DefaultRadioFilter", onChange: e => {
|
|
792
793
|
handleClick(e.currentTarget.value);
|
|
793
|
-
}, value: selectedRadioId, children: jsxRuntime.jsx(DynamicFilterList, { checked: index => { var _a; return filterBarActions.objectArrayIncludesValue(filterDefinition.filterKey, ((_a = res[index]) === null || _a === void 0 ? void 0 : _a.key) || ""); }, count: index => { var _a; return (_a = res[index]) === null || _a === void 0 ? void 0 : _a.count; }, keyMapper: index => { var _a; return ((_a = res[index]) === null || _a === void 0 ? void 0 : _a.key) || ""; }, labelMapper: index => { var _a; return ((_a = res[index]) === null || _a === void 0 ? void 0 : _a.label) || ""; },
|
|
794
|
-
};
|
|
795
|
-
|
|
796
|
-
/**
|
|
797
|
-
* Capitalizes the first letter of a string.
|
|
798
|
-
*
|
|
799
|
-
* @param {string | null | undefined} s - The input string to capitalize. Can be null or undefined.
|
|
800
|
-
* @returns {string} The input string with its first letter capitalized, or an empty string if the input is null or undefined.
|
|
801
|
-
*/
|
|
802
|
-
const capitalize = (s) => {
|
|
803
|
-
if (!s) {
|
|
804
|
-
return "";
|
|
805
|
-
}
|
|
806
|
-
return s.charAt(0).toUpperCase() + s.substring(1);
|
|
794
|
+
}, value: selectedRadioId, children: jsxRuntime.jsx(DynamicFilterList, { checked: index => { var _a; return filterBarActions.objectArrayIncludesValue(filterDefinition.filterKey, ((_a = res[index]) === null || _a === void 0 ? void 0 : _a.key) || ""); }, count: index => { var _a; return (_a = res[index]) === null || _a === void 0 ? void 0 : _a.count; }, keyMapper: index => { var _a; return ((_a = res[index]) === null || _a === void 0 ? void 0 : _a.key) || ""; }, labelMapper: index => { var _a; return ((_a = res[index]) === null || _a === void 0 ? void 0 : _a.label) || ""; }, rowCount: res.length, showRequestMoreUseSearch: showRequestMoreUseSearch, type: "Radio" }) })) })] }));
|
|
807
795
|
};
|
|
808
796
|
|
|
809
797
|
/**
|
|
@@ -814,7 +802,7 @@ const capitalize = (s) => {
|
|
|
814
802
|
*/
|
|
815
803
|
const getInitialValueFromType = (type) => {
|
|
816
804
|
if (type === "string") {
|
|
817
|
-
return
|
|
805
|
+
return "";
|
|
818
806
|
}
|
|
819
807
|
if (type === "stringArray") {
|
|
820
808
|
return [];
|
|
@@ -854,7 +842,7 @@ const createInitialState = (name, mainFilters, initialState, setValue) => {
|
|
|
854
842
|
const key = curr.filterKey;
|
|
855
843
|
return {
|
|
856
844
|
...prev,
|
|
857
|
-
[`set${capitalize(key)}`]: (callback) => setValue(key, callback),
|
|
845
|
+
[`set${stringTs.capitalize(key)}`]: (callback) => setValue(key, callback),
|
|
858
846
|
};
|
|
859
847
|
}, {});
|
|
860
848
|
const updatedInitialState = mainFilters.reduce((prev, curr) => {
|
|
@@ -1040,7 +1028,7 @@ const useFilterBar = ({ name, onValuesChange, filterBarDefinition, initialState,
|
|
|
1040
1028
|
// eslint-disable-next-line no-autofix/local-rules/prefer-custom-object-keys
|
|
1041
1029
|
Object.keys(initialFilterBarConfig.values).forEach(key => {
|
|
1042
1030
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1043
|
-
initialFilterBarConfig.setters[`set${capitalize(key)}`] = (callback) => setValue(key, callback);
|
|
1031
|
+
initialFilterBarConfig.setters[`set${stringTs.capitalize(key)}`] = (callback) => setValue(key, callback);
|
|
1044
1032
|
});
|
|
1045
1033
|
return initialFilterBarConfig;
|
|
1046
1034
|
});
|
|
@@ -1175,20 +1163,13 @@ const useFilterBar = ({ name, onValuesChange, filterBarDefinition, initialState,
|
|
|
1175
1163
|
};
|
|
1176
1164
|
});
|
|
1177
1165
|
},
|
|
1178
|
-
//For bounding box
|
|
1179
1166
|
setBoundingBox(boundingBox) {
|
|
1180
1167
|
setFilterBarConfig(prevState => {
|
|
1181
|
-
var _a;
|
|
1182
|
-
// cleaning because something here is allergic to getting the "__typename" property
|
|
1183
|
-
const cleanedBoundingBox = {
|
|
1184
|
-
nw: { latitude: boundingBox.nw.latitude, longitude: boundingBox.nw.longitude },
|
|
1185
|
-
se: { latitude: boundingBox.se.latitude, longitude: boundingBox.se.longitude },
|
|
1186
|
-
};
|
|
1187
1168
|
return {
|
|
1188
1169
|
...prevState,
|
|
1189
1170
|
values: {
|
|
1190
1171
|
...prevState.values,
|
|
1191
|
-
|
|
1172
|
+
boundingBox,
|
|
1192
1173
|
},
|
|
1193
1174
|
};
|
|
1194
1175
|
});
|
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, VirtualizedList } from '@trackunit/react-components';
|
|
6
|
-
import { objectValues, truthy, capitalize
|
|
6
|
+
import { objectValues, truthy, capitalize, nonNullable } from '@trackunit/shared-utils';
|
|
7
7
|
import { useMemo, useState, Fragment as Fragment$1, useRef, useEffect, useCallback } 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';
|
|
@@ -11,6 +11,7 @@ import { createEvent } from '@trackunit/react-core-contexts-api';
|
|
|
11
11
|
import { Search, NumberField, RadioGroup } from '@trackunit/react-form-components';
|
|
12
12
|
import { DayRangePicker } from '@trackunit/react-date-and-time-components';
|
|
13
13
|
import { dequal } from 'dequal';
|
|
14
|
+
import { capitalize as capitalize$1 } from 'string-ts';
|
|
14
15
|
import isEqual from 'lodash/isEqual';
|
|
15
16
|
|
|
16
17
|
var defaultTranslations = {
|
|
@@ -554,14 +555,14 @@ const toggleFilterValue = (value) => {
|
|
|
554
555
|
*
|
|
555
556
|
* @returns {JSX.Element} - Returns the DynamicFilterList component.
|
|
556
557
|
*/
|
|
557
|
-
const DynamicFilterList = ({ rowCount, keyMapper, labelMapper,
|
|
558
|
+
const DynamicFilterList = ({ rowCount, keyMapper, labelMapper, onChange, checked, count, showRequestMoreUseSearch = false, type, }) => {
|
|
558
559
|
const [t] = useTranslation();
|
|
559
560
|
const parentRef = useRef(null);
|
|
560
561
|
const updatedRowCount = useMemo(() => (showRequestMoreUseSearch ? rowCount + 1 : rowCount), [rowCount, showRequestMoreUseSearch]);
|
|
561
|
-
return (jsx(FilterBody, { limitSize: true, ref: parentRef, children: jsx(VirtualizedList, { count: updatedRowCount, rowHeight: 40, separator: "space", children: index => {
|
|
562
|
-
return (jsx("div", { children: showRequestMoreUseSearch && index === rowCount ? (jsxs("div", { className: "p-3 pt-2", children: [jsx("span", { className: "text-sm text-gray-600", children: t("filter.more.options.if.you.search.title", { count: rowCount }) }), jsx("br", {}), jsx("span", { className: "text-sm italic text-gray-400", children: t("filter.more.options.if.you.search.description") })] })) : type === "Radio" ? (jsx(RadioFilterItem, { dataTestId: "dynamic-filter-radio-" + keyMapper(index), itemCount: count(index), label: labelMapper(index),
|
|
562
|
+
return (jsx(FilterBody, { dataTestId: "FUUUCK", limitSize: true, ref: parentRef, children: jsx(VirtualizedList, { count: updatedRowCount, rowHeight: 40, separator: "space", children: index => {
|
|
563
|
+
return (jsx("div", { children: showRequestMoreUseSearch && index === rowCount ? (jsxs("div", { className: "p-3 pt-2", children: [jsx("span", { className: "text-sm text-gray-600", children: t("filter.more.options.if.you.search.title", { count: rowCount }) }), jsx("br", {}), jsx("span", { className: "text-sm italic text-gray-400", children: t("filter.more.options.if.you.search.description") })] })) : type === "Radio" ? (jsx(RadioFilterItem, { dataTestId: "dynamic-filter-radio-" + keyMapper(index), itemCount: count(index), label: labelMapper(index), selected: checked(index), value: keyMapper(index) }, keyMapper(index))) : (jsx(CheckBoxFilterItem, { checked: checked(index), dataTestId: "dynamic-filter-check-box-" + keyMapper(index), itemCount: count(index), label: labelMapper(index), name: keyMapper(index), onChange: () => {
|
|
563
564
|
onChange === null || onChange === void 0 ? void 0 : onChange(index);
|
|
564
|
-
}
|
|
565
|
+
} }, keyMapper(index))) }));
|
|
565
566
|
} }) }));
|
|
566
567
|
};
|
|
567
568
|
|
|
@@ -576,7 +577,7 @@ const FilterHeader = ({ filterKey, title, searchEnabled, searchProps, filterHasC
|
|
|
576
577
|
resetIndividualFilterToInitialState(filterKey);
|
|
577
578
|
onResetFilter === null || onResetFilter === void 0 ? void 0 : onResetFilter();
|
|
578
579
|
};
|
|
579
|
-
return (jsx(FilterHeader$1, { dataTestId: `${filterKey}-filter-header`, loading: loading, onReset: handleResetFilter, resetLabel: t("filtersBar.resetFilter"), showReset: filterHasChanged(filterKey), title: title, children: searchEnabled ? (jsx(Search, { autoFocus: true, fieldSize: "small", onChange: e => searchProps.onChange(e.currentTarget.value), placeholder: t("assetFilters.searchPlaceholder"), suffix: jsx(Text, { size: "small", subtle: true, children: searchProps.count }), value: searchProps.value })) : null }));
|
|
580
|
+
return (jsx(FilterHeader$1, { dataTestId: `${filterKey}-filter-header`, loading: loading, onReset: handleResetFilter, resetLabel: t("filtersBar.resetFilter"), showReset: filterHasChanged(filterKey), title: title, children: searchEnabled ? (jsx(Search, { autoFocus: true, fieldSize: "small", id: `${filterKey}-search`, onChange: e => searchProps.onChange(e.currentTarget.value), placeholder: t("assetFilters.searchPlaceholder"), suffix: jsx(Text, { size: "small", subtle: true, children: searchProps.count }), value: searchProps.value })) : null }));
|
|
580
581
|
};
|
|
581
582
|
|
|
582
583
|
/**
|
|
@@ -604,13 +605,13 @@ const EmptyResults = ({ loading }) => {
|
|
|
604
605
|
*
|
|
605
606
|
* @param {DefaultFilterProps<string[]>} props - The properties required for the `DefaultCheckboxFilter` component.
|
|
606
607
|
*/
|
|
607
|
-
const DefaultCheckboxFilter = ({ filterDefinition, filterBarActions, options, loading, setValue, filterName, customSearch, showRequestMoreUseSearch = false, showUndefinedOptionWithCountAtBottom = true,
|
|
608
|
+
const DefaultCheckboxFilter = ({ filterDefinition, filterBarActions, options, loading, setValue, filterName, customSearch, showRequestMoreUseSearch = false, showUndefinedOptionWithCountAtBottom = true, }) => {
|
|
608
609
|
var _a, _b, _c, _d, _e;
|
|
609
610
|
const [undefinedCount, setUndefinedCount] = useState(null);
|
|
610
611
|
const { logEvent } = useAnalytics(FilterEvents);
|
|
611
612
|
const handleSetValue = (value) => {
|
|
612
613
|
logEvent("Filters Applied - V2", {
|
|
613
|
-
type: filterName !== null && filterName !== void 0 ? filterName : `${capitalize
|
|
614
|
+
type: filterName !== null && filterName !== void 0 ? filterName : `${capitalize(filterDefinition.filterKey)}Filter`,
|
|
614
615
|
value: value.key,
|
|
615
616
|
});
|
|
616
617
|
if (filterDefinition.type === "stringArray") {
|
|
@@ -672,9 +673,9 @@ const DefaultCheckboxFilter = ({ filterDefinition, filterBarActions, options, lo
|
|
|
672
673
|
if (result) {
|
|
673
674
|
handleSetValue(result);
|
|
674
675
|
}
|
|
675
|
-
},
|
|
676
|
+
}, rowCount: undefinedCount ? res.length - 1 : res.length, showRequestMoreUseSearch: showRequestMoreUseSearch, type: "CheckBox" })) }), showUndefinedOptionWithCountAtBottom && undefinedCount ? (jsx(CheckBoxFilterItem, { checked: filterDefinition.type === "valueName"
|
|
676
677
|
? filterBarActions.objectArrayIncludesValue(filterDefinition.filterKey, ((_c = results[undefinedCount.index]) === null || _c === void 0 ? void 0 : _c.key) || "")
|
|
677
|
-
: filterBarActions.arrayIncludesValue(filterDefinition.filterKey, ((_d = results[undefinedCount.index]) === null || _d === void 0 ? void 0 : _d.key) || ""), className: "border-t-2", dataTestId: "dynamic-filter-check-box-undefined", itemCount: undefinedCount.count, label: (_e = results[undefinedCount.index]) === null || _e === void 0 ? void 0 : _e.label, name: "dynamic-filter-check-box-undefined", onChange: () => {
|
|
678
|
+
: filterBarActions.arrayIncludesValue(filterDefinition.filterKey, ((_d = results[undefinedCount.index]) === null || _d === void 0 ? void 0 : _d.key) || ""), className: "rounded-none border-t-2", dataTestId: "dynamic-filter-check-box-undefined", itemCount: undefinedCount.count, label: (_e = results[undefinedCount.index]) === null || _e === void 0 ? void 0 : _e.label, name: "dynamic-filter-check-box-undefined", onChange: () => {
|
|
678
679
|
const result = results[undefinedCount.index];
|
|
679
680
|
if (result) {
|
|
680
681
|
handleSetValue(result);
|
|
@@ -718,7 +719,7 @@ const DefaultDateRangeFilter = ({ filterDefinition, filterName, value, setValue,
|
|
|
718
719
|
const { logEvent } = useAnalytics(FilterEvents);
|
|
719
720
|
const handleApply = (fromDateValue, toDateValue) => {
|
|
720
721
|
logEvent("Filters Applied - V2", {
|
|
721
|
-
type: filterName !== null && filterName !== void 0 ? filterName : `${capitalize
|
|
722
|
+
type: filterName !== null && filterName !== void 0 ? filterName : `${capitalize(filterDefinition.filterKey)}Filter`,
|
|
722
723
|
value: JSON.stringify({ from: fromDateValue, to: toDateValue }),
|
|
723
724
|
});
|
|
724
725
|
setValue(() => ({ from: fromDateValue, to: toDateValue }));
|
|
@@ -751,7 +752,7 @@ const DefaultMinMaxFilter = ({ filterDefinition, filterName, value, setValue, fi
|
|
|
751
752
|
const realMinValue = minValue === 0 ? undefined : minValue !== null && minValue !== void 0 ? minValue : undefined;
|
|
752
753
|
const realMaxValue = maxValue === 0 ? undefined : maxValue !== null && maxValue !== void 0 ? maxValue : undefined;
|
|
753
754
|
logEvent("Filters Applied - V2", {
|
|
754
|
-
type: filterName !== null && filterName !== void 0 ? filterName : `${capitalize
|
|
755
|
+
type: filterName !== null && filterName !== void 0 ? filterName : `${capitalize(filterDefinition.filterKey)}Filter`,
|
|
755
756
|
value: JSON.stringify({ min: realMinValue, max: realMaxValue }),
|
|
756
757
|
});
|
|
757
758
|
setValue(() => {
|
|
@@ -766,7 +767,7 @@ const DefaultMinMaxFilter = ({ filterDefinition, filterName, value, setValue, fi
|
|
|
766
767
|
*
|
|
767
768
|
* @returns {JSX.Element} - Returns the DefaultRadioFilter component.
|
|
768
769
|
*/
|
|
769
|
-
const DefaultRadioFilter = ({ filterDefinition, filterBarActions, options, loading, filterName, customSearch, showRequestMoreUseSearch = false,
|
|
770
|
+
const DefaultRadioFilter = ({ filterDefinition, filterBarActions, options, loading, filterName, customSearch, showRequestMoreUseSearch = false, }) => {
|
|
770
771
|
var _a, _b, _c;
|
|
771
772
|
const { logEvent } = useAnalytics(FilterEvents);
|
|
772
773
|
const [filteredOptions, searchText, setSearchText] = useTextSearch(options, item => [item.label]);
|
|
@@ -776,7 +777,7 @@ const DefaultRadioFilter = ({ filterDefinition, filterBarActions, options, loadi
|
|
|
776
777
|
if (key && label) {
|
|
777
778
|
filterBarActions.setArrayObjectValue(filterDefinition.filterKey, [{ value: key, name: label }]);
|
|
778
779
|
logEvent("Filters Applied - V2", {
|
|
779
|
-
type: filterName !== null && filterName !== void 0 ? filterName : `${capitalize
|
|
780
|
+
type: filterName !== null && filterName !== void 0 ? filterName : `${capitalize(filterDefinition.filterKey)}Filter`,
|
|
780
781
|
value: String(label),
|
|
781
782
|
});
|
|
782
783
|
}
|
|
@@ -788,20 +789,7 @@ const DefaultRadioFilter = ({ filterDefinition, filterBarActions, options, loadi
|
|
|
788
789
|
count: filteredOptions.length,
|
|
789
790
|
} }), jsx(FilterResults, { loading: loading, results: customSearch ? options : filteredOptions, children: res => (jsx(RadioGroup, { id: "DefaultRadioFilter", onChange: e => {
|
|
790
791
|
handleClick(e.currentTarget.value);
|
|
791
|
-
}, value: selectedRadioId, children: jsx(DynamicFilterList, { checked: index => { var _a; return filterBarActions.objectArrayIncludesValue(filterDefinition.filterKey, ((_a = res[index]) === null || _a === void 0 ? void 0 : _a.key) || ""); }, count: index => { var _a; return (_a = res[index]) === null || _a === void 0 ? void 0 : _a.count; }, keyMapper: index => { var _a; return ((_a = res[index]) === null || _a === void 0 ? void 0 : _a.key) || ""; }, labelMapper: index => { var _a; return ((_a = res[index]) === null || _a === void 0 ? void 0 : _a.label) || ""; },
|
|
792
|
-
};
|
|
793
|
-
|
|
794
|
-
/**
|
|
795
|
-
* Capitalizes the first letter of a string.
|
|
796
|
-
*
|
|
797
|
-
* @param {string | null | undefined} s - The input string to capitalize. Can be null or undefined.
|
|
798
|
-
* @returns {string} The input string with its first letter capitalized, or an empty string if the input is null or undefined.
|
|
799
|
-
*/
|
|
800
|
-
const capitalize = (s) => {
|
|
801
|
-
if (!s) {
|
|
802
|
-
return "";
|
|
803
|
-
}
|
|
804
|
-
return s.charAt(0).toUpperCase() + s.substring(1);
|
|
792
|
+
}, value: selectedRadioId, children: jsx(DynamicFilterList, { checked: index => { var _a; return filterBarActions.objectArrayIncludesValue(filterDefinition.filterKey, ((_a = res[index]) === null || _a === void 0 ? void 0 : _a.key) || ""); }, count: index => { var _a; return (_a = res[index]) === null || _a === void 0 ? void 0 : _a.count; }, keyMapper: index => { var _a; return ((_a = res[index]) === null || _a === void 0 ? void 0 : _a.key) || ""; }, labelMapper: index => { var _a; return ((_a = res[index]) === null || _a === void 0 ? void 0 : _a.label) || ""; }, rowCount: res.length, showRequestMoreUseSearch: showRequestMoreUseSearch, type: "Radio" }) })) })] }));
|
|
805
793
|
};
|
|
806
794
|
|
|
807
795
|
/**
|
|
@@ -812,7 +800,7 @@ const capitalize = (s) => {
|
|
|
812
800
|
*/
|
|
813
801
|
const getInitialValueFromType = (type) => {
|
|
814
802
|
if (type === "string") {
|
|
815
|
-
return
|
|
803
|
+
return "";
|
|
816
804
|
}
|
|
817
805
|
if (type === "stringArray") {
|
|
818
806
|
return [];
|
|
@@ -852,7 +840,7 @@ const createInitialState = (name, mainFilters, initialState, setValue) => {
|
|
|
852
840
|
const key = curr.filterKey;
|
|
853
841
|
return {
|
|
854
842
|
...prev,
|
|
855
|
-
[`set${capitalize(key)}`]: (callback) => setValue(key, callback),
|
|
843
|
+
[`set${capitalize$1(key)}`]: (callback) => setValue(key, callback),
|
|
856
844
|
};
|
|
857
845
|
}, {});
|
|
858
846
|
const updatedInitialState = mainFilters.reduce((prev, curr) => {
|
|
@@ -1038,7 +1026,7 @@ const useFilterBar = ({ name, onValuesChange, filterBarDefinition, initialState,
|
|
|
1038
1026
|
// eslint-disable-next-line no-autofix/local-rules/prefer-custom-object-keys
|
|
1039
1027
|
Object.keys(initialFilterBarConfig.values).forEach(key => {
|
|
1040
1028
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1041
|
-
initialFilterBarConfig.setters[`set${capitalize(key)}`] = (callback) => setValue(key, callback);
|
|
1029
|
+
initialFilterBarConfig.setters[`set${capitalize$1(key)}`] = (callback) => setValue(key, callback);
|
|
1042
1030
|
});
|
|
1043
1031
|
return initialFilterBarConfig;
|
|
1044
1032
|
});
|
|
@@ -1173,20 +1161,13 @@ const useFilterBar = ({ name, onValuesChange, filterBarDefinition, initialState,
|
|
|
1173
1161
|
};
|
|
1174
1162
|
});
|
|
1175
1163
|
},
|
|
1176
|
-
//For bounding box
|
|
1177
1164
|
setBoundingBox(boundingBox) {
|
|
1178
1165
|
setFilterBarConfig(prevState => {
|
|
1179
|
-
var _a;
|
|
1180
|
-
// cleaning because something here is allergic to getting the "__typename" property
|
|
1181
|
-
const cleanedBoundingBox = {
|
|
1182
|
-
nw: { latitude: boundingBox.nw.latitude, longitude: boundingBox.nw.longitude },
|
|
1183
|
-
se: { latitude: boundingBox.se.latitude, longitude: boundingBox.se.longitude },
|
|
1184
|
-
};
|
|
1185
1166
|
return {
|
|
1186
1167
|
...prevState,
|
|
1187
1168
|
values: {
|
|
1188
1169
|
...prevState.values,
|
|
1189
|
-
|
|
1170
|
+
boundingBox,
|
|
1190
1171
|
},
|
|
1191
1172
|
};
|
|
1192
1173
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/filters-filter-bar",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.448",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"@trackunit/i18n-library-translation": "*",
|
|
21
21
|
"@trackunit/css-class-variance-utilities": "*",
|
|
22
22
|
"tailwind-merge": "^2.0.0",
|
|
23
|
-
"@trackunit/react-date-and-time-components": "*"
|
|
23
|
+
"@trackunit/react-date-and-time-components": "*",
|
|
24
|
+
"string-ts": "^2.0.0"
|
|
24
25
|
},
|
|
25
26
|
"module": "./index.esm.js",
|
|
26
27
|
"main": "./index.cjs.js",
|
|
@@ -6,5 +6,5 @@ type FilterDefinitionValue = string[] | ValueName[];
|
|
|
6
6
|
*
|
|
7
7
|
* @param {DefaultFilterProps<string[]>} props - The properties required for the `DefaultCheckboxFilter` component.
|
|
8
8
|
*/
|
|
9
|
-
export declare const DefaultCheckboxFilter: <T extends FilterDefinitionValue>({ filterDefinition, filterBarActions, options, loading, setValue, filterName, customSearch, showRequestMoreUseSearch, showUndefinedOptionWithCountAtBottom,
|
|
9
|
+
export declare const DefaultCheckboxFilter: <T extends FilterDefinitionValue>({ filterDefinition, filterBarActions, options, loading, setValue, filterName, customSearch, showRequestMoreUseSearch, showUndefinedOptionWithCountAtBottom, }: DefaultFilterProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
10
10
|
export {};
|
|
@@ -27,10 +27,6 @@ export interface DefaultFilterProps<TReturnType> extends FilterViewProps<TReturn
|
|
|
27
27
|
* Indicates whether the filter is in a loading state.
|
|
28
28
|
*/
|
|
29
29
|
loading?: boolean;
|
|
30
|
-
/**
|
|
31
|
-
* A flag indicating whether tooltips should be displayed for the filter options.
|
|
32
|
-
*/
|
|
33
|
-
showTooltip?: boolean;
|
|
34
30
|
/**
|
|
35
31
|
* A custom filter name, if provided.
|
|
36
32
|
*/
|
|
@@ -5,4 +5,4 @@ import { DefaultFilterProps } from "./DefaultFilterTypes";
|
|
|
5
5
|
*
|
|
6
6
|
* @returns {JSX.Element} - Returns the DefaultRadioFilter component.
|
|
7
7
|
*/
|
|
8
|
-
export declare const DefaultRadioFilter: ({ filterDefinition, filterBarActions, options, loading, filterName, customSearch, showRequestMoreUseSearch,
|
|
8
|
+
export declare const DefaultRadioFilter: ({ filterDefinition, filterBarActions, options, loading, filterName, customSearch, showRequestMoreUseSearch, }: DefaultFilterProps<ValueName[]>) => JSX.Element;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
2
1
|
interface DynamicFilterListProps {
|
|
3
2
|
/**
|
|
4
3
|
* The type of input element to use in the list.
|
|
@@ -22,13 +21,6 @@ interface DynamicFilterListProps {
|
|
|
22
21
|
* @returns {string} - The label for the row.
|
|
23
22
|
*/
|
|
24
23
|
labelMapper: (rowIndex: number) => string;
|
|
25
|
-
/**
|
|
26
|
-
* An optional function that maps a row's index to a prefix element.
|
|
27
|
-
*
|
|
28
|
-
* @param {number} rowIndex - The index of the row.
|
|
29
|
-
* @returns {ReactNode} - The prefix element for the row.
|
|
30
|
-
*/
|
|
31
|
-
prefixMapper?: (rowIndex: number) => ReactNode;
|
|
32
24
|
/**
|
|
33
25
|
* An optional callback function called when a row's input element value changes.
|
|
34
26
|
*
|
|
@@ -49,10 +41,6 @@ interface DynamicFilterListProps {
|
|
|
49
41
|
* @returns {number|undefined} - The count for the row, or `undefined` if not applicable.
|
|
50
42
|
*/
|
|
51
43
|
count: (rowIndex: number) => number | undefined;
|
|
52
|
-
/**
|
|
53
|
-
* A flag indicating whether tooltips should be displayed for the rows.
|
|
54
|
-
*/
|
|
55
|
-
showTooltip?: boolean;
|
|
56
44
|
/**
|
|
57
45
|
* A flag indicating whether the "Use search to refine results." option should be displayed.
|
|
58
46
|
*/
|
|
@@ -63,5 +51,5 @@ interface DynamicFilterListProps {
|
|
|
63
51
|
*
|
|
64
52
|
* @returns {JSX.Element} - Returns the DynamicFilterList component.
|
|
65
53
|
*/
|
|
66
|
-
export declare const DynamicFilterList: ({ rowCount, keyMapper, labelMapper,
|
|
54
|
+
export declare const DynamicFilterList: ({ rowCount, keyMapper, labelMapper, onChange, checked, count, showRequestMoreUseSearch, type, }: DynamicFilterListProps) => JSX.Element;
|
|
67
55
|
export {};
|
|
@@ -18,8 +18,6 @@ export type BoundingBox = {
|
|
|
18
18
|
nw: Coordinate;
|
|
19
19
|
/** The coordinates for the South/East values of the bounding box. */
|
|
20
20
|
se: Coordinate;
|
|
21
|
-
/** The zoom level from which the bound box spans. */
|
|
22
|
-
zoom?: number | null;
|
|
23
21
|
};
|
|
24
22
|
export type MinMaxFilterValue = {
|
|
25
23
|
min?: number;
|