@bigbinary/neeto-filters-frontend 4.0.1 → 4.1.1
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/README.md +2 -0
- package/dist/Bar.js +672 -0
- package/dist/Bar.js.map +1 -0
- package/dist/Filters.js +368 -0
- package/dist/Filters.js.map +1 -0
- package/dist/Segments.js +534 -0
- package/dist/Segments.js.map +1 -0
- package/dist/cjs/Bar.js +686 -0
- package/dist/cjs/Bar.js.map +1 -0
- package/dist/cjs/Filters.js +379 -0
- package/dist/cjs/Filters.js.map +1 -0
- package/dist/cjs/Segments.js +548 -0
- package/dist/cjs/Segments.js.map +1 -0
- package/dist/cjs/hooks.js +17 -0
- package/dist/cjs/hooks.js.map +1 -0
- package/dist/cjs/index.js +72 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/utils.js +24 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/constants-8f6e851e.js +125 -0
- package/dist/constants-8f6e851e.js.map +1 -0
- package/dist/constants-fb0f688a.js +135 -0
- package/dist/constants-fb0f688a.js.map +1 -0
- package/dist/hooks.js +7 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index-03114015.js +336 -0
- package/dist/index-03114015.js.map +1 -0
- package/dist/index-2d1d9838.js +971 -0
- package/dist/index-2d1d9838.js.map +1 -0
- package/dist/index-31aaf3e4.js +302 -0
- package/dist/index-31aaf3e4.js.map +1 -0
- package/dist/index-95fe069e.js +958 -0
- package/dist/index-95fe069e.js.map +1 -0
- package/dist/index.js +53 -3703
- package/dist/index.js.map +1 -1
- package/dist/useSegmentsApi-003055eb.js +96 -0
- package/dist/useSegmentsApi-003055eb.js.map +1 -0
- package/dist/useSegmentsApi-c514647d.js +86 -0
- package/dist/useSegmentsApi-c514647d.js.map +1 -0
- package/dist/utils-61b4223d.js +861 -0
- package/dist/utils-61b4223d.js.map +1 -0
- package/dist/utils-9ea34335.js +809 -0
- package/dist/utils-9ea34335.js.map +1 -0
- package/dist/utils.js +12 -0
- package/dist/utils.js.map +1 -0
- package/package.json +24 -12
- package/types.d.ts +2 -0
- package/dist/index.cjs.js +0 -3773
- package/dist/index.cjs.js.map +0 -1
package/README.md
CHANGED
|
@@ -127,6 +127,7 @@ export default App;
|
|
|
127
127
|
- `entity`: The entity associated with the filters.
|
|
128
128
|
- `defaultSegmentName`: The name of segment which results all entities without applying any filter. Default name is "All results".
|
|
129
129
|
- `customFilters`: To specify the custom components specific to the host application. This should be same as `children` passed to the `Filters` component.
|
|
130
|
+
- `segmentsBaseUrl`: The base url to which the segments will be appended after creating the segment. by default the current path will be used.
|
|
130
131
|
|
|
131
132
|
All these props must be same as that passed to the `Filters` component. The
|
|
132
133
|
option to save filters as segments will be enabled only when the entity prop is
|
|
@@ -187,6 +188,7 @@ export default App;
|
|
|
187
188
|
- `defaultSegmentName`: The name of segment which results all entities without applying any filter. Default name is "All results".
|
|
188
189
|
- `customFilters`: To specify the custom components specific to the host application. This should be same as `children` passed to the `Filters` component.
|
|
189
190
|
- `childrenKeys`: The list of keys which has to be cleared from url during clear filters operation.
|
|
191
|
+
- `baseUrl`: The base url to which the segments will be appended. by default the current path will be used.
|
|
190
192
|
|
|
191
193
|
The "columns" prop must be same as that passed to the `Filters` component.
|
|
192
194
|
|
package/dist/Bar.js
ADDED
|
@@ -0,0 +1,672 @@
|
|
|
1
|
+
import { S as SEARCH_TERM_KEY, c as SINGLE_DATE_OPTIONS, d as SINGLE_TIME_OPTIONS, _ as _defineProperty } from './constants-8f6e851e.js';
|
|
2
|
+
import React, { useRef, useState, useEffect } from 'react';
|
|
3
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
import { t } from 'i18next';
|
|
6
|
+
import { findBy, humanize, removeBy, hyphenate, isPresent, isNotEmpty, noop, findById, isNotPresent } from '@bigbinary/neeto-cist';
|
|
7
|
+
import { useQueryParams } from '@bigbinary/neeto-commons-frontend/react-utils';
|
|
8
|
+
import { reject, modify, sortBy, prop, project, has, omit, isEmpty, assoc, identity } from 'ramda';
|
|
9
|
+
import { S as SegmentForm } from './index-31aaf3e4.js';
|
|
10
|
+
import { u as useCreateSegment, a as useUpdateSegment, Q as QUERY_KEYS } from './useSegmentsApi-c514647d.js';
|
|
11
|
+
import { dateFormat, buildUrl, showThumbsUpToastr } from '@bigbinary/neeto-commons-frontend/utils';
|
|
12
|
+
import Button from '@bigbinary/neetoui/Button';
|
|
13
|
+
import { useTranslation } from 'react-i18next';
|
|
14
|
+
import { useHistory } from 'react-router-dom';
|
|
15
|
+
import useHotkeys from '@bigbinary/neeto-hotkeys';
|
|
16
|
+
import Close from '@bigbinary/neeto-icons/Close';
|
|
17
|
+
import Tooltip from '@bigbinary/neetoui/Tooltip';
|
|
18
|
+
import Typography from '@bigbinary/neetoui/Typography';
|
|
19
|
+
import { i as isRuleEmpty } from './index-95fe069e.js';
|
|
20
|
+
import dayjs from 'dayjs';
|
|
21
|
+
import { x as isDate, q as isCustomDateRange, y as isTime, t as isCustomTimeRange, m as isMulti, n as isTreeSelect, z as isSingleDate, A as isSingleTime, B as isBoolean, E as getLabelFromBool, v as isText, F as TEXT_RULES, w as isDigit, N as NUMBER_RULES, G as isSingle, h as getSnakeCasedQueryParams, i as isKeywordFilterPresent, _ as _slicedToArray, b as buildFiltersFromSearchParams, d as _toConsumableArray, c as buildUrlFromFilters, g as getSearchTermFromUrl, H as buildSegmentsPayload, I as buildUrlFromSegment } from './utils-9ea34335.js';
|
|
22
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
23
|
+
import Dropdown from '@bigbinary/neetoui/Dropdown';
|
|
24
|
+
import '@bigbinary/neeto-icons/Delete';
|
|
25
|
+
import '@bigbinary/neetoui/Accordion';
|
|
26
|
+
import '@bigbinary/neetoui/Pane';
|
|
27
|
+
import '@bigbinary/neetoui/formik/ActionBlock';
|
|
28
|
+
import '@bigbinary/neetoui/formik/Form';
|
|
29
|
+
import '@bigbinary/neetoui/formik/Input';
|
|
30
|
+
import 'react-router-dom/cjs/react-router-dom.min';
|
|
31
|
+
import '@bigbinary/neeto-icons/Plus';
|
|
32
|
+
import '@bigbinary/neetoui/Select';
|
|
33
|
+
import 'yup';
|
|
34
|
+
import 'axios';
|
|
35
|
+
import '@bigbinary/neetoui/DatePicker';
|
|
36
|
+
import '@bigbinary/neetoui/TimePicker';
|
|
37
|
+
import '@bigbinary/neetoui/Input';
|
|
38
|
+
import '@bigbinary/neetoui/TreeSelect';
|
|
39
|
+
import 'dayjs/plugin/timezone';
|
|
40
|
+
import 'dayjs/plugin/utc';
|
|
41
|
+
import 'dayjs/plugin/weekday';
|
|
42
|
+
import '@bigbinary/neeto-icons/Help';
|
|
43
|
+
|
|
44
|
+
var DEFAULT_SEGMENTS_CACHE = {
|
|
45
|
+
segments: []
|
|
46
|
+
};
|
|
47
|
+
var SEGMENT_ACTIONS = {
|
|
48
|
+
EDIT: "edit",
|
|
49
|
+
CREATE: "create"
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
var SHORTCUTS = {
|
|
53
|
+
closePane: {
|
|
54
|
+
sequence: "escape",
|
|
55
|
+
description: t("neetoFilters.shortcuts.closePane")
|
|
56
|
+
},
|
|
57
|
+
deleteBlock: {
|
|
58
|
+
sequence: "backspace",
|
|
59
|
+
description: t("neetoFilters.shortcuts.deleteBlock")
|
|
60
|
+
},
|
|
61
|
+
openFilterPane: {
|
|
62
|
+
sequence: "enter",
|
|
63
|
+
description: t("neetoFilters.shortcuts.openFilterPane")
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
var buildCustomDateValue = function buildCustomDateValue(value) {
|
|
68
|
+
var isBeforeOrAfter = Math.abs(dayjs(value[1]).diff(dayjs(value[0]), "year")) >= 90;
|
|
69
|
+
if (isBeforeOrAfter) {
|
|
70
|
+
var currentMoment = dayjs();
|
|
71
|
+
var diffWithStart = Math.abs(currentMoment.diff(dayjs(value[0]), "year"));
|
|
72
|
+
var diffWithEnd = Math.abs(currentMoment.diff(dayjs(value[1]), "year"));
|
|
73
|
+
return diffWithStart < diffWithEnd ? "after-".concat(dateFormat.date(dayjs(value[0]).subtract(1, "day"))) : "before-".concat(dateFormat.date(dayjs(value[1]).add(1, "day")));
|
|
74
|
+
}
|
|
75
|
+
return value.map(dateFormat.date).join(" - ");
|
|
76
|
+
};
|
|
77
|
+
var buildFilterValue = function buildFilterValue(filter) {
|
|
78
|
+
var _findBy2;
|
|
79
|
+
var _filter$defaultType = filter.defaultType,
|
|
80
|
+
defaultType = _filter$defaultType === void 0 ? filter.type : _filter$defaultType,
|
|
81
|
+
value = filter.value,
|
|
82
|
+
rule = filter.rule,
|
|
83
|
+
_filter$values = filter.values,
|
|
84
|
+
initialValues = _filter$values === void 0 ? [] : _filter$values;
|
|
85
|
+
var values = initialValues.map(modify("value", function (value) {
|
|
86
|
+
return value.toString();
|
|
87
|
+
}));
|
|
88
|
+
if (isDate(defaultType) && isCustomDateRange(value)) {
|
|
89
|
+
return buildCustomDateValue(value);
|
|
90
|
+
} else if (isTime(defaultType) && isCustomTimeRange(value)) {
|
|
91
|
+
return value.map(dateFormat.time).join(" - ");
|
|
92
|
+
} else if (isDate(defaultType) || isTime(defaultType)) {
|
|
93
|
+
return humanize(value);
|
|
94
|
+
} else if (isMulti(defaultType) || isTreeSelect(defaultType)) {
|
|
95
|
+
return value.map(function (value) {
|
|
96
|
+
var _findBy;
|
|
97
|
+
return ((_findBy = findBy({
|
|
98
|
+
value: value
|
|
99
|
+
}, values)) === null || _findBy === void 0 ? void 0 : _findBy.label) || value;
|
|
100
|
+
}).join(", ");
|
|
101
|
+
} else if (isSingleDate(defaultType)) {
|
|
102
|
+
return rule === "between" ? value.map(dateFormat.date).join(" - ") : dateFormat.date(value);
|
|
103
|
+
} else if (isSingleTime(defaultType)) {
|
|
104
|
+
return rule === "between" ? value.map(dateFormat.time).join(" - ") : dateFormat.time(value);
|
|
105
|
+
} else if (isBoolean(defaultType)) {
|
|
106
|
+
return getLabelFromBool({
|
|
107
|
+
value: value,
|
|
108
|
+
values: values
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return ((_findBy2 = findBy({
|
|
112
|
+
value: value
|
|
113
|
+
}, values)) === null || _findBy2 === void 0 ? void 0 : _findBy2.label) || value;
|
|
114
|
+
};
|
|
115
|
+
var buildRuleValue = function buildRuleValue(_ref) {
|
|
116
|
+
var rule = _ref.rule,
|
|
117
|
+
defaultType = _ref.defaultType;
|
|
118
|
+
if (isText(defaultType)) {
|
|
119
|
+
return findBy({
|
|
120
|
+
value: rule
|
|
121
|
+
}, TEXT_RULES).label;
|
|
122
|
+
} else if (isDigit(defaultType)) {
|
|
123
|
+
return findBy({
|
|
124
|
+
value: rule
|
|
125
|
+
}, NUMBER_RULES).label;
|
|
126
|
+
} else if (isSingleDate(defaultType)) {
|
|
127
|
+
return findBy({
|
|
128
|
+
value: rule
|
|
129
|
+
}, SINGLE_DATE_OPTIONS).label;
|
|
130
|
+
} else if (isSingleTime(defaultType)) {
|
|
131
|
+
return findBy({
|
|
132
|
+
value: rule
|
|
133
|
+
}, SINGLE_TIME_OPTIONS).label;
|
|
134
|
+
} else if (isMulti(defaultType) || isSingle(defaultType) || isTreeSelect(defaultType)) {
|
|
135
|
+
return isRuleEmpty(rule) ? t("neetoFilters.rules.isEmpty") : "";
|
|
136
|
+
}
|
|
137
|
+
return "";
|
|
138
|
+
};
|
|
139
|
+
var hasOnlyKeywordFilter = function hasOnlyKeywordFilter(filters) {
|
|
140
|
+
return filters.length === 1 && filters[0].key === SEARCH_TERM_KEY;
|
|
141
|
+
};
|
|
142
|
+
var deepCompare = function deepCompare(segments, filters) {
|
|
143
|
+
var comparisonHelper = function comparisonHelper(filters) {
|
|
144
|
+
return sortBy(prop("key"), removeBy({
|
|
145
|
+
key: SEARCH_TERM_KEY
|
|
146
|
+
}, project(["key", "rule", "value", "label"], filters)));
|
|
147
|
+
};
|
|
148
|
+
return reject(function (filters) {
|
|
149
|
+
var segment = findBy({
|
|
150
|
+
key: filters.key
|
|
151
|
+
}, segments);
|
|
152
|
+
return segment && segment.value === filters.value;
|
|
153
|
+
}, comparisonHelper(filters));
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
var Block = function Block(_ref) {
|
|
157
|
+
var filter = _ref.filter,
|
|
158
|
+
handleDelete = _ref.handleDelete,
|
|
159
|
+
setIsPaneOpen = _ref.setIsPaneOpen;
|
|
160
|
+
var key = filter.key,
|
|
161
|
+
_filter$defaultType = filter.defaultType,
|
|
162
|
+
defaultType = _filter$defaultType === void 0 ? filter.type : _filter$defaultType,
|
|
163
|
+
label = filter.label,
|
|
164
|
+
rule = filter.rule,
|
|
165
|
+
defaultValue = filter.defaultValue;
|
|
166
|
+
var filterValue = buildFilterValue(filter);
|
|
167
|
+
var ruleContent = buildRuleValue({
|
|
168
|
+
rule: rule,
|
|
169
|
+
defaultType: defaultType
|
|
170
|
+
});
|
|
171
|
+
var blockLength = label.length + ruleContent.length + filterValue.length;
|
|
172
|
+
var toolTipDisabled = blockLength <= 50;
|
|
173
|
+
var blockContent = !toolTipDisabled ? "".concat(filterValue.slice(0, 50 - blockLength), "...") : filterValue;
|
|
174
|
+
var deleteBlockHotKeyRef = useHotkeys(SHORTCUTS.deleteBlock.sequence, function () {
|
|
175
|
+
return handleDelete(key);
|
|
176
|
+
}, {
|
|
177
|
+
mode: "scoped"
|
|
178
|
+
});
|
|
179
|
+
var openFilterPaneHotKeyRef = useHotkeys(SHORTCUTS.openFilterPane.sequence, function () {
|
|
180
|
+
return setIsPaneOpen(key);
|
|
181
|
+
}, {
|
|
182
|
+
mode: "scoped"
|
|
183
|
+
});
|
|
184
|
+
return /*#__PURE__*/jsx(Tooltip, {
|
|
185
|
+
content: filterValue,
|
|
186
|
+
disabled: toolTipDisabled,
|
|
187
|
+
position: "bottom",
|
|
188
|
+
theme: "light",
|
|
189
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
190
|
+
className: "neeto-filters-bar__block",
|
|
191
|
+
"data-cy": "neeto-filters-".concat(hyphenate(key), "-block"),
|
|
192
|
+
tabIndex: 0,
|
|
193
|
+
ref: function ref(node) {
|
|
194
|
+
deleteBlockHotKeyRef.current = node;
|
|
195
|
+
openFilterPaneHotKeyRef.current = node;
|
|
196
|
+
},
|
|
197
|
+
onClick: function onClick() {
|
|
198
|
+
return setIsPaneOpen(key);
|
|
199
|
+
},
|
|
200
|
+
children: [/*#__PURE__*/jsxs(Typography, {
|
|
201
|
+
style: "body2",
|
|
202
|
+
children: [label, ":"]
|
|
203
|
+
}), /*#__PURE__*/jsx(Typography, {
|
|
204
|
+
className: "neeto-ui-text-gray-600",
|
|
205
|
+
style: "body2",
|
|
206
|
+
children: ruleContent
|
|
207
|
+
}), !isRuleEmpty(rule) && /*#__PURE__*/jsx(Typography, {
|
|
208
|
+
style: "body2",
|
|
209
|
+
children: blockContent
|
|
210
|
+
}), !defaultValue && /*#__PURE__*/jsx("div", {
|
|
211
|
+
className: "neeto-filters-bar__block-close",
|
|
212
|
+
children: /*#__PURE__*/jsx(Close, {
|
|
213
|
+
"data-cy": "neeto-filters-".concat(hyphenate(key), "-block-close-btn"),
|
|
214
|
+
size: 16,
|
|
215
|
+
strokeWidth: 2,
|
|
216
|
+
onClick: function onClick(event) {
|
|
217
|
+
event.stopPropagation();
|
|
218
|
+
handleDelete(key);
|
|
219
|
+
}
|
|
220
|
+
})
|
|
221
|
+
})]
|
|
222
|
+
})
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
var ChildBlock = function ChildBlock(_ref) {
|
|
227
|
+
var childKey = _ref.childKey,
|
|
228
|
+
setIsPaneOpen = _ref.setIsPaneOpen,
|
|
229
|
+
handleDelete = _ref.handleDelete;
|
|
230
|
+
var deleteBlockHotKeyRef = useHotkeys(SHORTCUTS.deleteBlock.sequence, function () {
|
|
231
|
+
return handleDelete(childKey);
|
|
232
|
+
}, {
|
|
233
|
+
mode: "scoped"
|
|
234
|
+
});
|
|
235
|
+
var openFilterPaneHotKeyRef = useHotkeys(SHORTCUTS.openFilterPane.sequence, function () {
|
|
236
|
+
return setIsPaneOpen(childKey);
|
|
237
|
+
}, {
|
|
238
|
+
mode: "scoped"
|
|
239
|
+
});
|
|
240
|
+
return /*#__PURE__*/jsxs("div", {
|
|
241
|
+
className: "neeto-filters-bar__block",
|
|
242
|
+
"data-cy": "neeto-filters-".concat(hyphenate(childKey), "-block"),
|
|
243
|
+
tabIndex: 0,
|
|
244
|
+
ref: function ref(node) {
|
|
245
|
+
deleteBlockHotKeyRef.current = node;
|
|
246
|
+
openFilterPaneHotKeyRef.current = node;
|
|
247
|
+
},
|
|
248
|
+
onClick: function onClick() {
|
|
249
|
+
return setIsPaneOpen(childKey);
|
|
250
|
+
},
|
|
251
|
+
children: [/*#__PURE__*/jsx(Typography, {
|
|
252
|
+
style: "body2",
|
|
253
|
+
weight: "medium",
|
|
254
|
+
children: childKey
|
|
255
|
+
}), /*#__PURE__*/jsx("div", {
|
|
256
|
+
className: "neeto-filters-bar__block-close",
|
|
257
|
+
children: /*#__PURE__*/jsx(Close, {
|
|
258
|
+
"data-cy": "neeto-filters-".concat(hyphenate(childKey), "-block-close-btn"),
|
|
259
|
+
size: 16,
|
|
260
|
+
strokeWidth: 2,
|
|
261
|
+
onClick: function onClick(event) {
|
|
262
|
+
event.stopPropagation();
|
|
263
|
+
handleDelete(childKey);
|
|
264
|
+
}
|
|
265
|
+
})
|
|
266
|
+
})]
|
|
267
|
+
});
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
var FilterBar = function FilterBar(_ref) {
|
|
271
|
+
var entity = _ref.entity,
|
|
272
|
+
filters = _ref.filters,
|
|
273
|
+
setIsSavePaneOpen = _ref.setIsSavePaneOpen,
|
|
274
|
+
setIsPaneOpen = _ref.setIsPaneOpen,
|
|
275
|
+
childrenKeys = _ref.childrenKeys,
|
|
276
|
+
nonHiddenFilters = _ref.nonHiddenFilters,
|
|
277
|
+
childrenFiltersApplied = _ref.childrenFiltersApplied,
|
|
278
|
+
keywordFilter = _ref.keywordFilter,
|
|
279
|
+
handleApplyFilters = _ref.handleApplyFilters;
|
|
280
|
+
var _useTranslation = useTranslation(),
|
|
281
|
+
t = _useTranslation.t;
|
|
282
|
+
var history = useHistory();
|
|
283
|
+
var searchParams = useQueryParams({
|
|
284
|
+
toCamelCase: false
|
|
285
|
+
});
|
|
286
|
+
var handleDelete = function handleDelete(key) {
|
|
287
|
+
if (key === SEARCH_TERM_KEY) {
|
|
288
|
+
var params = omit([SEARCH_TERM_KEY], getSnakeCasedQueryParams());
|
|
289
|
+
var pathname = window.location.pathname;
|
|
290
|
+
history.push(buildUrl(pathname, params));
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
if (childrenKeys.includes(key)) {
|
|
294
|
+
var _params = omit([key], getSnakeCasedQueryParams());
|
|
295
|
+
var _pathname = window.location.pathname;
|
|
296
|
+
history.push(buildUrl(_pathname, _params));
|
|
297
|
+
}
|
|
298
|
+
var newFilters = removeBy({
|
|
299
|
+
key: key
|
|
300
|
+
}, filters);
|
|
301
|
+
handleApplyFilters(newFilters);
|
|
302
|
+
};
|
|
303
|
+
var handleClearAll = function handleClearAll() {
|
|
304
|
+
var params = isKeywordFilterPresent(keywordFilter) ? omit([SEARCH_TERM_KEY], getSnakeCasedQueryParams()) : getSnakeCasedQueryParams();
|
|
305
|
+
var pathname = window.location.pathname;
|
|
306
|
+
history.push(buildUrl(pathname, params));
|
|
307
|
+
handleApplyFilters([], true);
|
|
308
|
+
};
|
|
309
|
+
var hideClearButton = nonHiddenFilters.every(function (_ref2) {
|
|
310
|
+
var defaultValue = _ref2.defaultValue,
|
|
311
|
+
isClearable = _ref2.isClearable;
|
|
312
|
+
return defaultValue && !isClearable;
|
|
313
|
+
}) && !childrenFiltersApplied;
|
|
314
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
315
|
+
children: [nonHiddenFilters.map(function (filter) {
|
|
316
|
+
var _filter$suffixCompone;
|
|
317
|
+
return /*#__PURE__*/jsxs(React.Fragment, {
|
|
318
|
+
children: [/*#__PURE__*/jsx(Block, {
|
|
319
|
+
filter: filter,
|
|
320
|
+
handleDelete: handleDelete,
|
|
321
|
+
setIsPaneOpen: setIsPaneOpen
|
|
322
|
+
}), (_filter$suffixCompone = filter.suffixComponent) === null || _filter$suffixCompone === void 0 ? void 0 : _filter$suffixCompone.call(filter), /*#__PURE__*/jsx("div", {
|
|
323
|
+
className: "neeto-filters-bar--separator"
|
|
324
|
+
})]
|
|
325
|
+
}, filter.key);
|
|
326
|
+
}), childrenKeys.filter(function (childKey) {
|
|
327
|
+
return has(childKey, searchParams);
|
|
328
|
+
}).map(function (childKey) {
|
|
329
|
+
return /*#__PURE__*/jsxs(React.Fragment, {
|
|
330
|
+
children: [/*#__PURE__*/jsx(ChildBlock, {
|
|
331
|
+
childKey: childKey,
|
|
332
|
+
handleDelete: handleDelete,
|
|
333
|
+
setIsPaneOpen: setIsPaneOpen
|
|
334
|
+
}), /*#__PURE__*/jsx("div", {
|
|
335
|
+
className: "neeto-filters-bar--separator"
|
|
336
|
+
})]
|
|
337
|
+
}, childKey);
|
|
338
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
339
|
+
className: "flex items-center gap-x-2",
|
|
340
|
+
children: [isPresent(entity) && !hasOnlyKeywordFilter(filters) && /*#__PURE__*/jsx(Button, {
|
|
341
|
+
"data-cy": "save-segment-button",
|
|
342
|
+
label: t("neetoFilters.segments.saveAsNewSegment"),
|
|
343
|
+
style: "secondary",
|
|
344
|
+
onClick: function onClick() {
|
|
345
|
+
setIsPaneOpen(false);
|
|
346
|
+
setIsSavePaneOpen({
|
|
347
|
+
action: SEGMENT_ACTIONS.CREATE
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
}), !hideClearButton && /*#__PURE__*/jsx(Button, {
|
|
351
|
+
"data-cy": "neeto-filters-bar-clear-btn",
|
|
352
|
+
label: t("neetoFilters.common.clearFilters"),
|
|
353
|
+
style: "text",
|
|
354
|
+
onClick: handleClearAll
|
|
355
|
+
})]
|
|
356
|
+
})]
|
|
357
|
+
});
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
361
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
362
|
+
var useSegment = function useSegment(_ref) {
|
|
363
|
+
var entity = _ref.entity,
|
|
364
|
+
keyword = _ref.keyword,
|
|
365
|
+
columns = _ref.columns,
|
|
366
|
+
childrenKeys = _ref.childrenKeys,
|
|
367
|
+
segmentsBaseUrl = _ref.segmentsBaseUrl;
|
|
368
|
+
var history = useHistory();
|
|
369
|
+
var _useTranslation = useTranslation(),
|
|
370
|
+
t = _useTranslation.t;
|
|
371
|
+
var initialRenderRef = useRef(true);
|
|
372
|
+
var _useQueryParams = useQueryParams(),
|
|
373
|
+
segmentId = _useQueryParams.segmentId;
|
|
374
|
+
var _useState = useState({
|
|
375
|
+
action: undefined
|
|
376
|
+
}),
|
|
377
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
378
|
+
isSavePaneOpen = _useState2[0],
|
|
379
|
+
setIsSavePaneOpen = _useState2[1];
|
|
380
|
+
var _useCreateSegment = useCreateSegment(),
|
|
381
|
+
createSegment = _useCreateSegment.mutate,
|
|
382
|
+
isCreating = _useCreateSegment.isPending;
|
|
383
|
+
var _useUpdateSegment = useUpdateSegment(),
|
|
384
|
+
updateSegment = _useUpdateSegment.mutate,
|
|
385
|
+
isUpdating = _useUpdateSegment.isPending;
|
|
386
|
+
var isSubmitting = isCreating || isUpdating;
|
|
387
|
+
var searchParams = useQueryParams({
|
|
388
|
+
toCamelCase: false
|
|
389
|
+
});
|
|
390
|
+
var keywordValue = searchParams[SEARCH_TERM_KEY] || "";
|
|
391
|
+
var isEdit = isSavePaneOpen.action === SEGMENT_ACTIONS.EDIT;
|
|
392
|
+
var keywordFilter = _objectSpread(_objectSpread({
|
|
393
|
+
type: "text",
|
|
394
|
+
rule: "contains",
|
|
395
|
+
label: t("neetoFilters.common.searchTerm")
|
|
396
|
+
}, keyword), {}, {
|
|
397
|
+
key: SEARCH_TERM_KEY,
|
|
398
|
+
value: keywordValue
|
|
399
|
+
});
|
|
400
|
+
var filters = buildFiltersFromSearchParams(isKeywordFilterPresent(keywordFilter) && isNotEmpty(keywordValue) ? [keywordFilter].concat(_toConsumableArray(columns)) : columns);
|
|
401
|
+
var nonHiddenFilters = removeBy({
|
|
402
|
+
hidden: true
|
|
403
|
+
}, filters);
|
|
404
|
+
var handleApplyFilters = function handleApplyFilters(newFilters, isClearAll) {
|
|
405
|
+
var params = buildUrlFromFilters(_objectSpread({
|
|
406
|
+
columns: columns,
|
|
407
|
+
filters: isKeywordFilterPresent(keywordFilter) && isNotEmpty(getSearchTermFromUrl()) ? [].concat(_toConsumableArray(newFilters), [keywordFilter]) : newFilters
|
|
408
|
+
}, isClearAll && {
|
|
409
|
+
isClearAll: true,
|
|
410
|
+
childrenKeys: childrenKeys
|
|
411
|
+
}));
|
|
412
|
+
history.push({
|
|
413
|
+
search: params
|
|
414
|
+
});
|
|
415
|
+
};
|
|
416
|
+
var childrenFiltersApplied = childrenKeys.some(function (key) {
|
|
417
|
+
return has(key, searchParams);
|
|
418
|
+
});
|
|
419
|
+
useEffect(function () {
|
|
420
|
+
if (initialRenderRef.current) {
|
|
421
|
+
initialRenderRef.current = false;
|
|
422
|
+
return noop;
|
|
423
|
+
}
|
|
424
|
+
var handler = setTimeout(function () {
|
|
425
|
+
handleApplyFilters(filters);
|
|
426
|
+
}, 500);
|
|
427
|
+
return function () {
|
|
428
|
+
return clearTimeout(handler);
|
|
429
|
+
};
|
|
430
|
+
}, [keywordValue]);
|
|
431
|
+
var handleCreateSuccess = function handleCreateSuccess(_ref2) {
|
|
432
|
+
var _filters$;
|
|
433
|
+
var _ref2$segment = _ref2.segment,
|
|
434
|
+
id = _ref2$segment.id,
|
|
435
|
+
filters = _ref2$segment.filters;
|
|
436
|
+
history.push({
|
|
437
|
+
pathname: segmentsBaseUrl,
|
|
438
|
+
search: buildUrlFromSegment({
|
|
439
|
+
columns: columns,
|
|
440
|
+
filters: (_filters$ = filters[0]) === null || _filters$ === void 0 ? void 0 : _filters$.conditions,
|
|
441
|
+
id: id
|
|
442
|
+
})
|
|
443
|
+
});
|
|
444
|
+
setIsSavePaneOpen({
|
|
445
|
+
action: undefined
|
|
446
|
+
});
|
|
447
|
+
showThumbsUpToastr();
|
|
448
|
+
};
|
|
449
|
+
var handleCreate = function handleCreate(_ref3, _ref4) {
|
|
450
|
+
var name = _ref3.name;
|
|
451
|
+
var setFieldError = _ref4.setFieldError;
|
|
452
|
+
var filtersPayload = buildSegmentsPayload(filters, childrenKeys);
|
|
453
|
+
createSegment({
|
|
454
|
+
name: name,
|
|
455
|
+
entity: entity,
|
|
456
|
+
filters: filtersPayload
|
|
457
|
+
}, {
|
|
458
|
+
onSuccess: handleCreateSuccess,
|
|
459
|
+
onError: function onError(error) {
|
|
460
|
+
return setFieldError("name", error.response.data.error);
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
};
|
|
464
|
+
var handleUpdate = function handleUpdate(_ref5, _ref6) {
|
|
465
|
+
var name = _ref5.name;
|
|
466
|
+
var setFieldError = _ref6.setFieldError;
|
|
467
|
+
var filtersPayload = buildSegmentsPayload(filters, childrenKeys);
|
|
468
|
+
updateSegment({
|
|
469
|
+
id: segmentId,
|
|
470
|
+
payload: {
|
|
471
|
+
name: name,
|
|
472
|
+
filters: filtersPayload
|
|
473
|
+
}
|
|
474
|
+
}, {
|
|
475
|
+
onSuccess: function onSuccess() {
|
|
476
|
+
setIsSavePaneOpen({
|
|
477
|
+
action: undefined
|
|
478
|
+
});
|
|
479
|
+
showThumbsUpToastr();
|
|
480
|
+
},
|
|
481
|
+
onError: function onError(error) {
|
|
482
|
+
return setFieldError("name", error.response.data.error);
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
};
|
|
486
|
+
return {
|
|
487
|
+
isEdit: isEdit,
|
|
488
|
+
filters: filters,
|
|
489
|
+
keywordFilter: keywordFilter,
|
|
490
|
+
isSubmitting: isSubmitting,
|
|
491
|
+
nonHiddenFilters: nonHiddenFilters,
|
|
492
|
+
isSavePaneOpen: isSavePaneOpen,
|
|
493
|
+
setIsSavePaneOpen: setIsSavePaneOpen,
|
|
494
|
+
handleApplyFilters: handleApplyFilters,
|
|
495
|
+
childrenFiltersApplied: childrenFiltersApplied,
|
|
496
|
+
handleSubmit: isEdit ? handleUpdate : handleCreate
|
|
497
|
+
};
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
var Menu = Dropdown.Menu,
|
|
501
|
+
MenuItem = Dropdown.MenuItem;
|
|
502
|
+
var SegmentBar = function SegmentBar(_ref) {
|
|
503
|
+
var entity = _ref.entity,
|
|
504
|
+
filters = _ref.filters,
|
|
505
|
+
setIsSavePaneOpen = _ref.setIsSavePaneOpen,
|
|
506
|
+
setIsPaneOpen = _ref.setIsPaneOpen,
|
|
507
|
+
handleApplyFilters = _ref.handleApplyFilters,
|
|
508
|
+
childrenKeys = _ref.childrenKeys;
|
|
509
|
+
var _useTranslation = useTranslation(),
|
|
510
|
+
t = _useTranslation.t;
|
|
511
|
+
var history = useHistory();
|
|
512
|
+
var _useQueryParams = useQueryParams(),
|
|
513
|
+
segmentId = _useQueryParams.segmentId;
|
|
514
|
+
var queryClient = useQueryClient();
|
|
515
|
+
var cachedSegments = queryClient.getQueryData([QUERY_KEYS.SEGMENTS_LIST, entity, ""]) || DEFAULT_SEGMENTS_CACHE;
|
|
516
|
+
var segment = findById(segmentId, cachedSegments.segments);
|
|
517
|
+
if (isNotPresent(segment)) return null;
|
|
518
|
+
var handleDelete = function handleDelete(key) {
|
|
519
|
+
if (key === SEARCH_TERM_KEY) {
|
|
520
|
+
var params = omit([SEARCH_TERM_KEY], getSnakeCasedQueryParams());
|
|
521
|
+
var pathname = window.location.pathname;
|
|
522
|
+
history.push(buildUrl(pathname, params));
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
if (childrenKeys.includes(key)) {
|
|
526
|
+
var _params = omit([key], getSnakeCasedQueryParams());
|
|
527
|
+
var _pathname = window.location.pathname;
|
|
528
|
+
history.push(buildUrl(_pathname, _params));
|
|
529
|
+
}
|
|
530
|
+
var newFilters = removeBy({
|
|
531
|
+
key: key
|
|
532
|
+
}, filters);
|
|
533
|
+
handleApplyFilters(newFilters);
|
|
534
|
+
};
|
|
535
|
+
var changedFilters = deepCompare(segment.filters[0].conditions, filters);
|
|
536
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
537
|
+
children: [/*#__PURE__*/jsx(Typography, {
|
|
538
|
+
className: "neeto-ui-text-gray-600 mr-4 px-2",
|
|
539
|
+
"data-cy": "neeto-filters-segment-name",
|
|
540
|
+
style: "h4",
|
|
541
|
+
children: segment.name
|
|
542
|
+
}), isNotEmpty(changedFilters) && /*#__PURE__*/jsxs(Fragment, {
|
|
543
|
+
children: [/*#__PURE__*/jsx(Dropdown, {
|
|
544
|
+
buttonProps: {
|
|
545
|
+
className: "mr-2"
|
|
546
|
+
},
|
|
547
|
+
buttonStyle: "secondary",
|
|
548
|
+
label: t("neetoFilters.segments.updateSegment"),
|
|
549
|
+
children: /*#__PURE__*/jsxs(Menu, {
|
|
550
|
+
children: [/*#__PURE__*/jsx(MenuItem.Button, {
|
|
551
|
+
onClick: function onClick() {
|
|
552
|
+
return setIsSavePaneOpen({
|
|
553
|
+
action: SEGMENT_ACTIONS.EDIT
|
|
554
|
+
});
|
|
555
|
+
},
|
|
556
|
+
children: t("neetoFilters.segments.updateSegment")
|
|
557
|
+
}), /*#__PURE__*/jsx(MenuItem.Button, {
|
|
558
|
+
onClick: function onClick() {
|
|
559
|
+
setIsPaneOpen(false);
|
|
560
|
+
setIsSavePaneOpen({
|
|
561
|
+
action: SEGMENT_ACTIONS.CREATE
|
|
562
|
+
});
|
|
563
|
+
},
|
|
564
|
+
children: t("neetoFilters.segments.saveAsNewSegment")
|
|
565
|
+
})]
|
|
566
|
+
})
|
|
567
|
+
}), changedFilters.map(function (filter) {
|
|
568
|
+
var _filter$suffixCompone;
|
|
569
|
+
return /*#__PURE__*/jsxs(React.Fragment, {
|
|
570
|
+
children: [/*#__PURE__*/jsx(Block, {
|
|
571
|
+
filter: filter,
|
|
572
|
+
handleDelete: handleDelete,
|
|
573
|
+
setIsPaneOpen: setIsPaneOpen
|
|
574
|
+
}), (_filter$suffixCompone = filter.suffixComponent) === null || _filter$suffixCompone === void 0 ? void 0 : _filter$suffixCompone.call(filter), /*#__PURE__*/jsx("div", {
|
|
575
|
+
className: "neeto-filters-bar--separator"
|
|
576
|
+
})]
|
|
577
|
+
}, filter.key);
|
|
578
|
+
})]
|
|
579
|
+
})]
|
|
580
|
+
});
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
var Bar = function Bar(_ref) {
|
|
584
|
+
var entity = _ref.entity,
|
|
585
|
+
className = _ref.className,
|
|
586
|
+
_ref$columns = _ref.columns,
|
|
587
|
+
columns = _ref$columns === void 0 ? [] : _ref$columns,
|
|
588
|
+
_ref$keyword = _ref.keyword,
|
|
589
|
+
keyword = _ref$keyword === void 0 ? {
|
|
590
|
+
node: "",
|
|
591
|
+
value: "",
|
|
592
|
+
setValue: noop
|
|
593
|
+
} : _ref$keyword,
|
|
594
|
+
_ref$setIsPaneOpen = _ref.setIsPaneOpen,
|
|
595
|
+
setIsPaneOpen = _ref$setIsPaneOpen === void 0 ? identity : _ref$setIsPaneOpen,
|
|
596
|
+
_ref$childrenKeys = _ref.childrenKeys,
|
|
597
|
+
childrenKeys = _ref$childrenKeys === void 0 ? [] : _ref$childrenKeys,
|
|
598
|
+
_ref$defaultSegmentNa = _ref.defaultSegmentName,
|
|
599
|
+
defaultSegmentName = _ref$defaultSegmentNa === void 0 ? t("neetoFilters.common.allResults") : _ref$defaultSegmentNa,
|
|
600
|
+
_ref$segmentsBaseUrl = _ref.segmentsBaseUrl,
|
|
601
|
+
segmentsBaseUrl = _ref$segmentsBaseUrl === void 0 ? window.location.pathname : _ref$segmentsBaseUrl,
|
|
602
|
+
customFilters = _ref.customFilters;
|
|
603
|
+
var queryClient = useQueryClient();
|
|
604
|
+
var _useQueryParams = useQueryParams(),
|
|
605
|
+
segmentId = _useQueryParams.segmentId;
|
|
606
|
+
var segmentFormInitialRef = useRef(null);
|
|
607
|
+
var _useSegment = useSegment({
|
|
608
|
+
entity: entity,
|
|
609
|
+
keyword: keyword,
|
|
610
|
+
columns: columns,
|
|
611
|
+
childrenKeys: childrenKeys,
|
|
612
|
+
segmentsBaseUrl: segmentsBaseUrl
|
|
613
|
+
}),
|
|
614
|
+
isEdit = _useSegment.isEdit,
|
|
615
|
+
filters = _useSegment.filters,
|
|
616
|
+
handleSubmit = _useSegment.handleSubmit,
|
|
617
|
+
isSubmitting = _useSegment.isSubmitting,
|
|
618
|
+
keywordFilter = _useSegment.keywordFilter,
|
|
619
|
+
isSavePaneOpen = _useSegment.isSavePaneOpen,
|
|
620
|
+
nonHiddenFilters = _useSegment.nonHiddenFilters,
|
|
621
|
+
setIsSavePaneOpen = _useSegment.setIsSavePaneOpen,
|
|
622
|
+
handleApplyFilters = _useSegment.handleApplyFilters,
|
|
623
|
+
childrenFiltersApplied = _useSegment.childrenFiltersApplied;
|
|
624
|
+
var BarComponent = segmentId ? SegmentBar : FilterBar;
|
|
625
|
+
var cachedSegments = queryClient.getQueryData([QUERY_KEYS.SEGMENTS_LIST, entity, ""]) || DEFAULT_SEGMENTS_CACHE;
|
|
626
|
+
var segment = findById(segmentId, cachedSegments.segments);
|
|
627
|
+
if (isEmpty(nonHiddenFilters) && !childrenFiltersApplied) return null;
|
|
628
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
629
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
630
|
+
className: classnames("neeto-filters-bar", _defineProperty({}, className, className)),
|
|
631
|
+
children: /*#__PURE__*/jsx(BarComponent, {
|
|
632
|
+
childrenFiltersApplied: childrenFiltersApplied,
|
|
633
|
+
childrenKeys: childrenKeys,
|
|
634
|
+
entity: entity,
|
|
635
|
+
filters: filters,
|
|
636
|
+
handleApplyFilters: handleApplyFilters,
|
|
637
|
+
keywordFilter: keywordFilter,
|
|
638
|
+
nonHiddenFilters: nonHiddenFilters,
|
|
639
|
+
setIsPaneOpen: setIsPaneOpen,
|
|
640
|
+
setIsSavePaneOpen: setIsSavePaneOpen
|
|
641
|
+
})
|
|
642
|
+
}), /*#__PURE__*/jsx(SegmentForm, {
|
|
643
|
+
childrenKeys: childrenKeys,
|
|
644
|
+
columns: columns,
|
|
645
|
+
customFilters: customFilters,
|
|
646
|
+
defaultSegmentName: defaultSegmentName,
|
|
647
|
+
filters: filters,
|
|
648
|
+
handleSubmit: handleSubmit,
|
|
649
|
+
isEdit: isEdit,
|
|
650
|
+
isSubmitting: isSubmitting,
|
|
651
|
+
keywordFilter: keywordFilter,
|
|
652
|
+
segmentFormInitialRef: segmentFormInitialRef,
|
|
653
|
+
isOpen: isPresent(isSavePaneOpen.action),
|
|
654
|
+
initialValues: isEdit ? assoc("filters", [{
|
|
655
|
+
conditions: filters
|
|
656
|
+
}], segment) : {
|
|
657
|
+
name: "",
|
|
658
|
+
filters: [{
|
|
659
|
+
conditions: filters
|
|
660
|
+
}]
|
|
661
|
+
},
|
|
662
|
+
onClose: function onClose() {
|
|
663
|
+
return setIsSavePaneOpen({
|
|
664
|
+
action: undefined
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
})]
|
|
668
|
+
});
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
export { Bar as default };
|
|
672
|
+
//# sourceMappingURL=Bar.js.map
|