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