es-grid-template 1.2.7 → 1.2.9

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.
Files changed (29) hide show
  1. package/es/grid-component/AdvanceFilter.d.ts +11 -7
  2. package/es/grid-component/AdvanceFilter.js +419 -509
  3. package/es/grid-component/EditableCell.d.ts +2 -2
  4. package/es/grid-component/TableGrid.js +11 -2
  5. package/es/grid-component/checkbox-control/index.d.ts +13 -0
  6. package/es/grid-component/checkbox-control/index.js +40 -0
  7. package/es/grid-component/hooks/columns/index.d.ts +4 -4
  8. package/es/grid-component/hooks/columns/index.js +6 -1
  9. package/es/grid-component/hooks/useColumns.js +3 -2
  10. package/es/grid-component/hooks/utils.d.ts +9 -7
  11. package/es/grid-component/hooks/utils.js +10 -1
  12. package/es/grid-component/table/GridEdit.d.ts +2 -3
  13. package/es/grid-component/table/GridEdit.js +35 -11
  14. package/es/grid-component/type.d.ts +8 -27
  15. package/lib/grid-component/AdvanceFilter.d.ts +11 -7
  16. package/lib/grid-component/AdvanceFilter.js +415 -506
  17. package/lib/grid-component/EditableCell.d.ts +2 -2
  18. package/lib/grid-component/TableGrid.js +11 -2
  19. package/lib/grid-component/checkbox-control/index.d.ts +13 -0
  20. package/lib/grid-component/checkbox-control/index.js +48 -0
  21. package/lib/grid-component/hooks/columns/index.d.ts +4 -4
  22. package/lib/grid-component/hooks/columns/index.js +6 -1
  23. package/lib/grid-component/hooks/useColumns.js +3 -2
  24. package/lib/grid-component/hooks/utils.d.ts +9 -7
  25. package/lib/grid-component/hooks/utils.js +15 -4
  26. package/lib/grid-component/table/GridEdit.d.ts +2 -3
  27. package/lib/grid-component/table/GridEdit.js +34 -9
  28. package/lib/grid-component/type.d.ts +8 -27
  29. package/package.json +108 -108
@@ -4,544 +4,439 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.ColumnsChoose = void 0;
7
+ exports.default = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
8
9
  var _react = _interopRequireWildcard(require("react"));
9
10
  var _styledComponents = _interopRequireDefault(require("styled-components"));
10
11
  var _antd = require("antd");
11
- var _icons = require("@ant-design/icons");
12
+ var _becoxyIcons = require("becoxy-icons");
13
+ var _rcMasterUi = require("rc-master-ui");
12
14
  var _hooks = require("./hooks");
13
- var _tree = _interopRequireDefault(require("rc-master-ui/es/tree"));
14
- var _SearchOutlined = _interopRequireDefault(require("@ant-design/icons/SearchOutlined"));
15
+ var _checkboxControl = _interopRequireDefault(require("./checkbox-control"));
16
+ var _asyncSelect = require("./async-select");
17
+ var _reactNumericComponent = require("react-numeric-component");
18
+ var _classnames = _interopRequireDefault(require("classnames"));
19
+ var _util = require("rc-master-ui/es/table/util");
15
20
  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
21
  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)
22
+ const {
23
+ RangePicker
24
+ } = _rcMasterUi.DatePicker;
25
+ const MainFilter = _styledComponents.default.div.withConfig({
26
+ displayName: "MainFilter",
27
+ componentId: "es-grid-template__sc-zdl2xa-0"
28
+ })([".filter-left{display:flex;flex-direction:column;gap:1rem;width:", ";border-right:1px solid #c4c4c4;}@media (max-width:576px){flex-direction:column-reverse;gap:1rem;.filter-left{width:100%;border-right:0;}}"], props => `${props.leftFilterWidth}px`);
29
+ const GridFilter = _styledComponents.default.div.withConfig({
30
+ displayName: "GridFilter",
31
+ componentId: "es-grid-template__sc-zdl2xa-1"
32
+ })(["display:grid;gap:10px;padding-right:1rem;padding-left:1rem;max-height:500px;overflow:auto;overflow-x:hidden;flex-wrap:wrap;grid-template-columns:repeat(2,minmax(250px,1fr));.grid-item-filter{}.adv-form-input{height:32px;}@media (max-width:720px){grid-template-columns:repeat(1,minmax(250px,1fr));}"]);
33
+ const BoxAction = _styledComponents.default.div.withConfig({
34
+ displayName: "BoxAction",
35
+ componentId: "es-grid-template__sc-zdl2xa-2"
36
+ })(["border-top:1px solid #c4c4c4;padding-top:0.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;}}"]);
37
+
38
+ // const FilterContainer = styled.div<{ contentWidth?: number }>`
39
+ // .customizer {
40
+ // right: ${props => (props.contentWidth ? `-${props.contentWidth}px` : '-400px')};
41
+ // width: ${props => (props.contentWidth ? `${props.contentWidth}px` : '400px')};
194
42
  // }
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
- //
43
+ // .customizer.open {
44
+ // right: 0;
235
45
  // }
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
- //
46
+ // .adv-form-input {
47
+ // height: 32px;
250
48
  // }
251
- //
252
- // const handleCancel = () => {
253
- // // setSelectedKeys(defaultSelectedKeys)
254
- // hide()
49
+ // .checkbox-dropdown {
50
+ // .ant-select-tree-treenode {
51
+ // .ant-select-tree-switcher.ant-select-tree-switcher-noop {
52
+ // width: 0 !important;
53
+ // }
54
+ // }
255
55
  // }
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";
56
+ // `
340
57
 
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 => {
58
+ const AdvanceFilter = props => {
346
59
  const {
347
- columns: propsColumns,
348
- triggerChangeColumns,
349
- triggerChangeKeys,
350
- t,
351
- columnsGroup
60
+ columns: defaultColumns,
61
+ dataSourceFilter,
62
+ onFilter,
63
+ // mode = 'dropdown',
64
+ defaultFilter,
65
+ leftFilterWidth = 280,
66
+ format,
67
+ t
352
68
  } = props;
353
69
 
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()
70
+ // const columnsChooseRef: any = useRef(null)
71
+ const menuRef = _react.default.useRef(null);
362
72
 
363
- // const [columns, setColumns] = useState<TableColumnsType>([])
364
- const [selectedKeys, setSelectedKeys] = (0, _react.useState)([]);
365
- const [isManualUpdate, setIsManualUpdate] = (0, _react.useState)(false);
73
+ // const [selectedKeys, setSelectedKeys] = useState<string[]>([]);
74
+ // const [isManualUpdate, setIsManualUpdate] = useState(false);
366
75
 
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]);
76
+ const [prevFilter, setPrevFilter] = (0, _react.useState)([]);
77
+ const [filterColumns, setFilterColumns] = (0, _react.useState)([]);
391
78
  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
- // }
79
+ const [columns, setColumns] = (0, _react.useState)([]);
80
+ const count = 4;
81
+ // const count = useMemo(() => {
414
82
  //
415
- // return {
416
- // title,
417
- // key: item.key,
418
- // };
419
- // });
83
+ // const uniqueItems = prevFilter.filter((item, index, arr) => {
84
+ // return arr.findIndex(el => el.field === item.field) === index
85
+ // })
420
86
  //
421
- // // return loop(defaultData);
422
- // return loop(columns as any);
423
- // }, [searchValue, columns]);
87
+ // return uniqueItems?.filter((quer: any) => quer.filterOption && quer.filterOption?.value).length ?? 0
88
+ //
89
+ // }, [prevFilter])
424
90
 
91
+ _react.default.useEffect(() => {
92
+ if (defaultColumns) {
93
+ const filter = defaultColumns.filter(it => it.visible !== false && it.allowFiltering !== false && it.field !== '#' && it.field !== 'command');
94
+ const tmpFilter = filter.map(it => ({
95
+ ...it,
96
+ filterOption: {
97
+ key: it.field,
98
+ field: it.field,
99
+ value: undefined,
100
+ predicate: undefined,
101
+ operator: it?.filterOption?.operator ? it.filterOption.operator : (0, _util.getDefaultOperator)(it)
102
+ }
103
+ }));
104
+ setColumns(filter);
105
+ setPrevFilter(tmpFilter);
106
+ setFilterColumns(tmpFilter);
107
+ }
108
+ }, [defaultColumns, defaultFilter]);
425
109
  const hide = () => {
426
110
  setClicked(false);
427
111
  };
428
112
  const handleClickChange = open => {
429
113
  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);
114
+ if (defaultFilter) {
115
+ setFilterColumns(defaultFilter ?? []);
116
+ }
470
117
  };
471
118
  const handleAccept = () => {
472
- const rs1 = (0, _hooks.updateColumns)(propsColumns, selectedKeys);
473
- triggerChangeKeys?.(selectedKeys);
474
- triggerChangeColumns?.(rs1, 'columnChoose');
119
+ const query = filterColumns.filter(quer => quer.filterOption && (quer.filterOption?.value || quer.filterOption?.value === 0)).map(quer => quer.filterOption);
120
+ if (onFilter && !(0, _hooks.isArraysEqual)(filterColumns, defaultFilter ?? [])) {
121
+ onFilter(query, filterColumns);
122
+ }
475
123
  hide();
124
+ setPrevFilter(filterColumns);
125
+ };
126
+ const handleReset = () => {
127
+ setFilterColumns(columns);
476
128
  };
477
129
  const handleCancel = () => {
478
- setSelectedKeys(defaultSelectedKeys);
479
130
  hide();
131
+ setFilterColumns(prevFilter);
480
132
  };
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", {
133
+ const renderFilter = (tmpColumn, index) => {
134
+ const find = filterColumns.find(it => it.field === tmpColumn.field);
135
+ const column = find ? find : tmpColumn;
136
+ let valueFilter;
137
+ if (column?.typeFilter === 'Checkbox' || column?.typeFilter === 'CheckboxDropdown' || tmpColumn?.filterOption?.multiple) {
138
+ const currentValueFilter = filterColumns.filter(it => it.field === column?.field && (it.filterOption?.value || it.filterOption?.value === 0));
139
+ valueFilter = currentValueFilter.map(it => it.filterOption?.value);
140
+ } else if (column?.typeFilter === 'DateRange') {
141
+ const currentValueFilter = filterColumns.filter(it => it.field === column?.field);
142
+ const findStartDate = currentValueFilter.find(it => it.filterOption?.operator === 'greaterthanorequal');
143
+ const findEndDate = currentValueFilter.find(it => it.filterOption?.operator === 'lessthanorequal');
144
+ const startDate = findStartDate ? (0, _hooks.convertDateToDayjs)(findStartDate.filterOption?.value, column?.format?.dateFormat ?? 'DD/MM/YYYY') : '';
145
+ const endDate = findEndDate ? (0, _hooks.convertDateToDayjs)(findEndDate.filterOption?.value, column?.format?.dateFormat ?? 'DD/MM/YYYY') : '';
146
+ valueFilter = [startDate, endDate];
147
+ } else {
148
+ // single Value
149
+ valueFilter = column?.filterOption?.value;
150
+ }
151
+ const options = dataSourceFilter?.find(it => it.key === column?.field)?.data;
152
+ const loadOptions = dataSourceFilter?.find(it => it.key === column?.field)?.loadOptions;
153
+ switch (column?.typeFilter) {
154
+ case "Checkbox":
155
+ return /*#__PURE__*/_react.default.createElement(_checkboxControl.default, {
156
+ value: valueFilter,
157
+ options: options ?? [],
158
+ onChange: val => {
159
+ console.log(val);
160
+ // onChangeValueFilter(column, val, true)
161
+ }
162
+ });
163
+ case 'Dropdown':
164
+ return (
165
+ /*#__PURE__*/
166
+ // <Select
167
+ // showSearch
168
+ // allowClear
169
+ // style={{ width: '100%' }}
170
+ // placeholder='Search to Select'
171
+ // optionFilterProp='label'
172
+ // value={valueFilter}
173
+ // mode={tmpColumn.filterOption?.multiple ? 'multiple' : undefined}
174
+ // options={options ?? []}
175
+ // onChange={val => {
176
+ // onChangeValueFilter(column, val)
177
+ // }}
178
+ // dropdownStyle={{ zIndex: 9999 }}
179
+ // popupClassName={'adv-popup-container'}
180
+ // getPopupContainer={() => menuRef.current}
181
+ // className='filter-item-control'
182
+ // />
183
+ _react.default.createElement(_asyncSelect.AsyncSelect, {
184
+ showSearch: true,
185
+ allowClear: true,
186
+ style: {
187
+ width: '100%'
188
+ },
189
+ placeholder: "Search to Select",
190
+ optionFilterProp: "label",
191
+ value: valueFilter,
192
+ mode: tmpColumn.filterOption?.multiple ? 'multiple' : undefined,
193
+ options: options ?? [],
194
+ defaultOptions: options ?? [],
195
+ onChange: val => {
196
+ console.log(val);
197
+ // onChangeValueFilter(column, val)
198
+ },
199
+ loadOptions: loadOptions,
200
+ dropdownStyle: {
201
+ zIndex: 9999
202
+ },
203
+ popupClassName: 'adv-popup-container'
204
+ // getPopupContainer={() => menuRef.current}
205
+ ,
206
+ className: "filter-item-control"
207
+ })
208
+ );
209
+ case 'CheckboxDropdown':
210
+ return /*#__PURE__*/_react.default.createElement(_rcMasterUi.TreeSelect, {
211
+ showSearch: true,
212
+ style: {
213
+ width: '100%'
214
+ },
215
+ value: valueFilter,
216
+ multiple: true,
217
+ treeCheckable: true,
218
+ dropdownStyle: {
219
+ maxHeight: 400,
220
+ overflow: 'auto',
221
+ zIndex: 9999
222
+ },
223
+ placeholder: "Please select",
224
+ allowClear: true,
225
+ maxTagCount: 'responsive',
226
+ onChange: val => {
227
+ console.log(val);
228
+ // onChangeValueFilter(column, val, true)
229
+ },
230
+ treeData: options,
231
+ popupClassName: 'adv-popup-container checkbox-dropdown'
232
+ // getPopupContainer={() => menuRef.current}
233
+ });
234
+ case 'DateRange':
235
+ return /*#__PURE__*/_react.default.createElement(RangePicker, {
236
+ format: {
237
+ format: column.format?.dateFormat ?? 'DD/MM/YYYY',
238
+ type: 'mask'
239
+ },
240
+ defaultValue: valueFilter,
241
+ value: valueFilter,
242
+ placeholder: ['Ngày bắt đầu', 'Ngày kết thúc'],
243
+ popupStyle: {
244
+ zIndex: 9999
245
+ },
246
+ onChange: (value, dateString) => {
247
+ const newDateRangeValue = [dateString[0] ? (0, _hooks.convertDayjsToDate)(dateString[0], column.format?.dateFormat ?? 'DD/MM/YYYY') : '', dateString[1] ? (0, _hooks.convertDayjsToDate)(dateString[1], column.format?.dateFormat ?? 'DD/MM/YYYY') : ''];
248
+ console.log(newDateRangeValue);
249
+
250
+ // onChangeValueFilter(column, newDateRangeValue)
251
+ },
252
+ style: {
253
+ width: '100%'
254
+ },
255
+ popupClassName: 'adv-popup-container'
256
+ // getPopupContainer={() => menuRef.current}
257
+ });
258
+ case 'Date':
259
+ const dateValue = valueFilter ? (0, _hooks.convertDateToDayjs)(valueFilter, column.format?.dateFormat ?? 'DD/MM/YYYY') : null;
260
+ return /*#__PURE__*/_react.default.createElement(_rcMasterUi.DatePicker, {
261
+ format: {
262
+ format: column.format?.dateFormat ?? 'DD/MM/YYYY',
263
+ type: 'mask'
264
+ },
265
+ style: {
266
+ width: '100%'
267
+ },
268
+ defaultValue: dateValue,
269
+ value: dateValue,
270
+ placeholder: 'Chọn ngày',
271
+ onChange: (val, dateString) => {
272
+ const newDateTimeValue = dateString ? (0, _hooks.convertDayjsToDate)(dateString, column.format?.dateFormat ?? 'DD/MM/YYYY') : null;
273
+ // onChangeValueFilter(column, newDateTimeValue)
274
+ console.log(newDateTimeValue);
275
+ },
276
+ popupStyle: {
277
+ zIndex: 9999
278
+ },
279
+ popupClassName: 'adv-popup-container'
280
+ // getPopupContainer={() => menuRef.current}
281
+ });
282
+ case 'Datetime':
283
+ const dateTimeValue = valueFilter ? (0, _hooks.convertDateToDayjs)(valueFilter, column.format?.dateFormat ?? 'DD/MM/YYYY HH:mm') : null;
284
+ return /*#__PURE__*/_react.default.createElement(_rcMasterUi.DatePicker, {
285
+ format: {
286
+ format: column.format?.datetimeFormat ?? 'DD/MM/YYYY HH:mm',
287
+ type: 'mask'
288
+ },
289
+ style: {
290
+ width: '100%'
291
+ },
292
+ showTime: column.typeFilter === 'Datetime',
293
+ defaultValue: dateTimeValue,
294
+ value: dateTimeValue,
295
+ placeholder: 'Chọn ngày',
296
+ onChange: (val, dateString) => {
297
+ const newDateTimeValue = dateString ? (0, _hooks.convertDayjsToDate)(dateString, column.format?.datetimeFormat ?? 'DD/MM/YYYY HH:mm') : null;
298
+ console.log('newDateTimeValue', newDateTimeValue);
299
+ // onChangeValueFilter(column, newDateTimeValue)
300
+ },
301
+ popupStyle: {
302
+ zIndex: 9999
303
+ },
304
+ popupClassName: 'adv-popup-container'
305
+ });
306
+ case 'DropTree':
307
+ return /*#__PURE__*/_react.default.createElement(_rcMasterUi.TreeSelect, {
308
+ showSearch: true,
309
+ style: {
310
+ width: '100%'
311
+ },
312
+ value: valueFilter,
313
+ multiple: tmpColumn.filterOption?.multiple,
314
+ treeCheckable: tmpColumn.filterOption?.treeCheckable,
315
+ dropdownStyle: {
316
+ maxHeight: 400,
317
+ overflow: 'auto',
318
+ zIndex: 9999
319
+ },
320
+ placeholder: "Please select",
321
+ allowClear: true,
322
+ onChange: () => {
323
+ // onChangeValueFilter(column, val, tmpColumn.filterOption?.multiple)
324
+ },
325
+ treeData: options,
326
+ maxTagCount: 'responsive',
327
+ popupClassName: 'adv-popup-container'
328
+ });
329
+ case 'Time':
330
+ return /*#__PURE__*/_react.default.createElement(_rcMasterUi.TimePicker, {
331
+ format: {
332
+ format: column.format?.timeFormat ?? 'HH:mm',
333
+ type: 'mask'
334
+ },
335
+ defaultValue: valueFilter ?? null,
336
+ onChange: (values, timeString) => {
337
+ const newTimeValue = timeString ? timeString : null;
338
+ console.log(newTimeValue);
339
+ // onChangeValueFilter(column, newTimeValue)
340
+ },
341
+ style: {
342
+ width: '100%'
343
+ },
344
+ popupStyle: {
345
+ zIndex: 9999
346
+ },
347
+ popupClassName: 'adv-popup-container'
348
+ });
349
+ case 'Number':
350
+ const thousandSeparator = column.format?.thousandSeparator ? column.format?.thousandSeparator : format?.thousandSeparator;
351
+ const decimalSeparator = column.format?.decimalSeparator ? column.format?.decimalSeparator : format?.decimalSeparator;
352
+ const numericFormatProps = {
353
+ thousandSeparator: (0, _hooks.checkThousandSeparator)(thousandSeparator, decimalSeparator),
354
+ decimalSeparator: (0, _hooks.checkDecimalSeparator)(thousandSeparator, decimalSeparator),
355
+ decimalScale: !(0, _hooks.isObjEmpty)(column.format?.decimalScale) ? column.format?.decimalScale : undefined,
356
+ fixedDecimalScale: !(0, _hooks.isEmpty)(column.format?.fixedDecimalScale) ? column.format?.fixedDecimalScale : false,
357
+ allowNegative: column.format?.allowNegative ?? false,
358
+ prefix: column.format?.prefix ?? undefined,
359
+ suffix: column.format?.suffix ?? undefined
360
+ };
361
+ const valueNumeric = valueFilter || valueFilter === 0 ? valueFilter.toString() : '';
362
+ return /*#__PURE__*/_react.default.createElement(_reactNumericComponent.NumericFormat, (0, _extends2.default)({}, numericFormatProps, {
363
+ value: valueNumeric,
364
+ customInput: _rcMasterUi.Input
365
+ // valueIsNumericString={true}
366
+ ,
367
+ autoComplete: 'off',
368
+ className: (0, _classnames.default)('adv-form-input form-control', {}),
369
+ onValueChange: values => {
370
+ console.log('values', values);
371
+ // onChangeValueFilter(column as any, values.floatValue)
372
+ }
373
+ }));
374
+ default:
375
+ return /*#__PURE__*/_react.default.createElement(_rcMasterUi.Input, {
376
+ placeholder: 'Nhập giá trị',
377
+ value: valueFilter ? valueFilter : '',
378
+ style: {
379
+ padding: '0.3rem 0.5rem',
380
+ lineHeight: '1.25'
381
+ },
382
+ autoFocus: index === 0,
383
+ onChange: val => {
384
+ console.log(val);
385
+ // onChangeValueFilter(column as any, val.target.value)
386
+ },
387
+ className: "adv-form-input"
388
+ });
389
+ }
390
+ };
391
+ const content = /*#__PURE__*/_react.default.createElement("div", {
392
+ ref: menuRef,
393
+ className: 'd-flex flex-column'
394
+ }, /*#__PURE__*/_react.default.createElement(MainFilter, {
395
+ leftFilterWidth: leftFilterWidth,
396
+ className: 'd-flex pb-1'
397
+ }, /*#__PURE__*/_react.default.createElement("div", {
398
+ style: {
399
+ flex: 1
400
+ }
401
+ }, /*#__PURE__*/_react.default.createElement(GridFilter, {
402
+ className: 'grid-filter'
403
+ }, columns.map((it, index) => {
404
+ return /*#__PURE__*/_react.default.createElement("div", {
405
+ className: 'grid-item-filter',
406
+ key: index
407
+ }, /*#__PURE__*/_react.default.createElement("p", {
408
+ className: 'm-0',
484
409
  style: {
485
- minWidth: 250
410
+ minHeight: 21
486
411
  }
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'))),
412
+ }, t ? t(it.headerText ?? '') : it.headerText), renderFilter(it, index));
413
+ })))), /*#__PURE__*/_react.default.createElement(BoxAction, {
414
+ className: ''
415
+ }, /*#__PURE__*/_react.default.createElement(_antd.Button, {
416
+ className: 'btn-action btn-action-cancel',
417
+ variant: "outlined",
418
+ onClick: handleReset
419
+ }, t ? t('Reset') : 'Reset'), /*#__PURE__*/_react.default.createElement(_antd.Button, {
420
+ className: 'btn-action btn-action-cancel',
421
+ variant: "outlined",
422
+ onClick: handleCancel
423
+ }, t ? t('Cancel') : 'Cancel'), /*#__PURE__*/_react.default.createElement(_antd.Button, {
424
+ className: (0, _classnames.default)('btn-action btn-action-submit', {
425
+ disable: !columns.find(item => item.visible !== false || item.visible)
426
+ }),
427
+ variant: "outlined",
428
+ onClick: handleAccept,
429
+ disabled: !columns.find(item => item.visible !== false || item.visible)
430
+ }, t ? t('Accept') : 'Accept')));
431
+ return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(_rcMasterUi.Popover, {
432
+ placement: 'bottomLeft'
433
+ // content={
434
+ // <div style={{minWidth: 250}}>
435
+ //
436
+ // </div>
437
+ // }
438
+ ,
439
+ content: content,
545
440
  trigger: "click",
546
441
  open: clicked,
547
442
  onOpenChange: handleClickChange,
@@ -549,6 +444,20 @@ const ColumnsChoose = props => {
549
444
  }, /*#__PURE__*/_react.default.createElement(_antd.Tooltip, {
550
445
  arrow: false,
551
446
  title: 'Cài đặt'
552
- }, /*#__PURE__*/_react.default.createElement(_icons.SettingOutlined, null))));
447
+ }, count > 0 ? /*#__PURE__*/_react.default.createElement(_antd.Badge, {
448
+ size: "small",
449
+ count: count,
450
+ color: "danger"
451
+ }, /*#__PURE__*/_react.default.createElement(_becoxyIcons.Filter, {
452
+ fontSize: 16,
453
+ style: {
454
+ cursor: 'pointer'
455
+ }
456
+ })) : /*#__PURE__*/_react.default.createElement(_becoxyIcons.Filter, {
457
+ fontSize: 16,
458
+ style: {
459
+ cursor: 'pointer'
460
+ }
461
+ }))));
553
462
  };
554
- exports.ColumnsChoose = ColumnsChoose;
463
+ var _default = exports.default = AdvanceFilter;