@bigbinary/neeto-filters-frontend 3.3.0-beta.2 → 3.3.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/index.cjs.js +138 -39
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +139 -40
- package/dist/index.js.map +1 -1
- package/package.json +7 -5
package/dist/index.js
CHANGED
|
@@ -6,17 +6,18 @@ import { useDebounce, useQueryParams, useMutationWithInvalidation, withT } from
|
|
|
6
6
|
import { groupBy, anyPass, isNil, isEmpty, any, concat, omit, mergeLeft, toLower, identity, mergeRight, toPairs, pluck, either, not, has, equals, pick, last, modify, append, mergeDeepRight, prop, assoc, sortBy, project } from 'ramda';
|
|
7
7
|
import { useQuery, useQueryClient } from 'react-query';
|
|
8
8
|
import { Help, Delete as Delete$1, Plus, Close, Down } from '@bigbinary/neeto-icons';
|
|
9
|
-
import { Select, DatePicker,
|
|
9
|
+
import { Select, DatePicker, TimePickerInput, Input, Button, Pane as Pane$1, Typography, Accordion, Tooltip, Dropdown as Dropdown$2, Alert, Spinner } from '@bigbinary/neetoui';
|
|
10
10
|
import { Form, Input as Input$1, ActionBlock } from '@bigbinary/neetoui/formik';
|
|
11
11
|
import { useTranslation, Trans } from 'react-i18next';
|
|
12
12
|
import { useHistory } from 'react-router-dom/cjs/react-router-dom.min';
|
|
13
13
|
import { buildUrl, getQueryParams, dateFormat, showThumbsUpToastr } from '@bigbinary/neeto-commons-frontend/utils';
|
|
14
14
|
import * as yup from 'yup';
|
|
15
|
-
import useHotkeys from '@bigbinary/neeto-hotkeys';
|
|
16
15
|
import { useHistory as useHistory$1, useLocation } from 'react-router-dom';
|
|
16
|
+
import useHotkeys from '@bigbinary/neeto-hotkeys';
|
|
17
17
|
import axios from 'axios';
|
|
18
18
|
import Search from '@bigbinary/neeto-molecules/Search';
|
|
19
19
|
import MenuBar from '@bigbinary/neeto-molecules/MenuBar';
|
|
20
|
+
import { DragDropContext, Droppable, Draggable } from '@hello-pangea/dnd';
|
|
20
21
|
import MoreDropdown from '@bigbinary/neeto-molecules/MoreDropdown';
|
|
21
22
|
|
|
22
23
|
function _typeof(o) {
|
|
@@ -534,7 +535,7 @@ var buildFiltersFromSearchParams = function buildFiltersFromSearchParams(columns
|
|
|
534
535
|
}, column);
|
|
535
536
|
} else if (isTime(defaultType) && isCustomTimeRange(value)) {
|
|
536
537
|
return mergeLeft({
|
|
537
|
-
value: value
|
|
538
|
+
value: value
|
|
538
539
|
}, column);
|
|
539
540
|
} else if (isSingleDate(defaultType)) {
|
|
540
541
|
var _value$split3 = value.split("+rule-"),
|
|
@@ -940,6 +941,9 @@ var getColumnsWithStandardizedType = function getColumnsWithStandardizedType(col
|
|
|
940
941
|
});
|
|
941
942
|
});
|
|
942
943
|
};
|
|
944
|
+
var isNilOrEmpty = function isNilOrEmpty(param) {
|
|
945
|
+
return isNil(param) || isEmpty(param);
|
|
946
|
+
};
|
|
943
947
|
var isKeywordFilterPresent = function isKeywordFilterPresent(keyworFilter) {
|
|
944
948
|
return not(isEmpty(keyworFilter.node));
|
|
945
949
|
};
|
|
@@ -1035,6 +1039,31 @@ var buildDateValues = function buildDateValues(dates, selectedRule) {
|
|
|
1035
1039
|
var buildHelpIconProps = function buildHelpIconProps(helpIconProps) {
|
|
1036
1040
|
return mergeDeepRight(DEFAULT_HELP_ICON_PROPS, helpIconProps);
|
|
1037
1041
|
};
|
|
1042
|
+
var hasInvalidTimes = function hasInvalidTimes(times) {
|
|
1043
|
+
if (Array.isArray(times)) {
|
|
1044
|
+
return times.some(function (time) {
|
|
1045
|
+
return time.isValid();
|
|
1046
|
+
}) === false;
|
|
1047
|
+
}
|
|
1048
|
+
return !times.isValid();
|
|
1049
|
+
};
|
|
1050
|
+
var areCustomTimeRangeValuesNotValid = function areCustomTimeRangeValuesNotValid(times) {
|
|
1051
|
+
return !times.every(function (time) {
|
|
1052
|
+
return time.isValid();
|
|
1053
|
+
});
|
|
1054
|
+
};
|
|
1055
|
+
|
|
1056
|
+
// eslint-disable-next-line @bigbinary/neeto/use-standard-date-time-formats
|
|
1057
|
+
var formatSingleTime = function formatSingleTime(time) {
|
|
1058
|
+
return dayjs(time).format("HH:mm:ss");
|
|
1059
|
+
};
|
|
1060
|
+
var formatTime = function formatTime(value, timePickerType) {
|
|
1061
|
+
if (isNilOrEmpty(value)) return null;
|
|
1062
|
+
if (timePickerType === "range") {
|
|
1063
|
+
return value.map(formatSingleTime);
|
|
1064
|
+
}
|
|
1065
|
+
return formatSingleTime(value);
|
|
1066
|
+
};
|
|
1038
1067
|
|
|
1039
1068
|
var Boolean = function Boolean(_ref) {
|
|
1040
1069
|
var column = _ref.column,
|
|
@@ -1381,6 +1410,15 @@ var SingleTime = function SingleTime(_ref) {
|
|
|
1381
1410
|
handleApplyFilter(updatedFilter);
|
|
1382
1411
|
};
|
|
1383
1412
|
var handleChange = function handleChange(times) {
|
|
1413
|
+
if (hasInvalidTimes(times)) {
|
|
1414
|
+
handleApplyFilter({
|
|
1415
|
+
_delete: true
|
|
1416
|
+
});
|
|
1417
|
+
return;
|
|
1418
|
+
}
|
|
1419
|
+
if (timePickerType === "range" && areCustomTimeRangeValuesNotValid(times)) {
|
|
1420
|
+
return;
|
|
1421
|
+
}
|
|
1384
1422
|
var value = timePickerType === "range" ? pluck("$d", times).map(function (time) {
|
|
1385
1423
|
return time.toISOString();
|
|
1386
1424
|
}) : times["$d"].toISOString();
|
|
@@ -1393,6 +1431,7 @@ var SingleTime = function SingleTime(_ref) {
|
|
|
1393
1431
|
});
|
|
1394
1432
|
handleApplyFilter(updatedFilter);
|
|
1395
1433
|
};
|
|
1434
|
+
var formattedTime = formatTime(value, timePickerType);
|
|
1396
1435
|
return /*#__PURE__*/React.createElement("div", {
|
|
1397
1436
|
className: "neeto-filters-pane-filter__item-wrapper"
|
|
1398
1437
|
}, /*#__PURE__*/React.createElement(Select, _extends({
|
|
@@ -1407,15 +1446,12 @@ var SingleTime = function SingleTime(_ref) {
|
|
|
1407
1446
|
}
|
|
1408
1447
|
}, {
|
|
1409
1448
|
onChange: handleRuleChange
|
|
1410
|
-
})), /*#__PURE__*/React.createElement(
|
|
1449
|
+
})), /*#__PURE__*/React.createElement(TimePickerInput, _extends({
|
|
1411
1450
|
autoFocus: autoFocus,
|
|
1412
|
-
value: value,
|
|
1413
|
-
use12Hours: true,
|
|
1414
1451
|
className: "w-full",
|
|
1415
1452
|
"data-cy": "neeto-filters-".concat(hyphenate(key), "-filter"),
|
|
1416
|
-
format: "h:mm A",
|
|
1417
|
-
getPopupContainer: prop("parentNode"),
|
|
1418
1453
|
type: timePickerType,
|
|
1454
|
+
value: formattedTime,
|
|
1419
1455
|
onChange: handleChange
|
|
1420
1456
|
}, otherProps)));
|
|
1421
1457
|
};
|
|
@@ -1558,6 +1594,15 @@ var Time = function Time(_ref) {
|
|
|
1558
1594
|
handleApplyFilter(updatedFilter);
|
|
1559
1595
|
};
|
|
1560
1596
|
var handleTimeRangeChange = function handleTimeRangeChange(times) {
|
|
1597
|
+
if (hasInvalidTimes(times)) {
|
|
1598
|
+
handleApplyFilter({
|
|
1599
|
+
_delete: true
|
|
1600
|
+
});
|
|
1601
|
+
return;
|
|
1602
|
+
}
|
|
1603
|
+
if (isCustomTimeRangeShown && areCustomTimeRangeValuesNotValid(times)) {
|
|
1604
|
+
return;
|
|
1605
|
+
}
|
|
1561
1606
|
var updatedFilter = buildUpdatedFilter({
|
|
1562
1607
|
column: column,
|
|
1563
1608
|
defaultType: defaultType,
|
|
@@ -1588,13 +1633,11 @@ var Time = function Time(_ref) {
|
|
|
1588
1633
|
}
|
|
1589
1634
|
}, {
|
|
1590
1635
|
onChange: handleChange
|
|
1591
|
-
})), isCustomTimeRangeShown && /*#__PURE__*/React.createElement(
|
|
1592
|
-
|
|
1636
|
+
})), isCustomTimeRangeShown && /*#__PURE__*/React.createElement(TimePickerInput, _extends({
|
|
1637
|
+
className: "w-full",
|
|
1593
1638
|
"data-cy": "neeto-filters-".concat(hyphenate(key), "-date-range"),
|
|
1594
|
-
format: "h:mm A",
|
|
1595
|
-
getPopupContainer: prop("parentNode"),
|
|
1596
1639
|
type: "range",
|
|
1597
|
-
value: filter.value,
|
|
1640
|
+
value: formatTime(filter.value, "range"),
|
|
1598
1641
|
onChange: handleTimeRangeChange
|
|
1599
1642
|
}, otherProps)));
|
|
1600
1643
|
};
|
|
@@ -2169,7 +2212,7 @@ var FilterBar = function FilterBar(_ref) {
|
|
|
2169
2212
|
handleApplyFilters = _ref.handleApplyFilters;
|
|
2170
2213
|
var _useTranslation = useTranslation(),
|
|
2171
2214
|
t = _useTranslation.t;
|
|
2172
|
-
var history = useHistory();
|
|
2215
|
+
var history = useHistory$1();
|
|
2173
2216
|
var searchParams = useQueryParams({
|
|
2174
2217
|
toCamelCase: false
|
|
2175
2218
|
});
|
|
@@ -2227,6 +2270,7 @@ var FilterBar = function FilterBar(_ref) {
|
|
|
2227
2270
|
}), /*#__PURE__*/React.createElement("div", {
|
|
2228
2271
|
className: "flex items-center gap-x-2"
|
|
2229
2272
|
}, isPresent(entity) && !hasOnlyKeywordFilter(filters) && /*#__PURE__*/React.createElement(Button, {
|
|
2273
|
+
"data-cy": "save-segment-button",
|
|
2230
2274
|
label: t("neetoFilters.segments.saveAsNewSegment"),
|
|
2231
2275
|
style: "secondary",
|
|
2232
2276
|
onClick: function onClick() {
|
|
@@ -2952,6 +2996,15 @@ var Delete = function Delete(_ref) {
|
|
|
2952
2996
|
});
|
|
2953
2997
|
};
|
|
2954
2998
|
|
|
2999
|
+
var reorderList = function reorderList(list, startIndex, endIndex) {
|
|
3000
|
+
var result = Array.from(list);
|
|
3001
|
+
var _result$splice = result.splice(startIndex, 1),
|
|
3002
|
+
_result$splice2 = _slicedToArray(_result$splice, 1),
|
|
3003
|
+
removed = _result$splice2[0];
|
|
3004
|
+
result.splice(endIndex, 0, removed);
|
|
3005
|
+
return result;
|
|
3006
|
+
};
|
|
3007
|
+
|
|
2955
3008
|
var useSegments = function useSegments(_ref) {
|
|
2956
3009
|
var entity = _ref.entity,
|
|
2957
3010
|
columns = _ref.columns,
|
|
@@ -2960,22 +3013,39 @@ var useSegments = function useSegments(_ref) {
|
|
|
2960
3013
|
var _useTranslation = useTranslation(),
|
|
2961
3014
|
t = _useTranslation.t;
|
|
2962
3015
|
var history = useHistory$1();
|
|
3016
|
+
var _useState = useState([]),
|
|
3017
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
3018
|
+
segments = _useState2[0],
|
|
3019
|
+
setSegments = _useState2[1];
|
|
2963
3020
|
var _useFetchSegments = useFetchSegments({
|
|
2964
3021
|
entity: entity
|
|
2965
3022
|
}),
|
|
2966
|
-
|
|
2967
|
-
segments = _useFetchSegments$dat === void 0 ? [] : _useFetchSegments$dat,
|
|
3023
|
+
fetchedSegments = _useFetchSegments.data,
|
|
2968
3024
|
isLoading = _useFetchSegments.isLoading;
|
|
2969
3025
|
var _useUpdateSegment = useUpdateSegment(),
|
|
2970
3026
|
updateSegment = _useUpdateSegment.mutate,
|
|
2971
3027
|
isUpdating = _useUpdateSegment.isLoading;
|
|
2972
|
-
var
|
|
3028
|
+
var _useState3 = useState({
|
|
2973
3029
|
action: "",
|
|
2974
3030
|
segment: undefined
|
|
2975
3031
|
}),
|
|
2976
|
-
|
|
2977
|
-
confirmAction =
|
|
2978
|
-
setConfirmAction =
|
|
3032
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
3033
|
+
confirmAction = _useState4[0],
|
|
3034
|
+
setConfirmAction = _useState4[1];
|
|
3035
|
+
var handleSegmentsReorder = function handleSegmentsReorder(_ref2) {
|
|
3036
|
+
var source = _ref2.source,
|
|
3037
|
+
destination = _ref2.destination;
|
|
3038
|
+
if (!destination || source.index === destination.index) return;
|
|
3039
|
+
var reorderedSegments = reorderList(segments, source.index, destination.index);
|
|
3040
|
+
updateSegment({
|
|
3041
|
+
id: segments[source.index].id,
|
|
3042
|
+
payload: {
|
|
3043
|
+
position: destination.index + 1
|
|
3044
|
+
},
|
|
3045
|
+
showToastr: false
|
|
3046
|
+
});
|
|
3047
|
+
setSegments(reorderedSegments);
|
|
3048
|
+
};
|
|
2979
3049
|
var clearAppliedFilters = function clearAppliedFilters() {
|
|
2980
3050
|
var _filters$, _filters$2;
|
|
2981
3051
|
var filters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : appliedFilters;
|
|
@@ -2990,10 +3060,10 @@ var useSegments = function useSegments(_ref) {
|
|
|
2990
3060
|
})
|
|
2991
3061
|
});
|
|
2992
3062
|
};
|
|
2993
|
-
var handleSelectSegment = function handleSelectSegment(
|
|
3063
|
+
var handleSelectSegment = function handleSelectSegment(_ref3) {
|
|
2994
3064
|
var _filters$3;
|
|
2995
|
-
var id =
|
|
2996
|
-
filters =
|
|
3065
|
+
var id = _ref3.id,
|
|
3066
|
+
filters = _ref3.filters;
|
|
2997
3067
|
history.push({
|
|
2998
3068
|
search: buildUrlFromSegment({
|
|
2999
3069
|
columns: columns,
|
|
@@ -3002,6 +3072,9 @@ var useSegments = function useSegments(_ref) {
|
|
|
3002
3072
|
})
|
|
3003
3073
|
});
|
|
3004
3074
|
};
|
|
3075
|
+
useEffect(function () {
|
|
3076
|
+
setSegments(fetchedSegments);
|
|
3077
|
+
}, [fetchedSegments]);
|
|
3005
3078
|
if (isLoading) {
|
|
3006
3079
|
return /*#__PURE__*/React.createElement(Spinner, null);
|
|
3007
3080
|
}
|
|
@@ -3010,9 +3083,9 @@ var useSegments = function useSegments(_ref) {
|
|
|
3010
3083
|
style: "body2"
|
|
3011
3084
|
}, t("neetoFilters.segments.noSegmentsFound"));
|
|
3012
3085
|
}
|
|
3013
|
-
var handleUpdate = function handleUpdate(
|
|
3014
|
-
var name =
|
|
3015
|
-
var setFieldError =
|
|
3086
|
+
var handleUpdate = function handleUpdate(_ref4, _ref5) {
|
|
3087
|
+
var name = _ref4.name;
|
|
3088
|
+
var setFieldError = _ref5.setFieldError;
|
|
3016
3089
|
var filtersPayload = buildSegmentsPayload(filters, childrenKeys);
|
|
3017
3090
|
updateSegment({
|
|
3018
3091
|
id: confirmAction.segment.id,
|
|
@@ -3039,6 +3112,7 @@ var useSegments = function useSegments(_ref) {
|
|
|
3039
3112
|
segments: segments,
|
|
3040
3113
|
clearAppliedFilters: clearAppliedFilters,
|
|
3041
3114
|
handleSelectSegment: handleSelectSegment,
|
|
3115
|
+
handleSegmentsReorder: handleSegmentsReorder,
|
|
3042
3116
|
setConfirmAction: setConfirmAction,
|
|
3043
3117
|
isUpdating: isUpdating,
|
|
3044
3118
|
handleUpdate: handleUpdate,
|
|
@@ -3087,6 +3161,7 @@ var Segment = function Segment(_ref) {
|
|
|
3087
3161
|
}];
|
|
3088
3162
|
return /*#__PURE__*/React.createElement("div", {
|
|
3089
3163
|
onClick: onClick,
|
|
3164
|
+
"data-cy": "neeto-filters-segment-block-".concat(hyphenate(label)),
|
|
3090
3165
|
className: classnames("neeto-ui-border-gray-400 neeto-ui-bg-white hover:neeto-ui-bg-gray-200 neeto-ui-rounded-lg mb-2 flex h-10 cursor-pointer items-center gap-2 border p-3 transition-all duration-300 ease-in-out", {
|
|
3091
3166
|
"neeto-filters-segment--active": isActive
|
|
3092
3167
|
})
|
|
@@ -3132,6 +3207,7 @@ var MenuBlocks = function MenuBlocks(_ref) {
|
|
|
3132
3207
|
segments = _useSegments$segments === void 0 ? [] : _useSegments$segments,
|
|
3133
3208
|
clearAppliedFilters = _useSegments.clearAppliedFilters,
|
|
3134
3209
|
handleSelectSegment = _useSegments.handleSelectSegment,
|
|
3210
|
+
handleSegmentsReorder = _useSegments.handleSegmentsReorder,
|
|
3135
3211
|
onClose = _useSegments.onClose,
|
|
3136
3212
|
setConfirmAction = _useSegments.setConfirmAction,
|
|
3137
3213
|
selectedSegment = _useSegments.selectedSegment,
|
|
@@ -3155,20 +3231,43 @@ var MenuBlocks = function MenuBlocks(_ref) {
|
|
|
3155
3231
|
isActive: isEmpty(appliedFilters),
|
|
3156
3232
|
label: defaultSegmentName,
|
|
3157
3233
|
onClick: clearAppliedFilters
|
|
3158
|
-
}),
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3234
|
+
}), /*#__PURE__*/React.createElement(DragDropContext, {
|
|
3235
|
+
onDragEnd: handleSegmentsReorder
|
|
3236
|
+
}, /*#__PURE__*/React.createElement(Droppable, {
|
|
3237
|
+
droppableId: "neeto-filters-segments-".concat(entity)
|
|
3238
|
+
}, function (_ref2) {
|
|
3239
|
+
var innerRef = _ref2.innerRef,
|
|
3240
|
+
droppableProps = _ref2.droppableProps,
|
|
3241
|
+
placeholder = _ref2.placeholder;
|
|
3242
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
3243
|
+
ref: innerRef
|
|
3244
|
+
}, droppableProps), segments.slice(0, showAll ? segments.length : ITEMS_MAX_COUNT).map(function (segment, index) {
|
|
3245
|
+
return /*#__PURE__*/React.createElement(Draggable, {
|
|
3246
|
+
index: index,
|
|
3247
|
+
draggableId: segment.id.toString(),
|
|
3248
|
+
isDragDisabled: isUpdating,
|
|
3249
|
+
key: segment.id.toString()
|
|
3250
|
+
}, function (_ref3) {
|
|
3251
|
+
var innerRef = _ref3.innerRef,
|
|
3252
|
+
draggableProps = _ref3.draggableProps,
|
|
3253
|
+
dragHandleProps = _ref3.dragHandleProps;
|
|
3254
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
3255
|
+
ref: innerRef
|
|
3256
|
+
}, draggableProps, dragHandleProps), /*#__PURE__*/React.createElement(Segment, {
|
|
3257
|
+
segments: segments,
|
|
3258
|
+
setConfirmAction: setConfirmAction,
|
|
3259
|
+
shouldShowDropdown: true,
|
|
3260
|
+
id: segment.id,
|
|
3261
|
+
isActive: segment.id === segmentId,
|
|
3262
|
+
key: segment.id,
|
|
3263
|
+
label: segment.name,
|
|
3264
|
+
onClick: function onClick() {
|
|
3265
|
+
return handleSelectSegment(segment);
|
|
3266
|
+
}
|
|
3267
|
+
}));
|
|
3268
|
+
});
|
|
3269
|
+
}), placeholder);
|
|
3270
|
+
})), /*#__PURE__*/React.createElement(SegmentForm, {
|
|
3172
3271
|
childrenKeys: childrenKeys,
|
|
3173
3272
|
columns: columns,
|
|
3174
3273
|
customFilters: customFilters,
|