-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathAdjustColumns.tsx
More file actions
88 lines (81 loc) · 2.11 KB
/
AdjustColumns.tsx
File metadata and controls
88 lines (81 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import React, { useEffect, useState } from 'react';
import { Button, Popover, Select } from 'antd';
import { ControlOutlined } from '@ant-design/icons';
import { useContext } from '@graphscope/studio-graph';
import { getTable } from './getTableData';
interface IAdjustColumnsProps {
onChange: (columnIds: string[]) => void;
columnKeys: string[];
}
export function getTableColumns(columnIds: string[]) {
return columnIds?.map(key => {
return {
title: key,
dataIndex: key,
key: key,
sorter: (a, b) => a[key] - b[key],
};
})||[];
}
const AdjustColumns: React.FunctionComponent<IAdjustColumnsProps> = props => {
const { store } = useContext();
const { source } = store;
const { columns } = getTable(source.nodes);
const { onChange, columnKeys } = props;
const [state, setState] = useState({
columnIds: columnKeys,
tableColumns: getTableColumns(columnKeys),
});
useEffect(()=>{
setState(preState => {
return {
...preState,
columnIds: columnKeys,
tableColumns: getTableColumns(columnKeys),
};
});
},[columnKeys])
const { columnIds } = state;
const onChangeColumns = value => {
setState(preState => {
return {
...preState,
columnIds: value,
tableColumns: getTableColumns(value),
};
});
if (onChange) {
onChange(value);
}
};
const options = columns.map(item => {
return {
label: item.key,
value: item.key,
};
});
return (
<Popover
title="Select Display Columns"
arrow={false}
placement="bottomRight"
style={{ padding: '0px' }}
content={
<Select
// maxTagCount="responsive"
mode="multiple"
allowClear
style={{ width: '300px' }}
variant="borderless"
placeholder="Adjust Table Columns"
value={columnIds}
onChange={onChangeColumns}
options={options}
/>
}
>
<Button style={{ padding: '12px 0px' }} type="text" icon={<ControlOutlined />}></Button>
</Popover>
);
};
export default React.memo(AdjustColumns);