@synerise/ds-column-manager 1.0.13 → 1.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/CHANGELOG.md +19 -0
- package/README.md +29 -96
- package/dist/ColumnManager.d.ts +4 -6
- package/dist/ColumnManager.js +108 -420
- package/dist/ColumnManager.styles.d.ts +5 -0
- package/dist/ColumnManager.styles.js +15 -0
- package/dist/ColumnManager.types.d.ts +15 -45
- package/dist/ColumnManagerActions/ColumnManagerActions.d.ts +2 -10
- package/dist/ColumnManagerActions/ColumnManagerActions.js +16 -122
- package/dist/ColumnManagerActions/ColumnManagerActions.styles.d.ts +0 -2
- package/dist/ColumnManagerActions/ColumnManagerActions.styles.js +2 -11
- package/dist/ColumnManagerActions/ColumnManagerActions.types.d.ts +3 -17
- package/dist/ColumnManagerActions/ColumnManagerActions.types.js +1 -1
- package/dist/ColumnManagerItem/ColumManagerItem.types.d.ts +14 -14
- package/dist/ColumnManagerItem/ColumnManagerItem.d.ts +3 -14
- package/dist/ColumnManagerItem/ColumnManagerItem.js +25 -82
- package/dist/ColumnManagerItem/ColumnManagerItem.styles.d.ts +3 -1
- package/dist/ColumnManagerItem/ColumnManagerItem.styles.js +6 -2
- package/dist/ColumnManagerList/ColumnManager.style.d.ts +5 -0
- package/dist/ColumnManagerList/ColumnManager.style.js +14 -7
- package/dist/ColumnManagerList/ColumnManagerList.d.ts +5 -3
- package/dist/ColumnManagerList/ColumnManagerList.js +86 -53
- package/dist/ColumnManagerList/ColumnManagerList.types.d.ts +7 -15
- package/dist/ColumnManagerSortableItem/ColumnManagerSortableItem.d.ts +4 -0
- package/dist/ColumnManagerSortableItem/ColumnManagerSortableItem.js +36 -0
- package/dist/ColumnManagerSortableItem/ColumnManagerSortableItem.types.d.ts +3 -0
- package/dist/hooks/useTranslations.d.ts +2 -0
- package/dist/hooks/useTranslations.js +43 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/utils/matchesSearchQuery.d.ts +1 -0
- package/dist/utils/matchesSearchQuery.js +3 -0
- package/package.json +15 -22
- package/dist/ColumnManagerGroupSettings/ColumnManagerGroupSettings.d.ts +0 -4
- package/dist/ColumnManagerGroupSettings/ColumnManagerGroupSettings.js +0 -210
- package/dist/ColumnManagerGroupSettings/ColumnManagerGroupSettings.types.d.ts +0 -27
- package/dist/ColumnManagerGroupSettings/ColumnManagerGroupSettings.types.js +0 -6
- package/dist/ColumnManagerGroupSettings/ColumnManangerGroupSettings.styles.d.ts +0 -4
- package/dist/ColumnManagerGroupSettings/ColumnManangerGroupSettings.styles.js +0 -19
- package/dist/ColumnManagerGroupSettings/RangesForm/RangeInput.d.ts +0 -9
- package/dist/ColumnManagerGroupSettings/RangesForm/RangeInput.js +0 -30
- package/dist/ColumnManagerGroupSettings/RangesForm/RangeRow.d.ts +0 -16
- package/dist/ColumnManagerGroupSettings/RangesForm/RangeRow.js +0 -64
- package/dist/ColumnManagerGroupSettings/RangesForm/RangesForm.d.ts +0 -13
- package/dist/ColumnManagerGroupSettings/RangesForm/RangesForm.js +0 -37
- package/dist/ColumnManagerGroupSettings/RangesForm/RangesForm.styles.d.ts +0 -7
- package/dist/ColumnManagerGroupSettings/RangesForm/RangesForm.styles.js +0 -24
- package/dist/ColumnManagerSearchResults/ColumManagerResults.types.d.ts +0 -12
- package/dist/ColumnManagerSearchResults/ColumnManagerSearchResults.d.ts +0 -4
- package/dist/ColumnManagerSearchResults/ColumnManagerSearchResults.js +0 -32
- package/dist/ColumnManagerSearchResults/ColumnMangerSearchResults.styles.d.ts +0 -1
- package/dist/ColumnManagerSearchResults/ColumnMangerSearchResults.styles.js +0 -7
- package/dist/styles/ColumnManager.styles.d.ts +0 -2
- package/dist/styles/ColumnManager.styles.js +0 -9
- /package/dist/{ColumnManagerSearchResults/ColumManagerResults.types.js → ColumnManagerSortableItem/ColumnManagerSortableItem.types.js} +0 -0
|
@@ -1,62 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import React, { useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { DragOverlay } from '@dnd-kit/core';
|
|
3
|
+
import { SortableContainer } from '@synerise/ds-sortable';
|
|
4
|
+
import Scrollbar from '@synerise/ds-scrollbar';
|
|
5
|
+
import Result from '@synerise/ds-result';
|
|
6
|
+
import { useResizeObserver } from '@synerise/ds-utils';
|
|
7
|
+
import { ColumnManagerSortableItem } from '../ColumnManagerSortableItem/ColumnManagerSortableItem';
|
|
8
|
+
import { ColumnManagerItem } from '../ColumnManagerItem/ColumnManagerItem';
|
|
4
9
|
import * as S from './ColumnManager.style';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
ghostClass: 'sortable-list-ghost-element',
|
|
9
|
-
className: 'sortable-list',
|
|
10
|
-
animation: 150,
|
|
11
|
-
group: 'column-manager',
|
|
12
|
-
forceFallback: true
|
|
10
|
+
export var LIST_STYLE = {
|
|
11
|
+
overflowX: 'unset',
|
|
12
|
+
overflowY: 'unset'
|
|
13
13
|
};
|
|
14
14
|
var ColumnManagerList = function ColumnManagerList(_ref) {
|
|
15
15
|
var searchQuery = _ref.searchQuery,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
updateHiddenList = _ref.updateHiddenList,
|
|
20
|
-
setFixed = _ref.setFixed,
|
|
21
|
-
showGroupSettings = _ref.showGroupSettings,
|
|
16
|
+
columns = _ref.columns,
|
|
17
|
+
draggable = _ref.draggable,
|
|
18
|
+
handleOrderChange = _ref.handleOrderChange,
|
|
22
19
|
toggleColumn = _ref.toggleColumn,
|
|
23
|
-
searchResults = _ref.searchResults,
|
|
24
20
|
texts = _ref.texts;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
21
|
+
var _useState = useState(),
|
|
22
|
+
activeItem = _useState[0],
|
|
23
|
+
setActiveItem = _useState[1];
|
|
24
|
+
var _useState2 = useState(0),
|
|
25
|
+
containerHeight = _useState2[0],
|
|
26
|
+
setContainerHeight = _useState2[1];
|
|
27
|
+
var listRef = useRef(null);
|
|
28
|
+
var containerRef = useRef(null);
|
|
29
|
+
var isItemDraggable = draggable && !searchQuery;
|
|
30
|
+
var items = useMemo(function () {
|
|
31
|
+
return columns.map(function (column) {
|
|
32
|
+
return {
|
|
33
|
+
key: column.id,
|
|
34
|
+
id: column.id,
|
|
35
|
+
item: column,
|
|
36
|
+
isDragged: (activeItem == null ? void 0 : activeItem.id) === column.id,
|
|
37
|
+
switchAction: toggleColumn,
|
|
38
|
+
draggable: isItemDraggable,
|
|
39
|
+
texts: texts
|
|
40
|
+
};
|
|
38
41
|
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
42
|
+
}, [columns, toggleColumn, texts, activeItem, isItemDraggable]);
|
|
43
|
+
var handleScroll = function handleScroll(_ref2) {
|
|
44
|
+
var currentTarget = _ref2.currentTarget;
|
|
45
|
+
var scrollTop = currentTarget.scrollTop;
|
|
46
|
+
if (listRef.current) {
|
|
47
|
+
listRef.current.scrollTo(scrollTop);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
useResizeObserver(containerRef, function (dimensions) {
|
|
51
|
+
setContainerHeight(dimensions.height);
|
|
52
|
+
});
|
|
53
|
+
return /*#__PURE__*/React.createElement(S.ColumnManagerList, {
|
|
54
|
+
ref: containerRef,
|
|
55
|
+
"data-testid": "ds-column-manager-list"
|
|
56
|
+
}, !items.length && searchQuery ? /*#__PURE__*/React.createElement(Result, {
|
|
57
|
+
description: texts.noResults,
|
|
58
|
+
type: "no-results",
|
|
59
|
+
noSearchResults: true
|
|
60
|
+
}) : /*#__PURE__*/React.createElement(SortableContainer, {
|
|
61
|
+
onDragStart: function onDragStart(_ref3) {
|
|
62
|
+
var active = _ref3.active;
|
|
63
|
+
var column = items.find(function (item) {
|
|
64
|
+
return item.id === active.id;
|
|
65
|
+
});
|
|
66
|
+
setActiveItem(column);
|
|
67
|
+
},
|
|
68
|
+
onDragEnd: function onDragEnd() {
|
|
69
|
+
setActiveItem(undefined);
|
|
70
|
+
},
|
|
71
|
+
onOrderChange: handleOrderChange,
|
|
72
|
+
onDragCancel: function onDragCancel() {
|
|
73
|
+
return setActiveItem(undefined);
|
|
74
|
+
},
|
|
75
|
+
items: items,
|
|
76
|
+
axis: "y"
|
|
77
|
+
}, /*#__PURE__*/React.createElement(Scrollbar, {
|
|
78
|
+
absolute: true,
|
|
79
|
+
withDnd: true,
|
|
80
|
+
onScroll: handleScroll,
|
|
81
|
+
maxHeight: containerHeight
|
|
82
|
+
}, /*#__PURE__*/React.createElement(S.List, {
|
|
83
|
+
isDragging: !!activeItem,
|
|
84
|
+
height: containerHeight,
|
|
85
|
+
itemCount: items.length,
|
|
86
|
+
itemSize: 56,
|
|
87
|
+
itemData: items,
|
|
88
|
+
width: "100%",
|
|
89
|
+
ref: listRef,
|
|
90
|
+
style: LIST_STYLE
|
|
91
|
+
}, function (props) {
|
|
92
|
+
return /*#__PURE__*/React.createElement(ColumnManagerSortableItem, props);
|
|
93
|
+
})), /*#__PURE__*/React.createElement(DragOverlay, null, activeItem && /*#__PURE__*/React.createElement(ColumnManagerItem, activeItem))));
|
|
61
94
|
};
|
|
62
95
|
export default ColumnManagerList;
|
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export type Props = {
|
|
1
|
+
import type { Column, ColumnManagerItemProps } from '../ColumnManagerItem/ColumManagerItem.types';
|
|
2
|
+
import type { ColumnManagerTexts } from '../ColumnManager.types';
|
|
3
|
+
export type ColumnManagerListProps<ColumnType extends Column> = {
|
|
5
4
|
searchQuery: string;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
setFixed: (id: string, fixed?: string) => void;
|
|
10
|
-
showGroupSettings: (item: Column) => void;
|
|
5
|
+
columns: ColumnType[];
|
|
6
|
+
draggable?: boolean;
|
|
7
|
+
handleOrderChange: (items: ColumnManagerItemProps<ColumnType>[]) => void;
|
|
11
8
|
toggleColumn: (id: string, visible: boolean) => void;
|
|
12
|
-
|
|
13
|
-
updateVisibleList: (newList: Column[]) => void;
|
|
14
|
-
updateHiddenList: (newList: Column[]) => void;
|
|
15
|
-
texts: {
|
|
16
|
-
[k: string]: string | React.ReactNode;
|
|
17
|
-
};
|
|
9
|
+
texts: ColumnManagerTexts;
|
|
18
10
|
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ColumnManagerSortableItemProps } from './ColumnManagerSortableItem.types';
|
|
3
|
+
import { Column } from '../ColumnManagerItem/ColumManagerItem.types';
|
|
4
|
+
export declare const ColumnManagerSortableItem: <ColumnType extends Column>(props: ColumnManagerSortableItemProps<ColumnType>) => React.JSX.Element;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var _excluded = ["index", "style", "data"];
|
|
2
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { useSortable } from '@dnd-kit/sortable';
|
|
6
|
+
import { CSS } from '@dnd-kit/utilities';
|
|
7
|
+
import { ColumnManagerItem } from '../ColumnManagerItem/ColumnManagerItem';
|
|
8
|
+
export var ColumnManagerSortableItem = function ColumnManagerSortableItem(props) {
|
|
9
|
+
var index = props.index,
|
|
10
|
+
styleProp = props.style,
|
|
11
|
+
data = props.data,
|
|
12
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded);
|
|
13
|
+
var id = data[index].id;
|
|
14
|
+
var _useSortable = useSortable({
|
|
15
|
+
id: id
|
|
16
|
+
}),
|
|
17
|
+
attributes = _useSortable.attributes,
|
|
18
|
+
listeners = _useSortable.listeners,
|
|
19
|
+
setNodeRef = _useSortable.setNodeRef,
|
|
20
|
+
transform = _useSortable.transform,
|
|
21
|
+
transition = _useSortable.transition;
|
|
22
|
+
var style = _extends({}, styleProp, {
|
|
23
|
+
transform: CSS.Transform.toString(transform),
|
|
24
|
+
transition: transition
|
|
25
|
+
});
|
|
26
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
|
|
27
|
+
key: "column-manager-item-" + id,
|
|
28
|
+
style: style,
|
|
29
|
+
ref: setNodeRef
|
|
30
|
+
}), /*#__PURE__*/React.createElement(ColumnManagerItem, _extends({}, data[index], {
|
|
31
|
+
dragHandleProps: {
|
|
32
|
+
attributes: attributes,
|
|
33
|
+
listeners: listeners
|
|
34
|
+
}
|
|
35
|
+
})));
|
|
36
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ListChildComponentProps } from 'react-window';
|
|
2
|
+
import type { ColumnManagerItemProps, Column } from '../ColumnManagerItem/ColumManagerItem.types';
|
|
3
|
+
export type ColumnManagerSortableItemProps<ColumnType extends Column> = ListChildComponentProps<ColumnManagerItemProps<ColumnType>[]>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
+
import { useIntl } from 'react-intl';
|
|
3
|
+
export var useTranslations = function useTranslations(texts) {
|
|
4
|
+
var intl = useIntl();
|
|
5
|
+
return _extends({
|
|
6
|
+
title: intl.formatMessage({
|
|
7
|
+
id: 'DS.COLUMN-MANAGER.TITLE',
|
|
8
|
+
defaultMessage: 'Manage columns'
|
|
9
|
+
}),
|
|
10
|
+
searchPlaceholder: intl.formatMessage({
|
|
11
|
+
id: 'DS.COLUMN-MANAGER.SEARCH-PLACEHOLDER',
|
|
12
|
+
defaultMessage: 'Search columns'
|
|
13
|
+
}),
|
|
14
|
+
searchClearTooltip: intl.formatMessage({
|
|
15
|
+
id: 'DS.ITEM-FILTER.SEARCH-CLEAR',
|
|
16
|
+
defaultMessage: 'Clear'
|
|
17
|
+
}),
|
|
18
|
+
noResults: intl.formatMessage({
|
|
19
|
+
id: 'DS.COLUMN-MANAGER.NO-RESULTS',
|
|
20
|
+
defaultMessage: 'No results'
|
|
21
|
+
}),
|
|
22
|
+
cancel: intl.formatMessage({
|
|
23
|
+
id: 'DS.COLUMN-MANAGER.CANCEL',
|
|
24
|
+
defaultMessage: 'Cancel'
|
|
25
|
+
}),
|
|
26
|
+
apply: intl.formatMessage({
|
|
27
|
+
id: 'DS.COLUMN-MANAGER.APPLY',
|
|
28
|
+
defaultMessage: 'Apply'
|
|
29
|
+
}),
|
|
30
|
+
clear: intl.formatMessage({
|
|
31
|
+
id: 'DS.COLUMN-MANAGER.CLEAR',
|
|
32
|
+
defaultMessage: 'Clear'
|
|
33
|
+
}),
|
|
34
|
+
switchOn: intl.formatMessage({
|
|
35
|
+
id: 'DS.COLUMN-MANAGER.SWITCH-ON',
|
|
36
|
+
defaultMessage: 'Hide column'
|
|
37
|
+
}),
|
|
38
|
+
switchOff: intl.formatMessage({
|
|
39
|
+
id: 'DS.COLUMN-MANAGER.SWITCH-OFF',
|
|
40
|
+
defaultMessage: 'Show column'
|
|
41
|
+
})
|
|
42
|
+
}, texts || {});
|
|
43
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export { default } from './ColumnManager';
|
|
2
|
-
export {
|
|
3
|
-
export type { SavedView, GroupSettings, ColumnManagerProps } from './ColumnManager.types';
|
|
2
|
+
export type { ColumnManagerProps } from './ColumnManager.types';
|
|
4
3
|
export type { Column } from './ColumnManagerItem/ColumManagerItem.types';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export { default } from './ColumnManager';
|
|
2
|
-
export { GROUP_BY } from './ColumnManagerGroupSettings/ColumnManagerGroupSettings.types';
|
|
1
|
+
export { default } from './ColumnManager';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const matchesSearchQuery: (text: string, searchQuery: string) => boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synerise/ds-column-manager",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "ColumnManager UI Component for the Synerise Design System",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": "Synerise/synerise-design",
|
|
@@ -31,26 +31,19 @@
|
|
|
31
31
|
"sideEffects": false,
|
|
32
32
|
"types": "dist/index.d.ts",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@synerise/ds-
|
|
35
|
-
"@synerise/ds-
|
|
36
|
-
"@synerise/ds-
|
|
37
|
-
"@synerise/ds-
|
|
38
|
-
"@synerise/ds-
|
|
39
|
-
"@synerise/ds-
|
|
40
|
-
"@synerise/ds-
|
|
41
|
-
"@synerise/ds-
|
|
42
|
-
"@synerise/ds-
|
|
43
|
-
"@synerise/ds-
|
|
44
|
-
"@synerise/ds-
|
|
45
|
-
"@synerise/ds-
|
|
46
|
-
"
|
|
47
|
-
"@synerise/ds-select": "^1.1.4",
|
|
48
|
-
"@synerise/ds-switch": "^1.1.4",
|
|
49
|
-
"@synerise/ds-tooltip": "^1.1.8",
|
|
50
|
-
"@synerise/ds-typography": "^1.0.9",
|
|
51
|
-
"@synerise/ds-utils": "^1.1.1",
|
|
52
|
-
"react-sortablejs": "^6.0.0",
|
|
53
|
-
"uuid": "^8.3.2"
|
|
34
|
+
"@synerise/ds-button": "^1.3.3",
|
|
35
|
+
"@synerise/ds-drawer": "^1.0.4",
|
|
36
|
+
"@synerise/ds-icon": "^1.5.2",
|
|
37
|
+
"@synerise/ds-menu": "^1.0.11",
|
|
38
|
+
"@synerise/ds-result": "^1.0.11",
|
|
39
|
+
"@synerise/ds-scrollbar": "^1.0.10",
|
|
40
|
+
"@synerise/ds-search-bar": "^1.3.0",
|
|
41
|
+
"@synerise/ds-sortable": "^1.2.0",
|
|
42
|
+
"@synerise/ds-switch": "^1.1.5",
|
|
43
|
+
"@synerise/ds-tooltip": "^1.1.9",
|
|
44
|
+
"@synerise/ds-typography": "^1.0.10",
|
|
45
|
+
"@synerise/ds-utils": "^1.2.0",
|
|
46
|
+
"react-window": "1.8.5"
|
|
54
47
|
},
|
|
55
48
|
"peerDependencies": {
|
|
56
49
|
"@synerise/ds-core": "*",
|
|
@@ -59,5 +52,5 @@
|
|
|
59
52
|
"react-intl": ">=3.12.0 <= 6.8",
|
|
60
53
|
"styled-components": "^5.3.3"
|
|
61
54
|
},
|
|
62
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "35c8f09d6a248f199237766c1f5181f4b3fc88af"
|
|
63
56
|
}
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
-
import Modal from '@synerise/ds-modal';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import Select from '@synerise/ds-select';
|
|
5
|
-
import Icon, { InfoFillS, Add3M } from '@synerise/ds-icon';
|
|
6
|
-
import Tooltip from '@synerise/ds-tooltip';
|
|
7
|
-
import { theme } from '@synerise/ds-core';
|
|
8
|
-
import Button from '@synerise/ds-button';
|
|
9
|
-
import InputNumber from '@synerise/ds-input-number';
|
|
10
|
-
import Alert from '@synerise/ds-alert';
|
|
11
|
-
import * as S from './ColumnManangerGroupSettings.styles';
|
|
12
|
-
import RangesForm from './RangesForm/RangesForm';
|
|
13
|
-
import { GROUP_BY } from './ColumnManagerGroupSettings.types';
|
|
14
|
-
var EMPTY_RANGE = {
|
|
15
|
-
from: {
|
|
16
|
-
value: undefined,
|
|
17
|
-
error: undefined
|
|
18
|
-
},
|
|
19
|
-
to: {
|
|
20
|
-
value: undefined,
|
|
21
|
-
error: undefined
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
var validateRange = function validateRange(range, index, ranges, texts) {
|
|
25
|
-
var validRange = _extends({}, range);
|
|
26
|
-
if ((range.from.value === undefined || range.from.value === '') && (range.to.value === undefined || range.to.value === '')) {
|
|
27
|
-
validRange.from.error = texts.errorEmptyRange;
|
|
28
|
-
validRange.to.error = texts.errorEmptyRange;
|
|
29
|
-
} else {
|
|
30
|
-
if ((range.from.value === undefined || range.from.value === '') && index > 0) {
|
|
31
|
-
validRange.from.error = texts.errorEmptyFromField;
|
|
32
|
-
} else {
|
|
33
|
-
validRange.from.error = undefined;
|
|
34
|
-
}
|
|
35
|
-
if ((range.to.value === undefined || range.from.value === '') && index < ranges.length - 1) {
|
|
36
|
-
validRange.to.error = texts.errorEmptyToField;
|
|
37
|
-
} else {
|
|
38
|
-
validRange.to.error = undefined;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return validRange;
|
|
42
|
-
};
|
|
43
|
-
var ColumnManagerGroupSettings = function ColumnManagerGroupSettings(_ref) {
|
|
44
|
-
var hide = _ref.hide,
|
|
45
|
-
visible = _ref.visible,
|
|
46
|
-
column = _ref.column,
|
|
47
|
-
onOk = _ref.onOk,
|
|
48
|
-
settings = _ref.settings,
|
|
49
|
-
texts = _ref.texts;
|
|
50
|
-
var _React$useState = React.useState(undefined),
|
|
51
|
-
groupBy = _React$useState[0],
|
|
52
|
-
setGroupBy = _React$useState[1];
|
|
53
|
-
var _React$useState2 = React.useState([EMPTY_RANGE]),
|
|
54
|
-
ranges = _React$useState2[0],
|
|
55
|
-
setRanges = _React$useState2[1];
|
|
56
|
-
var _React$useState3 = React.useState(undefined),
|
|
57
|
-
interval = _React$useState3[0],
|
|
58
|
-
setIntervalValue = _React$useState3[1];
|
|
59
|
-
var _React$useState4 = React.useState(undefined),
|
|
60
|
-
error = _React$useState4[0],
|
|
61
|
-
setError = _React$useState4[1];
|
|
62
|
-
var clearState = React.useCallback(function () {
|
|
63
|
-
setRanges([EMPTY_RANGE]);
|
|
64
|
-
setError(undefined);
|
|
65
|
-
setGroupBy(undefined);
|
|
66
|
-
setIntervalValue(undefined);
|
|
67
|
-
}, []);
|
|
68
|
-
React.useEffect(function () {
|
|
69
|
-
setGroupBy(settings == null ? void 0 : settings.settings.type);
|
|
70
|
-
setRanges((settings == null ? void 0 : settings.settings.ranges) || [EMPTY_RANGE]);
|
|
71
|
-
setIntervalValue((settings == null ? void 0 : settings.settings.interval) || undefined);
|
|
72
|
-
return function () {
|
|
73
|
-
clearState();
|
|
74
|
-
};
|
|
75
|
-
}, [settings, setGroupBy, setRanges, clearState, setIntervalValue]);
|
|
76
|
-
var validate = React.useCallback(function () {
|
|
77
|
-
if (groupBy === GROUP_BY.value) return true;
|
|
78
|
-
if (groupBy === undefined) {
|
|
79
|
-
setError(texts.errorChooseGrouping);
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
if (groupBy === GROUP_BY.interval) {
|
|
83
|
-
if (!interval) {
|
|
84
|
-
setError(texts.errorInterval);
|
|
85
|
-
} else {
|
|
86
|
-
setError(undefined);
|
|
87
|
-
}
|
|
88
|
-
return Boolean(interval);
|
|
89
|
-
}
|
|
90
|
-
if (groupBy === GROUP_BY.ranges) {
|
|
91
|
-
var validatedRanges = ranges.map(function (range, index, allRanges) {
|
|
92
|
-
return validateRange(range, index, allRanges, texts);
|
|
93
|
-
});
|
|
94
|
-
var errors = validatedRanges.filter(function (range) {
|
|
95
|
-
return range.from.error || range.to.error;
|
|
96
|
-
});
|
|
97
|
-
setRanges(validatedRanges);
|
|
98
|
-
if (errors.length) {
|
|
99
|
-
setError(texts.errorRange);
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
setError(undefined);
|
|
104
|
-
return true;
|
|
105
|
-
}, [groupBy, ranges, interval, setError, setRanges, texts]);
|
|
106
|
-
var handleOk = React.useCallback(function () {
|
|
107
|
-
if (groupBy === GROUP_BY.disabled) {
|
|
108
|
-
onOk(undefined);
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
if (validate()) {
|
|
112
|
-
var currentSettings = {
|
|
113
|
-
column: column,
|
|
114
|
-
settings: {
|
|
115
|
-
type: groupBy,
|
|
116
|
-
ranges: groupBy === GROUP_BY.ranges && ranges.map(function (range) {
|
|
117
|
-
return {
|
|
118
|
-
from: range.from,
|
|
119
|
-
to: range.to
|
|
120
|
-
};
|
|
121
|
-
}),
|
|
122
|
-
interval: groupBy === GROUP_BY.interval && interval
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
clearState();
|
|
126
|
-
onOk(currentSettings);
|
|
127
|
-
}
|
|
128
|
-
}, [onOk, column, groupBy, ranges, interval, clearState, validate]);
|
|
129
|
-
var selectLabel = React.useMemo(function () {
|
|
130
|
-
return /*#__PURE__*/React.createElement(S.Title, null, texts.groupingType, /*#__PURE__*/React.createElement(Tooltip, {
|
|
131
|
-
title: texts.groupingTypeTooltip,
|
|
132
|
-
trigger: ['hover']
|
|
133
|
-
}, /*#__PURE__*/React.createElement(S.IconWrapper, null, /*#__PURE__*/React.createElement(Icon, {
|
|
134
|
-
component: /*#__PURE__*/React.createElement(InfoFillS, null),
|
|
135
|
-
color: theme.palette['grey-600']
|
|
136
|
-
}))));
|
|
137
|
-
}, [texts]);
|
|
138
|
-
var addRow = React.useCallback(function () {
|
|
139
|
-
setRanges([].concat(ranges, [EMPTY_RANGE]));
|
|
140
|
-
}, [setRanges, ranges]);
|
|
141
|
-
var renderForm = React.useCallback(function () {
|
|
142
|
-
if (groupBy === GROUP_BY.ranges) {
|
|
143
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(RangesForm, {
|
|
144
|
-
setRanges: setRanges,
|
|
145
|
-
ranges: ranges,
|
|
146
|
-
type: (column == null ? void 0 : column.type) || '',
|
|
147
|
-
texts: texts
|
|
148
|
-
}), /*#__PURE__*/React.createElement(Button, {
|
|
149
|
-
onClick: addRow,
|
|
150
|
-
type: "ghost-primary",
|
|
151
|
-
mode: "icon-label"
|
|
152
|
-
}, /*#__PURE__*/React.createElement(Icon, {
|
|
153
|
-
component: /*#__PURE__*/React.createElement(Add3M, null)
|
|
154
|
-
}), texts.addRange));
|
|
155
|
-
}
|
|
156
|
-
if (groupBy === GROUP_BY.interval) {
|
|
157
|
-
return /*#__PURE__*/React.createElement(S.IntervalInput, null, /*#__PURE__*/React.createElement(InputNumber, {
|
|
158
|
-
"data-testid": "group-by-interval",
|
|
159
|
-
min: 1,
|
|
160
|
-
label: texts.intervalPlaceholder,
|
|
161
|
-
value: Number(interval),
|
|
162
|
-
onChange: setIntervalValue
|
|
163
|
-
}));
|
|
164
|
-
}
|
|
165
|
-
return null;
|
|
166
|
-
}, [groupBy, ranges, column, interval, addRow, texts]);
|
|
167
|
-
var handleHide = React.useCallback(function () {
|
|
168
|
-
clearState();
|
|
169
|
-
hide();
|
|
170
|
-
}, [hide, clearState]);
|
|
171
|
-
var groupByRangesDisabled = React.useMemo(function () {
|
|
172
|
-
var availableColumnTypes = ['text', 'number', 'date'];
|
|
173
|
-
var type = (column == null ? void 0 : column.type) || undefined;
|
|
174
|
-
return !type || !availableColumnTypes.includes(type);
|
|
175
|
-
}, [column]);
|
|
176
|
-
var handleGroupTypeChange = React.useCallback(function (value) {
|
|
177
|
-
setGroupBy(value);
|
|
178
|
-
setError(undefined);
|
|
179
|
-
}, [setGroupBy, setError]);
|
|
180
|
-
return /*#__PURE__*/React.createElement(Modal, {
|
|
181
|
-
onCancel: handleHide,
|
|
182
|
-
visible: visible,
|
|
183
|
-
onOk: handleOk,
|
|
184
|
-
size: "small",
|
|
185
|
-
title: texts.groupTitle
|
|
186
|
-
}, /*#__PURE__*/React.createElement(S.ModalContent, null, /*#__PURE__*/React.createElement(Select, {
|
|
187
|
-
label: selectLabel,
|
|
188
|
-
value: groupBy,
|
|
189
|
-
onChange: handleGroupTypeChange,
|
|
190
|
-
placeholder: texts.selectPlaceholder,
|
|
191
|
-
style: {
|
|
192
|
-
width: '100%'
|
|
193
|
-
}
|
|
194
|
-
}, /*#__PURE__*/React.createElement(Select.Option, {
|
|
195
|
-
value: GROUP_BY.value
|
|
196
|
-
}, texts.groupByValue), /*#__PURE__*/React.createElement(Select.Option, {
|
|
197
|
-
value: GROUP_BY.ranges,
|
|
198
|
-
disabled: groupByRangesDisabled
|
|
199
|
-
}, texts.groupByRanges), /*#__PURE__*/React.createElement(Select.Option, {
|
|
200
|
-
value: GROUP_BY.interval
|
|
201
|
-
}, texts.groupByIntervals), /*#__PURE__*/React.createElement(Select.Option, {
|
|
202
|
-
value: GROUP_BY.disabled
|
|
203
|
-
}, texts.groupDisabled)), error && /*#__PURE__*/React.createElement(Alert, {
|
|
204
|
-
type: "error",
|
|
205
|
-
description: error,
|
|
206
|
-
message: "",
|
|
207
|
-
showIcon: true
|
|
208
|
-
}), renderForm()));
|
|
209
|
-
};
|
|
210
|
-
export default ColumnManagerGroupSettings;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { GroupSettings } from '../ColumnManager.types';
|
|
3
|
-
import { Column } from '../ColumnManagerItem/ColumManagerItem.types';
|
|
4
|
-
export type GroupSettingsTexts = 'groupByValue' | 'groupByRanges' | 'groupByIntervals' | 'groupDisabled' | 'groupTitle' | 'selectPlaceholder' | 'intervalPlaceholder' | 'groupingType' | 'groupingTypeTooltip' | 'from' | 'to' | 'remove' | 'addRange' | 'errorEmptyRange' | 'errorEmptyFromField' | 'errorEmptyToField' | 'errorChooseGrouping' | 'errorInterval' | 'errorRange';
|
|
5
|
-
export declare const GROUP_BY: {
|
|
6
|
-
[key: string]: string;
|
|
7
|
-
};
|
|
8
|
-
export interface GroupSettingsProps {
|
|
9
|
-
hide: () => void;
|
|
10
|
-
onOk: (settings: GroupSettings | undefined) => void;
|
|
11
|
-
visible: boolean;
|
|
12
|
-
settings?: GroupSettings;
|
|
13
|
-
column?: Column;
|
|
14
|
-
texts: {
|
|
15
|
-
[k in GroupSettingsTexts]: string | React.ReactNode;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
export interface Range {
|
|
19
|
-
from: {
|
|
20
|
-
value: string | number | null | undefined;
|
|
21
|
-
error: React.ReactNode | undefined;
|
|
22
|
-
};
|
|
23
|
-
to: {
|
|
24
|
-
value: string | number | null | undefined;
|
|
25
|
-
error: React.ReactNode | undefined;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export declare const Title: import("styled-components").StyledComponent<"span", any, {}, never>;
|
|
2
|
-
export declare const IconWrapper: import("styled-components").StyledComponent<"span", any, {}, never>;
|
|
3
|
-
export declare const ModalContent: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
4
|
-
export declare const IntervalInput: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import styled from 'styled-components';
|
|
2
|
-
import { AntdSelect } from '@synerise/ds-select/dist/Select.styles';
|
|
3
|
-
import { AntdAlert } from '@synerise/ds-alert/dist/Alert.styles';
|
|
4
|
-
export var Title = styled.span.withConfig({
|
|
5
|
-
displayName: "ColumnManangerGroupSettingsstyles__Title",
|
|
6
|
-
componentId: "sc-15dq2h5-0"
|
|
7
|
-
})(["display:flex;align-items:center;justify-content:flex-start;"]);
|
|
8
|
-
export var IconWrapper = styled.span.withConfig({
|
|
9
|
-
displayName: "ColumnManangerGroupSettingsstyles__IconWrapper",
|
|
10
|
-
componentId: "sc-15dq2h5-1"
|
|
11
|
-
})([""]);
|
|
12
|
-
export var ModalContent = styled.div.withConfig({
|
|
13
|
-
displayName: "ColumnManangerGroupSettingsstyles__ModalContent",
|
|
14
|
-
componentId: "sc-15dq2h5-2"
|
|
15
|
-
})(["display:flex;flex-direction:column;align-items:flex-start;justify-content:flex-start;min-height:250px;", "{margin-bottom:20px;}", "{width:100%;margin-bottom:26px;}"], AntdAlert, AntdSelect);
|
|
16
|
-
export var IntervalInput = styled.div.withConfig({
|
|
17
|
-
displayName: "ColumnManangerGroupSettingsstyles__IntervalInput",
|
|
18
|
-
componentId: "sc-15dq2h5-3"
|
|
19
|
-
})(["width:100%;.ant-input-number{width:100%;}"]);
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { InputProps } from '@synerise/ds-input';
|
|
3
|
-
import { Props as NumberInputProps } from '@synerise/ds-input-number/dist/InputNumber.types';
|
|
4
|
-
type RangeInputProps = Omit<InputProps, 'value' | 'onChange'> & Omit<NumberInputProps, 'value' | 'onChange'> & {
|
|
5
|
-
value: string | number | null | undefined;
|
|
6
|
-
onChange: (value: string | number | null | undefined) => void;
|
|
7
|
-
};
|
|
8
|
-
declare const RangeInput: ({ type, value, onChange, handleInputRef, ...inputProps }: RangeInputProps) => React.JSX.Element;
|
|
9
|
-
export default RangeInput;
|