@bigbinary/neeto-filters-frontend 3.0.5 → 3.0.6
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 +4 -0
- package/app/javascript/src/translations/en.json +4 -2
- package/dist/index.cjs.js +256 -212
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +256 -213
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/types.d.ts +2 -0
package/dist/index.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import React, { useState, useRef, useEffect, useTransition, useMemo } from 'react';
|
|
2
2
|
import classnames from 'classnames';
|
|
3
|
-
import
|
|
3
|
+
import i18next, { t as t$1 } from 'i18next';
|
|
4
|
+
import { capitalize, removeBy, findBy, isNotEmpty, humanize, noop as noop$1, toLabelAndValue, replaceBy, isPresent, existsBy, isNotPresent, filterBy } from '@bigbinary/neeto-cist';
|
|
4
5
|
import { useHotKeys, useMutationWithInvalidation, useQueryParams, useDebounce, withT } from '@bigbinary/neeto-commons-frontend/react-utils';
|
|
5
6
|
import { getQueryParams, dateFormat, buildUrl } from '@bigbinary/neeto-commons-frontend/utils';
|
|
6
7
|
import { Tooltip, Typography, Dropdown as Dropdown$2, Button, Pane as Pane$1, Alert, Select, DatePicker, TimePicker, Input as Input$1, Accordion, Spinner } from '@bigbinary/neetoui';
|
|
7
8
|
import { groupBy, anyPass, isNil, isEmpty, any, toLower, mergeLeft, identity, omit, mergeRight, toPairs, not, pluck, either, has, concat, equals, pick, modify, prop, isNotNil, append, last } from 'ramda';
|
|
8
9
|
import { useTranslation, Trans } from 'react-i18next';
|
|
9
10
|
import { useHistory, useLocation } from 'react-router-dom';
|
|
10
|
-
import { Close,
|
|
11
|
-
import i18next, { t as t$1 } from 'i18next';
|
|
12
|
-
import * as yup from 'yup';
|
|
11
|
+
import { Close, MenuHorizontal, Down, Search as Search$1, Settings } from '@bigbinary/neeto-icons';
|
|
13
12
|
import { Form, Input, ActionBlock } from '@bigbinary/neetoui/formik';
|
|
14
13
|
import { useQuery } from 'react-query';
|
|
15
14
|
import axios from 'axios';
|
|
15
|
+
import * as yup from 'yup';
|
|
16
|
+
import Search from '@bigbinary/neeto-molecules/Search';
|
|
16
17
|
import ReactDOM, { createPortal } from 'react-dom';
|
|
17
18
|
import MenuBar from '@bigbinary/neeto-molecules/MenuBar';
|
|
18
19
|
import { FormikInlineInput } from '@bigbinary/neeto-molecules/InlineInput';
|
|
@@ -104,9 +105,6 @@ var SHORTCUTS = {
|
|
|
104
105
|
}
|
|
105
106
|
};
|
|
106
107
|
|
|
107
|
-
var SEGMENT_VALIDATION_SCHEMA = yup.object({
|
|
108
|
-
name: yup.string().trim().required()
|
|
109
|
-
});
|
|
110
108
|
var SEGMENTS_BASE_URL = "/neeto_filters/segments";
|
|
111
109
|
var DATE_OPTIONS = [{
|
|
112
110
|
label: "Today",
|
|
@@ -750,7 +748,8 @@ var compareFilters = function compareFilters(oldFilters, newFilters) {
|
|
|
750
748
|
return equals(formatFilters(oldFilters), formatFilters(newFilters));
|
|
751
749
|
};
|
|
752
750
|
var buildFilteredColumns = function buildFilteredColumns(_ref11) {
|
|
753
|
-
var searchTerm = _ref11.searchTerm,
|
|
751
|
+
var _ref11$searchTerm = _ref11.searchTerm,
|
|
752
|
+
searchTerm = _ref11$searchTerm === void 0 ? "" : _ref11$searchTerm,
|
|
754
753
|
columns = _ref11.columns;
|
|
755
754
|
var groupedColumsObject = groupByGroup(columns.filter(function (_ref12) {
|
|
756
755
|
var label = _ref12.label,
|
|
@@ -1189,6 +1188,18 @@ var useDestroySegment = function useDestroySegment(options) {
|
|
|
1189
1188
|
}, options));
|
|
1190
1189
|
};
|
|
1191
1190
|
|
|
1191
|
+
var buildSegmentsValidationSchema = function buildSegmentsValidationSchema(defaultSegmentName) {
|
|
1192
|
+
return yup.object({
|
|
1193
|
+
name: yup.string().trim().required().test({
|
|
1194
|
+
name: "not-default-segment-name",
|
|
1195
|
+
test: function test(value) {
|
|
1196
|
+
return (value === null || value === void 0 ? void 0 : value.toLocaleLowerCase()) !== defaultSegmentName.toLocaleLowerCase();
|
|
1197
|
+
},
|
|
1198
|
+
message: t$1("neetoFilters.segments.reservedNameErrorMessage")
|
|
1199
|
+
})
|
|
1200
|
+
});
|
|
1201
|
+
};
|
|
1202
|
+
|
|
1192
1203
|
var Menu = Dropdown$2.Menu,
|
|
1193
1204
|
MenuItem = Dropdown$2.MenuItem;
|
|
1194
1205
|
var Segment = function Segment(_ref) {
|
|
@@ -1196,7 +1207,8 @@ var Segment = function Segment(_ref) {
|
|
|
1196
1207
|
filters = _ref.filters,
|
|
1197
1208
|
columns = _ref.columns,
|
|
1198
1209
|
childrenKeys = _ref.childrenKeys,
|
|
1199
|
-
setIsFilterPaneOpen = _ref.setIsFilterPaneOpen
|
|
1210
|
+
setIsFilterPaneOpen = _ref.setIsFilterPaneOpen,
|
|
1211
|
+
defaultSegmentName = _ref.defaultSegmentName;
|
|
1200
1212
|
var _useState = useState(false),
|
|
1201
1213
|
_useState2 = _slicedToArray(_useState, 2),
|
|
1202
1214
|
isSavePaneOpen = _useState2[0],
|
|
@@ -1299,7 +1311,7 @@ var Segment = function Segment(_ref) {
|
|
|
1299
1311
|
},
|
|
1300
1312
|
validateOnChange: true,
|
|
1301
1313
|
validateOnBlur: true,
|
|
1302
|
-
validationSchema:
|
|
1314
|
+
validationSchema: buildSegmentsValidationSchema(defaultSegmentName),
|
|
1303
1315
|
onSubmit: handleSubmit
|
|
1304
1316
|
}
|
|
1305
1317
|
}, /*#__PURE__*/React.createElement(Pane$1.Body, null, /*#__PURE__*/React.createElement(Input, {
|
|
@@ -1350,118 +1362,123 @@ var Bar = function Bar(_ref) {
|
|
|
1350
1362
|
_ref$setIsPaneOpen = _ref.setIsPaneOpen,
|
|
1351
1363
|
setIsPaneOpen = _ref$setIsPaneOpen === void 0 ? identity : _ref$setIsPaneOpen,
|
|
1352
1364
|
_ref$childrenKeys = _ref.childrenKeys,
|
|
1353
|
-
childrenKeys = _ref$childrenKeys === void 0 ? [] : _ref$childrenKeys
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
hidden: true
|
|
1370
|
-
}, filters);
|
|
1371
|
-
var history = useHistory();
|
|
1372
|
-
var handleSubmit = function handleSubmit(newFilters, isClearAll) {
|
|
1373
|
-
var params = buildUrlFromFilters(_objectSpread$2({
|
|
1374
|
-
columns: columns,
|
|
1375
|
-
filters: isKeywordFilterPresent(keywordFilter) && isNotEmpty(getSearchTermFromUrl()) ? [].concat(_toConsumableArray(newFilters), [keywordFilter]) : newFilters
|
|
1376
|
-
}, isClearAll && {
|
|
1377
|
-
isClearAll: true,
|
|
1378
|
-
childrenKeys: childrenKeys
|
|
1379
|
-
}));
|
|
1380
|
-
history.push({
|
|
1381
|
-
search: params
|
|
1365
|
+
childrenKeys = _ref$childrenKeys === void 0 ? [] : _ref$childrenKeys,
|
|
1366
|
+
_ref$defaultSegmentNa = _ref.defaultSegmentName,
|
|
1367
|
+
defaultSegmentName = _ref$defaultSegmentNa === void 0 ? t$1("neetoFilters.common.allResults") : _ref$defaultSegmentNa;
|
|
1368
|
+
return function () {
|
|
1369
|
+
var _useTranslation = useTranslation(),
|
|
1370
|
+
t = _useTranslation.t;
|
|
1371
|
+
var initialRenderRef = useRef(true);
|
|
1372
|
+
var searchParams = useQueryParams();
|
|
1373
|
+
var keywordValue = searchParams.search_term || "";
|
|
1374
|
+
var keywordFilter = _objectSpread$2(_objectSpread$2({
|
|
1375
|
+
type: "text",
|
|
1376
|
+
rule: "contains",
|
|
1377
|
+
label: t("neetoFilters.common.searchTerm")
|
|
1378
|
+
}, keyword), {}, {
|
|
1379
|
+
key: "search_term",
|
|
1380
|
+
value: keywordValue
|
|
1382
1381
|
});
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1382
|
+
var filters = buildFiltersFromSearchParams(isKeywordFilterPresent(keywordFilter) && isNotEmpty(keywordValue) ? [keywordFilter].concat(_toConsumableArray(columns)) : columns);
|
|
1383
|
+
var nonHiddenFilters = removeBy({
|
|
1384
|
+
hidden: true
|
|
1385
|
+
}, filters);
|
|
1386
|
+
var history = useHistory();
|
|
1387
|
+
var handleSubmit = function handleSubmit(newFilters, isClearAll) {
|
|
1388
|
+
var params = buildUrlFromFilters(_objectSpread$2({
|
|
1389
|
+
columns: columns,
|
|
1390
|
+
filters: isKeywordFilterPresent(keywordFilter) && isNotEmpty(getSearchTermFromUrl()) ? [].concat(_toConsumableArray(newFilters), [keywordFilter]) : newFilters
|
|
1391
|
+
}, isClearAll && {
|
|
1392
|
+
isClearAll: true,
|
|
1393
|
+
childrenKeys: childrenKeys
|
|
1394
|
+
}));
|
|
1395
|
+
history.push({
|
|
1396
|
+
search: params
|
|
1397
|
+
});
|
|
1398
|
+
};
|
|
1399
|
+
var handleDelete = function handleDelete(key) {
|
|
1400
|
+
if (key === "search_term") {
|
|
1401
|
+
var params = omit(["search_term"], getQueryParams());
|
|
1402
|
+
var pathname = window.location.pathname;
|
|
1403
|
+
history.push(buildUrl(pathname, params));
|
|
1404
|
+
return;
|
|
1405
|
+
}
|
|
1406
|
+
if (childrenKeys.includes(key)) {
|
|
1407
|
+
var _params = omit([key], getQueryParams());
|
|
1408
|
+
var _pathname = window.location.pathname;
|
|
1409
|
+
history.push(buildUrl(_pathname, _params));
|
|
1410
|
+
}
|
|
1411
|
+
var newFilters = removeBy({
|
|
1412
|
+
key: key
|
|
1413
|
+
}, filters);
|
|
1414
|
+
handleSubmit(newFilters);
|
|
1415
|
+
};
|
|
1416
|
+
var handleClearAll = function handleClearAll() {
|
|
1417
|
+
var params = isKeywordFilterPresent(keywordFilter) ? omit(["search_term"], getQueryParams()) : getQueryParams();
|
|
1387
1418
|
var pathname = window.location.pathname;
|
|
1388
1419
|
history.push(buildUrl(pathname, params));
|
|
1389
|
-
|
|
1390
|
-
}
|
|
1391
|
-
if (childrenKeys.includes(key)) {
|
|
1392
|
-
var _params = omit([key], getQueryParams());
|
|
1393
|
-
var _pathname = window.location.pathname;
|
|
1394
|
-
history.push(buildUrl(_pathname, _params));
|
|
1395
|
-
}
|
|
1396
|
-
var newFilters = removeBy({
|
|
1397
|
-
key: key
|
|
1398
|
-
}, filters);
|
|
1399
|
-
handleSubmit(newFilters);
|
|
1400
|
-
};
|
|
1401
|
-
var handleClearAll = function handleClearAll() {
|
|
1402
|
-
var params = isKeywordFilterPresent(keywordFilter) ? omit(["search_term"], getQueryParams()) : getQueryParams();
|
|
1403
|
-
var pathname = window.location.pathname;
|
|
1404
|
-
history.push(buildUrl(pathname, params));
|
|
1405
|
-
handleSubmit([], true);
|
|
1406
|
-
};
|
|
1407
|
-
var childrenFiltersApplied = childrenKeys.some(function (key) {
|
|
1408
|
-
return has(key, searchParams);
|
|
1409
|
-
});
|
|
1410
|
-
var hideClearButton = nonHiddenFilters.every(function (_ref2) {
|
|
1411
|
-
var defaultValue = _ref2.defaultValue,
|
|
1412
|
-
isClearable = _ref2.isClearable;
|
|
1413
|
-
return defaultValue && !isClearable;
|
|
1414
|
-
}) && !childrenFiltersApplied;
|
|
1415
|
-
useEffect(function () {
|
|
1416
|
-
if (initialRenderRef.current) {
|
|
1417
|
-
initialRenderRef.current = false;
|
|
1418
|
-
return noop$1;
|
|
1419
|
-
}
|
|
1420
|
-
var handler = setTimeout(function () {
|
|
1421
|
-
handleSubmit(filters);
|
|
1422
|
-
}, 500);
|
|
1423
|
-
return function () {
|
|
1424
|
-
return clearTimeout(handler);
|
|
1420
|
+
handleSubmit([], true);
|
|
1425
1421
|
};
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1422
|
+
var childrenFiltersApplied = childrenKeys.some(function (key) {
|
|
1423
|
+
return has(key, searchParams);
|
|
1424
|
+
});
|
|
1425
|
+
var hideClearButton = nonHiddenFilters.every(function (_ref2) {
|
|
1426
|
+
var defaultValue = _ref2.defaultValue,
|
|
1427
|
+
isClearable = _ref2.isClearable;
|
|
1428
|
+
return defaultValue && !isClearable;
|
|
1429
|
+
}) && !childrenFiltersApplied;
|
|
1430
|
+
useEffect(function () {
|
|
1431
|
+
if (initialRenderRef.current) {
|
|
1432
|
+
initialRenderRef.current = false;
|
|
1433
|
+
return noop$1;
|
|
1434
|
+
}
|
|
1435
|
+
var handler = setTimeout(function () {
|
|
1436
|
+
handleSubmit(filters);
|
|
1437
|
+
}, 500);
|
|
1438
|
+
return function () {
|
|
1439
|
+
return clearTimeout(handler);
|
|
1440
|
+
};
|
|
1441
|
+
}, [keywordValue]);
|
|
1442
|
+
if (isEmpty(nonHiddenFilters) && !childrenFiltersApplied) return null;
|
|
1443
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1444
|
+
className: classnames("neeto-filters-bar", _defineProperty({}, className, className))
|
|
1445
|
+
}, nonHiddenFilters.map(function (filter) {
|
|
1446
|
+
var _filter$suffixCompone;
|
|
1447
|
+
return /*#__PURE__*/React.createElement(React.Fragment, {
|
|
1448
|
+
key: filter.key
|
|
1449
|
+
}, /*#__PURE__*/React.createElement(Block, {
|
|
1450
|
+
filter: filter,
|
|
1451
|
+
handleDelete: handleDelete,
|
|
1452
|
+
setIsPaneOpen: setIsPaneOpen
|
|
1453
|
+
}), (_filter$suffixCompone = filter.suffixComponent) === null || _filter$suffixCompone === void 0 ? void 0 : _filter$suffixCompone.call(filter), /*#__PURE__*/React.createElement("div", {
|
|
1454
|
+
className: "neeto-filters-bar--separator"
|
|
1455
|
+
}));
|
|
1456
|
+
}), childrenKeys.filter(function (childKey) {
|
|
1457
|
+
return has(childKey, searchParams);
|
|
1458
|
+
}).map(function (childKey) {
|
|
1459
|
+
return /*#__PURE__*/React.createElement(React.Fragment, {
|
|
1460
|
+
key: childKey
|
|
1461
|
+
}, /*#__PURE__*/React.createElement(ChildBlock, {
|
|
1462
|
+
childKey: childKey,
|
|
1463
|
+
handleDelete: handleDelete,
|
|
1464
|
+
setIsPaneOpen: setIsPaneOpen
|
|
1465
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
1466
|
+
className: "neeto-filters-bar--separator"
|
|
1467
|
+
}));
|
|
1468
|
+
}), isNotNil(entity) && /*#__PURE__*/React.createElement(Segment, {
|
|
1469
|
+
childrenKeys: childrenKeys,
|
|
1470
|
+
columns: columns,
|
|
1471
|
+
defaultSegmentName: defaultSegmentName,
|
|
1472
|
+
entity: entity,
|
|
1473
|
+
filters: filters,
|
|
1474
|
+
setIsFilterPaneOpen: setIsPaneOpen
|
|
1475
|
+
}), !hideClearButton && /*#__PURE__*/React.createElement(Button, {
|
|
1476
|
+
"data-cy": "neeto-filters-bar-clear-btn",
|
|
1477
|
+
label: t("neetoFilters.common.clearFilters"),
|
|
1478
|
+
style: "text",
|
|
1479
|
+
onClick: handleClearAll
|
|
1452
1480
|
}));
|
|
1453
|
-
}
|
|
1454
|
-
childrenKeys: childrenKeys,
|
|
1455
|
-
columns: columns,
|
|
1456
|
-
entity: entity,
|
|
1457
|
-
filters: filters,
|
|
1458
|
-
setIsFilterPaneOpen: setIsPaneOpen
|
|
1459
|
-
}), !hideClearButton && /*#__PURE__*/React.createElement(Button, {
|
|
1460
|
-
"data-cy": "neeto-filters-bar-clear-btn",
|
|
1461
|
-
label: t("neetoFilters.common.clearFilters"),
|
|
1462
|
-
style: "text",
|
|
1463
|
-
onClick: handleClearAll
|
|
1464
|
-
}));
|
|
1481
|
+
}();
|
|
1465
1482
|
};
|
|
1466
1483
|
|
|
1467
1484
|
function _extends() {
|
|
@@ -3241,16 +3258,13 @@ var Pane = function Pane(_ref) {
|
|
|
3241
3258
|
weight: "semibold"
|
|
3242
3259
|
}, t("neetoFilters.common.filters"))), /*#__PURE__*/React.createElement(Slider.Body, {
|
|
3243
3260
|
className: "neeto-filters-pane-filter__body neeto-ui-pt-2"
|
|
3244
|
-
}, isSearchable && /*#__PURE__*/React.createElement(
|
|
3245
|
-
autoFocus: true,
|
|
3261
|
+
}, isSearchable && /*#__PURE__*/React.createElement(Search, {
|
|
3246
3262
|
"data-cy": "neeto-filters-column-search",
|
|
3247
|
-
prefix: /*#__PURE__*/React.createElement(Search, null),
|
|
3248
|
-
value: searchTerm,
|
|
3249
3263
|
placeholder: t("neetoFilters.messages.searchResources", {
|
|
3250
3264
|
resources: t("neetoFilters.common.filters").toLocaleLowerCase()
|
|
3251
3265
|
}),
|
|
3252
|
-
|
|
3253
|
-
return setSearchTerm(
|
|
3266
|
+
onSearch: function onSearch(value) {
|
|
3267
|
+
return setSearchTerm(value);
|
|
3254
3268
|
}
|
|
3255
3269
|
}), ungroupedColumns.map(function (column) {
|
|
3256
3270
|
return /*#__PURE__*/React.createElement(Item, {
|
|
@@ -3410,7 +3424,8 @@ var DeleteAlert = function DeleteAlert(_ref) {
|
|
|
3410
3424
|
|
|
3411
3425
|
var Card = function Card(_ref) {
|
|
3412
3426
|
var segment = _ref.segment,
|
|
3413
|
-
columns = _ref.columns
|
|
3427
|
+
columns = _ref.columns,
|
|
3428
|
+
defaultSegmentName = _ref.defaultSegmentName;
|
|
3414
3429
|
var _useState = useState(false),
|
|
3415
3430
|
_useState2 = _slicedToArray(_useState, 2),
|
|
3416
3431
|
isEditing = _useState2[0],
|
|
@@ -3444,7 +3459,7 @@ var Card = function Card(_ref) {
|
|
|
3444
3459
|
initialValues: segment,
|
|
3445
3460
|
validateOnChange: true,
|
|
3446
3461
|
validateOnBlur: true,
|
|
3447
|
-
validationSchema:
|
|
3462
|
+
validationSchema: buildSegmentsValidationSchema(defaultSegmentName),
|
|
3448
3463
|
onSubmit: handleRename,
|
|
3449
3464
|
enableReinitialize: true
|
|
3450
3465
|
}
|
|
@@ -3462,6 +3477,7 @@ var Card = function Card(_ref) {
|
|
|
3462
3477
|
style: "body2"
|
|
3463
3478
|
}, segment.name), /*#__PURE__*/React.createElement(Dropdown$2, {
|
|
3464
3479
|
buttonStyle: "text",
|
|
3480
|
+
disabled: isNotPresent(segment.id),
|
|
3465
3481
|
icon: MenuHorizontal,
|
|
3466
3482
|
size: "small"
|
|
3467
3483
|
}, /*#__PURE__*/React.createElement(Menu, null, /*#__PURE__*/React.createElement(MenuItem.Button, {
|
|
@@ -3489,7 +3505,8 @@ var ManagePane = function ManagePane(_ref) {
|
|
|
3489
3505
|
var isOpen = _ref.isOpen,
|
|
3490
3506
|
onClose = _ref.onClose,
|
|
3491
3507
|
entity = _ref.entity,
|
|
3492
|
-
columns = _ref.columns
|
|
3508
|
+
columns = _ref.columns,
|
|
3509
|
+
defaultSegmentName = _ref.defaultSegmentName;
|
|
3493
3510
|
var _useState = useState(""),
|
|
3494
3511
|
_useState2 = _slicedToArray(_useState, 2),
|
|
3495
3512
|
searchTerm = _useState2[0],
|
|
@@ -3513,25 +3530,26 @@ var ManagePane = function ManagePane(_ref) {
|
|
|
3513
3530
|
style: "h2"
|
|
3514
3531
|
}, t("neetoFilters.segments.manageSegments"))), /*#__PURE__*/React.createElement(Pane$1.Body, {
|
|
3515
3532
|
className: "max-h-full gap-4 overflow-scroll"
|
|
3516
|
-
}, /*#__PURE__*/React.createElement(
|
|
3533
|
+
}, /*#__PURE__*/React.createElement(Search, {
|
|
3517
3534
|
className: "w-full flex-grow-0",
|
|
3518
3535
|
placeholder: t("neetoFilters.segments.searchSegments"),
|
|
3519
|
-
prefix: /*#__PURE__*/React.createElement(Search, null),
|
|
3520
3536
|
ref: inputRef,
|
|
3521
|
-
|
|
3522
|
-
value: searchTerm,
|
|
3523
|
-
onChange: function onChange(_ref2) {
|
|
3524
|
-
var value = _ref2.target.value;
|
|
3537
|
+
onSearch: function onSearch(value) {
|
|
3525
3538
|
return setSearchTerm(value);
|
|
3526
3539
|
}
|
|
3527
3540
|
}), isLoading ? /*#__PURE__*/React.createElement(Spinner, {
|
|
3528
3541
|
className: "mx-auto mt-4"
|
|
3529
|
-
}) : /*#__PURE__*/React.createElement(React.Fragment, null,
|
|
3542
|
+
}) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Card$1, {
|
|
3543
|
+
segment: {
|
|
3544
|
+
name: defaultSegmentName
|
|
3545
|
+
}
|
|
3546
|
+
}), isEmpty(segments) ? /*#__PURE__*/React.createElement(Typography, {
|
|
3530
3547
|
className: "mx-auto",
|
|
3531
3548
|
style: "body2"
|
|
3532
3549
|
}, t("neetoFilters.segments.noSegmentsFound")) : segments.map(function (segment) {
|
|
3533
3550
|
return /*#__PURE__*/React.createElement(Card$1, {
|
|
3534
3551
|
columns: columns,
|
|
3552
|
+
defaultSegmentName: defaultSegmentName,
|
|
3535
3553
|
segment: segment,
|
|
3536
3554
|
key: segment.id
|
|
3537
3555
|
});
|
|
@@ -3543,7 +3561,8 @@ var ITEMS_MAX_COUNT = 20;
|
|
|
3543
3561
|
var MenuBlocks = function MenuBlocks(_ref) {
|
|
3544
3562
|
var entity = _ref.entity,
|
|
3545
3563
|
searchTerm = _ref.searchTerm,
|
|
3546
|
-
columns = _ref.columns
|
|
3564
|
+
columns = _ref.columns,
|
|
3565
|
+
defaultSegmentName = _ref.defaultSegmentName;
|
|
3547
3566
|
var _useState = useState(false),
|
|
3548
3567
|
_useState2 = _slicedToArray(_useState, 2),
|
|
3549
3568
|
showAll = _useState2[0],
|
|
@@ -3554,6 +3573,7 @@ var MenuBlocks = function MenuBlocks(_ref) {
|
|
|
3554
3573
|
t = _useTranslation.t;
|
|
3555
3574
|
var _Object$fromEntries = Object.fromEntries(new URLSearchParams(location.search)),
|
|
3556
3575
|
segmentId = _Object$fromEntries.segmentId;
|
|
3576
|
+
var appliedFilters = buildFiltersFromURL(columns);
|
|
3557
3577
|
var _useFetchSegments = useFetchSegments({
|
|
3558
3578
|
entity: entity,
|
|
3559
3579
|
searchTerm: searchTerm
|
|
@@ -3561,27 +3581,40 @@ var MenuBlocks = function MenuBlocks(_ref) {
|
|
|
3561
3581
|
_useFetchSegments$dat = _useFetchSegments.data,
|
|
3562
3582
|
segments = _useFetchSegments$dat === void 0 ? [] : _useFetchSegments$dat,
|
|
3563
3583
|
isLoading = _useFetchSegments.isLoading;
|
|
3564
|
-
var
|
|
3584
|
+
var clearAppliedFilters = function clearAppliedFilters() {
|
|
3565
3585
|
var _filters$, _filters$2;
|
|
3566
|
-
var
|
|
3567
|
-
|
|
3568
|
-
return equals(id, segmentId) ? history.push({
|
|
3586
|
+
var filters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : appliedFilters;
|
|
3587
|
+
history.push({
|
|
3569
3588
|
search: buildUrlFromFilters({
|
|
3570
3589
|
columns: columns,
|
|
3571
3590
|
filters: [],
|
|
3572
3591
|
isClearAll: true,
|
|
3573
|
-
childrenKeys: pluck("key", filterBy({
|
|
3592
|
+
childrenKeys: ((_filters$ = filters[0]) === null || _filters$ === void 0 ? void 0 : _filters$.conditions) && pluck("key", filterBy({
|
|
3574
3593
|
node: "children"
|
|
3575
|
-
}, (_filters$ = filters[0]) === null || _filters$ === void 0 ? void 0 : _filters
|
|
3594
|
+
}, (_filters$2 = filters[0]) === null || _filters$2 === void 0 ? void 0 : _filters$2.conditions))
|
|
3576
3595
|
})
|
|
3577
|
-
})
|
|
3596
|
+
});
|
|
3597
|
+
};
|
|
3598
|
+
var applySelectedSegment = function applySelectedSegment(_ref2) {
|
|
3599
|
+
var _filters$3;
|
|
3600
|
+
var id = _ref2.id,
|
|
3601
|
+
filters = _ref2.filters;
|
|
3602
|
+
history.push({
|
|
3578
3603
|
search: buildUrlFromSegment({
|
|
3579
3604
|
columns: columns,
|
|
3580
|
-
filters: (_filters$
|
|
3605
|
+
filters: (_filters$3 = filters[0]) === null || _filters$3 === void 0 ? void 0 : _filters$3.conditions,
|
|
3581
3606
|
id: id
|
|
3582
3607
|
})
|
|
3583
3608
|
});
|
|
3584
3609
|
};
|
|
3610
|
+
var handleSelectSegment = function handleSelectSegment(_ref3) {
|
|
3611
|
+
var id = _ref3.id,
|
|
3612
|
+
filters = _ref3.filters;
|
|
3613
|
+
return equals(id, segmentId) ? clearAppliedFilters(filters) : applySelectedSegment({
|
|
3614
|
+
id: id,
|
|
3615
|
+
filters: filters
|
|
3616
|
+
});
|
|
3617
|
+
};
|
|
3585
3618
|
if (isLoading) {
|
|
3586
3619
|
return /*#__PURE__*/React.createElement(Spinner, null);
|
|
3587
3620
|
}
|
|
@@ -3601,6 +3634,10 @@ var MenuBlocks = function MenuBlocks(_ref) {
|
|
|
3601
3634
|
return !open;
|
|
3602
3635
|
});
|
|
3603
3636
|
}
|
|
3637
|
+
}), /*#__PURE__*/React.createElement(MenuBar.Block, {
|
|
3638
|
+
active: isEmpty(appliedFilters),
|
|
3639
|
+
label: defaultSegmentName,
|
|
3640
|
+
onClick: clearAppliedFilters
|
|
3604
3641
|
}), segments.slice(0, showAll ? segments.length : ITEMS_MAX_COUNT).map(function (segment) {
|
|
3605
3642
|
return /*#__PURE__*/React.createElement(MenuBar.Block, {
|
|
3606
3643
|
active: segment.id === segmentId,
|
|
@@ -3619,77 +3656,83 @@ var Segments = function Segments(_ref) {
|
|
|
3619
3656
|
var entity = _ref.entity,
|
|
3620
3657
|
columns = _ref.columns,
|
|
3621
3658
|
_ref$setIsFilterPaneO = _ref.setIsFilterPaneOpen,
|
|
3622
|
-
setIsFilterPaneOpen = _ref$setIsFilterPaneO === void 0 ? noop$1 : _ref$setIsFilterPaneO
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3659
|
+
setIsFilterPaneOpen = _ref$setIsFilterPaneO === void 0 ? noop$1 : _ref$setIsFilterPaneO,
|
|
3660
|
+
_ref$defaultSegmentNa = _ref.defaultSegmentName,
|
|
3661
|
+
defaultSegmentName = _ref$defaultSegmentNa === void 0 ? t$1("neetoFilters.common.allResults") : _ref$defaultSegmentNa;
|
|
3662
|
+
return function () {
|
|
3663
|
+
var _useState = useState(""),
|
|
3664
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
3665
|
+
searchTerm = _useState2[0],
|
|
3666
|
+
setSearchTerm = _useState2[1];
|
|
3667
|
+
var _useState3 = useState(true),
|
|
3668
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
3669
|
+
isSearchCollapsed = _useState4[0],
|
|
3670
|
+
setIsSearchCollapsed = _useState4[1];
|
|
3671
|
+
var _useState5 = useState(false),
|
|
3672
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
3673
|
+
isSegmentsPaneOpen = _useState6[0],
|
|
3674
|
+
setIsSegmentsPaneOpen = _useState6[1];
|
|
3675
|
+
var _useTranslation = useTranslation(),
|
|
3676
|
+
t = _useTranslation.t;
|
|
3677
|
+
var debouncedSearchTerm = useDebounce(searchTerm);
|
|
3678
|
+
var iconProps = [{
|
|
3679
|
+
icon: Search$1,
|
|
3680
|
+
onClick: function onClick() {
|
|
3681
|
+
setSearchTerm("");
|
|
3682
|
+
setIsSearchCollapsed(function (collapsed) {
|
|
3683
|
+
return !collapsed;
|
|
3684
|
+
});
|
|
3685
|
+
},
|
|
3686
|
+
tooltipProps: {
|
|
3687
|
+
content: t("neetoFilters.segments.searchSegments"),
|
|
3688
|
+
position: "top"
|
|
3689
|
+
}
|
|
3690
|
+
}, {
|
|
3691
|
+
icon: Settings,
|
|
3692
|
+
onClick: function onClick() {
|
|
3693
|
+
setIsFilterPaneOpen(false);
|
|
3694
|
+
setIsSegmentsPaneOpen(true);
|
|
3695
|
+
},
|
|
3696
|
+
tooltipProps: {
|
|
3697
|
+
content: t("neetoFilters.segments.manageSegments"),
|
|
3698
|
+
position: "top"
|
|
3699
|
+
}
|
|
3700
|
+
}];
|
|
3701
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MenuBar.SubTitle, {
|
|
3702
|
+
iconProps: iconProps
|
|
3703
|
+
}, /*#__PURE__*/React.createElement(Typography, {
|
|
3704
|
+
component: "h4",
|
|
3705
|
+
style: "h5",
|
|
3706
|
+
textTransform: "uppercase",
|
|
3707
|
+
weight: "bold"
|
|
3708
|
+
}, t("neetoFilters.common.segments"))), /*#__PURE__*/React.createElement(MenuBar.Search, {
|
|
3709
|
+
autoFocus: true,
|
|
3710
|
+
isCollapsed: isSearchCollapsed,
|
|
3711
|
+
placeholder: t("neetoFilters.segments.searchSegments"),
|
|
3712
|
+
value: searchTerm,
|
|
3713
|
+
onChange: function onChange(_ref2) {
|
|
3714
|
+
var value = _ref2.target.value;
|
|
3715
|
+
return setSearchTerm(value);
|
|
3716
|
+
},
|
|
3717
|
+
onCollapse: function onCollapse() {
|
|
3718
|
+
setSearchTerm("");
|
|
3719
|
+
setIsSearchCollapsed(true);
|
|
3720
|
+
}
|
|
3721
|
+
}), /*#__PURE__*/React.createElement(MenuBlocks$1, {
|
|
3722
|
+
columns: columns,
|
|
3723
|
+
defaultSegmentName: defaultSegmentName,
|
|
3724
|
+
entity: entity,
|
|
3725
|
+
searchTerm: debouncedSearchTerm
|
|
3726
|
+
}), /*#__PURE__*/React.createElement(ManagePane, {
|
|
3727
|
+
columns: columns,
|
|
3728
|
+
defaultSegmentName: defaultSegmentName,
|
|
3729
|
+
entity: entity,
|
|
3730
|
+
isOpen: isSegmentsPaneOpen,
|
|
3731
|
+
onClose: function onClose() {
|
|
3732
|
+
return setIsSegmentsPaneOpen(false);
|
|
3733
|
+
}
|
|
3734
|
+
}));
|
|
3735
|
+
}();
|
|
3693
3736
|
};
|
|
3694
3737
|
var index = /*#__PURE__*/React.memo(Segments);
|
|
3695
3738
|
|