Skip to content

Commit bc187fa

Browse files
gurbirkalsiportante
authored andcommitted
Utilize "selectedRows" from onSelect, onSelectAll callback using ant
design Table API
1 parent 35041ff commit bc187fa

File tree

3 files changed

+24
-41
lines changed

3 files changed

+24
-41
lines changed

web-server/v0.4/src/pages/ComparisonSelect/index.js

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ import Table from '@/components/Table';
2424
class ComparisonSelect extends React.Component {
2525
constructor(props) {
2626
super(props);
27-
const { iterations, selectedIterationKeys } = props;
27+
const { iterations } = props;
2828

2929
this.state = {
3030
resultIterations: iterations,
31-
selectedRowKeys: selectedIterationKeys,
31+
selectedRows: [],
3232
};
3333
}
3434

@@ -48,7 +48,6 @@ class ComparisonSelect extends React.Component {
4848

4949
if (nextProps.iterations !== iterations) {
5050
this.setState({ resultIterations: nextProps.iterations });
51-
this.setState({ selectedRowKeys: nextProps.selectedIterationKeys });
5251
}
5352
}
5453

@@ -61,16 +60,10 @@ class ComparisonSelect extends React.Component {
6160
};
6261

6362
onCompareIterations = () => {
64-
const { selectedRowKeys, resultIterations } = this.state;
65-
66-
if (selectedRowKeys.flat(1).length > 0) {
67-
const selectedRowData = [];
68-
selectedRowKeys.forEach(rowKey => {
69-
selectedRowKeys[rowKey].forEach(row => {
70-
selectedRowData.push(resultIterations[rowKey].iterations[selectedRowKeys[rowKey][row]]);
71-
});
72-
});
73-
this.compareIterations(selectedRowData);
63+
const { selectedRows, resultIterations } = this.state;
64+
65+
if (selectedRows.length > 0) {
66+
this.compareIterations(selectedRows);
7467
} else {
7568
let selectedIterations = [];
7669
resultIterations.forEach(result => {
@@ -80,15 +73,8 @@ class ComparisonSelect extends React.Component {
8073
}
8174
};
8275

83-
onSelectChange = record => {
84-
const { selectedRowKeys } = this.state;
85-
86-
if (selectedRowKeys[record.table].includes(record.key)) {
87-
selectedRowKeys[record.table].splice(selectedRowKeys[record.table].indexOf(record.key), 1);
88-
} else {
89-
selectedRowKeys[record.table].push(record.key);
90-
}
91-
this.setState({ selectedRowKeys });
76+
onSelectChange = selectedRows => {
77+
this.setState({ selectedRows });
9278
};
9379

9480
onFilterTable = (selectedParams, selectedPorts) => {
@@ -114,7 +100,7 @@ class ComparisonSelect extends React.Component {
114100
};
115101

116102
render() {
117-
const { resultIterations, selectedRowKeys } = this.state;
103+
const { resultIterations } = this.state;
118104
const { iterationParams, iterationPorts, selectedControllers, loading } = this.props;
119105
return (
120106
<PageHeaderLayout
@@ -134,10 +120,10 @@ class ComparisonSelect extends React.Component {
134120
filters={iterationParams}
135121
ports={iterationPorts}
136122
/>
137-
{resultIterations.map((iteration, index) => {
123+
{resultIterations.map(iteration => {
138124
const rowSelection = {
139-
selectedRowKeys: selectedRowKeys[index],
140-
onSelect: record => this.onSelectChange(record),
125+
onSelect: (record, selected, selectedRows) => this.onSelectChange(selectedRows),
126+
onSelectAll: (selected, selectedRows) => this.onSelectAll(selectedRows),
141127
};
142128
return (
143129
<div key={iteration.resultName} style={{ marginTop: 32 }}>
@@ -152,6 +138,7 @@ class ComparisonSelect extends React.Component {
152138
rowSelection={rowSelection}
153139
columns={iteration.columns}
154140
dataSource={iteration.iterations}
141+
hideDefaultSelections
155142
bordered
156143
/>
157144
</div>

web-server/v0.4/src/pages/Results/index.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Results extends Component {
2121

2222
this.state = {
2323
results: props.results,
24-
selectedRowKeys: [],
24+
selectedRows: [],
2525
};
2626
}
2727

@@ -46,14 +46,10 @@ class Results extends Component {
4646
}
4747
}
4848

49-
onSelectChange = selectedRowKeys => {
50-
const { dispatch, results } = this.props;
51-
const selectedRows = [];
52-
selectedRowKeys.forEach(key => {
53-
const selectedKey = results.find(result => result.key === key);
54-
selectedRows.push(selectedKey);
55-
});
56-
this.setState({ selectedRowKeys });
49+
onSelectChange = selectedRows => {
50+
const { dispatch } = this.props;
51+
52+
this.setState({ selectedRows });
5753

5854
dispatch({
5955
type: 'global/updateSelectedResults',
@@ -122,11 +118,11 @@ class Results extends Component {
122118
};
123119

124120
render() {
125-
const { results, selectedRowKeys } = this.state;
121+
const { results, selectedRows } = this.state;
126122
const { selectedControllers, loading } = this.props;
127123
const rowSelection = {
128-
selectedRowKeys,
129-
onChange: this.onSelectChange,
124+
// eslint-disable-next-line no-shadow
125+
onSelect: (record, selected, selectedRows) => this.onSelectChange(selectedRows),
130126
};
131127

132128
const columns = [
@@ -164,7 +160,7 @@ class Results extends Component {
164160
onSearch={this.onSearch}
165161
/>
166162
<RowSelection
167-
selectedItems={selectedRowKeys}
163+
selectedItems={selectedRows}
168164
compareActionName="Compare Results"
169165
onCompare={this.compareResults}
170166
/>

web-server/v0.4/src/utils/parse.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ export const parseIterationData = results => {
2525
};
2626
selectedIterationKeys.push([]);
2727

28-
result.iterationData.forEach((iteration, index) => {
28+
result.iterationData.forEach(iteration => {
2929
let iterationMetadata = {
3030
iteration_name: iteration.iteration_name,
3131
iteration_number: iteration.iteration_number,
3232
result_name: result.resultName,
3333
controller_name: result.controllerName,
3434
table: result.tableId,
35-
key: index,
35+
key: iteration.iteration_number,
3636
};
3737
const iterationConfig = iteration.iteration_data.parameters.benchmark
3838
? Object.entries(iteration.iteration_data.parameters.benchmark[0])

0 commit comments

Comments
 (0)