@stenajs-webui/filter 17.6.0 → 17.9.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/CHANGELOG.md +12 -0
- package/dist/features/search-filter/components/SearchFilterButton.d.ts +6 -6
- package/dist/features/search-filter/components/SearchFilterDrawer.d.ts +7 -7
- package/dist/features/search-filter/components/SearchFilterPanelHeader.d.ts +7 -7
- package/dist/features/search-filter/components/SearchFilterSection.d.ts +14 -14
- package/dist/features/search-filter/components/context/SearchFilterContext.d.ts +10 -10
- package/dist/features/search-filter/components/context/SearchFilterLocalStateContext.d.ts +7 -7
- package/dist/features/search-filter/config/SearchFilterConfig.d.ts +13 -13
- package/dist/features/search-filter/context/SearchFilterActionsContext.d.ts +4 -4
- package/dist/features/search-filter/context/SearchFilterDispatchContext.d.ts +4 -4
- package/dist/features/search-filter/context/SearchFilterModelContext.d.ts +3 -3
- package/dist/features/search-filter/context/SearchFilterStateContext.d.ts +4 -4
- package/dist/features/search-filter/features/chips/ChipSpacer.d.ts +5 -5
- package/dist/features/search-filter/features/chips/EmptyChip.d.ts +7 -7
- package/dist/features/search-filter/features/chips/SearchFilterChip.d.ts +10 -10
- package/dist/features/search-filter/features/chips/SearchFilterChips.d.ts +8 -8
- package/dist/features/search-filter/features/chips/SectionChips.d.ts +9 -9
- package/dist/features/search-filter/hooks/UseLocalSearchFilterState.d.ts +11 -11
- package/dist/features/search-filter/redux/SearchFilterRedux.d.ts +30 -30
- package/dist/features/search-filter/section-factories/boolean-record/BooleanRecordChips.d.ts +6 -6
- package/dist/features/search-filter/section-factories/boolean-record/BooleanRecordTypes.d.ts +6 -6
- package/dist/features/search-filter/section-factories/boolean-record/components/ChipMultiSelectSection.d.ts +10 -10
- package/dist/features/search-filter/section-factories/boolean-record/components/SimpleCheckboxListSection.d.ts +8 -8
- package/dist/features/search-filter/section-factories/date-range/DateRangeChips.d.ts +6 -6
- package/dist/features/search-filter/section-factories/date-range/DateRangePropsFactory.d.ts +2 -2
- package/dist/features/search-filter/section-factories/date-range/components/DateRangeCalendarSection.d.ts +13 -13
- package/dist/features/search-filter/types/FilterEntity.d.ts +5 -5
- package/dist/index.d.ts +28 -28
- package/dist/index.es.js +471 -385
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +4 -465
- package/dist/index.js.map +1 -1
- package/package.json +14 -15
- package/dist/features/search-filter/stories/SearchFilter.stories.d.ts +0 -15
package/dist/index.es.js
CHANGED
|
@@ -1,407 +1,493 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { Collapsible, CollapsibleContent, CollapsibleClickableContent } from
|
|
8
|
-
import { upperFirst, lowerCase } from
|
|
9
|
-
import { combineReducers } from
|
|
10
|
-
import { reducerIdGate, createValueByIdReducer, createEntityReducer, reducerIdGateAction, createEntityActions, createValueByIdActions } from
|
|
11
|
-
import styled from
|
|
12
|
-
import { Checkbox } from
|
|
13
|
-
import { ChipMultiSelect } from
|
|
14
|
-
import { stringsToDateRange, dateRangeToStrings, DateRangeCalendar } from
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return __assign.apply(this, arguments);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
function __rest(s, e) {
|
|
43
|
-
var t = {};
|
|
44
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
45
|
-
t[p] = s[p];
|
|
46
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
47
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
48
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
49
|
-
t[p[i]] = s[p[i]];
|
|
50
|
-
}
|
|
51
|
-
return t;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function __makeTemplateObject(cooked, raw) {
|
|
55
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
56
|
-
return cooked;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
var SearchFilterPanelHeader = function (_a) {
|
|
60
|
-
var onRequestClose = _a.onRequestClose, _b = _a.header, header = _b === void 0 ? "Filters" : _b;
|
|
61
|
-
return (React.createElement(Row, { height: "56px", justifyContent: "space-between", alignItems: "center", indent: 2 },
|
|
62
|
-
React.createElement(Row, { alignItems: "center" },
|
|
63
|
-
React.createElement(Icon, { icon: stenaSliders, color: cssColor("--lhds-color-ui-800"), size: 24 }),
|
|
64
|
-
React.createElement(Indent, null),
|
|
65
|
-
React.createElement(Heading, { variant: "h4" }, header)),
|
|
66
|
-
React.createElement(SecondaryButton, { leftIcon: stenaTimes, onClick: onRequestClose })));
|
|
1
|
+
(function(){ try {var elementStyle = document.createElement('style'); elementStyle.appendChild(document.createTextNode("")); document.head.appendChild(elementStyle);} catch(e) {console.error('vite-plugin-css-injected-by-js', e);} })();import { createContext, useContext, useCallback, useState, useReducer, useMemo } from "react";
|
|
2
|
+
import { Drawer } from "@stenajs-webui/modal";
|
|
3
|
+
import { cssColor } from "@stenajs-webui/theme";
|
|
4
|
+
import { Row, Indent, Heading, Column, SeparatorLine, truthyKeysAsList, Text, Box } from "@stenajs-webui/core";
|
|
5
|
+
import { Icon, stenaSliders, SecondaryButton, stenaTimes, Spinner, Banner, FlatButton, Chip } from "@stenajs-webui/elements";
|
|
6
|
+
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
7
|
+
import { Collapsible, CollapsibleContent, CollapsibleClickableContent } from "@stenajs-webui/panels";
|
|
8
|
+
import { upperFirst, lowerCase } from "lodash";
|
|
9
|
+
import { combineReducers } from "redux";
|
|
10
|
+
import { reducerIdGate, createValueByIdReducer, createEntityReducer, reducerIdGateAction, createEntityActions, createValueByIdActions } from "@stenajs-webui/redux";
|
|
11
|
+
import styled from "@emotion/styled";
|
|
12
|
+
import { Checkbox } from "@stenajs-webui/forms";
|
|
13
|
+
import { ChipMultiSelect } from "@stenajs-webui/select";
|
|
14
|
+
import { stringsToDateRange, dateRangeToStrings, DateRangeCalendar } from "@stenajs-webui/calendar";
|
|
15
|
+
const SearchFilterPanelHeader = ({
|
|
16
|
+
onRequestClose,
|
|
17
|
+
header = "Filters"
|
|
18
|
+
}) => {
|
|
19
|
+
return /* @__PURE__ */ jsxs(Row, {
|
|
20
|
+
height: "56px",
|
|
21
|
+
justifyContent: "space-between",
|
|
22
|
+
alignItems: "center",
|
|
23
|
+
indent: 2,
|
|
24
|
+
children: [/* @__PURE__ */ jsxs(Row, {
|
|
25
|
+
alignItems: "center",
|
|
26
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
27
|
+
icon: stenaSliders,
|
|
28
|
+
color: cssColor("--lhds-color-ui-800"),
|
|
29
|
+
size: 24
|
|
30
|
+
}), /* @__PURE__ */ jsx(Indent, {}), /* @__PURE__ */ jsx(Heading, {
|
|
31
|
+
variant: "h4",
|
|
32
|
+
children: header
|
|
33
|
+
})]
|
|
34
|
+
}), /* @__PURE__ */ jsx(SecondaryButton, {
|
|
35
|
+
leftIcon: stenaTimes,
|
|
36
|
+
onClick: onRequestClose
|
|
37
|
+
})]
|
|
38
|
+
});
|
|
67
39
|
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return c;
|
|
40
|
+
const SearchFilterStateContext = createContext(null);
|
|
41
|
+
const useSearchFilterState = () => {
|
|
42
|
+
const c = useContext(SearchFilterStateContext);
|
|
43
|
+
if (!c) {
|
|
44
|
+
throw new Error("Missing search filter context, wrap components with SearchFilterContext component.");
|
|
45
|
+
}
|
|
46
|
+
return c;
|
|
76
47
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return c;
|
|
48
|
+
const SearchFilterDispatchContext = createContext(null);
|
|
49
|
+
const useSearchFilterDispatch = () => {
|
|
50
|
+
const c = useContext(SearchFilterDispatchContext);
|
|
51
|
+
if (!c) {
|
|
52
|
+
throw new Error("Missing search filter dispatch context.");
|
|
53
|
+
}
|
|
54
|
+
return c;
|
|
85
55
|
};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return c;
|
|
56
|
+
const SearchFilterActionsContext = createContext(null);
|
|
57
|
+
const useSearchFilterActions = () => {
|
|
58
|
+
const c = useContext(SearchFilterActionsContext);
|
|
59
|
+
if (!c) {
|
|
60
|
+
throw new Error("Missing search filter actions context.");
|
|
61
|
+
}
|
|
62
|
+
return c;
|
|
94
63
|
};
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
64
|
+
const SearchFilterDrawer = ({
|
|
65
|
+
children,
|
|
66
|
+
header,
|
|
67
|
+
...drawerProps
|
|
68
|
+
}) => {
|
|
69
|
+
const {
|
|
70
|
+
settings: {
|
|
71
|
+
open
|
|
72
|
+
}
|
|
73
|
+
} = useSearchFilterState();
|
|
74
|
+
const dispatch = useSearchFilterDispatch();
|
|
75
|
+
const actions = useSearchFilterActions();
|
|
76
|
+
const closeDrawer = useCallback(() => {
|
|
77
|
+
dispatch(actions.closeFilters());
|
|
78
|
+
}, [actions, dispatch]);
|
|
79
|
+
return /* @__PURE__ */ jsx(Drawer, {
|
|
80
|
+
background: cssColor("--lhds-color-ui-50"),
|
|
81
|
+
width: "370px",
|
|
82
|
+
isOpen: open,
|
|
83
|
+
onRequestClose: closeDrawer,
|
|
84
|
+
...drawerProps,
|
|
85
|
+
children: /* @__PURE__ */ jsxs(Column, {
|
|
86
|
+
children: [/* @__PURE__ */ jsx(SearchFilterPanelHeader, {
|
|
87
|
+
onRequestClose: closeDrawer,
|
|
88
|
+
header
|
|
89
|
+
}), /* @__PURE__ */ jsx(SeparatorLine, {}), children]
|
|
90
|
+
})
|
|
91
|
+
});
|
|
109
92
|
};
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
93
|
+
const SearchFilterButton = ({
|
|
94
|
+
label = "Filters"
|
|
95
|
+
}) => {
|
|
96
|
+
const dispatch = useSearchFilterDispatch();
|
|
97
|
+
const actions = useSearchFilterActions();
|
|
98
|
+
const onClickButton = useCallback(() => {
|
|
99
|
+
dispatch(actions.openFilters());
|
|
100
|
+
}, [actions, dispatch]);
|
|
101
|
+
return /* @__PURE__ */ jsx(SecondaryButton, {
|
|
102
|
+
label,
|
|
103
|
+
leftIcon: stenaSliders,
|
|
104
|
+
onClick: onClickButton
|
|
105
|
+
});
|
|
119
106
|
};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
107
|
+
const SearchFilterSection = function SearchFilterSection2({
|
|
108
|
+
sectionId,
|
|
109
|
+
label,
|
|
110
|
+
contentLeft,
|
|
111
|
+
contentRight,
|
|
112
|
+
loading,
|
|
113
|
+
error,
|
|
114
|
+
onRetry,
|
|
115
|
+
disableContentPadding,
|
|
116
|
+
children
|
|
117
|
+
}) {
|
|
118
|
+
var _a;
|
|
119
|
+
const state = useSearchFilterState();
|
|
120
|
+
const dispatch = useSearchFilterDispatch();
|
|
121
|
+
const actions = useSearchFilterActions();
|
|
122
|
+
const expanded = (_a = state.expandedSections.values[sectionId]) != null ? _a : false;
|
|
123
|
+
const onClickLabel = useCallback(() => {
|
|
124
|
+
dispatch(actions.setSectionExpanded(sectionId, !expanded));
|
|
125
|
+
}, [actions, dispatch, expanded, sectionId]);
|
|
126
|
+
const activeLabel = label != null ? label : formatColumnIdToHeaderCellLabel(sectionId);
|
|
127
|
+
return /* @__PURE__ */ jsx(Collapsible, {
|
|
128
|
+
label: activeLabel,
|
|
129
|
+
collapsed: !expanded,
|
|
130
|
+
onClick: onClickLabel,
|
|
131
|
+
contentLeft,
|
|
132
|
+
contentRight,
|
|
133
|
+
children: loading ? /* @__PURE__ */ jsx(CollapsibleContent, {
|
|
134
|
+
children: /* @__PURE__ */ jsx(Row, {
|
|
135
|
+
spacing: true,
|
|
136
|
+
justifyContent: "center",
|
|
137
|
+
flex: 1,
|
|
138
|
+
children: /* @__PURE__ */ jsx(Spinner, {
|
|
139
|
+
size: "small"
|
|
140
|
+
})
|
|
141
|
+
})
|
|
142
|
+
}) : error ? /* @__PURE__ */ jsx(Banner, {
|
|
143
|
+
variant: "error",
|
|
144
|
+
text: error,
|
|
145
|
+
contentRight: onRetry ? /* @__PURE__ */ jsx(FlatButton, {
|
|
146
|
+
label: "Retry",
|
|
147
|
+
onClick: onRetry
|
|
148
|
+
}) : null
|
|
149
|
+
}) : disableContentPadding ? children : /* @__PURE__ */ jsx(CollapsibleContent, {
|
|
150
|
+
children
|
|
151
|
+
})
|
|
152
|
+
});
|
|
138
153
|
};
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
154
|
+
const formatColumnIdToHeaderCellLabel = (columnId) => upperFirst(lowerCase(columnId));
|
|
155
|
+
const SearchFilterModelContext = createContext(null);
|
|
156
|
+
const useSearchFilterModel = () => {
|
|
157
|
+
const c = useContext(SearchFilterModelContext);
|
|
158
|
+
if (!c) {
|
|
159
|
+
throw new Error("Missing search filter context, wrap components with SearchFilterContext component.");
|
|
160
|
+
}
|
|
161
|
+
return c;
|
|
147
162
|
};
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
163
|
+
const SearchFilterContext = function SearchFilterScope({
|
|
164
|
+
state,
|
|
165
|
+
dispatch,
|
|
166
|
+
actions,
|
|
167
|
+
children
|
|
168
|
+
}) {
|
|
169
|
+
return /* @__PURE__ */ jsx(SearchFilterDispatchContext.Provider, {
|
|
170
|
+
value: dispatch,
|
|
171
|
+
children: /* @__PURE__ */ jsx(SearchFilterActionsContext.Provider, {
|
|
172
|
+
value: actions,
|
|
173
|
+
children: /* @__PURE__ */ jsx(SearchFilterStateContext.Provider, {
|
|
174
|
+
value: state,
|
|
175
|
+
children: /* @__PURE__ */ jsx(SearchFilterModelContext.Provider, {
|
|
176
|
+
value: state.formModel,
|
|
177
|
+
children
|
|
178
|
+
})
|
|
179
|
+
})
|
|
180
|
+
})
|
|
181
|
+
});
|
|
155
182
|
};
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
return reducerIdGateAction(getReducerIdFor(reducerId, "expandedSections"), createValueByIdActions().setValue(section, false));
|
|
193
|
-
},
|
|
194
|
-
setSectionExpanded: function (section, expanded) {
|
|
195
|
-
return reducerIdGateAction(getReducerIdFor(reducerId, "expandedSections"), createValueByIdActions().setValue(section, expanded));
|
|
196
|
-
},
|
|
197
|
-
clearExpandedSections: function () {
|
|
198
|
-
return reducerIdGateAction(getReducerIdFor(reducerId, "expandedSections"), createValueByIdActions().clearAllValues());
|
|
199
|
-
},
|
|
200
|
-
}); };
|
|
201
|
-
var getReducerIdFor = function (reducerId, reducerIdSuffix) { return "".concat(reducerId, ".").concat(reducerIdSuffix); };
|
|
202
|
-
|
|
203
|
-
var useLocalSearchFilterState = function (initialState) {
|
|
204
|
-
var reducer = useState(function () {
|
|
205
|
-
return createSearchFilterReducer("local", initialState);
|
|
206
|
-
})[0];
|
|
207
|
-
var actions = useState(function () {
|
|
208
|
-
return createSearchFilterActions("local", initialState.formModel);
|
|
209
|
-
})[0];
|
|
210
|
-
var _a = useReducer(reducer, initialState), state = _a[0], dispatch = _a[1];
|
|
211
|
-
return {
|
|
212
|
-
actions: actions,
|
|
213
|
-
state: state,
|
|
214
|
-
dispatch: dispatch,
|
|
215
|
-
};
|
|
183
|
+
const createSearchFilterInitialState = (initialFormModel) => ({
|
|
184
|
+
settings: {
|
|
185
|
+
open: false
|
|
186
|
+
},
|
|
187
|
+
formModel: initialFormModel,
|
|
188
|
+
expandedSections: { values: {} }
|
|
189
|
+
});
|
|
190
|
+
const createSearchFilterReducer = (reducerId, initialState) => combineReducers({
|
|
191
|
+
expandedSections: reducerIdGate(getReducerIdFor(reducerId, "expandedSections"), createValueByIdReducer(initialState.expandedSections)),
|
|
192
|
+
formModel: reducerIdGate(getReducerIdFor(reducerId, "formModel"), createEntityReducer(initialState.formModel)),
|
|
193
|
+
settings: reducerIdGate(getReducerIdFor(reducerId, "settings"), createEntityReducer(initialState.settings))
|
|
194
|
+
});
|
|
195
|
+
const createSearchFilterActions = (reducerId, initialFormModel) => ({
|
|
196
|
+
openFilters: () => reducerIdGateAction(getReducerIdFor(reducerId, "settings"), createEntityActions().setEntityFields({
|
|
197
|
+
open: true
|
|
198
|
+
})),
|
|
199
|
+
closeFilters: () => reducerIdGateAction(getReducerIdFor(reducerId, "settings"), createEntityActions().setEntityFields({
|
|
200
|
+
open: false
|
|
201
|
+
})),
|
|
202
|
+
setFormModelFields: (fields) => reducerIdGateAction(getReducerIdFor(reducerId, "formModel"), createEntityActions().setEntityFields(fields)),
|
|
203
|
+
clearFormModel: () => reducerIdGateAction(getReducerIdFor(reducerId, "formModel"), createEntityActions().setEntity(initialFormModel)),
|
|
204
|
+
expandSection: (section) => reducerIdGateAction(getReducerIdFor(reducerId, "expandedSections"), createValueByIdActions().setValue(section, true)),
|
|
205
|
+
collapseSection: (section) => reducerIdGateAction(getReducerIdFor(reducerId, "expandedSections"), createValueByIdActions().setValue(section, false)),
|
|
206
|
+
setSectionExpanded: (section, expanded) => reducerIdGateAction(getReducerIdFor(reducerId, "expandedSections"), createValueByIdActions().setValue(section, expanded)),
|
|
207
|
+
clearExpandedSections: () => reducerIdGateAction(getReducerIdFor(reducerId, "expandedSections"), createValueByIdActions().clearAllValues())
|
|
208
|
+
});
|
|
209
|
+
const getReducerIdFor = (reducerId, reducerIdSuffix) => `${reducerId}.${reducerIdSuffix}`;
|
|
210
|
+
const useLocalSearchFilterState = (initialState) => {
|
|
211
|
+
const [reducer] = useState(() => createSearchFilterReducer("local", initialState));
|
|
212
|
+
const [actions] = useState(() => createSearchFilterActions("local", initialState.formModel));
|
|
213
|
+
const [state, dispatch] = useReducer(reducer, initialState);
|
|
214
|
+
return {
|
|
215
|
+
actions,
|
|
216
|
+
state,
|
|
217
|
+
dispatch
|
|
218
|
+
};
|
|
216
219
|
};
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
220
|
+
const SearchFilterLocalStateContext = function SearchFilterLocalScope({
|
|
221
|
+
initialFormModel,
|
|
222
|
+
children
|
|
223
|
+
}) {
|
|
224
|
+
const {
|
|
225
|
+
state,
|
|
226
|
+
actions,
|
|
227
|
+
dispatch
|
|
228
|
+
} = useLocalSearchFilterState(createSearchFilterInitialState(initialFormModel));
|
|
229
|
+
return /* @__PURE__ */ jsx(SearchFilterContext, {
|
|
230
|
+
state,
|
|
231
|
+
actions,
|
|
232
|
+
dispatch,
|
|
233
|
+
children
|
|
234
|
+
});
|
|
222
235
|
};
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
var
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
+
const ChipSpacer = styled.div`
|
|
237
|
+
padding: calc(var(--swui-metrics-spacing) / 2)
|
|
238
|
+
calc(var(--swui-metrics-indent) / 2);
|
|
239
|
+
`;
|
|
240
|
+
const SearchFilterChips = ({
|
|
241
|
+
children,
|
|
242
|
+
disableClearAllButton = false
|
|
243
|
+
}) => {
|
|
244
|
+
const dispatch = useSearchFilterDispatch();
|
|
245
|
+
const actions = useSearchFilterActions();
|
|
246
|
+
const onClickClearAll = useCallback(() => dispatch(actions.clearFormModel()), [actions, dispatch]);
|
|
247
|
+
return /* @__PURE__ */ jsxs(Row, {
|
|
248
|
+
flexWrap: "wrap",
|
|
249
|
+
children: [children, !disableClearAllButton && /* @__PURE__ */ jsx(ChipSpacer, {
|
|
250
|
+
children: /* @__PURE__ */ jsx(FlatButton, {
|
|
251
|
+
size: "small",
|
|
252
|
+
label: "Clear all",
|
|
253
|
+
onClick: onClickClearAll
|
|
254
|
+
})
|
|
255
|
+
})]
|
|
256
|
+
});
|
|
236
257
|
};
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
258
|
+
const EmptyChip = function EmptyChip2({
|
|
259
|
+
label,
|
|
260
|
+
sectionId
|
|
261
|
+
}) {
|
|
262
|
+
const dispatch = useSearchFilterDispatch();
|
|
263
|
+
const actions = useSearchFilterActions();
|
|
264
|
+
const onClickLabel = useCallback(() => {
|
|
265
|
+
dispatch(actions.clearExpandedSections());
|
|
266
|
+
dispatch(actions.expandSection(sectionId));
|
|
267
|
+
dispatch(actions.openFilters());
|
|
268
|
+
}, [actions, dispatch, sectionId]);
|
|
269
|
+
return /* @__PURE__ */ jsx(ChipSpacer, {
|
|
270
|
+
children: /* @__PURE__ */ jsx(Chip, {
|
|
271
|
+
label,
|
|
272
|
+
variant: "secondary",
|
|
273
|
+
onClick: onClickLabel
|
|
274
|
+
})
|
|
275
|
+
});
|
|
249
276
|
};
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
277
|
+
const SearchFilterChip = function SearchFilterChip2({
|
|
278
|
+
sectionId,
|
|
279
|
+
label,
|
|
280
|
+
value,
|
|
281
|
+
onClickRemove
|
|
282
|
+
}) {
|
|
283
|
+
const dispatch = useSearchFilterDispatch();
|
|
284
|
+
const actions = useSearchFilterActions();
|
|
285
|
+
const setFormModelFields = useCallback((fields) => dispatch(actions.setFormModelFields(fields)), [dispatch, actions]);
|
|
286
|
+
const onClickRemoveHandler = useCallback(() => {
|
|
287
|
+
onClickRemove == null ? void 0 : onClickRemove({
|
|
288
|
+
value,
|
|
289
|
+
setFormModelFields
|
|
290
|
+
});
|
|
291
|
+
}, [onClickRemove, setFormModelFields, value]);
|
|
292
|
+
const onClickLabel = useCallback(() => {
|
|
293
|
+
dispatch(actions.clearExpandedSections());
|
|
294
|
+
dispatch(actions.expandSection(sectionId));
|
|
295
|
+
dispatch(actions.openFilters());
|
|
296
|
+
}, [actions, dispatch, sectionId]);
|
|
297
|
+
return /* @__PURE__ */ jsx(ChipSpacer, {
|
|
298
|
+
children: /* @__PURE__ */ jsx(Chip, {
|
|
299
|
+
label: label != null ? label : sectionId,
|
|
300
|
+
onClick: onClickLabel,
|
|
301
|
+
onClickRemove: onClickRemove ? onClickRemoveHandler : void 0
|
|
302
|
+
})
|
|
303
|
+
});
|
|
268
304
|
};
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
305
|
+
const SectionChips = function SectionChips2({
|
|
306
|
+
sectionId,
|
|
307
|
+
chips,
|
|
308
|
+
emptyChipLabel,
|
|
309
|
+
onClickRemoveOnChip
|
|
310
|
+
}) {
|
|
311
|
+
if (!(chips == null ? void 0 : chips.length)) {
|
|
312
|
+
if (!emptyChipLabel) {
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
return /* @__PURE__ */ jsx(EmptyChip, {
|
|
316
|
+
sectionId,
|
|
317
|
+
label: emptyChipLabel
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
321
|
+
children: chips.map(({
|
|
322
|
+
label,
|
|
323
|
+
value
|
|
324
|
+
}) => /* @__PURE__ */ jsx(SearchFilterChip, {
|
|
325
|
+
label: label != null ? label : sectionId,
|
|
326
|
+
sectionId,
|
|
327
|
+
onClickRemove: onClickRemoveOnChip,
|
|
328
|
+
value
|
|
329
|
+
}, value))
|
|
330
|
+
});
|
|
282
331
|
};
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
var
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
newRecord[value] = false;
|
|
301
|
-
setFormModelFields((_b = {},
|
|
302
|
-
_b[fieldName] = newRecord,
|
|
303
|
-
_b));
|
|
304
|
-
};
|
|
332
|
+
const createChipsPropsForBooleanRecord = (formModel, fieldName, options) => ({
|
|
333
|
+
chips: createChipsForBooleanRecord(formModel[fieldName], options),
|
|
334
|
+
onClickRemoveOnChip: createOnClickRemoveOnChipForBooleanRecord(formModel, fieldName)
|
|
335
|
+
});
|
|
336
|
+
const createChipsForBooleanRecord = (booleanRecord, options) => truthyKeysAsList(booleanRecord).map((key) => {
|
|
337
|
+
var _a;
|
|
338
|
+
const option = options == null ? void 0 : options.find((o) => o.value === key);
|
|
339
|
+
return { value: key, label: (_a = option == null ? void 0 : option.label) != null ? _a : key };
|
|
340
|
+
});
|
|
341
|
+
const createOnClickRemoveOnChipForBooleanRecord = (formModel, fieldName) => {
|
|
342
|
+
return ({ setFormModelFields, value }) => {
|
|
343
|
+
const newRecord = { ...formModel[fieldName] };
|
|
344
|
+
newRecord[value] = false;
|
|
345
|
+
setFormModelFields({
|
|
346
|
+
[fieldName]: newRecord
|
|
347
|
+
});
|
|
348
|
+
};
|
|
305
349
|
};
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
350
|
+
const SimpleCheckboxListSection = ({
|
|
351
|
+
options,
|
|
352
|
+
value,
|
|
353
|
+
onValueChange,
|
|
354
|
+
...sectionProps
|
|
355
|
+
}) => /* @__PURE__ */ jsx(SearchFilterSection, {
|
|
356
|
+
disableContentPadding: true,
|
|
357
|
+
...sectionProps,
|
|
358
|
+
children: /* @__PURE__ */ jsx(Column, {
|
|
359
|
+
maxHeight: "400px",
|
|
360
|
+
overflowY: "auto",
|
|
361
|
+
flex: 1,
|
|
362
|
+
children: options == null ? void 0 : options.map((d) => /* @__PURE__ */ jsx(CollapsibleClickableContent, {
|
|
363
|
+
onClick: () => {
|
|
364
|
+
if (value && onValueChange) {
|
|
365
|
+
const sel = !value[d.value];
|
|
366
|
+
onValueChange({
|
|
367
|
+
...value,
|
|
368
|
+
[d.value]: sel
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
contentLeft: /* @__PURE__ */ jsx(Checkbox, {
|
|
373
|
+
tabIndex: -1,
|
|
374
|
+
value: value == null ? void 0 : value[d.value]
|
|
375
|
+
}),
|
|
376
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
377
|
+
children: d.label
|
|
378
|
+
})
|
|
379
|
+
}, d.value))
|
|
380
|
+
})
|
|
381
|
+
});
|
|
382
|
+
const ChipMultiSelectSection = ({
|
|
383
|
+
options,
|
|
384
|
+
value,
|
|
385
|
+
noneSelectedLabel,
|
|
386
|
+
onValueChange,
|
|
387
|
+
...sectionProps
|
|
388
|
+
}) => {
|
|
389
|
+
const [text, setText] = useState("");
|
|
390
|
+
const listValue = useMemo(() => value ? truthyKeysAsList(value).map((key) => {
|
|
391
|
+
var _a;
|
|
392
|
+
const option = options == null ? void 0 : options.find((o) => o.value === key);
|
|
393
|
+
return {
|
|
394
|
+
value: key,
|
|
395
|
+
label: (_a = option == null ? void 0 : option.label) != null ? _a : key
|
|
396
|
+
};
|
|
397
|
+
}) : [], [options, value]);
|
|
398
|
+
const filteredOptions = useMemo(() => {
|
|
399
|
+
return options == null ? void 0 : options.filter((p) => p.value.toLocaleLowerCase().indexOf(text.toLocaleLowerCase()) > -1 || p.label.toLocaleLowerCase().indexOf(text.toLocaleLowerCase()) > -1);
|
|
400
|
+
}, [options, text]);
|
|
401
|
+
const onValueChangeInternal = useCallback((value2) => {
|
|
402
|
+
onValueChange == null ? void 0 : onValueChange(createBooleanRecordFromValue(value2));
|
|
403
|
+
}, [onValueChange]);
|
|
404
|
+
return /* @__PURE__ */ jsx(SearchFilterSection, {
|
|
405
|
+
...sectionProps,
|
|
406
|
+
children: /* @__PURE__ */ jsx(ChipMultiSelect, {
|
|
407
|
+
options: filteredOptions,
|
|
408
|
+
value: listValue,
|
|
409
|
+
onValueChange: onValueChangeInternal,
|
|
410
|
+
inputValue: text,
|
|
411
|
+
noneSelectedLabel,
|
|
412
|
+
onInputChange: setText,
|
|
413
|
+
closeMenuOnSelect: false
|
|
414
|
+
})
|
|
415
|
+
});
|
|
318
416
|
};
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
return value
|
|
325
|
-
? truthyKeysAsList(value).map(function (key) {
|
|
326
|
-
var _a;
|
|
327
|
-
var option = options === null || options === void 0 ? void 0 : options.find(function (o) { return o.value === key; });
|
|
328
|
-
return { value: key, label: (_a = option === null || option === void 0 ? void 0 : option.label) !== null && _a !== void 0 ? _a : key };
|
|
329
|
-
})
|
|
330
|
-
: [];
|
|
331
|
-
}, [options, value]);
|
|
332
|
-
var filteredOptions = useMemo(function () {
|
|
333
|
-
return options === null || options === void 0 ? void 0 : options.filter(function (p) {
|
|
334
|
-
return p.value.toLocaleLowerCase().indexOf(text.toLocaleLowerCase()) > -1 ||
|
|
335
|
-
p.label.toLocaleLowerCase().indexOf(text.toLocaleLowerCase()) > -1;
|
|
336
|
-
});
|
|
337
|
-
}, [options, text]);
|
|
338
|
-
var onValueChangeInternal = useCallback(function (value) {
|
|
339
|
-
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(createBooleanRecordFromValue(value));
|
|
340
|
-
}, [onValueChange]);
|
|
341
|
-
return (React.createElement(SearchFilterSection, __assign({}, sectionProps),
|
|
342
|
-
React.createElement(ChipMultiSelect, { options: filteredOptions, value: listValue, onValueChange: onValueChangeInternal, inputValue: text, noneSelectedLabel: noneSelectedLabel, onInputChange: setText, closeMenuOnSelect: false })));
|
|
343
|
-
};
|
|
344
|
-
var createBooleanRecordFromValue = function (value) {
|
|
345
|
-
return value.reduce(function (sum, item) {
|
|
346
|
-
sum[item.value] = true;
|
|
347
|
-
return sum;
|
|
348
|
-
}, {});
|
|
417
|
+
const createBooleanRecordFromValue = (value) => {
|
|
418
|
+
return value.reduce((sum, item) => {
|
|
419
|
+
sum[item.value] = true;
|
|
420
|
+
return sum;
|
|
421
|
+
}, {});
|
|
349
422
|
};
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
];
|
|
362
|
-
};
|
|
363
|
-
var createOnClickRemoveOnChipForDateRange = function (startDateFieldName, endDateFieldName) {
|
|
364
|
-
return function (_a) {
|
|
365
|
-
var _b;
|
|
366
|
-
var setFormModelFields = _a.setFormModelFields;
|
|
367
|
-
setFormModelFields((_b = {},
|
|
368
|
-
_b[startDateFieldName] = undefined,
|
|
369
|
-
_b[endDateFieldName] = undefined,
|
|
370
|
-
_b));
|
|
371
|
-
};
|
|
423
|
+
const createChipsPropsForDateRange = (formModel, startDateFieldName, endDateFieldName) => ({
|
|
424
|
+
chips: createChipsForDateRange(formModel[startDateFieldName], formModel[endDateFieldName]),
|
|
425
|
+
onClickRemoveOnChip: createOnClickRemoveOnChipForDateRange(startDateFieldName, endDateFieldName)
|
|
426
|
+
});
|
|
427
|
+
const createChipsForDateRange = (startDate, endDate) => {
|
|
428
|
+
if (!startDate && !endDate) {
|
|
429
|
+
return [];
|
|
430
|
+
}
|
|
431
|
+
return [
|
|
432
|
+
{ value: "dateRange", label: `${startDate != null ? startDate : ""} - ${endDate != null ? endDate : ""}` }
|
|
433
|
+
];
|
|
372
434
|
};
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
435
|
+
const createOnClickRemoveOnChipForDateRange = (startDateFieldName, endDateFieldName) => {
|
|
436
|
+
return ({ setFormModelFields }) => {
|
|
437
|
+
setFormModelFields({
|
|
438
|
+
[startDateFieldName]: void 0,
|
|
439
|
+
[endDateFieldName]: void 0
|
|
440
|
+
});
|
|
441
|
+
};
|
|
442
|
+
};
|
|
443
|
+
const createDateRangeSectionProps = (formModel, startDateFieldName, endDateFieldName) => ({
|
|
444
|
+
value: {
|
|
445
|
+
startDate: formModel[startDateFieldName],
|
|
446
|
+
endDate: formModel[endDateFieldName]
|
|
447
|
+
},
|
|
448
|
+
onValueChange: (value, { dispatch, actions }) => {
|
|
449
|
+
const fields = {
|
|
450
|
+
[startDateFieldName]: value.startDate,
|
|
451
|
+
[endDateFieldName]: value.endDate
|
|
452
|
+
};
|
|
453
|
+
dispatch(actions.setFormModelFields(fields));
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
const DateRangeCalendarSection = ({
|
|
457
|
+
value,
|
|
458
|
+
onValueChange,
|
|
459
|
+
sectionId,
|
|
460
|
+
...dateRangeCalendarProps
|
|
461
|
+
}) => {
|
|
462
|
+
const dispatch = useSearchFilterDispatch();
|
|
463
|
+
const actions = useSearchFilterActions();
|
|
464
|
+
const options = useMemo(() => ({
|
|
465
|
+
dispatch,
|
|
466
|
+
actions
|
|
467
|
+
}), [actions, dispatch]);
|
|
468
|
+
const [focusedInput, setFocusedInput] = useState("startDate");
|
|
469
|
+
const dateRangeValue = useMemo(() => stringsToDateRange(value), [value]);
|
|
470
|
+
const onValueChangeHandler = useCallback((value2) => {
|
|
471
|
+
onValueChange(dateRangeToStrings(value2), options);
|
|
472
|
+
}, [onValueChange, options]);
|
|
473
|
+
return /* @__PURE__ */ jsx(SearchFilterSection, {
|
|
474
|
+
sectionId,
|
|
475
|
+
children: /* @__PURE__ */ jsx(Box, {
|
|
476
|
+
flex: 1,
|
|
477
|
+
alignItems: "center",
|
|
478
|
+
children: /* @__PURE__ */ jsx(Box, {
|
|
479
|
+
background: "white",
|
|
480
|
+
indent: true,
|
|
481
|
+
children: /* @__PURE__ */ jsx(DateRangeCalendar, {
|
|
482
|
+
setFocusedInput,
|
|
483
|
+
focusedInput,
|
|
484
|
+
value: dateRangeValue,
|
|
485
|
+
onValueChange: onValueChangeHandler,
|
|
486
|
+
...dateRangeCalendarProps
|
|
487
|
+
})
|
|
488
|
+
})
|
|
489
|
+
})
|
|
490
|
+
});
|
|
404
491
|
};
|
|
405
|
-
|
|
406
492
|
export { ChipMultiSelectSection, DateRangeCalendarSection, EmptyChip, SearchFilterActionsContext, SearchFilterButton, SearchFilterChip, SearchFilterChips, SearchFilterContext, SearchFilterDispatchContext, SearchFilterDrawer, SearchFilterLocalStateContext, SearchFilterModelContext, SearchFilterPanelHeader, SearchFilterSection, SearchFilterStateContext, SectionChips, SimpleCheckboxListSection, createChipsForBooleanRecord, createChipsForDateRange, createChipsPropsForBooleanRecord, createChipsPropsForDateRange, createDateRangeSectionProps, createOnClickRemoveOnChipForBooleanRecord, createOnClickRemoveOnChipForDateRange, createSearchFilterActions, createSearchFilterInitialState, createSearchFilterReducer, formatColumnIdToHeaderCellLabel, getReducerIdFor, useLocalSearchFilterState, useSearchFilterActions, useSearchFilterDispatch, useSearchFilterModel, useSearchFilterState };
|
|
407
493
|
//# sourceMappingURL=index.es.js.map
|