es-grid-template 1.2.4 → 1.2.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/es/grid-component/AdvanceFilter.d.ts +10 -0
- package/es/grid-component/AdvanceFilter.js +544 -0
- package/es/grid-component/EditableCell.d.ts +1 -0
- package/es/grid-component/EditableCell.js +17 -2
- package/es/grid-component/InternalTable.js +2 -2
- package/es/grid-component/TableGrid.js +8 -5
- package/es/grid-component/hooks/content/HeaderContent.js +1 -1
- package/es/grid-component/hooks/utils.d.ts +1 -0
- package/es/grid-component/hooks/utils.js +6 -0
- package/es/grid-component/table/GridEdit.js +12 -3
- package/es/grid-component/type.d.ts +3 -1
- package/lib/grid-component/AdvanceFilter.d.ts +10 -0
- package/lib/grid-component/AdvanceFilter.js +554 -0
- package/lib/grid-component/EditableCell.d.ts +1 -0
- package/lib/grid-component/EditableCell.js +16 -2
- package/lib/grid-component/InternalTable.js +2 -2
- package/lib/grid-component/TableGrid.js +8 -5
- package/lib/grid-component/hooks/content/HeaderContent.js +1 -1
- package/lib/grid-component/hooks/utils.d.ts +1 -0
- package/lib/grid-component/hooks/utils.js +9 -2
- package/lib/grid-component/table/GridEdit.js +11 -2
- package/lib/grid-component/type.d.ts +3 -1
- package/package.json +1 -1
|
@@ -65,7 +65,7 @@ const HeaderContent = props => {
|
|
|
65
65
|
// style={{flex: 1}}
|
|
66
66
|
,
|
|
67
67
|
className: classnames('', {})
|
|
68
|
-
}), headerTemplate ? getTemplate(headerTemplate) : text), isOpen && (headerTooltip !== false || headerTemplate || headerTooltip || columnGroupText || headerText) && /*#__PURE__*/React.createElement(FloatingPortal, {
|
|
68
|
+
}), headerTemplate ? getTemplate(headerTemplate) : t ? t(text) : text), isOpen && (headerTooltip !== false || headerTemplate || headerTooltip || columnGroupText || headerText) && /*#__PURE__*/React.createElement(FloatingPortal, {
|
|
69
69
|
root: document.body
|
|
70
70
|
}, /*#__PURE__*/React.createElement(TooltipStyle, _extends({
|
|
71
71
|
className: "Tooltip",
|
|
@@ -68,3 +68,4 @@ export declare const removeColumns: <RecordType>(columns: ColumnsTable<RecordTyp
|
|
|
68
68
|
export declare const convertFlatColumn: (array: ColumnsTable) => ColumnsTable[];
|
|
69
69
|
export declare const convertColumns: <RecordType>(cols: ColumnsTable<RecordType>) => ColumnsTable<RecordType>;
|
|
70
70
|
export declare const checkChild: (inputArray: any[]) => boolean;
|
|
71
|
+
export declare const isEditable: <RecordType>(column: ColumnEditType, rowData: RecordType) => boolean | ((rowData: any) => boolean);
|
|
@@ -772,4 +772,10 @@ export const convertColumns = cols => {
|
|
|
772
772
|
};
|
|
773
773
|
export const checkChild = inputArray => {
|
|
774
774
|
return inputArray.some(item => item.children && item.children.length > 0);
|
|
775
|
+
};
|
|
776
|
+
export const isEditable = (column, rowData) => {
|
|
777
|
+
if (column && typeof column.editEnable === 'function') {
|
|
778
|
+
return column.editEnable(rowData);
|
|
779
|
+
}
|
|
780
|
+
return column?.editEnable;
|
|
775
781
|
};
|
|
@@ -13,7 +13,7 @@ import dayjs from "dayjs";
|
|
|
13
13
|
import 'dayjs/locale/es';
|
|
14
14
|
import 'dayjs/locale/vi';
|
|
15
15
|
import TableGrid from "../TableGrid";
|
|
16
|
-
import { addRows8, checkChild, findAllChildrenKeys, findItemByKey, flattenArray, flattenData, getDefaultValue, getEditType, getFirstSelectCell, getLastSelectCell, getRowNumber, getRowsPasteIndex, isObjEmpty, newGuid, totalFixedWidth, updateArrayByKey } from "../hooks";
|
|
16
|
+
import { addRows8, checkChild, findAllChildrenKeys, findItemByKey, flattenArray, flattenData, getDefaultValue, getEditType, getFirstSelectCell, getLastSelectCell, getRowNumber, getRowsPasteIndex, isEditable, isObjEmpty, newGuid, totalFixedWidth, updateArrayByKey } from "../hooks";
|
|
17
17
|
import Message from "../../Message/Message";
|
|
18
18
|
|
|
19
19
|
// import Command from "../Command";
|
|
@@ -49,6 +49,7 @@ const GridEdit = props => {
|
|
|
49
49
|
defaultValue,
|
|
50
50
|
expandable,
|
|
51
51
|
onCellClick,
|
|
52
|
+
rowEditable,
|
|
52
53
|
...rest
|
|
53
54
|
} = props;
|
|
54
55
|
const {
|
|
@@ -82,6 +83,7 @@ const GridEdit = props => {
|
|
|
82
83
|
const [editingKey, setEditingKey] = useState('');
|
|
83
84
|
const [selectedCells, setSelectedCells] = useState(new Set());
|
|
84
85
|
const [pasteCells, setPasteCells] = useState(new Set());
|
|
86
|
+
const [cellEditing, setCellEditing] = useState(null);
|
|
85
87
|
const [isSelectDragging, setSelectIsDragging] = useState(false);
|
|
86
88
|
const [isPasteDragging, setIsPasteDragging] = useState(false); // isPasteDragging == tiếp tục hiển thị con trỏ crosshair
|
|
87
89
|
|
|
@@ -1079,6 +1081,10 @@ const GridEdit = props => {
|
|
|
1079
1081
|
const handleEdit = (record, col, editType, e) => {
|
|
1080
1082
|
// @ts-ignore
|
|
1081
1083
|
setEditingKey(record[rowKey]);
|
|
1084
|
+
setCellEditing({
|
|
1085
|
+
row: record,
|
|
1086
|
+
column: col
|
|
1087
|
+
});
|
|
1082
1088
|
reset();
|
|
1083
1089
|
|
|
1084
1090
|
// const formattedRecord = { ...record };
|
|
@@ -1365,7 +1371,9 @@ const GridEdit = props => {
|
|
|
1365
1371
|
title: getValueCell(column, record[column.field], format),
|
|
1366
1372
|
'data-col-index': colIndex,
|
|
1367
1373
|
'data-row-index': rowNumber,
|
|
1368
|
-
editing: isEditing(record),
|
|
1374
|
+
editing: isEditing(record) && rowEditable?.(record) !== false && isEditable(column, record) !== false,
|
|
1375
|
+
cellEditing,
|
|
1376
|
+
// editing: isEditing(record) && rowEditable?.(record) !== false,
|
|
1369
1377
|
tabIndex: (rowIndex ?? 0) * columns.length + colIndex,
|
|
1370
1378
|
style: isPasteDragging ? {
|
|
1371
1379
|
cursor: "crosshair"
|
|
@@ -1384,7 +1392,7 @@ const GridEdit = props => {
|
|
|
1384
1392
|
onMouseUp: handleMouseUp
|
|
1385
1393
|
}, /*#__PURE__*/React.createElement("div", {
|
|
1386
1394
|
className: 'ui-rc_content'
|
|
1387
|
-
}, renderContent(column, value, record, rowIndex, format)), selectedCells && selectedCells.size > 0 && getLastSelectCell(selectedCells).row === rowNumber && getLastSelectCell(selectedCells).col === colIndex && !isSelectDragging &&
|
|
1395
|
+
}, renderContent(column, value, record, rowIndex, format)), selectedCells && selectedCells.size > 0 && getLastSelectCell(selectedCells).row === rowNumber && getLastSelectCell(selectedCells).col === colIndex && isEditable(column, record) !== false && !isSelectDragging &&
|
|
1388
1396
|
/*#__PURE__*/
|
|
1389
1397
|
// showDraggingPoint &&
|
|
1390
1398
|
React.createElement("div", {
|
|
@@ -1490,6 +1498,7 @@ const GridEdit = props => {
|
|
|
1490
1498
|
...components,
|
|
1491
1499
|
body: {
|
|
1492
1500
|
cell: EditableCell
|
|
1501
|
+
// cell: () => <EditableCell />,
|
|
1493
1502
|
}
|
|
1494
1503
|
},
|
|
1495
1504
|
className: classNames(className, 'grid-editable'),
|
|
@@ -46,7 +46,7 @@ export type ColumnSelectTable = {
|
|
|
46
46
|
};
|
|
47
47
|
export type IEditSelectSettings = {
|
|
48
48
|
fieldKey?: string;
|
|
49
|
-
options: any[];
|
|
49
|
+
options: any[] | ((rowData: any, field: string) => any[]);
|
|
50
50
|
/** get value form other field **/
|
|
51
51
|
fieldValue?: string;
|
|
52
52
|
/** get label form other field **/
|
|
@@ -114,6 +114,7 @@ export type ColumnType<RecordType> = Omit<RcColumnType<RecordType>, 'headerTempl
|
|
|
114
114
|
export type ColumnEditType<RecordType = AnyObject> = Omit<ColumnType<RecordType>, 'children'> & {
|
|
115
115
|
editType?: EditType | ((rowData?: RecordType) => EditType);
|
|
116
116
|
disable?: boolean | ((rowData: any) => boolean);
|
|
117
|
+
editEnable?: boolean | ((rowData: any) => boolean);
|
|
117
118
|
isClearable?: boolean;
|
|
118
119
|
maxDate?: any;
|
|
119
120
|
minDate?: any;
|
|
@@ -185,6 +186,7 @@ export interface TableEditProps<RecordType = AnyObject> extends Omit<TableProps<
|
|
|
185
186
|
onCellPaste?: ICellPasteModel<RecordType>;
|
|
186
187
|
onCellChange?: (args: CellChangeArgs<RecordType>, handleCallback: (rowData: any, index: any, value?: any) => void) => void;
|
|
187
188
|
onCellClick?: (args: ICellClick, callback?: any) => void;
|
|
189
|
+
rowEditable?: (rowData: RecordType) => boolean;
|
|
188
190
|
}
|
|
189
191
|
export type ICellClick = {
|
|
190
192
|
index: number;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { ColumnsTable } from "./type";
|
|
3
|
+
export type IColumnsChoose<RecordType> = {
|
|
4
|
+
columns: ColumnsTable<RecordType>;
|
|
5
|
+
columnsGroup?: string[];
|
|
6
|
+
triggerChangeColumns?: (columns: ColumnsTable<RecordType>, type: string) => void;
|
|
7
|
+
t?: any;
|
|
8
|
+
triggerChangeKeys?: any;
|
|
9
|
+
};
|
|
10
|
+
export declare const ColumnsChoose: <RecordType extends object>(props: IColumnsChoose<RecordType>) => React.JSX.Element;
|
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.ColumnsChoose = void 0;
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
10
|
+
var _antd = require("antd");
|
|
11
|
+
var _icons = require("@ant-design/icons");
|
|
12
|
+
var _hooks = require("./hooks");
|
|
13
|
+
var _tree = _interopRequireDefault(require("rc-master-ui/es/tree"));
|
|
14
|
+
var _SearchOutlined = _interopRequireDefault(require("@ant-design/icons/SearchOutlined"));
|
|
15
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
16
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
|
+
// import React, {Fragment, useMemo, useState} from "react"
|
|
18
|
+
//
|
|
19
|
+
// import styled from "styled-components"
|
|
20
|
+
// import {Button, Input, Popover, Tooltip} from "antd";
|
|
21
|
+
// import {SettingOutlined} from "@ant-design/icons";
|
|
22
|
+
// import {
|
|
23
|
+
// getVisibleColumnKeys,
|
|
24
|
+
// updateColumns
|
|
25
|
+
// } from "./hooks";
|
|
26
|
+
//
|
|
27
|
+
// // import type {TableColumnsType} from "rc-master-ui";
|
|
28
|
+
// import Tree from "rc-master-ui/es/tree";
|
|
29
|
+
// import SearchOutlined from "@ant-design/icons/SearchOutlined";
|
|
30
|
+
// import type {ColumnsTable} from "./type";
|
|
31
|
+
// import useMergedState from "rc-util/lib/hooks/useMergedState";
|
|
32
|
+
//
|
|
33
|
+
//
|
|
34
|
+
// const BoxAction = styled.div`
|
|
35
|
+
// border-top: 1px solid #c4c4c4;
|
|
36
|
+
// padding-top: .75rem;
|
|
37
|
+
// display: flex;
|
|
38
|
+
// justify-content: end;
|
|
39
|
+
// gap: 10px;
|
|
40
|
+
//
|
|
41
|
+
// .btn-action {
|
|
42
|
+
// background: none !important;
|
|
43
|
+
// border: none !important;
|
|
44
|
+
// &.btn-action-submit {
|
|
45
|
+
// color: #df4318;
|
|
46
|
+
// &:disabled {
|
|
47
|
+
// background-color: #f0f0f0 !important;
|
|
48
|
+
// }
|
|
49
|
+
// &:hover {
|
|
50
|
+
// color: #df4318 !important;
|
|
51
|
+
// }
|
|
52
|
+
// }
|
|
53
|
+
//
|
|
54
|
+
// &:hover {
|
|
55
|
+
// background-color: #f0f0f0 !important;
|
|
56
|
+
// }
|
|
57
|
+
// }
|
|
58
|
+
// `
|
|
59
|
+
//
|
|
60
|
+
// export type IColumnsChoose<RecordType> = {
|
|
61
|
+
// columns: ColumnsTable<RecordType>
|
|
62
|
+
// columnsGroup?: string[]
|
|
63
|
+
// triggerChangeColumns?: (columns: ColumnsTable<RecordType>, type: string) => void
|
|
64
|
+
// t?: any
|
|
65
|
+
//
|
|
66
|
+
// }
|
|
67
|
+
//
|
|
68
|
+
//
|
|
69
|
+
// export const ColumnsChoose = <RecordType extends object>(props: IColumnsChoose<RecordType>) => {
|
|
70
|
+
// const {
|
|
71
|
+
// columns: propsColumns,
|
|
72
|
+
// triggerChangeColumns,
|
|
73
|
+
// t,
|
|
74
|
+
// columnsGroup,
|
|
75
|
+
// } = props
|
|
76
|
+
//
|
|
77
|
+
// // const dataList: { key: React.Key; title: string }[] = [];
|
|
78
|
+
//
|
|
79
|
+
// // const defaultColumns = useMemo(() => {
|
|
80
|
+
// // return propsColumns.filter((it) => it.key || it.dataIndex && it.showColumnChoose !== false)
|
|
81
|
+
// // }, [propsColumns])
|
|
82
|
+
//
|
|
83
|
+
//
|
|
84
|
+
// // const columnsChooseRef: any = useRef()
|
|
85
|
+
// // const searchRef: any = useRef()
|
|
86
|
+
//
|
|
87
|
+
//
|
|
88
|
+
//
|
|
89
|
+
// // const [columns, setColumns] = useState<TableColumnsType>([])
|
|
90
|
+
//
|
|
91
|
+
// // const [selectedKeys, setSelectedKeys] = useState<string[]>([]);
|
|
92
|
+
//
|
|
93
|
+
// // const [isManualUpdate, setIsManualUpdate] = useState(false);
|
|
94
|
+
//
|
|
95
|
+
//
|
|
96
|
+
// // useEffect(() => {
|
|
97
|
+
// //
|
|
98
|
+
// // const defaultColumns = propsColumns.filter((it) => it.key || it.dataIndex && it.showInColumnChoose !== false)
|
|
99
|
+
// // setColumns(defaultColumns as TableColumnsType)
|
|
100
|
+
// //
|
|
101
|
+
// // }, [propsColumns])
|
|
102
|
+
//
|
|
103
|
+
// const columns = useMemo(() => {
|
|
104
|
+
//
|
|
105
|
+
// // return propsColumns.filter((it) => (it.key || it.dataIndex) && it.showInColumnChoose !== false && !columnsGroup?.includes(it.field as string))
|
|
106
|
+
// return propsColumns.filter((it) => (it.key || it.dataIndex) && it.showInColumnChoose !== false)
|
|
107
|
+
// // setColumns(defaultColumns as TableColumnsType)
|
|
108
|
+
// }, [columnsGroup, propsColumns])
|
|
109
|
+
//
|
|
110
|
+
//
|
|
111
|
+
// // useEffect(() => {
|
|
112
|
+
// //
|
|
113
|
+
// // const defaultColumns = propsColumns.filter((it) => it.key || it.dataIndex && it.showInColumnChoose !== false)
|
|
114
|
+
// //
|
|
115
|
+
// // const defaultSelectedKeys = getVisibleColumnKeys(defaultColumns)
|
|
116
|
+
// //
|
|
117
|
+
// // if (!isManualUpdate) {
|
|
118
|
+
// // setSelectedKeys(defaultSelectedKeys)
|
|
119
|
+
// // }
|
|
120
|
+
// // setIsManualUpdate(false);
|
|
121
|
+
// //
|
|
122
|
+
// //
|
|
123
|
+
// // }, [isManualUpdate, propsColumns])
|
|
124
|
+
//
|
|
125
|
+
// const defaultSelectedKeys = React.useMemo(() => {
|
|
126
|
+
//
|
|
127
|
+
// const rs = propsColumns.filter((it) => (it.key || it.dataIndex) && it.showInColumnChoose !== false && !columnsGroup?.includes(it.field as string))
|
|
128
|
+
// return getVisibleColumnKeys(rs)
|
|
129
|
+
//
|
|
130
|
+
// }, [columnsGroup, propsColumns])
|
|
131
|
+
//
|
|
132
|
+
// const [mergedSelectedKeys, setMergedSelectedKeys] = useMergedState(
|
|
133
|
+
// defaultSelectedKeys || [],
|
|
134
|
+
// {
|
|
135
|
+
// value: defaultSelectedKeys,
|
|
136
|
+
// },
|
|
137
|
+
// );
|
|
138
|
+
//
|
|
139
|
+
// //
|
|
140
|
+
// // const defaultSelectedKeys = useMemo(() => {
|
|
141
|
+
// //
|
|
142
|
+
// // return getVisibleColumnKeys(propsColumns)
|
|
143
|
+
// //
|
|
144
|
+
// // }, [propsColumns])
|
|
145
|
+
//
|
|
146
|
+
//
|
|
147
|
+
// const [clicked, setClicked] = useState(false);
|
|
148
|
+
// const [autoExpandParent, setAutoExpandParent] = useState(true);
|
|
149
|
+
//
|
|
150
|
+
//
|
|
151
|
+
// // const treeData = useMemo(() => {
|
|
152
|
+
// // const loop = (data: TreeDataNode[]): TreeDataNode[] =>
|
|
153
|
+
// // data.map((item) => {
|
|
154
|
+
// // const strTitle = item.title as string;
|
|
155
|
+
// // const index = strTitle.indexOf(searchValue);
|
|
156
|
+
// // const beforeStr = strTitle.substring(0, index);
|
|
157
|
+
// // const afterStr = strTitle.slice(index + searchValue.length);
|
|
158
|
+
// // const title =
|
|
159
|
+
// // index > -1 ? (
|
|
160
|
+
// // <span key={item.key}>
|
|
161
|
+
// // {beforeStr}
|
|
162
|
+
// // <span className="site-tree-search-value">{searchValue}</span>
|
|
163
|
+
// // {afterStr}
|
|
164
|
+
// // </span>
|
|
165
|
+
// // ) : (
|
|
166
|
+
// // <span key={item.key}>{strTitle}</span>
|
|
167
|
+
// // );
|
|
168
|
+
// // if (item.children) {
|
|
169
|
+
// // return { title, key: item.key, children: loop(item.children) };
|
|
170
|
+
// // }
|
|
171
|
+
// //
|
|
172
|
+
// // return {
|
|
173
|
+
// // title,
|
|
174
|
+
// // key: item.key,
|
|
175
|
+
// // };
|
|
176
|
+
// // });
|
|
177
|
+
// //
|
|
178
|
+
// // // return loop(defaultData);
|
|
179
|
+
// // return loop(columns as any);
|
|
180
|
+
// // }, [searchValue, columns]);
|
|
181
|
+
//
|
|
182
|
+
//
|
|
183
|
+
// const hide = () => {
|
|
184
|
+
// setClicked(false)
|
|
185
|
+
// }
|
|
186
|
+
//
|
|
187
|
+
// const handleClickChange = (open: boolean) => {
|
|
188
|
+
// setClicked(open)
|
|
189
|
+
// }
|
|
190
|
+
//
|
|
191
|
+
// const onExpand = () => {
|
|
192
|
+
// // setExpandedKeys(newExpandedKeys)
|
|
193
|
+
// setAutoExpandParent(false)
|
|
194
|
+
// }
|
|
195
|
+
//
|
|
196
|
+
// // const getParentKey = (key: React.Key, tree: TreeDataNode[]): React.Key => {
|
|
197
|
+
// // let parentKey: React.Key
|
|
198
|
+
// // for (let i = 0; i < tree.length; i++) {
|
|
199
|
+
// // const node = tree[i]
|
|
200
|
+
// // if (node.children) {
|
|
201
|
+
// // if (node.children.some((item) => item.key === key)) {
|
|
202
|
+
// // parentKey = node.key
|
|
203
|
+
// // } else if (getParentKey(key, node.children)) {
|
|
204
|
+
// // parentKey = getParentKey(key, node.children)
|
|
205
|
+
// // }
|
|
206
|
+
// // }
|
|
207
|
+
// // }
|
|
208
|
+
// // return parentKey!
|
|
209
|
+
// // }
|
|
210
|
+
//
|
|
211
|
+
// // const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
212
|
+
// const onChange = () => {
|
|
213
|
+
// // const { value } = e.target
|
|
214
|
+
// // const newExpandedKeys = dataList
|
|
215
|
+
// // .map((item) => {
|
|
216
|
+
// // if (item.title.indexOf(value) > -1) {
|
|
217
|
+
// // return getParentKey(item.key, defaultData)
|
|
218
|
+
// // }
|
|
219
|
+
// // return null
|
|
220
|
+
// // })
|
|
221
|
+
// // .filter((item, i, self): item is React.Key => !!(item && self.indexOf(item) === i))
|
|
222
|
+
// // setExpandedKeys(newExpandedKeys)
|
|
223
|
+
//
|
|
224
|
+
// // setSearchValue(value)
|
|
225
|
+
// setAutoExpandParent(true)
|
|
226
|
+
// };
|
|
227
|
+
//
|
|
228
|
+
// const onCheck = (keys: string[]) => {
|
|
229
|
+
//
|
|
230
|
+
// console.log('keys', keys)
|
|
231
|
+
// // setSelectedKeys(keys)
|
|
232
|
+
// setMergedSelectedKeys(keys)
|
|
233
|
+
// // setIsManualUpdate(true)
|
|
234
|
+
//
|
|
235
|
+
// }
|
|
236
|
+
//
|
|
237
|
+
// const handleAccept = () => {
|
|
238
|
+
//
|
|
239
|
+
// console.log('mergedSelectedKeys', mergedSelectedKeys)
|
|
240
|
+
//
|
|
241
|
+
// // const rs1 = updateColumns(propsColumns, selectedKeys)
|
|
242
|
+
// const rs1 = updateColumns(propsColumns, mergedSelectedKeys)
|
|
243
|
+
//
|
|
244
|
+
// console.log('rs1', rs1)
|
|
245
|
+
//
|
|
246
|
+
// triggerChangeColumns?.(rs1, 'columnChoose')
|
|
247
|
+
//
|
|
248
|
+
// hide()
|
|
249
|
+
//
|
|
250
|
+
// }
|
|
251
|
+
//
|
|
252
|
+
// const handleCancel = () => {
|
|
253
|
+
// // setSelectedKeys(defaultSelectedKeys)
|
|
254
|
+
// hide()
|
|
255
|
+
// }
|
|
256
|
+
//
|
|
257
|
+
//
|
|
258
|
+
// return (
|
|
259
|
+
// <Fragment>
|
|
260
|
+
// <Popover
|
|
261
|
+
// placement={'bottomLeft'}
|
|
262
|
+
// content={
|
|
263
|
+
// <div style={{minWidth: 250}}>
|
|
264
|
+
// <Input style={{ marginBottom: 8 }} placeholder={t ? t("Search") : 'Search'} prefix={<SearchOutlined />} onChange={onChange} />
|
|
265
|
+
//
|
|
266
|
+
// <Tree
|
|
267
|
+
// onExpand={onExpand}
|
|
268
|
+
// // expandedKeys={expandedKeys}
|
|
269
|
+
// autoExpandParent={autoExpandParent}
|
|
270
|
+
// // treeData={treeData}
|
|
271
|
+
// treeData={columns}
|
|
272
|
+
// defaultExpandAll={true}
|
|
273
|
+
// checkable={true}
|
|
274
|
+
// // onSelect={(keys, info) => {
|
|
275
|
+
// // const key = info.node.key
|
|
276
|
+
// //
|
|
277
|
+
// // const find = findItemByKey(columns, 'key', key)
|
|
278
|
+
// //
|
|
279
|
+
// // // const tmpColumn
|
|
280
|
+
// //
|
|
281
|
+
// // // if (selectedKeys.includes(key as string)) {
|
|
282
|
+
// // // const rssss = findKeyPath(columns, key as string)
|
|
283
|
+
// // // const rs = selectedKeys.filter(item => !rssss.includes(item));
|
|
284
|
+
// // //
|
|
285
|
+
// // // setSelectedKeys(rs)
|
|
286
|
+
// // // } else {
|
|
287
|
+
// //
|
|
288
|
+
// // // const rs = [...selectedKeys, keys[0]]
|
|
289
|
+
// //
|
|
290
|
+
// // // setSelectedKeys(keys)
|
|
291
|
+
// // // }
|
|
292
|
+
// // }}
|
|
293
|
+
// onCheck={(keys) => onCheck(keys as string[])}
|
|
294
|
+
//
|
|
295
|
+
//
|
|
296
|
+
// multiple={true}
|
|
297
|
+
// // checkedKeys={selectedKeys}
|
|
298
|
+
//
|
|
299
|
+
// defaultCheckedKeys={mergedSelectedKeys}
|
|
300
|
+
// // defaultCheckedKeys={defaultSelectedKeys}
|
|
301
|
+
// // selectedKeys={[]}
|
|
302
|
+
//
|
|
303
|
+
// height={window.innerHeight - 200}
|
|
304
|
+
//
|
|
305
|
+
// />
|
|
306
|
+
//
|
|
307
|
+
//
|
|
308
|
+
// <BoxAction className={'px-1'}>
|
|
309
|
+
// <Button
|
|
310
|
+
// // className={classnames('btn-action btn-action-submit', {
|
|
311
|
+
// // // disable: !columns.find((item) => item.visible !== false || item.visible)
|
|
312
|
+
// // })}
|
|
313
|
+
// onClick={handleAccept}
|
|
314
|
+
// // disabled={!columns.find((item) => item.visible !== false || item.visible)}
|
|
315
|
+
// >
|
|
316
|
+
// {t ? t('OK') : 'OK'}
|
|
317
|
+
// {/*{'OK'}*/}
|
|
318
|
+
// </Button>
|
|
319
|
+
//
|
|
320
|
+
// {/*<Button className={'btn-action btn-action-cancel'} onClick={hide} >{('Cancel') }</Button>*/}
|
|
321
|
+
// <Button className={'btn-action btn-action-cancel'} onClick={handleCancel} >{t ? t('Cancel') : 'Cancel' }</Button>
|
|
322
|
+
// </BoxAction>
|
|
323
|
+
// </div>
|
|
324
|
+
// }
|
|
325
|
+
// trigger="click"
|
|
326
|
+
// open={clicked}
|
|
327
|
+
// onOpenChange={handleClickChange}
|
|
328
|
+
// arrow={false}
|
|
329
|
+
// >
|
|
330
|
+
// <Tooltip arrow={false} title={'Cài đặt'} >
|
|
331
|
+
// <SettingOutlined size={16} color={'#555555'} style={{fontSize: 16, color: '#555555'}} />
|
|
332
|
+
// </Tooltip>
|
|
333
|
+
//
|
|
334
|
+
// </Popover>
|
|
335
|
+
// </Fragment>
|
|
336
|
+
// )
|
|
337
|
+
// }
|
|
338
|
+
|
|
339
|
+
// import type {TableColumnsType} from "rc-master-ui";
|
|
340
|
+
|
|
341
|
+
const BoxAction = _styledComponents.default.div.withConfig({
|
|
342
|
+
displayName: "BoxAction",
|
|
343
|
+
componentId: "es-grid-template__sc-zdl2xa-0"
|
|
344
|
+
})(["border-top:1px solid #c4c4c4;padding-top:.75rem;display:flex;justify-content:end;gap:10px;.btn-action{background:none !important;border:none !important;&.btn-action-submit{color:#df4318;&:disabled{background-color:#f0f0f0 !important;}&:hover{color:#df4318 !important;}}&:hover{background-color:#f0f0f0 !important;}}"]);
|
|
345
|
+
const ColumnsChoose = props => {
|
|
346
|
+
const {
|
|
347
|
+
columns: propsColumns,
|
|
348
|
+
triggerChangeColumns,
|
|
349
|
+
triggerChangeKeys,
|
|
350
|
+
t,
|
|
351
|
+
columnsGroup
|
|
352
|
+
} = props;
|
|
353
|
+
|
|
354
|
+
// const dataList: { key: React.Key; title: string }[] = [];
|
|
355
|
+
|
|
356
|
+
// const defaultColumns = useMemo(() => {
|
|
357
|
+
// return propsColumns.filter((it) => it.key || it.dataIndex && it.showColumnChoose !== false)
|
|
358
|
+
// }, [propsColumns])
|
|
359
|
+
|
|
360
|
+
// const columnsChooseRef: any = useRef()
|
|
361
|
+
// const searchRef: any = useRef()
|
|
362
|
+
|
|
363
|
+
// const [columns, setColumns] = useState<TableColumnsType>([])
|
|
364
|
+
const [selectedKeys, setSelectedKeys] = (0, _react.useState)([]);
|
|
365
|
+
const [isManualUpdate, setIsManualUpdate] = (0, _react.useState)(false);
|
|
366
|
+
|
|
367
|
+
// useEffect(() => {
|
|
368
|
+
//
|
|
369
|
+
// const defaultColumns = propsColumns.filter((it) => it.key || it.dataIndex && it.showInColumnChoose !== false)
|
|
370
|
+
// setColumns(defaultColumns as TableColumnsType)
|
|
371
|
+
//
|
|
372
|
+
// }, [propsColumns])
|
|
373
|
+
|
|
374
|
+
const columns = (0, _react.useMemo)(() => {
|
|
375
|
+
return propsColumns.filter(it => it.key || it.dataIndex && it.showInColumnChoose !== false);
|
|
376
|
+
// setColumns(defaultColumns as TableColumnsType)
|
|
377
|
+
}, [propsColumns]);
|
|
378
|
+
(0, _react.useEffect)(() => {
|
|
379
|
+
// const defaultColumns = propsColumns.filter((it) => it.key || it.dataIndex && it.showInColumnChoose !== false)
|
|
380
|
+
const defaultColumns = propsColumns.filter(it => (it.key || it.dataIndex) && it.showInColumnChoose !== false && !columnsGroup?.includes(it.field));
|
|
381
|
+
const defaultSelectedKeys = (0, _hooks.getVisibleColumnKeys)(defaultColumns);
|
|
382
|
+
if (!isManualUpdate) {
|
|
383
|
+
setSelectedKeys(defaultSelectedKeys);
|
|
384
|
+
}
|
|
385
|
+
setIsManualUpdate(false);
|
|
386
|
+
}, [propsColumns]);
|
|
387
|
+
const defaultSelectedKeys = (0, _react.useMemo)(() => {
|
|
388
|
+
const defaultColumns = propsColumns.filter(it => (it.key || it.dataIndex) && it.showInColumnChoose !== false && !columnsGroup?.includes(it.field));
|
|
389
|
+
return (0, _hooks.getVisibleColumnKeys)(defaultColumns);
|
|
390
|
+
}, [propsColumns]);
|
|
391
|
+
const [clicked, setClicked] = (0, _react.useState)(false);
|
|
392
|
+
const [autoExpandParent, setAutoExpandParent] = (0, _react.useState)(true);
|
|
393
|
+
|
|
394
|
+
// const treeData = useMemo(() => {
|
|
395
|
+
// const loop = (data: TreeDataNode[]): TreeDataNode[] =>
|
|
396
|
+
// data.map((item) => {
|
|
397
|
+
// const strTitle = item.title as string;
|
|
398
|
+
// const index = strTitle.indexOf(searchValue);
|
|
399
|
+
// const beforeStr = strTitle.substring(0, index);
|
|
400
|
+
// const afterStr = strTitle.slice(index + searchValue.length);
|
|
401
|
+
// const title =
|
|
402
|
+
// index > -1 ? (
|
|
403
|
+
// <span key={item.key}>
|
|
404
|
+
// {beforeStr}
|
|
405
|
+
// <span className="site-tree-search-value">{searchValue}</span>
|
|
406
|
+
// {afterStr}
|
|
407
|
+
// </span>
|
|
408
|
+
// ) : (
|
|
409
|
+
// <span key={item.key}>{strTitle}</span>
|
|
410
|
+
// );
|
|
411
|
+
// if (item.children) {
|
|
412
|
+
// return { title, key: item.key, children: loop(item.children) };
|
|
413
|
+
// }
|
|
414
|
+
//
|
|
415
|
+
// return {
|
|
416
|
+
// title,
|
|
417
|
+
// key: item.key,
|
|
418
|
+
// };
|
|
419
|
+
// });
|
|
420
|
+
//
|
|
421
|
+
// // return loop(defaultData);
|
|
422
|
+
// return loop(columns as any);
|
|
423
|
+
// }, [searchValue, columns]);
|
|
424
|
+
|
|
425
|
+
const hide = () => {
|
|
426
|
+
setClicked(false);
|
|
427
|
+
};
|
|
428
|
+
const handleClickChange = open => {
|
|
429
|
+
setClicked(open);
|
|
430
|
+
};
|
|
431
|
+
const onExpand = () => {
|
|
432
|
+
// setExpandedKeys(newExpandedKeys)
|
|
433
|
+
setAutoExpandParent(false);
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
// const getParentKey = (key: React.Key, tree: TreeDataNode[]): React.Key => {
|
|
437
|
+
// let parentKey: React.Key
|
|
438
|
+
// for (let i = 0; i < tree.length; i++) {
|
|
439
|
+
// const node = tree[i]
|
|
440
|
+
// if (node.children) {
|
|
441
|
+
// if (node.children.some((item) => item.key === key)) {
|
|
442
|
+
// parentKey = node.key
|
|
443
|
+
// } else if (getParentKey(key, node.children)) {
|
|
444
|
+
// parentKey = getParentKey(key, node.children)
|
|
445
|
+
// }
|
|
446
|
+
// }
|
|
447
|
+
// }
|
|
448
|
+
// return parentKey!
|
|
449
|
+
// }
|
|
450
|
+
|
|
451
|
+
// const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
452
|
+
const onChange = () => {
|
|
453
|
+
// const { value } = e.target
|
|
454
|
+
// const newExpandedKeys = dataList
|
|
455
|
+
// .map((item) => {
|
|
456
|
+
// if (item.title.indexOf(value) > -1) {
|
|
457
|
+
// return getParentKey(item.key, defaultData)
|
|
458
|
+
// }
|
|
459
|
+
// return null
|
|
460
|
+
// })
|
|
461
|
+
// .filter((item, i, self): item is React.Key => !!(item && self.indexOf(item) === i))
|
|
462
|
+
// setExpandedKeys(newExpandedKeys)
|
|
463
|
+
|
|
464
|
+
// setSearchValue(value)
|
|
465
|
+
setAutoExpandParent(true);
|
|
466
|
+
};
|
|
467
|
+
const onCheck = keys => {
|
|
468
|
+
setSelectedKeys(keys);
|
|
469
|
+
setIsManualUpdate(true);
|
|
470
|
+
};
|
|
471
|
+
const handleAccept = () => {
|
|
472
|
+
const rs1 = (0, _hooks.updateColumns)(propsColumns, selectedKeys);
|
|
473
|
+
triggerChangeKeys?.(selectedKeys);
|
|
474
|
+
triggerChangeColumns?.(rs1, 'columnChoose');
|
|
475
|
+
hide();
|
|
476
|
+
};
|
|
477
|
+
const handleCancel = () => {
|
|
478
|
+
setSelectedKeys(defaultSelectedKeys);
|
|
479
|
+
hide();
|
|
480
|
+
};
|
|
481
|
+
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(_antd.Popover, {
|
|
482
|
+
placement: 'bottomLeft',
|
|
483
|
+
content: /*#__PURE__*/_react.default.createElement("div", {
|
|
484
|
+
style: {
|
|
485
|
+
minWidth: 250
|
|
486
|
+
}
|
|
487
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Input, {
|
|
488
|
+
style: {
|
|
489
|
+
marginBottom: 8
|
|
490
|
+
},
|
|
491
|
+
placeholder: t ? t("Search") : 'Search',
|
|
492
|
+
prefix: /*#__PURE__*/_react.default.createElement(_SearchOutlined.default, null),
|
|
493
|
+
onChange: onChange
|
|
494
|
+
}), /*#__PURE__*/_react.default.createElement(_tree.default, {
|
|
495
|
+
onExpand: onExpand
|
|
496
|
+
// expandedKeys={expandedKeys}
|
|
497
|
+
,
|
|
498
|
+
autoExpandParent: autoExpandParent
|
|
499
|
+
// treeData={treeData}
|
|
500
|
+
,
|
|
501
|
+
treeData: columns,
|
|
502
|
+
defaultExpandAll: true,
|
|
503
|
+
checkable: true
|
|
504
|
+
// onSelect={(keys, info) => {
|
|
505
|
+
// const key = info.node.key
|
|
506
|
+
//
|
|
507
|
+
// const find = findItemByKey(columns, 'key', key)
|
|
508
|
+
//
|
|
509
|
+
// // const tmpColumn
|
|
510
|
+
//
|
|
511
|
+
// // if (selectedKeys.includes(key as string)) {
|
|
512
|
+
// // const rssss = findKeyPath(columns, key as string)
|
|
513
|
+
// // const rs = selectedKeys.filter(item => !rssss.includes(item));
|
|
514
|
+
// //
|
|
515
|
+
// // setSelectedKeys(rs)
|
|
516
|
+
// // } else {
|
|
517
|
+
//
|
|
518
|
+
// // const rs = [...selectedKeys, keys[0]]
|
|
519
|
+
//
|
|
520
|
+
// // setSelectedKeys(keys)
|
|
521
|
+
// // }
|
|
522
|
+
// }}
|
|
523
|
+
,
|
|
524
|
+
onCheck: keys => onCheck(keys),
|
|
525
|
+
multiple: true,
|
|
526
|
+
checkedKeys: selectedKeys,
|
|
527
|
+
defaultCheckedKeys: selectedKeys
|
|
528
|
+
// defaultCheckedKeys={defaultSelectedKeys}
|
|
529
|
+
,
|
|
530
|
+
selectedKeys: [],
|
|
531
|
+
height: window.innerHeight - 200
|
|
532
|
+
}), /*#__PURE__*/_react.default.createElement(BoxAction, {
|
|
533
|
+
className: 'px-1'
|
|
534
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Button
|
|
535
|
+
// className={classnames('btn-action btn-action-submit', {
|
|
536
|
+
// // disable: !columns.find((item) => item.visible !== false || item.visible)
|
|
537
|
+
// })}
|
|
538
|
+
, {
|
|
539
|
+
onClick: handleAccept
|
|
540
|
+
// disabled={!columns.find((item) => item.visible !== false || item.visible)}
|
|
541
|
+
}, t ? t('OK') : 'OK'), /*#__PURE__*/_react.default.createElement(_antd.Button, {
|
|
542
|
+
className: 'btn-action btn-action-cancel',
|
|
543
|
+
onClick: handleCancel
|
|
544
|
+
}, t ? t('Cancel') : 'Cancel'))),
|
|
545
|
+
trigger: "click",
|
|
546
|
+
open: clicked,
|
|
547
|
+
onOpenChange: handleClickChange,
|
|
548
|
+
arrow: false
|
|
549
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Tooltip, {
|
|
550
|
+
arrow: false,
|
|
551
|
+
title: 'Cài đặt'
|
|
552
|
+
}, /*#__PURE__*/_react.default.createElement(_icons.SettingOutlined, null))));
|
|
553
|
+
};
|
|
554
|
+
exports.ColumnsChoose = ColumnsChoose;
|