MDL-68977 core_table: Do not update dynamic tables on nullop

When a setting is added/removed (i.e. an empty filter is removed) and
there is no change, then we should treat this is a null-op and not
refresh the table unnecessarily.
This commit is contained in:
Andrew Nicols
2020-06-09 11:21:04 +08:00
parent efa490c61f
commit efc3dfff47
3 changed files with 38 additions and 5 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+36 -3
View File
@@ -123,9 +123,14 @@ export const updateTable = (tableRoot, {
checkTableIsDynamic(tableRoot);
const pendingPromise = new Pending('core_table/dynamic:updateTable');
let tableConfigChanged = false;
// Update sort fields.
if (sortBy && sortOrder) {
// Always update the table if requested and there were sort fields.
// These fields are only ever normalised in the backend.
tableConfigChanged = true;
const sortData = JSON.parse(tableRoot.dataset.tableSortData);
sortData.unshift({
sortby: sortBy,
@@ -136,33 +141,61 @@ export const updateTable = (tableRoot, {
// Update initials.
if (firstInitial !== null) {
if (tableRoot.dataset.tableFirstInitial !== firstInitial) {
tableConfigChanged = true;
}
tableRoot.dataset.tableFirstInitial = firstInitial;
}
if (lastInitial !== null) {
if (tableRoot.dataset.tableLastInitial !== lastInitial) {
tableConfigChanged = true;
}
tableRoot.dataset.tableLastInitial = lastInitial;
}
if (pageNumber !== null) {
if (tableRoot.dataset.tablePageNumber != pageNumber) {
tableConfigChanged = true;
}
tableRoot.dataset.tablePageNumber = pageNumber;
}
if (pageSize !== null) {
if (tableRoot.dataset.tablePageSize != pageSize) {
tableConfigChanged = true;
}
tableRoot.dataset.tablePageSize = pageSize;
}
// Update filters.
if (filters) {
tableRoot.dataset.tableFilters = JSON.stringify(filters);
const filterJson = JSON.stringify(filters);
if (tableRoot.dataset.tableFilters !== filterJson) {
tableConfigChanged = true;
}
tableRoot.dataset.tableFilters = filterJson;
}
// Update hidden columns.
if (hiddenColumns) {
tableRoot.dataset.tableHiddenColumns = JSON.stringify(hiddenColumns);
const columnJson = JSON.stringify(hiddenColumns);
if (tableRoot.dataset.tableHiddenColumns !== columnJson) {
tableConfigChanged = true;
}
tableRoot.dataset.tableHiddenColumns = columnJson;
}
// Refresh.
if (refreshContent) {
if (refreshContent && tableConfigChanged) {
return refreshTableContent(tableRoot)
.then(tableRoot => {
pendingPromise.resolve();