@trackunit/filters-filter-bar 0.0.366 → 0.0.369
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 +12 -12
- package/index.esm.js +12 -12
- package/package.json +1 -1
- package/src/lib/utils/createInitialState.d.ts +28 -8
package/index.cjs.js
CHANGED
|
@@ -504,9 +504,9 @@ const StarredFilters = ({ filterBarDefinition, filterBarConfig, disableCollapse,
|
|
|
504
504
|
const [expanded, setExpanded] = react.useState(false);
|
|
505
505
|
const [t] = useTranslation();
|
|
506
506
|
const dimensions = reactComponents.useResize();
|
|
507
|
-
return dimensions.width > 768 || disableCollapse ? (jsxRuntime.jsx(FilterSelection, { className: cvaFilterWithoutCollapse({ disableCollapse }), filterBarConfig: filterBarConfig, filterBarDefinition: filterBarDefinition, hiddenFilters: hiddenFilters })) : (jsxRuntime.jsx(reactComponents.Collapse, { className: cvaCollapse({ disableCollapse }), id: "storybook_collapsible", initialExpanded: expanded, label: t("filtersBar.filtersHeading") + (filterBarConfig.filtersHaveBeenApplied
|
|
507
|
+
return dimensions.width > 768 || disableCollapse ? (jsxRuntime.jsx(FilterSelection, { className: cvaFilterWithoutCollapse({ disableCollapse }), filterBarConfig: filterBarConfig, filterBarDefinition: filterBarDefinition, hiddenFilters: hiddenFilters })) : (jsxRuntime.jsx(reactComponents.Collapse, { className: cvaCollapse({ disableCollapse }), id: "storybook_collapsible", initialExpanded: expanded, label: t("filtersBar.filtersHeading") + (filterBarConfig.filtersHaveBeenApplied ? " *" : ""), onToggle: () => setExpanded(prev => !prev), children: jsxRuntime.jsx(FilterSelection, { className: "flex", filterBarConfig: filterBarConfig, filterBarDefinition: filterBarDefinition, hiddenFilters: hiddenFilters }) }));
|
|
508
508
|
};
|
|
509
|
-
const FilterSelection = ({ filterBarDefinition, filterBarConfig, hiddenFilters = [], className,
|
|
509
|
+
const FilterSelection = ({ filterBarDefinition, filterBarConfig, hiddenFilters = [], className, }) => {
|
|
510
510
|
const hideInFilterBar = react.useMemo(() => {
|
|
511
511
|
return sharedUtils.objectValues(filterBarDefinition)
|
|
512
512
|
.map(filter => {
|
|
@@ -818,15 +818,15 @@ const capitalize = (s) => {
|
|
|
818
818
|
* @returns {string[] | ValueName[] | null | { min: undefined, max: undefined } | { from: undefined, to: undefined }} - The initial value corresponding to the given filter type.
|
|
819
819
|
*/
|
|
820
820
|
const getInitialValueFromType = (type) => {
|
|
821
|
+
if (type === "string") {
|
|
822
|
+
return '';
|
|
823
|
+
}
|
|
821
824
|
if (type === "stringArray") {
|
|
822
825
|
return [];
|
|
823
826
|
}
|
|
824
827
|
if (type === "valueName") {
|
|
825
828
|
return [];
|
|
826
829
|
}
|
|
827
|
-
if (type === "boolean") {
|
|
828
|
-
return null;
|
|
829
|
-
}
|
|
830
830
|
if (type === "minMax") {
|
|
831
831
|
return { min: undefined, max: undefined };
|
|
832
832
|
}
|
|
@@ -1013,14 +1013,14 @@ const useFilterBar = ({ name, onValuesChange, filterBarDefinition, initialState,
|
|
|
1013
1013
|
//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.
|
|
1014
1014
|
//This mean that filterbars that have this functionality wouldn't be able to save the state of the filterbar.
|
|
1015
1015
|
//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.
|
|
1016
|
-
const hasNonVisibleDefaultValues = sharedUtils.objectValues(filterBarDefinition).some(
|
|
1016
|
+
const hasNonVisibleDefaultValues = sharedUtils.objectValues(filterBarDefinition).some(value => {
|
|
1017
1017
|
var _a;
|
|
1018
|
-
return
|
|
1019
|
-
!
|
|
1020
|
-
|
|
1021
|
-
!
|
|
1022
|
-
((_a =
|
|
1023
|
-
|
|
1018
|
+
return value.showInStarredMenu &&
|
|
1019
|
+
!value.showInStarredMenu() &&
|
|
1020
|
+
value.showInFilterBar &&
|
|
1021
|
+
!value.showInFilterBar() &&
|
|
1022
|
+
((_a = value.defaultValue) === null || _a === void 0 ? void 0 : _a.toString) &&
|
|
1023
|
+
value.defaultValue.toString().length > 0;
|
|
1024
1024
|
});
|
|
1025
1025
|
if (initialFilterBarConfig === undefined || hasNonVisibleDefaultValues) {
|
|
1026
1026
|
initialFilterBarConfig = createInitialState(name, sharedUtils.objectValues(filterBarDefinition), initialState || {}, setValue);
|
package/index.esm.js
CHANGED
|
@@ -496,9 +496,9 @@ const StarredFilters = ({ filterBarDefinition, filterBarConfig, disableCollapse,
|
|
|
496
496
|
const [expanded, setExpanded] = useState(false);
|
|
497
497
|
const [t] = useTranslation();
|
|
498
498
|
const dimensions = useResize();
|
|
499
|
-
return dimensions.width > 768 || disableCollapse ? (jsx(FilterSelection, { className: cvaFilterWithoutCollapse({ disableCollapse }), filterBarConfig: filterBarConfig, filterBarDefinition: filterBarDefinition, hiddenFilters: hiddenFilters })) : (jsx(Collapse, { className: cvaCollapse({ disableCollapse }), id: "storybook_collapsible", initialExpanded: expanded, label: t("filtersBar.filtersHeading") + (filterBarConfig.filtersHaveBeenApplied
|
|
499
|
+
return dimensions.width > 768 || disableCollapse ? (jsx(FilterSelection, { className: cvaFilterWithoutCollapse({ disableCollapse }), filterBarConfig: filterBarConfig, filterBarDefinition: filterBarDefinition, hiddenFilters: hiddenFilters })) : (jsx(Collapse, { className: cvaCollapse({ disableCollapse }), id: "storybook_collapsible", initialExpanded: expanded, label: t("filtersBar.filtersHeading") + (filterBarConfig.filtersHaveBeenApplied ? " *" : ""), onToggle: () => setExpanded(prev => !prev), children: jsx(FilterSelection, { className: "flex", filterBarConfig: filterBarConfig, filterBarDefinition: filterBarDefinition, hiddenFilters: hiddenFilters }) }));
|
|
500
500
|
};
|
|
501
|
-
const FilterSelection = ({ filterBarDefinition, filterBarConfig, hiddenFilters = [], className,
|
|
501
|
+
const FilterSelection = ({ filterBarDefinition, filterBarConfig, hiddenFilters = [], className, }) => {
|
|
502
502
|
const hideInFilterBar = useMemo(() => {
|
|
503
503
|
return objectValues(filterBarDefinition)
|
|
504
504
|
.map(filter => {
|
|
@@ -810,15 +810,15 @@ const capitalize = (s) => {
|
|
|
810
810
|
* @returns {string[] | ValueName[] | null | { min: undefined, max: undefined } | { from: undefined, to: undefined }} - The initial value corresponding to the given filter type.
|
|
811
811
|
*/
|
|
812
812
|
const getInitialValueFromType = (type) => {
|
|
813
|
+
if (type === "string") {
|
|
814
|
+
return '';
|
|
815
|
+
}
|
|
813
816
|
if (type === "stringArray") {
|
|
814
817
|
return [];
|
|
815
818
|
}
|
|
816
819
|
if (type === "valueName") {
|
|
817
820
|
return [];
|
|
818
821
|
}
|
|
819
|
-
if (type === "boolean") {
|
|
820
|
-
return null;
|
|
821
|
-
}
|
|
822
822
|
if (type === "minMax") {
|
|
823
823
|
return { min: undefined, max: undefined };
|
|
824
824
|
}
|
|
@@ -1005,14 +1005,14 @@ const useFilterBar = ({ name, onValuesChange, filterBarDefinition, initialState,
|
|
|
1005
1005
|
//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.
|
|
1006
1006
|
//This mean that filterbars that have this functionality wouldn't be able to save the state of the filterbar.
|
|
1007
1007
|
//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.
|
|
1008
|
-
const hasNonVisibleDefaultValues = objectValues(filterBarDefinition).some(
|
|
1008
|
+
const hasNonVisibleDefaultValues = objectValues(filterBarDefinition).some(value => {
|
|
1009
1009
|
var _a;
|
|
1010
|
-
return
|
|
1011
|
-
!
|
|
1012
|
-
|
|
1013
|
-
!
|
|
1014
|
-
((_a =
|
|
1015
|
-
|
|
1010
|
+
return value.showInStarredMenu &&
|
|
1011
|
+
!value.showInStarredMenu() &&
|
|
1012
|
+
value.showInFilterBar &&
|
|
1013
|
+
!value.showInFilterBar() &&
|
|
1014
|
+
((_a = value.defaultValue) === null || _a === void 0 ? void 0 : _a.toString) &&
|
|
1015
|
+
value.defaultValue.toString().length > 0;
|
|
1016
1016
|
});
|
|
1017
1017
|
if (initialFilterBarConfig === undefined || hasNonVisibleDefaultValues) {
|
|
1018
1018
|
initialFilterBarConfig = createInitialState(name, objectValues(filterBarDefinition), initialState || {}, setValue);
|
package/package.json
CHANGED
|
@@ -1,17 +1,36 @@
|
|
|
1
|
-
import { FilterBarConfig, FilterBarDefinition, FilterBarInferredValue, FilterDefinition,
|
|
1
|
+
import { FilterBarConfig, FilterBarDefinition, FilterBarInferredValue, FilterDefinition, InitialState, ValueName } from "../types/FilterTypes";
|
|
2
|
+
type InitialTypes = {
|
|
3
|
+
Arg: "string";
|
|
4
|
+
Init: '';
|
|
5
|
+
} | {
|
|
6
|
+
Arg: "stringArray";
|
|
7
|
+
Init: string[];
|
|
8
|
+
} | {
|
|
9
|
+
Arg: "valueName";
|
|
10
|
+
Init: ValueName[];
|
|
11
|
+
} | {
|
|
12
|
+
Arg: "minMax";
|
|
13
|
+
Init: {
|
|
14
|
+
min: undefined;
|
|
15
|
+
max: undefined;
|
|
16
|
+
};
|
|
17
|
+
} | {
|
|
18
|
+
Arg: "dateRange";
|
|
19
|
+
Init: {
|
|
20
|
+
from: undefined;
|
|
21
|
+
to: undefined;
|
|
22
|
+
};
|
|
23
|
+
} | {
|
|
24
|
+
Arg: unknown;
|
|
25
|
+
Init: null;
|
|
26
|
+
};
|
|
2
27
|
/**
|
|
3
28
|
* A helper function that returns a default value based on the filter type.
|
|
4
29
|
*
|
|
5
30
|
* @param {FilterTypes} type - The filter type for which to retrieve the initial value.
|
|
6
31
|
* @returns {string[] | ValueName[] | null | { min: undefined, max: undefined } | { from: undefined, to: undefined }} - The initial value corresponding to the given filter type.
|
|
7
32
|
*/
|
|
8
|
-
export declare const getInitialValueFromType: (type:
|
|
9
|
-
min: undefined;
|
|
10
|
-
max: undefined;
|
|
11
|
-
} | {
|
|
12
|
-
from: undefined;
|
|
13
|
-
to: undefined;
|
|
14
|
-
};
|
|
33
|
+
export declare const getInitialValueFromType: <InitialType extends InitialTypes>(type: InitialType['Arg']) => InitialType['Init'];
|
|
15
34
|
/**
|
|
16
35
|
* Creates an initial state object for a filter bar configuration based on the provided parameters.
|
|
17
36
|
*
|
|
@@ -19,3 +38,4 @@ export declare const getInitialValueFromType: (type: FilterTypes) => string[] |
|
|
|
19
38
|
* @returns {FilterBarConfig<TFilterBarDefinition>} - Returns an initial filter bar configuration object.
|
|
20
39
|
*/
|
|
21
40
|
export declare const createInitialState: <TFilterBarDefinition extends FilterBarDefinition>(name: string, mainFilters: FilterDefinition[], initialState: InitialState<TFilterBarDefinition>, setValue: (key: string, callback: (prev: FilterBarInferredValue<TFilterBarDefinition, never> | undefined) => FilterBarInferredValue<TFilterBarDefinition, never> | undefined) => void) => FilterBarConfig<TFilterBarDefinition>;
|
|
41
|
+
export {};
|