Reset selected row(s) when table data is changed (#3576)

* Fixed selected row resets when table data is changed

Added cypress test case to test selected row resets when table data changes

* Fixed cypress test case
This commit is contained in:
Vicky Bansal 2021-03-17 17:27:38 +05:30 committed by GitHub
parent 084faf8d54
commit 1195a0b694
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 17 deletions

View File

@ -268,6 +268,21 @@ describe("Table Widget Functionality", function() {
});
});
it("Check Selected Row(s) Resets When Table Data Changes", function() {
cy.isSelectRow(1);
cy.openPropertyPane("tablewidget");
const newTableData = [...this.data.TableInput];
newTableData[0].userName = "";
cy.testJsontext("tabledata", JSON.stringify(newTableData));
cy.wait("@updateLayout");
const selectedRowsSelector = `.t--widget-tablewidget .tbody .tr.selected-row`;
cy.get(selectedRowsSelector).should(($p) => {
// should found 0 rows
expect($p).to.have.length(0);
});
});
/*
To enabled later

View File

@ -712,6 +712,8 @@ class TableWidget extends BaseWidget<TableWidgetProps, WidgetState> {
"filteredTableData",
filteredTableData,
);
//Update selectedRow indices since tableData is changed
this.updateSelectedRowIndex();
}
}
@ -736,23 +738,7 @@ class TableWidget extends BaseWidget<TableWidgetProps, WidgetState> {
// If the user changed the defaultSelectedRow(s)
if (!isEqual(this.props.defaultSelectedRow, prevProps.defaultSelectedRow)) {
//Runs only when defaultSelectedRow is changed from property pane
if (!this.props.multiRowSelection) {
const selectedRowIndex = isNumber(this.props.defaultSelectedRow)
? this.props.defaultSelectedRow
: -1;
this.props.updateWidgetMetaProperty(
"selectedRowIndex",
selectedRowIndex,
);
} else {
const selectedRowIndices = Array.isArray(this.props.defaultSelectedRow)
? this.props.defaultSelectedRow
: [];
this.props.updateWidgetMetaProperty(
"selectedRowIndices",
selectedRowIndices,
);
}
this.updateSelectedRowIndex();
}
if (this.props.pageSize !== prevProps.pageSize) {
@ -767,6 +753,23 @@ class TableWidget extends BaseWidget<TableWidgetProps, WidgetState> {
}
}
updateSelectedRowIndex = () => {
if (!this.props.multiRowSelection) {
const selectedRowIndex = isNumber(this.props.defaultSelectedRow)
? this.props.defaultSelectedRow
: -1;
this.props.updateWidgetMetaProperty("selectedRowIndex", selectedRowIndex);
} else {
const selectedRowIndices = Array.isArray(this.props.defaultSelectedRow)
? this.props.defaultSelectedRow
: [];
this.props.updateWidgetMetaProperty(
"selectedRowIndices",
selectedRowIndices,
);
}
};
getSelectedRowIndexes = (selectedRowIndices: string) => {
return selectedRowIndices
? selectedRowIndices.split(",").map((i) => Number(i))