@bigbinary/neeto-filters-frontend 4.0.0 → 4.1.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/dist/Bar.js +667 -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 +529 -0
- package/dist/Segments.js.map +1 -0
- package/dist/cjs/Bar.js +681 -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 +543 -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 -3716
- 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 +27 -13
- package/dist/index.cjs.js +0 -3786
- package/dist/index.cjs.js.map +0 -1
package/dist/Bar.js
ADDED
|
@@ -0,0 +1,667 @@
|
|
|
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
|
+
var history = useHistory();
|
|
368
|
+
var _useTranslation = useTranslation(),
|
|
369
|
+
t = _useTranslation.t;
|
|
370
|
+
var initialRenderRef = useRef(true);
|
|
371
|
+
var _useQueryParams = useQueryParams(),
|
|
372
|
+
segmentId = _useQueryParams.segmentId;
|
|
373
|
+
var _useState = useState({
|
|
374
|
+
action: undefined
|
|
375
|
+
}),
|
|
376
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
377
|
+
isSavePaneOpen = _useState2[0],
|
|
378
|
+
setIsSavePaneOpen = _useState2[1];
|
|
379
|
+
var _useCreateSegment = useCreateSegment(),
|
|
380
|
+
createSegment = _useCreateSegment.mutate,
|
|
381
|
+
isCreating = _useCreateSegment.isPending;
|
|
382
|
+
var _useUpdateSegment = useUpdateSegment(),
|
|
383
|
+
updateSegment = _useUpdateSegment.mutate,
|
|
384
|
+
isUpdating = _useUpdateSegment.isPending;
|
|
385
|
+
var isSubmitting = isCreating || isUpdating;
|
|
386
|
+
var searchParams = useQueryParams({
|
|
387
|
+
toCamelCase: false
|
|
388
|
+
});
|
|
389
|
+
var keywordValue = searchParams[SEARCH_TERM_KEY] || "";
|
|
390
|
+
var isEdit = isSavePaneOpen.action === SEGMENT_ACTIONS.EDIT;
|
|
391
|
+
var keywordFilter = _objectSpread(_objectSpread({
|
|
392
|
+
type: "text",
|
|
393
|
+
rule: "contains",
|
|
394
|
+
label: t("neetoFilters.common.searchTerm")
|
|
395
|
+
}, keyword), {}, {
|
|
396
|
+
key: SEARCH_TERM_KEY,
|
|
397
|
+
value: keywordValue
|
|
398
|
+
});
|
|
399
|
+
var filters = buildFiltersFromSearchParams(isKeywordFilterPresent(keywordFilter) && isNotEmpty(keywordValue) ? [keywordFilter].concat(_toConsumableArray(columns)) : columns);
|
|
400
|
+
var nonHiddenFilters = removeBy({
|
|
401
|
+
hidden: true
|
|
402
|
+
}, filters);
|
|
403
|
+
var handleApplyFilters = function handleApplyFilters(newFilters, isClearAll) {
|
|
404
|
+
var params = buildUrlFromFilters(_objectSpread({
|
|
405
|
+
columns: columns,
|
|
406
|
+
filters: isKeywordFilterPresent(keywordFilter) && isNotEmpty(getSearchTermFromUrl()) ? [].concat(_toConsumableArray(newFilters), [keywordFilter]) : newFilters
|
|
407
|
+
}, isClearAll && {
|
|
408
|
+
isClearAll: true,
|
|
409
|
+
childrenKeys: childrenKeys
|
|
410
|
+
}));
|
|
411
|
+
history.push({
|
|
412
|
+
search: params
|
|
413
|
+
});
|
|
414
|
+
};
|
|
415
|
+
var childrenFiltersApplied = childrenKeys.some(function (key) {
|
|
416
|
+
return has(key, searchParams);
|
|
417
|
+
});
|
|
418
|
+
useEffect(function () {
|
|
419
|
+
if (initialRenderRef.current) {
|
|
420
|
+
initialRenderRef.current = false;
|
|
421
|
+
return noop;
|
|
422
|
+
}
|
|
423
|
+
var handler = setTimeout(function () {
|
|
424
|
+
handleApplyFilters(filters);
|
|
425
|
+
}, 500);
|
|
426
|
+
return function () {
|
|
427
|
+
return clearTimeout(handler);
|
|
428
|
+
};
|
|
429
|
+
}, [keywordValue]);
|
|
430
|
+
var handleCreateSuccess = function handleCreateSuccess(_ref2) {
|
|
431
|
+
var _filters$;
|
|
432
|
+
var _ref2$segment = _ref2.segment,
|
|
433
|
+
id = _ref2$segment.id,
|
|
434
|
+
filters = _ref2$segment.filters;
|
|
435
|
+
history.push({
|
|
436
|
+
search: buildUrlFromSegment({
|
|
437
|
+
columns: columns,
|
|
438
|
+
filters: (_filters$ = filters[0]) === null || _filters$ === void 0 ? void 0 : _filters$.conditions,
|
|
439
|
+
id: id
|
|
440
|
+
})
|
|
441
|
+
});
|
|
442
|
+
setIsSavePaneOpen({
|
|
443
|
+
action: undefined
|
|
444
|
+
});
|
|
445
|
+
showThumbsUpToastr();
|
|
446
|
+
};
|
|
447
|
+
var handleCreate = function handleCreate(_ref3, _ref4) {
|
|
448
|
+
var name = _ref3.name;
|
|
449
|
+
var setFieldError = _ref4.setFieldError;
|
|
450
|
+
var filtersPayload = buildSegmentsPayload(filters, childrenKeys);
|
|
451
|
+
createSegment({
|
|
452
|
+
name: name,
|
|
453
|
+
entity: entity,
|
|
454
|
+
filters: filtersPayload
|
|
455
|
+
}, {
|
|
456
|
+
onSuccess: handleCreateSuccess,
|
|
457
|
+
onError: function onError(error) {
|
|
458
|
+
return setFieldError("name", error.response.data.error);
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
};
|
|
462
|
+
var handleUpdate = function handleUpdate(_ref5, _ref6) {
|
|
463
|
+
var name = _ref5.name;
|
|
464
|
+
var setFieldError = _ref6.setFieldError;
|
|
465
|
+
var filtersPayload = buildSegmentsPayload(filters, childrenKeys);
|
|
466
|
+
updateSegment({
|
|
467
|
+
id: segmentId,
|
|
468
|
+
payload: {
|
|
469
|
+
name: name,
|
|
470
|
+
filters: filtersPayload
|
|
471
|
+
}
|
|
472
|
+
}, {
|
|
473
|
+
onSuccess: function onSuccess() {
|
|
474
|
+
setIsSavePaneOpen({
|
|
475
|
+
action: undefined
|
|
476
|
+
});
|
|
477
|
+
showThumbsUpToastr();
|
|
478
|
+
},
|
|
479
|
+
onError: function onError(error) {
|
|
480
|
+
return setFieldError("name", error.response.data.error);
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
};
|
|
484
|
+
return {
|
|
485
|
+
isEdit: isEdit,
|
|
486
|
+
filters: filters,
|
|
487
|
+
keywordFilter: keywordFilter,
|
|
488
|
+
isSubmitting: isSubmitting,
|
|
489
|
+
nonHiddenFilters: nonHiddenFilters,
|
|
490
|
+
isSavePaneOpen: isSavePaneOpen,
|
|
491
|
+
setIsSavePaneOpen: setIsSavePaneOpen,
|
|
492
|
+
handleApplyFilters: handleApplyFilters,
|
|
493
|
+
childrenFiltersApplied: childrenFiltersApplied,
|
|
494
|
+
handleSubmit: isEdit ? handleUpdate : handleCreate
|
|
495
|
+
};
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
var Menu = Dropdown.Menu,
|
|
499
|
+
MenuItem = Dropdown.MenuItem;
|
|
500
|
+
var SegmentBar = function SegmentBar(_ref) {
|
|
501
|
+
var entity = _ref.entity,
|
|
502
|
+
filters = _ref.filters,
|
|
503
|
+
setIsSavePaneOpen = _ref.setIsSavePaneOpen,
|
|
504
|
+
setIsPaneOpen = _ref.setIsPaneOpen,
|
|
505
|
+
handleApplyFilters = _ref.handleApplyFilters,
|
|
506
|
+
childrenKeys = _ref.childrenKeys;
|
|
507
|
+
var _useTranslation = useTranslation(),
|
|
508
|
+
t = _useTranslation.t;
|
|
509
|
+
var history = useHistory();
|
|
510
|
+
var _useQueryParams = useQueryParams(),
|
|
511
|
+
segmentId = _useQueryParams.segmentId;
|
|
512
|
+
var queryClient = useQueryClient();
|
|
513
|
+
var cachedSegments = queryClient.getQueryData([QUERY_KEYS.SEGMENTS_LIST, entity, ""]) || DEFAULT_SEGMENTS_CACHE;
|
|
514
|
+
var segment = findById(segmentId, cachedSegments.segments);
|
|
515
|
+
if (isNotPresent(segment)) return null;
|
|
516
|
+
var handleDelete = function handleDelete(key) {
|
|
517
|
+
if (key === SEARCH_TERM_KEY) {
|
|
518
|
+
var params = omit([SEARCH_TERM_KEY], getSnakeCasedQueryParams());
|
|
519
|
+
var pathname = window.location.pathname;
|
|
520
|
+
history.push(buildUrl(pathname, params));
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
if (childrenKeys.includes(key)) {
|
|
524
|
+
var _params = omit([key], getSnakeCasedQueryParams());
|
|
525
|
+
var _pathname = window.location.pathname;
|
|
526
|
+
history.push(buildUrl(_pathname, _params));
|
|
527
|
+
}
|
|
528
|
+
var newFilters = removeBy({
|
|
529
|
+
key: key
|
|
530
|
+
}, filters);
|
|
531
|
+
handleApplyFilters(newFilters);
|
|
532
|
+
};
|
|
533
|
+
var changedFilters = deepCompare(segment.filters[0].conditions, filters);
|
|
534
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
535
|
+
children: [/*#__PURE__*/jsx(Typography, {
|
|
536
|
+
className: "neeto-ui-text-gray-600 mr-4 px-2",
|
|
537
|
+
"data-cy": "neeto-filters-segment-name",
|
|
538
|
+
style: "h4",
|
|
539
|
+
children: segment.name
|
|
540
|
+
}), isNotEmpty(changedFilters) && /*#__PURE__*/jsxs(Fragment, {
|
|
541
|
+
children: [/*#__PURE__*/jsx(Dropdown, {
|
|
542
|
+
buttonProps: {
|
|
543
|
+
className: "mr-2"
|
|
544
|
+
},
|
|
545
|
+
buttonStyle: "secondary",
|
|
546
|
+
label: t("neetoFilters.segments.updateSegment"),
|
|
547
|
+
children: /*#__PURE__*/jsxs(Menu, {
|
|
548
|
+
children: [/*#__PURE__*/jsx(MenuItem.Button, {
|
|
549
|
+
onClick: function onClick() {
|
|
550
|
+
return setIsSavePaneOpen({
|
|
551
|
+
action: SEGMENT_ACTIONS.EDIT
|
|
552
|
+
});
|
|
553
|
+
},
|
|
554
|
+
children: t("neetoFilters.segments.updateSegment")
|
|
555
|
+
}), /*#__PURE__*/jsx(MenuItem.Button, {
|
|
556
|
+
onClick: function onClick() {
|
|
557
|
+
setIsPaneOpen(false);
|
|
558
|
+
setIsSavePaneOpen({
|
|
559
|
+
action: SEGMENT_ACTIONS.CREATE
|
|
560
|
+
});
|
|
561
|
+
},
|
|
562
|
+
children: t("neetoFilters.segments.saveAsNewSegment")
|
|
563
|
+
})]
|
|
564
|
+
})
|
|
565
|
+
}), changedFilters.map(function (filter) {
|
|
566
|
+
var _filter$suffixCompone;
|
|
567
|
+
return /*#__PURE__*/jsxs(React.Fragment, {
|
|
568
|
+
children: [/*#__PURE__*/jsx(Block, {
|
|
569
|
+
filter: filter,
|
|
570
|
+
handleDelete: handleDelete,
|
|
571
|
+
setIsPaneOpen: setIsPaneOpen
|
|
572
|
+
}), (_filter$suffixCompone = filter.suffixComponent) === null || _filter$suffixCompone === void 0 ? void 0 : _filter$suffixCompone.call(filter), /*#__PURE__*/jsx("div", {
|
|
573
|
+
className: "neeto-filters-bar--separator"
|
|
574
|
+
})]
|
|
575
|
+
}, filter.key);
|
|
576
|
+
})]
|
|
577
|
+
})]
|
|
578
|
+
});
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
var Bar = function Bar(_ref) {
|
|
582
|
+
var entity = _ref.entity,
|
|
583
|
+
className = _ref.className,
|
|
584
|
+
_ref$columns = _ref.columns,
|
|
585
|
+
columns = _ref$columns === void 0 ? [] : _ref$columns,
|
|
586
|
+
_ref$keyword = _ref.keyword,
|
|
587
|
+
keyword = _ref$keyword === void 0 ? {
|
|
588
|
+
node: "",
|
|
589
|
+
value: "",
|
|
590
|
+
setValue: noop
|
|
591
|
+
} : _ref$keyword,
|
|
592
|
+
_ref$setIsPaneOpen = _ref.setIsPaneOpen,
|
|
593
|
+
setIsPaneOpen = _ref$setIsPaneOpen === void 0 ? identity : _ref$setIsPaneOpen,
|
|
594
|
+
_ref$childrenKeys = _ref.childrenKeys,
|
|
595
|
+
childrenKeys = _ref$childrenKeys === void 0 ? [] : _ref$childrenKeys,
|
|
596
|
+
_ref$defaultSegmentNa = _ref.defaultSegmentName,
|
|
597
|
+
defaultSegmentName = _ref$defaultSegmentNa === void 0 ? t("neetoFilters.common.allResults") : _ref$defaultSegmentNa,
|
|
598
|
+
customFilters = _ref.customFilters;
|
|
599
|
+
var queryClient = useQueryClient();
|
|
600
|
+
var _useQueryParams = useQueryParams(),
|
|
601
|
+
segmentId = _useQueryParams.segmentId;
|
|
602
|
+
var segmentFormInitialRef = useRef(null);
|
|
603
|
+
var _useSegment = useSegment({
|
|
604
|
+
entity: entity,
|
|
605
|
+
keyword: keyword,
|
|
606
|
+
columns: columns,
|
|
607
|
+
childrenKeys: childrenKeys
|
|
608
|
+
}),
|
|
609
|
+
isEdit = _useSegment.isEdit,
|
|
610
|
+
filters = _useSegment.filters,
|
|
611
|
+
handleSubmit = _useSegment.handleSubmit,
|
|
612
|
+
isSubmitting = _useSegment.isSubmitting,
|
|
613
|
+
keywordFilter = _useSegment.keywordFilter,
|
|
614
|
+
isSavePaneOpen = _useSegment.isSavePaneOpen,
|
|
615
|
+
nonHiddenFilters = _useSegment.nonHiddenFilters,
|
|
616
|
+
setIsSavePaneOpen = _useSegment.setIsSavePaneOpen,
|
|
617
|
+
handleApplyFilters = _useSegment.handleApplyFilters,
|
|
618
|
+
childrenFiltersApplied = _useSegment.childrenFiltersApplied;
|
|
619
|
+
var BarComponent = segmentId ? SegmentBar : FilterBar;
|
|
620
|
+
var cachedSegments = queryClient.getQueryData([QUERY_KEYS.SEGMENTS_LIST, entity, ""]) || DEFAULT_SEGMENTS_CACHE;
|
|
621
|
+
var segment = findById(segmentId, cachedSegments.segments);
|
|
622
|
+
if (isEmpty(nonHiddenFilters) && !childrenFiltersApplied) return null;
|
|
623
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
624
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
625
|
+
className: classnames("neeto-filters-bar", _defineProperty({}, className, className)),
|
|
626
|
+
children: /*#__PURE__*/jsx(BarComponent, {
|
|
627
|
+
childrenFiltersApplied: childrenFiltersApplied,
|
|
628
|
+
childrenKeys: childrenKeys,
|
|
629
|
+
entity: entity,
|
|
630
|
+
filters: filters,
|
|
631
|
+
handleApplyFilters: handleApplyFilters,
|
|
632
|
+
keywordFilter: keywordFilter,
|
|
633
|
+
nonHiddenFilters: nonHiddenFilters,
|
|
634
|
+
setIsPaneOpen: setIsPaneOpen,
|
|
635
|
+
setIsSavePaneOpen: setIsSavePaneOpen
|
|
636
|
+
})
|
|
637
|
+
}), /*#__PURE__*/jsx(SegmentForm, {
|
|
638
|
+
childrenKeys: childrenKeys,
|
|
639
|
+
columns: columns,
|
|
640
|
+
customFilters: customFilters,
|
|
641
|
+
defaultSegmentName: defaultSegmentName,
|
|
642
|
+
filters: filters,
|
|
643
|
+
handleSubmit: handleSubmit,
|
|
644
|
+
isEdit: isEdit,
|
|
645
|
+
isSubmitting: isSubmitting,
|
|
646
|
+
keywordFilter: keywordFilter,
|
|
647
|
+
segmentFormInitialRef: segmentFormInitialRef,
|
|
648
|
+
isOpen: isPresent(isSavePaneOpen.action),
|
|
649
|
+
initialValues: isEdit ? assoc("filters", [{
|
|
650
|
+
conditions: filters
|
|
651
|
+
}], segment) : {
|
|
652
|
+
name: "",
|
|
653
|
+
filters: [{
|
|
654
|
+
conditions: filters
|
|
655
|
+
}]
|
|
656
|
+
},
|
|
657
|
+
onClose: function onClose() {
|
|
658
|
+
return setIsSavePaneOpen({
|
|
659
|
+
action: undefined
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
})]
|
|
663
|
+
});
|
|
664
|
+
};
|
|
665
|
+
|
|
666
|
+
export { Bar as default };
|
|
667
|
+
//# sourceMappingURL=Bar.js.map
|