/
method-parameters.tsx
157 lines (152 loc) · 3.97 KB
/
method-parameters.tsx
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import React from 'react';
import { Table, Input, Button, Space } from 'antd';
//@ts-ignore
import Highlighter from 'react-highlight-words';
import { SearchOutlined } from '@ant-design/icons';
export class MethodParameters extends React.Component {
state = {
searchText: '',
searchedColumn: '',
};
getColumnSearchProps = (dataIndex: number) => ({
filterDropdown: ({
setSelectedKeys,
selectedKeys,
confirm,
clearFilters,
}: any) => (
<div style={{ padding: 8 }}>
<Input
ref={(node) => {
//@ts-ignore
this.searchInput = node;
}}
placeholder={`Search ${dataIndex}`}
value={selectedKeys[0]}
onChange={(e) =>
setSelectedKeys(e.target.value ? [e.target.value] : [])
}
onPressEnter={() =>
this.handleSearch(selectedKeys, confirm, dataIndex)
}
style={{ marginBottom: 8, display: 'block' }}
/>
<Space>
<Button
type="primary"
onClick={() => this.handleSearch(selectedKeys, confirm, dataIndex)}
icon={<SearchOutlined />}
size="small"
style={{ width: 90 }}
>
Search
</Button>
<Button
onClick={() => this.handleReset(clearFilters)}
size="small"
style={{ width: 90 }}
>
Reset
</Button>
<Button
type="link"
size="small"
onClick={() => {
confirm({ closeDropdown: false });
this.setState({
searchText: selectedKeys[0],
searchedColumn: dataIndex,
});
}}
>
Filter
</Button>
</Space>
</div>
),
filterIcon: (filtered: any) => (
<SearchOutlined style={{ color: filtered ? '#1890ff' : undefined }} />
),
onFilter: (value: any, record: any) =>
record[dataIndex]
? record[dataIndex]
.toString()
.toLowerCase()
.includes(value.toLowerCase())
: '',
onFilterDropdownVisibleChange: (visible: any) => {
if (visible) {
//@ts-ignore
setTimeout(() => this.searchInput.select(), 100);
}
},
render: (text: any) =>
//@ts-ignore
this.state.searchedColumn === dataIndex ? (
<Highlighter
highlightStyle={{ backgroundColor: '#ffc069', padding: 0 }}
searchWords={[this.state.searchText]}
autoEscape
textToHighlight={text ? text.toString() : ''}
/>
) : (
text
),
});
handleSearch = (selectedKeys: any, confirm: any, dataIndex: any) => {
confirm();
this.setState({
searchText: selectedKeys[0],
searchedColumn: dataIndex,
});
};
handleReset = (clearFilters: any) => {
clearFilters();
this.setState({ searchText: '' });
};
render() {
const columns = [
{
title: 'Name',
dataIndex: 'name',
key: 'name',
width: '30%',
//@ts-ignore
...this.getColumnSearchProps('name'),
},
{
title: 'Required *',
dataIndex: 'required',
key: 'required',
width: '20%',
//@ts-ignore
sorter: (a: any, b: any) => a.required - b.required,
sortDirections: ['descend', 'ascend'],
},
{
title: 'Default value',
dataIndex: 'default',
key: 'default',
},
{
title: 'Description',
dataIndex: 'description',
key: 'description',
//@ts-ignore
...this.getColumnSearchProps('description'),
},
{
title: 'Type of the data',
dataIndex: 'dataType',
key: 'dataType',
},
{
title: 'Value',
dataIndex: 'value',
key: 'value',
},
];
//@ts-ignore
return <Table columns={columns as any} dataSource={this.props.data} />;
}
}