@synerise/ds-table 1.9.11 → 1.9.13
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 +8 -0
- package/dist/Cell/Action/ActionCell.d.ts +2 -2
- package/dist/Cell/Action/ActionCell.js +15 -18
- package/dist/Cell/Action/ActionCell.styles.d.ts +2 -2
- package/dist/Cell/Action/ActionCell.styles.js +10 -11
- package/dist/Cell/Action/ActionCell.types.d.ts +2 -2
- package/dist/Cell/Action/ActionCell.types.js +1 -1
- package/dist/Cell/AvatarLabel/AvatarLabel.d.ts +2 -2
- package/dist/Cell/AvatarLabel/AvatarLabel.js +32 -43
- package/dist/Cell/AvatarLabel/AvatarLabel.styles.d.ts +13 -13
- package/dist/Cell/AvatarLabel/AvatarLabel.styles.js +27 -28
- package/dist/Cell/AvatarLabel/AvatarLabel.types.d.ts +2 -2
- package/dist/Cell/AvatarLabel/AvatarLabel.types.js +1 -1
- package/dist/Cell/Copyable/Copyable.styles.d.ts +2 -2
- package/dist/Cell/Copyable/Copyable.styles.js +9 -15
- package/dist/Cell/Copyable/Copyable.types.d.ts +1 -1
- package/dist/Cell/Copyable/Copyable.types.js +1 -1
- package/dist/Cell/Copyable/CopyableCell.d.ts +2 -2
- package/dist/Cell/Copyable/CopyableCell.js +23 -27
- package/dist/Cell/Editable/EditableCell.d.ts +2 -2
- package/dist/Cell/Editable/EditableCell.js +26 -39
- package/dist/Cell/Editable/EditableCell.styles.d.ts +2 -2
- package/dist/Cell/Editable/EditableCell.styles.js +9 -7
- package/dist/Cell/Editable/EditableCell.types.d.ts +1 -1
- package/dist/Cell/Editable/EditableCell.types.js +1 -1
- package/dist/Cell/FlagLabel/FlagLabelCell.d.ts +2 -2
- package/dist/Cell/FlagLabel/FlagLabelCell.js +15 -14
- package/dist/Cell/FlagLabel/FlagLabelCell.styles.d.ts +1 -1
- package/dist/Cell/FlagLabel/FlagLabelCell.styles.js +6 -3
- package/dist/Cell/FlagLabel/FlagLabelCell.types.d.ts +2 -2
- package/dist/Cell/FlagLabel/FlagLabelCell.types.js +1 -1
- package/dist/Cell/IconLabel/IconLabel.d.ts +2 -2
- package/dist/Cell/IconLabel/IconLabel.js +14 -15
- package/dist/Cell/IconLabel/IconLabel.styles.d.ts +1 -1
- package/dist/Cell/IconLabel/IconLabel.styles.js +7 -6
- package/dist/Cell/IconLabel/IconLabel.types.d.ts +3 -3
- package/dist/Cell/IconLabel/IconLabel.types.js +1 -1
- package/dist/Cell/IconTooltipCell/IconTooltipCell.d.ts +2 -2
- package/dist/Cell/IconTooltipCell/IconTooltipCell.js +18 -23
- package/dist/Cell/IconTooltipCell/IconTooltipCell.styles.d.ts +2 -2
- package/dist/Cell/IconTooltipCell/IconTooltipCell.styles.js +9 -11
- package/dist/Cell/IconTooltipCell/IconTooltipCell.types.d.ts +4 -4
- package/dist/Cell/IconTooltipCell/IconTooltipCell.types.js +1 -1
- package/dist/Cell/InputNumber/InputNumberCell.d.ts +2 -2
- package/dist/Cell/InputNumber/InputNumberCell.js +10 -17
- package/dist/Cell/InputNumber/InputNumberCell.styles.d.ts +1 -1
- package/dist/Cell/InputNumber/InputNumberCell.styles.js +9 -5
- package/dist/Cell/InputNumber/InputNumberCell.types.d.ts +2 -2
- package/dist/Cell/InputNumber/InputNumberCell.types.js +1 -1
- package/dist/Cell/LabelsWithShowMore/LabelsWithShowMore.d.ts +3 -3
- package/dist/Cell/LabelsWithShowMore/LabelsWithShowMore.js +29 -40
- package/dist/Cell/LabelsWithShowMore/LabelsWithShowMore.styles.d.ts +3 -3
- package/dist/Cell/LabelsWithShowMore/LabelsWithShowMore.styles.js +11 -8
- package/dist/Cell/LabelsWithShowMore/LabelsWithShowMore.types.d.ts +2 -2
- package/dist/Cell/LabelsWithShowMore/LabelsWithShowMore.types.js +1 -1
- package/dist/Cell/LabelsWithShowMore/Modal/Modal.d.ts +2 -2
- package/dist/Cell/LabelsWithShowMore/Modal/Modal.js +35 -64
- package/dist/Cell/LabelsWithShowMore/Modal/Modal.types.d.ts +3 -3
- package/dist/Cell/LabelsWithShowMore/Modal/Modal.types.js +1 -1
- package/dist/Cell/Star/StarCell.d.ts +45 -45
- package/dist/Cell/Star/StarCell.js +25 -31
- package/dist/Cell/Star/StarCell.styles.d.ts +2 -2
- package/dist/Cell/Star/StarCell.styles.js +11 -9
- package/dist/Cell/Star/StarCell.types.d.ts +2 -2
- package/dist/Cell/Star/StarCell.types.js +1 -1
- package/dist/Cell/StatusLabel/StatusLabel.d.ts +2 -2
- package/dist/Cell/StatusLabel/StatusLabel.js +17 -19
- package/dist/Cell/StatusLabel/StatusLabel.styles.d.ts +2 -2
- package/dist/Cell/StatusLabel/StatusLabel.styles.js +9 -9
- package/dist/Cell/StatusLabel/StatusLabel.types.d.ts +3 -3
- package/dist/Cell/StatusLabel/StatusLabel.types.js +1 -1
- package/dist/Cell/TagIcon/TagIcon.d.ts +2 -2
- package/dist/Cell/TagIcon/TagIcon.js +9 -13
- package/dist/Cell/TagIcon/TagIcon.styles.d.ts +1 -1
- package/dist/Cell/TagIcon/TagIcon.styles.js +7 -6
- package/dist/Cell/TagIcon/TagIcon.types.d.ts +2 -2
- package/dist/Cell/TagIcon/TagIcon.types.js +1 -1
- package/dist/Cell/TagsGroup/TagsGroup.d.ts +2 -2
- package/dist/Cell/TagsGroup/TagsGroup.js +22 -39
- package/dist/Cell/TagsGroup/TagsGroup.styles.d.ts +2 -2
- package/dist/Cell/TagsGroup/TagsGroup.styles.js +30 -9
- package/dist/Cell/TagsGroup/TagsGroup.types.d.ts +2 -2
- package/dist/Cell/TagsGroup/TagsGroup.types.js +1 -1
- package/dist/Cell/index.d.ts +12 -12
- package/dist/Cell/index.js +28 -14
- package/dist/ColumnSortMenu/SortIcons.d.ts +2 -2
- package/dist/ColumnSortMenu/SortIcons.js +26 -38
- package/dist/ColumnSortMenu/SortRender.styles.d.ts +34 -34
- package/dist/ColumnSortMenu/SortRender.styles.js +13 -10
- package/dist/ColumnSortMenu/SortRenderer.d.ts +2 -2
- package/dist/ColumnSortMenu/SortRenderer.js +74 -108
- package/dist/ColumnSortMenu/TitleWithSort.d.ts +2 -2
- package/dist/ColumnSortMenu/TitleWithSort.js +19 -16
- package/dist/ColumnSortMenu/columnWithSortButtons.d.ts +1 -2
- package/dist/ColumnSortMenu/columnWithSortButtons.js +26 -43
- package/dist/ColumnSortMenu/groupedColumnsSort.d.ts +3 -3
- package/dist/ColumnSortMenu/groupedColumnsSort.js +33 -28
- package/dist/ColumnSortMenu/replaceSortButtons.d.ts +1 -1
- package/dist/ColumnSortMenu/replaceSortButtons.js +14 -15
- package/dist/ColumnSortMenu/useSortState.d.ts +1 -1
- package/dist/ColumnSortMenu/useSortState.js +95 -93
- package/dist/DefaultTable/DefaultTable.d.ts +2 -2
- package/dist/DefaultTable/DefaultTable.js +147 -148
- package/dist/FilterTrigger/FilterTrigger.d.ts +2 -2
- package/dist/FilterTrigger/FilterTrigger.js +42 -67
- package/dist/FilterTrigger/FilterTrigger.styles.d.ts +53 -53
- package/dist/FilterTrigger/FilterTrigger.styles.js +19 -32
- package/dist/FilterTrigger/FilterTrigger.types.d.ts +1 -1
- package/dist/FilterTrigger/FilterTrigger.types.js +1 -1
- package/dist/GroupTable/GroupTable.d.ts +3 -4
- package/dist/GroupTable/GroupTable.js +97 -118
- package/dist/GroupTable/GroupTable.styles.d.ts +25 -25
- package/dist/GroupTable/GroupTable.styles.js +40 -37
- package/dist/GroupTable/GroupTable.types.d.ts +1 -1
- package/dist/GroupTable/GroupTable.types.js +9 -6
- package/dist/GroupTable/GroupTableBody/GroupTableBody.d.ts +1 -1
- package/dist/GroupTable/GroupTableBody/GroupTableBody.js +83 -107
- package/dist/GroupTable/GroupTableBody/GroupTableBody.types.d.ts +3 -3
- package/dist/GroupTable/GroupTableBody/GroupTableBody.types.js +1 -1
- package/dist/GroupTable/GroupTableHeader/GroupTableHeader.d.ts +1 -1
- package/dist/GroupTable/GroupTableHeader/GroupTableHeader.js +25 -28
- package/dist/GroupTable/GroupTableHeader/GroupTableHeader.types.js +1 -1
- package/dist/InfiniteScroll/BackToTopButton.d.ts +2 -2
- package/dist/InfiniteScroll/BackToTopButton.js +7 -15
- package/dist/InfiniteScroll/BackToTopButton.styles.d.ts +34 -34
- package/dist/InfiniteScroll/BackToTopButton.styles.js +11 -9
- package/dist/InfiniteScroll/ErrorItem.d.ts +1 -1
- package/dist/InfiniteScroll/ErrorItem.js +19 -23
- package/dist/InfiniteScroll/ErrorItem.styles.d.ts +1 -1
- package/dist/InfiniteScroll/ErrorItem.styles.js +6 -3
- package/dist/InfiniteScroll/InfiniteLoaderItem.d.ts +2 -2
- package/dist/InfiniteScroll/InfiniteLoaderItem.js +33 -28
- package/dist/InfiniteScroll/InfiniteLoaderItem.styles.d.ts +1 -1
- package/dist/InfiniteScroll/InfiniteLoaderItem.styles.js +7 -4
- package/dist/InfiniteScroll/InfiniteLoaderItem.types.d.ts +1 -1
- package/dist/InfiniteScroll/InfiniteLoaderItem.types.js +1 -1
- package/dist/InfiniteScroll/LoadingItem.d.ts +1 -1
- package/dist/InfiniteScroll/LoadingItem.js +10 -10
- package/dist/InfiniteScroll/NoMoreItem.d.ts +1 -1
- package/dist/InfiniteScroll/NoMoreItem.js +10 -10
- package/dist/InfiniteScroll/OuterListElement.d.ts +1 -1
- package/dist/InfiniteScroll/OuterListElement.js +45 -58
- package/dist/InfiniteScroll/constants.js +4 -1
- package/dist/InfiniteScroll/utils.d.ts +1 -1
- package/dist/InfiniteScroll/utils.js +15 -12
- package/dist/ItemsMenu/ItemsMenu.d.ts +2 -2
- package/dist/ItemsMenu/ItemsMenu.js +7 -6
- package/dist/ItemsMenu/ItemsMenu.styles.d.ts +1 -1
- package/dist/ItemsMenu/ItemsMenu.styles.js +6 -3
- package/dist/ItemsMenu/ItemsMenu.types.d.ts +1 -1
- package/dist/ItemsMenu/ItemsMenu.types.js +1 -1
- package/dist/RowSelection/RowSelectionColumn.d.ts +3 -3
- package/dist/RowSelection/RowSelectionColumn.js +77 -81
- package/dist/RowSelection/RowSelectionColumn.types.d.ts +3 -3
- package/dist/RowSelection/RowSelectionColumn.types.js +1 -1
- package/dist/RowSelection/index.js +4 -1
- package/dist/Table.d.ts +2 -4
- package/dist/Table.js +94 -129
- package/dist/Table.styles.d.ts +23 -23
- package/dist/Table.styles.js +86 -110
- package/dist/Table.types.d.ts +7 -7
- package/dist/Table.types.js +1 -1
- package/dist/TableHeader/TableHeader.d.ts +2 -2
- package/dist/TableHeader/TableHeader.js +91 -129
- package/dist/TableHeader/TableHeader.types.d.ts +2 -2
- package/dist/TableHeader/TableHeader.types.js +1 -1
- package/dist/TableHeader/TableLimit/TableLimit.d.ts +2 -2
- package/dist/TableHeader/TableLimit/TableLimit.js +44 -36
- package/dist/TableHeader/TableLimit/TableLimit.styles.d.ts +4 -4
- package/dist/TableHeader/TableLimit/TableLimit.styles.js +15 -13
- package/dist/TableHeader/TableLimit/TableLimit.types.d.ts +3 -3
- package/dist/TableHeader/TableLimit/TableLimit.types.js +1 -1
- package/dist/TableHeader/TableLimit/index.js +4 -2
- package/dist/TableHeader/TableSelection.d.ts +2 -2
- package/dist/TableHeader/TableSelection.js +163 -180
- package/dist/TableHeader/TableSelection.types.d.ts +1 -1
- package/dist/TableHeader/TableSelection.types.js +1 -1
- package/dist/TreeTable/TreeTable.d.ts +2 -3
- package/dist/TreeTable/TreeTable.js +51 -78
- package/dist/TreeTable/TreeTable.styles.d.ts +5 -5
- package/dist/TreeTable/TreeTable.styles.js +21 -20
- package/dist/VirtualTable/VirtualTable.d.ts +3 -3
- package/dist/VirtualTable/VirtualTable.js +342 -411
- package/dist/VirtualTable/VirtualTable.styles.d.ts +8 -8
- package/dist/VirtualTable/VirtualTable.styles.js +30 -40
- package/dist/VirtualTable/VirtualTable.types.d.ts +4 -4
- package/dist/VirtualTable/VirtualTable.types.js +1 -1
- package/dist/VirtualTable/VirtualTableRow.d.ts +4 -4
- package/dist/VirtualTable/VirtualTableRow.js +103 -111
- package/dist/VirtualTable/constants.js +8 -3
- package/dist/assets/style/index-tn0RQdqM.css +0 -0
- package/dist/constants/Table.constants.js +11 -6
- package/dist/constants/TableSkeleton.constants.d.ts +1 -1
- package/dist/constants/TableSkeleton.constants.js +48 -100
- package/dist/hooks/useBulkSelection/index.js +4 -1
- package/dist/hooks/useBulkSelection/useBulkSelection.d.ts +1 -1
- package/dist/hooks/useBulkSelection/useBulkSelection.js +55 -40
- package/dist/hooks/useRowKey/index.js +4 -1
- package/dist/hooks/useRowKey/useRowKey.js +11 -11
- package/dist/hooks/useRowStar/index.js +4 -2
- package/dist/hooks/useRowStar/useRowStar.d.ts +1 -1
- package/dist/hooks/useRowStar/useRowStar.js +54 -62
- package/dist/hooks/useRowStar/useRowStar.types.d.ts +2 -2
- package/dist/hooks/useRowStar/useRowStar.types.js +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +18 -9
- package/dist/modules.d.js +1 -1
- package/dist/modules.d.ts +0 -0
- package/dist/utils/calculateColumnWidths.d.ts +1 -1
- package/dist/utils/calculateColumnWidths.js +17 -16
- package/dist/utils/calculatePixels.js +11 -12
- package/dist/utils/columnWithCellTooltip.d.ts +1 -1
- package/dist/utils/columnWithCellTooltip.js +18 -15
- package/dist/utils/getChildrenColumnName.js +6 -3
- package/dist/utils/getRecordSelectionStatus.d.ts +1 -1
- package/dist/utils/getRecordSelectionStatus.js +11 -7
- package/dist/utils/getSkeletonProps.d.ts +1 -1
- package/dist/utils/getSkeletonProps.js +26 -36
- package/dist/utils/getValueFromPath.js +9 -6
- package/dist/utils/index.js +23 -9
- package/dist/utils/isGrouped.d.ts +1 -1
- package/dist/utils/isGrouped.js +6 -3
- package/dist/utils/isRecordSelectable.d.ts +1 -1
- package/dist/utils/isRecordSelectable.js +10 -6
- package/dist/utils/locale.d.ts +3 -3
- package/dist/utils/locale.js +115 -111
- package/package.json +31 -31
- package/dist/Cell/TagsGroup/TagsGroup.spec.d.ts +0 -1
- package/dist/ColumnSortMenu/__spec__/groupedColumnsSort.spec.d.ts +0 -1
- package/dist/VirtualTable/VirtualTable.spec.d.ts +0 -1
- package/dist/utils/__specs__/getValueFromPath.spec.d.ts +0 -1
|
@@ -1,44 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import Button from
|
|
4
|
-
import { DropdownMenu } from
|
|
5
|
-
import Icon, { OptionVerticalM } from
|
|
6
|
-
import Tooltip from
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import { useBulkSelectionCount } from
|
|
10
|
-
import { useRowKey } from
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useMemo } from "react";
|
|
3
|
+
import Button from "@synerise/ds-button";
|
|
4
|
+
import { DropdownMenu } from "@synerise/ds-dropdown";
|
|
5
|
+
import Icon, { OptionVerticalM } from "@synerise/ds-icon";
|
|
6
|
+
import Tooltip from "@synerise/ds-tooltip";
|
|
7
|
+
import { Selection } from "../Table.styles.js";
|
|
8
|
+
import { SELECTION_INVERT, SELECTION_ALL } from "../constants/Table.constants.js";
|
|
9
|
+
import { useBulkSelectionCount } from "../hooks/useBulkSelection/useBulkSelection.js";
|
|
10
|
+
import { useRowKey } from "../hooks/useRowKey/useRowKey.js";
|
|
11
|
+
import "unit-to-px";
|
|
12
|
+
import "@synerise/ds-skeleton";
|
|
13
|
+
import "uuid";
|
|
14
|
+
import "styled-components";
|
|
15
|
+
import "@synerise/ds-typography";
|
|
16
|
+
import "ramda";
|
|
17
|
+
import { isRecordSelectable } from "../utils/isRecordSelectable.js";
|
|
18
|
+
import "../utils/locale.js";
|
|
19
|
+
const TableSelection = ({
|
|
20
|
+
dataSource,
|
|
21
|
+
dataSourceFull,
|
|
22
|
+
selection,
|
|
23
|
+
rowKey,
|
|
24
|
+
locale,
|
|
25
|
+
hasSelectionLimit,
|
|
26
|
+
childrenColumnName
|
|
27
|
+
}) => {
|
|
28
|
+
const {
|
|
29
|
+
getRowKey
|
|
30
|
+
} = useRowKey(rowKey);
|
|
31
|
+
const allData = dataSourceFull || dataSource;
|
|
32
|
+
const isShowingSubset = dataSourceFull && dataSourceFull.length !== dataSource.length;
|
|
33
|
+
const getRowsForKeys = useCallback((keys) => {
|
|
26
34
|
if (selection) {
|
|
27
|
-
|
|
28
|
-
allData.forEach(
|
|
29
|
-
|
|
35
|
+
let rows = [];
|
|
36
|
+
allData.forEach((record) => {
|
|
37
|
+
const rowChildren = record[childrenColumnName];
|
|
30
38
|
if (Array.isArray(rowChildren)) {
|
|
31
|
-
rowChildren.forEach(
|
|
32
|
-
|
|
39
|
+
rowChildren.forEach((child) => {
|
|
40
|
+
const key = getRowKey(child);
|
|
33
41
|
if (rowChildren && key && keys.includes(key)) {
|
|
34
|
-
rows = [
|
|
42
|
+
rows = [...rows, record];
|
|
35
43
|
}
|
|
36
44
|
});
|
|
37
45
|
}
|
|
38
46
|
if (!Array.isArray(rowChildren) || selection.independentSelectionExpandedRows) {
|
|
39
|
-
|
|
47
|
+
const key = getRowKey(record);
|
|
40
48
|
if (key && keys.includes(key)) {
|
|
41
|
-
rows = [
|
|
49
|
+
rows = [...rows, record];
|
|
42
50
|
}
|
|
43
51
|
}
|
|
44
52
|
});
|
|
@@ -46,211 +54,186 @@ var TableSelection = function TableSelection(_ref) {
|
|
|
46
54
|
}
|
|
47
55
|
return [];
|
|
48
56
|
}, [allData, getRowKey, selection, childrenColumnName]);
|
|
49
|
-
|
|
57
|
+
const selectAll = useCallback(() => {
|
|
50
58
|
if (dataSource && selection) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
checkRowSelectionStatus
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
59
|
+
const {
|
|
60
|
+
selectedRowKeys,
|
|
61
|
+
checkRowSelectionStatus
|
|
62
|
+
} = selection;
|
|
63
|
+
let keys = isShowingSubset ? [...selectedRowKeys] : [];
|
|
64
|
+
dataSource.forEach((record) => {
|
|
65
|
+
const rowChildren = record[childrenColumnName];
|
|
57
66
|
if (Array.isArray(rowChildren)) {
|
|
58
|
-
keys = [
|
|
59
|
-
|
|
60
|
-
return key && (isRecordSelectable(child, checkRowSelectionStatus) || selectedRowKeys.includes(key)) ? [
|
|
61
|
-
}, [])
|
|
67
|
+
keys = [...keys, ...rowChildren.reduce((acc, child) => {
|
|
68
|
+
const key = getRowKey(child);
|
|
69
|
+
return key && (isRecordSelectable(child, checkRowSelectionStatus) || selectedRowKeys.includes(key)) ? [...acc, key] : acc;
|
|
70
|
+
}, [])];
|
|
62
71
|
}
|
|
63
72
|
if (!Array.isArray(rowChildren) || selection.independentSelectionExpandedRows) {
|
|
64
|
-
|
|
65
|
-
keys = key !==
|
|
73
|
+
const key = getRowKey(record);
|
|
74
|
+
keys = key !== void 0 && (isRecordSelectable(record, checkRowSelectionStatus) || selectedRowKeys.includes(key)) ? [...keys, key] : [...keys];
|
|
66
75
|
}
|
|
67
76
|
});
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
77
|
+
const uniqueKeys = Array.from(new Set(keys));
|
|
78
|
+
const rows = getRowsForKeys(uniqueKeys);
|
|
79
|
+
selection.globalSelection?.onChange(false);
|
|
71
80
|
selection.onChange(uniqueKeys, rows);
|
|
72
81
|
}
|
|
73
82
|
}, [childrenColumnName, dataSource, selection, isShowingSubset, getRowsForKeys, getRowKey]);
|
|
74
|
-
|
|
83
|
+
const unselectAll = useCallback(() => {
|
|
75
84
|
if (selection) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
const {
|
|
86
|
+
selectedRowKeys,
|
|
87
|
+
checkRowSelectionStatus
|
|
88
|
+
} = selection;
|
|
89
|
+
let keysToUnselect = [];
|
|
90
|
+
dataSource.forEach((record) => {
|
|
91
|
+
const rowChildren = record[childrenColumnName];
|
|
81
92
|
if (Array.isArray(rowChildren)) {
|
|
82
|
-
keysToUnselect = [
|
|
83
|
-
|
|
84
|
-
return key && isRecordSelectable(child, checkRowSelectionStatus) ? [
|
|
85
|
-
}, [])
|
|
93
|
+
keysToUnselect = [...keysToUnselect, ...rowChildren.reduce((acc, child) => {
|
|
94
|
+
const key = getRowKey(child);
|
|
95
|
+
return key && isRecordSelectable(child, checkRowSelectionStatus) ? [...acc, key] : acc;
|
|
96
|
+
}, [])];
|
|
86
97
|
}
|
|
87
98
|
if (!Array.isArray(rowChildren) || selection.independentSelectionExpandedRows) {
|
|
88
|
-
|
|
89
|
-
keysToUnselect = key !==
|
|
99
|
+
const key = getRowKey(record);
|
|
100
|
+
keysToUnselect = key !== void 0 && isRecordSelectable(record, checkRowSelectionStatus) ? [...keysToUnselect, key] : [...keysToUnselect];
|
|
90
101
|
}
|
|
91
102
|
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
});
|
|
95
|
-
var rows = getRowsForKeys(keysLeft);
|
|
103
|
+
const keysLeft = selectedRowKeys.filter((key) => !keysToUnselect.includes(key));
|
|
104
|
+
const rows = getRowsForKeys(keysLeft);
|
|
96
105
|
selection.onChange(keysLeft, rows);
|
|
97
106
|
}
|
|
98
107
|
}, [dataSource, getRowKey, getRowsForKeys, selection, childrenColumnName]);
|
|
99
|
-
|
|
100
|
-
var _selection$globalSele2;
|
|
108
|
+
const selectGlobalAll = useCallback(() => {
|
|
101
109
|
unselectAll();
|
|
102
|
-
|
|
110
|
+
selection.globalSelection?.onChange(true);
|
|
103
111
|
}, [unselectAll, selection.globalSelection]);
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
(_selection$globalSele3 = selection.globalSelection) == null || _selection$globalSele3.onChange(false);
|
|
112
|
+
const unselectGlobalAll = useCallback(() => {
|
|
113
|
+
selection.globalSelection?.onChange(false);
|
|
107
114
|
}, [selection.globalSelection]);
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return children ? children.filter(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}, [getRowKey, selection == null ? void 0 : selection.checkRowSelectionStatus]);
|
|
114
|
-
var selectInvert = useCallback(function () {
|
|
115
|
+
const getSelectableChildren = useCallback((children) => {
|
|
116
|
+
const selectionStatusValidator = selection?.checkRowSelectionStatus || void 0;
|
|
117
|
+
return children ? children.filter((child) => isRecordSelectable(child, selectionStatusValidator) && getRowKey(child) !== void 0) : [];
|
|
118
|
+
}, [getRowKey, selection?.checkRowSelectionStatus]);
|
|
119
|
+
const selectInvert = useCallback(() => {
|
|
115
120
|
if (dataSource && selection) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
const {
|
|
122
|
+
selectedRowKeys,
|
|
123
|
+
checkRowSelectionStatus
|
|
124
|
+
} = selection;
|
|
125
|
+
let keys = [...selectedRowKeys];
|
|
126
|
+
dataSource.forEach((record) => {
|
|
127
|
+
const rowChildren = record[childrenColumnName];
|
|
128
|
+
const hasChildren = Array.isArray(rowChildren);
|
|
129
|
+
const selectableChildren = hasChildren ? getSelectableChildren(rowChildren) : false;
|
|
123
130
|
if (selectableChildren) {
|
|
124
|
-
selectableChildren.forEach(
|
|
125
|
-
|
|
131
|
+
selectableChildren.forEach((child) => {
|
|
132
|
+
const key = getRowKey(child);
|
|
126
133
|
if (selectedRowKeys.includes(key)) {
|
|
127
134
|
keys.splice(keys.indexOf(key), 1);
|
|
128
135
|
} else {
|
|
129
|
-
keys = [
|
|
136
|
+
keys = [...keys, key];
|
|
130
137
|
}
|
|
131
138
|
});
|
|
132
139
|
}
|
|
133
140
|
if (!selectableChildren || selection.independentSelectionExpandedRows) {
|
|
134
|
-
|
|
135
|
-
|
|
141
|
+
const key = getRowKey(record);
|
|
142
|
+
const isSelectable = isRecordSelectable(record, checkRowSelectionStatus);
|
|
136
143
|
if (!isSelectable) {
|
|
137
144
|
return;
|
|
138
145
|
}
|
|
139
146
|
if (selectedRowKeys.includes(key)) {
|
|
140
147
|
keys.splice(keys.indexOf(key), 1);
|
|
141
148
|
} else {
|
|
142
|
-
keys = [
|
|
149
|
+
keys = [...keys, key];
|
|
143
150
|
}
|
|
144
151
|
}
|
|
145
152
|
});
|
|
146
|
-
|
|
153
|
+
const rows = getRowsForKeys(keys);
|
|
147
154
|
selection.onChange(keys, rows);
|
|
148
155
|
}
|
|
149
156
|
}, [childrenColumnName, dataSource, selection, getRowsForKeys, getSelectableChildren, getRowKey]);
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
157
|
+
const {
|
|
158
|
+
allRecordsCount,
|
|
159
|
+
selectableRecordsCount,
|
|
160
|
+
selectableAndSelectedRecordsCount,
|
|
161
|
+
selectedRecordsCount
|
|
162
|
+
} = useBulkSelectionCount({
|
|
163
|
+
dataSource,
|
|
164
|
+
selection,
|
|
165
|
+
childrenColumnName,
|
|
166
|
+
rowKey
|
|
167
|
+
});
|
|
168
|
+
const isIndeterminate = selectedRecordsCount > 0 && selectableRecordsCount !== selectableAndSelectedRecordsCount;
|
|
169
|
+
const disabledBulkSelection = allRecordsCount === 0 || selectableRecordsCount === 0 || hasSelectionLimit && selectedRecordsCount === 0;
|
|
170
|
+
const isAllSelected = !disabledBulkSelection && selectableRecordsCount === selectableAndSelectedRecordsCount;
|
|
171
|
+
const isAnySelected = allRecordsCount > 0 && selectedRecordsCount > 0;
|
|
172
|
+
const selectionTooltipTitle = useMemo(() => {
|
|
165
173
|
if (selection.globalSelection) {
|
|
166
|
-
return selection.globalSelection.isSelected ? locale
|
|
174
|
+
return selection.globalSelection.isSelected ? locale?.unselectGlobalAll : locale?.selectGlobalAll;
|
|
167
175
|
}
|
|
168
|
-
return isAllSelected ? locale
|
|
169
|
-
}, [isAllSelected, locale
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
var globalSelectionItem = selection.globalSelection ? [isGlobalAllSelected ? {
|
|
176
|
+
return isAllSelected ? locale?.unselectAll : locale?.selectAllTooltip;
|
|
177
|
+
}, [isAllSelected, locale?.selectAllTooltip, locale?.selectGlobalAll, locale?.unselectAll, locale?.unselectGlobalAll, selection.globalSelection]);
|
|
178
|
+
const dropdownDataSource = useMemo(() => {
|
|
179
|
+
const isGlobalAllSelected = selection.globalSelection?.isSelected;
|
|
180
|
+
const globalSelectionItem = selection.globalSelection ? [isGlobalAllSelected ? {
|
|
174
181
|
onClick: unselectGlobalAll,
|
|
175
|
-
text: locale
|
|
182
|
+
text: locale?.unselectGlobalAll
|
|
176
183
|
} : {
|
|
177
184
|
onClick: selectGlobalAll,
|
|
178
|
-
text: locale
|
|
185
|
+
text: locale?.selectGlobalAll
|
|
179
186
|
}] : [];
|
|
180
|
-
|
|
187
|
+
const menuItems = selection?.selections?.filter(Boolean).flatMap((selectionMenuElement) => {
|
|
181
188
|
switch (selectionMenuElement) {
|
|
182
|
-
case SELECTION_ALL:
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
if (isAnySelected) {
|
|
192
|
-
items.push({
|
|
193
|
-
onClick: unselectAll,
|
|
194
|
-
text: locale == null ? void 0 : locale.unselectAll
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
return items;
|
|
198
|
-
}
|
|
199
|
-
case SELECTION_INVERT:
|
|
200
|
-
{
|
|
201
|
-
return !hasSelectionLimit ? {
|
|
202
|
-
onClick: selectInvert,
|
|
203
|
-
text: locale == null ? void 0 : locale.selectInvert
|
|
204
|
-
} : [];
|
|
189
|
+
case SELECTION_ALL: {
|
|
190
|
+
const items = [];
|
|
191
|
+
if (!isAllSelected && !hasSelectionLimit) {
|
|
192
|
+
items.push({
|
|
193
|
+
onClick: selectAll,
|
|
194
|
+
text: locale?.selectAll
|
|
195
|
+
});
|
|
205
196
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
text: sel.label
|
|
197
|
+
if (isAnySelected) {
|
|
198
|
+
items.push({
|
|
199
|
+
onClick: unselectAll,
|
|
200
|
+
text: locale?.unselectAll
|
|
211
201
|
});
|
|
212
202
|
}
|
|
203
|
+
return items;
|
|
204
|
+
}
|
|
205
|
+
case SELECTION_INVERT: {
|
|
206
|
+
return !hasSelectionLimit ? {
|
|
207
|
+
onClick: selectInvert,
|
|
208
|
+
text: locale?.selectInvert
|
|
209
|
+
} : [];
|
|
210
|
+
}
|
|
211
|
+
default: {
|
|
212
|
+
const sel = selectionMenuElement;
|
|
213
|
+
return {
|
|
214
|
+
...sel,
|
|
215
|
+
text: sel.label
|
|
216
|
+
};
|
|
217
|
+
}
|
|
213
218
|
}
|
|
214
219
|
});
|
|
215
|
-
return [
|
|
216
|
-
}, [selection.globalSelection, selection
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
var isSelected = (_selection$globalSele5 = (_selection$globalSele6 = selection.globalSelection) == null ? void 0 : _selection$globalSele6.isSelected) != null ? _selection$globalSele5 : isAllSelected;
|
|
220
|
+
return [...globalSelectionItem, ...menuItems || []];
|
|
221
|
+
}, [selection.globalSelection, selection?.selections, unselectGlobalAll, locale?.unselectGlobalAll, locale?.selectGlobalAll, locale?.selectAll, locale?.unselectAll, locale?.selectInvert, selectGlobalAll, isAllSelected, hasSelectionLimit, isAnySelected, selectAll, unselectAll, selectInvert]);
|
|
222
|
+
const handleBatchSelectionChange = () => {
|
|
223
|
+
const isSelected = selection.globalSelection?.isSelected ?? isAllSelected;
|
|
220
224
|
if (selection.globalSelection) {
|
|
221
225
|
isSelected ? unselectGlobalAll() : selectGlobalAll();
|
|
222
226
|
} else {
|
|
223
227
|
isSelected ? unselectAll() : selectAll();
|
|
224
228
|
}
|
|
225
229
|
};
|
|
226
|
-
return selection
|
|
227
|
-
"data-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
indeterminate: isIndeterminate
|
|
236
|
-
})), selection.selections && /*#__PURE__*/React.createElement(DropdownMenu, {
|
|
237
|
-
disabled: disabledBulkSelection || (dropdownDataSource == null ? void 0 : dropdownDataSource.length) === 0,
|
|
238
|
-
getPopupContainer: function getPopupContainer() {
|
|
239
|
-
return document.body;
|
|
240
|
-
},
|
|
241
|
-
dataSource: dropdownDataSource || [],
|
|
242
|
-
popoverProps: {
|
|
243
|
-
testId: 'table-selection'
|
|
244
|
-
}
|
|
245
|
-
}, /*#__PURE__*/React.createElement(Tooltip, {
|
|
246
|
-
title: locale == null ? void 0 : locale.selectionOptionsTooltip
|
|
247
|
-
}, /*#__PURE__*/React.createElement(Button, {
|
|
248
|
-
disabled: disabledBulkSelection || (dropdownDataSource == null ? void 0 : dropdownDataSource.length) === 0,
|
|
249
|
-
mode: "single-icon",
|
|
250
|
-
type: "ghost",
|
|
251
|
-
"data-testid": "ds-table-batch-selection-options"
|
|
252
|
-
}, /*#__PURE__*/React.createElement(Icon, {
|
|
253
|
-
component: /*#__PURE__*/React.createElement(OptionVerticalM, null)
|
|
254
|
-
}))))) : null;
|
|
230
|
+
return selection?.selectedRowKeys ? /* @__PURE__ */ jsxs(Selection, { "data-popup-container": true, children: [
|
|
231
|
+
!hasSelectionLimit && /* @__PURE__ */ jsx(Tooltip, { title: selectionTooltipTitle, children: /* @__PURE__ */ jsx(Button.Checkbox, { disabled: disabledBulkSelection, "data-testid": "ds-table-batch-selection-button", checked: selection.globalSelection?.isSelected || isAllSelected, onChange: handleBatchSelectionChange, indeterminate: isIndeterminate }) }),
|
|
232
|
+
selection.selections && /* @__PURE__ */ jsx(DropdownMenu, { disabled: disabledBulkSelection || dropdownDataSource?.length === 0, getPopupContainer: () => document.body, dataSource: dropdownDataSource || [], popoverProps: {
|
|
233
|
+
testId: "table-selection"
|
|
234
|
+
}, children: /* @__PURE__ */ jsx(Tooltip, { title: locale?.selectionOptionsTooltip, children: /* @__PURE__ */ jsx(Button, { disabled: disabledBulkSelection || dropdownDataSource?.length === 0, mode: "single-icon", type: "ghost", "data-testid": "ds-table-batch-selection-options", children: /* @__PURE__ */ jsx(Icon, { component: /* @__PURE__ */ jsx(OptionVerticalM, {}) }) }) }) })
|
|
235
|
+
] }) : null;
|
|
236
|
+
};
|
|
237
|
+
export {
|
|
238
|
+
TableSelection as default
|
|
255
239
|
};
|
|
256
|
-
export default TableSelection;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import '
|
|
3
|
-
import { type DSTableProps } from '../Table.types';
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { DSTableProps } from '../Table.types';
|
|
4
3
|
declare function TreeTable<T extends object = any>(props: DSTableProps<T>): React.ReactElement;
|
|
5
4
|
export default TreeTable;
|
|
@@ -1,83 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
import classNames from
|
|
3
|
-
import React from
|
|
4
|
-
import { v4
|
|
5
|
-
import Button from
|
|
6
|
-
import { theme } from
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
var INDENT_SIZE = 42;
|
|
12
|
-
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import classNames from "classnames";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { v4 } from "uuid";
|
|
5
|
+
import Button from "@synerise/ds-button";
|
|
6
|
+
import { theme } from "@synerise/ds-core";
|
|
7
|
+
import Icon, { ChildRowLeftDownM } from "@synerise/ds-icon";
|
|
8
|
+
import DSTable from "../Table.js";
|
|
9
|
+
import { TreeTableRow, Indent, TreeTableCell, Indents, RowExpander } from "./TreeTable.styles.js";
|
|
10
|
+
const INDENT_SIZE = 42;
|
|
14
11
|
function TreeTable(props) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return
|
|
21
|
-
className: row.className + " ds-table-row"
|
|
22
|
-
}, row.children);
|
|
12
|
+
const {
|
|
13
|
+
className,
|
|
14
|
+
selection
|
|
15
|
+
} = props;
|
|
16
|
+
const RenderRow = React.useCallback((row) => {
|
|
17
|
+
return /* @__PURE__ */ jsx(TreeTableRow, { className: `${row.className} ds-table-row`, children: row.children });
|
|
23
18
|
}, []);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
})) == null ? void 0 : _cell$children$.split('-').pop();
|
|
31
|
-
if (indentLevel === undefined) {
|
|
32
|
-
return /*#__PURE__*/React.createElement("td", {
|
|
33
|
-
className: cell.className
|
|
34
|
-
}, cell.children);
|
|
35
|
-
}
|
|
36
|
-
var maxIndent = parseInt(indentLevel, 10);
|
|
37
|
-
var indents = [].concat(new Array(maxIndent)).map(function (indentElement, index) {
|
|
38
|
-
return /*#__PURE__*/React.createElement(S.Indent, {
|
|
39
|
-
key: uuid(),
|
|
40
|
-
width: INDENT_SIZE,
|
|
41
|
-
level: index,
|
|
42
|
-
active: index + 1 === maxIndent
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
return /*#__PURE__*/React.createElement(S.TreeTableCell, {
|
|
46
|
-
className: cell.className + " ds-table-cell"
|
|
47
|
-
}, /*#__PURE__*/React.createElement(S.Indents, {
|
|
48
|
-
width: indents.length * INDENT_SIZE,
|
|
49
|
-
withSelection: Boolean(selection)
|
|
50
|
-
}, indents), cell.children);
|
|
51
|
-
}, [selection]);
|
|
52
|
-
return /*#__PURE__*/React.createElement(DSTable, _extends({}, props, {
|
|
53
|
-
indentSize: INDENT_SIZE,
|
|
54
|
-
components: {
|
|
55
|
-
body: {
|
|
56
|
-
row: RenderRow,
|
|
57
|
-
cell: RenderCell
|
|
19
|
+
const RenderCell = React.useCallback(
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
(cell) => {
|
|
22
|
+
const indentLevel = cell.children[0]?.props?.children[0]?.props?.className.split(" ").find((value) => value.includes("indent-level-"))?.split("-").pop();
|
|
23
|
+
if (indentLevel === void 0) {
|
|
24
|
+
return /* @__PURE__ */ jsx("td", { className: cell.className, children: cell.children });
|
|
58
25
|
}
|
|
26
|
+
const maxIndent = parseInt(indentLevel, 10);
|
|
27
|
+
const indents = [...new Array(maxIndent)].map((indentElement, index) => /* @__PURE__ */ jsx(Indent, { width: INDENT_SIZE, level: index, active: index + 1 === maxIndent }, v4()));
|
|
28
|
+
return /* @__PURE__ */ jsxs(TreeTableCell, { className: `${cell.className} ds-table-cell`, children: [
|
|
29
|
+
/* @__PURE__ */ jsx(Indents, { width: indents.length * INDENT_SIZE, withSelection: Boolean(selection), children: indents }),
|
|
30
|
+
cell.children
|
|
31
|
+
] });
|
|
59
32
|
},
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
})
|
|
81
|
-
}));
|
|
33
|
+
[selection]
|
|
34
|
+
);
|
|
35
|
+
return /* @__PURE__ */ jsx(DSTable, { ...props, indentSize: INDENT_SIZE, components: {
|
|
36
|
+
body: {
|
|
37
|
+
row: RenderRow,
|
|
38
|
+
cell: RenderCell
|
|
39
|
+
}
|
|
40
|
+
}, expandable: {
|
|
41
|
+
expandIconColumnIndex: 0
|
|
42
|
+
}, expandIcon: (expandIconProps) => {
|
|
43
|
+
const {
|
|
44
|
+
expandable,
|
|
45
|
+
expanded,
|
|
46
|
+
onExpand,
|
|
47
|
+
record
|
|
48
|
+
} = expandIconProps;
|
|
49
|
+
return expandable ? /* @__PURE__ */ jsx(RowExpander, { children: /* @__PURE__ */ jsx(Button.Expander, { expanded, onClick: (e) => onExpand(record, e) }) }) : /* @__PURE__ */ jsx(RowExpander, { children: /* @__PURE__ */ jsx(Icon, { component: /* @__PURE__ */ jsx(ChildRowLeftDownM, {}), color: theme.palette["grey-400"] }) });
|
|
50
|
+
}, className: classNames(className, "ds-tree-table", {
|
|
51
|
+
"ds-tree-table-with-selection": Boolean(selection)
|
|
52
|
+
}) });
|
|
82
53
|
}
|
|
83
|
-
export
|
|
54
|
+
export {
|
|
55
|
+
TreeTable as default
|
|
56
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export declare const Indents: import(
|
|
1
|
+
export declare const Indents: import('styled-components').StyledComponent<"div", any, {
|
|
2
2
|
width: number;
|
|
3
3
|
withSelection: boolean;
|
|
4
4
|
}, never>;
|
|
5
|
-
export declare const Indent: import(
|
|
5
|
+
export declare const Indent: import('styled-components').StyledComponent<"span", any, {
|
|
6
6
|
width: number;
|
|
7
7
|
active: boolean;
|
|
8
8
|
level: number;
|
|
9
9
|
}, never>;
|
|
10
|
-
export declare const RowExpander: import(
|
|
11
|
-
export declare const TreeTableRow: import(
|
|
12
|
-
export declare const TreeTableCell: import(
|
|
10
|
+
export declare const RowExpander: import('styled-components').StyledComponent<"span", any, {}, never>;
|
|
11
|
+
export declare const TreeTableRow: import('styled-components').StyledComponent<"tr", any, {}, never>;
|
|
12
|
+
export declare const TreeTableCell: import('styled-components').StyledComponent<"td", any, {}, never>;
|