From 282b5a79567e4e276ff4b20a5ce98a54d729466d Mon Sep 17 00:00:00 2001 From: Nabeel Sait <49792733+NabeelSait@users.noreply.github.com> Date: Wed, 10 Nov 2021 13:24:19 -0600 Subject: [PATCH] Warn on fill/blank down when a sorting criterion is applied (#4284) * Fixes #3256, with Cypress tests Co-authored-by: Nabeel Sait <> --- .../edit-cells/warning-on-blank-down.spec.js | 56 +++++++++++++++++++ .../edit-cells/warning-on-fill-down.spec.js | 56 +++++++++++++++++++ .../tests/cypress/cypress/support/commands.js | 10 ++++ .../modules/core/langs/translation-en.json | 2 + .../views/data-table/data-table-view.js | 44 ++++++++++++++- .../views/data-table/menu-edit-cells.js | 18 +++++- .../data-table/warn-of-pending-sort.html | 17 ++++++ 7 files changed, 199 insertions(+), 4 deletions(-) create mode 100644 main/tests/cypress/cypress/integration/project/grid/column/edit-cells/warning-on-blank-down.spec.js create mode 100644 main/tests/cypress/cypress/integration/project/grid/column/edit-cells/warning-on-fill-down.spec.js create mode 100644 main/webapp/modules/core/scripts/views/data-table/warn-of-pending-sort.html diff --git a/main/tests/cypress/cypress/integration/project/grid/column/edit-cells/warning-on-blank-down.spec.js b/main/tests/cypress/cypress/integration/project/grid/column/edit-cells/warning-on-blank-down.spec.js new file mode 100644 index 000000000..4ee3cd3a0 --- /dev/null +++ b/main/tests/cypress/cypress/integration/project/grid/column/edit-cells/warning-on-blank-down.spec.js @@ -0,0 +1,56 @@ +describe(__filename, function () { + it('Ensure cells are blanked down', function () { + const fixture = [ + ['a', 'b', 'c'], + + ['0a', 'identical', '0c'], + ['1a', 'identical', '1c'], + ['2a', '2b', '2c'], + ['3a', 'also identical', '3c'], + ['4a', 'also identical', '4c'], + ['5a', 'also identical', '5c'], + ]; + + cy.loadAndVisitProject(fixture); + + //Create Pending Sort + cy.columnActionClick('b', ['Sort']); + cy.waitForDialogPanel(); + cy.confirmDialogPanel(); + + //Verify Sort occurred + cy.assertCellEquals(0, 'b', '2b'); + cy.assertCellEquals(1, 'b', 'also identical'); + cy.assertCellEquals(2, 'b', 'also identical'); + cy.assertCellEquals(3, 'b', 'also identical'); + cy.assertCellEquals(4, 'b', 'identical'); + cy.assertCellEquals(5, 'b', 'identical'); + + // click, then cancel dialog window + cy.columnActionClick('b', ['Edit cells', 'Blank down']); + cy.waitForDialogPanel(); + cy.cancelDialogPanel(); + + //Verify blank down did not occur + cy.assertCellEquals(0, 'b', '2b'); + cy.assertCellEquals(1, 'b', 'also identical'); + cy.assertCellEquals(2, 'b', 'also identical'); + cy.assertCellEquals(3, 'b', 'also identical'); + cy.assertCellEquals(4, 'b', 'identical'); + cy.assertCellEquals(5, 'b', 'identical'); + + // click, then confirm dialog window + cy.columnActionClick('b', ['Edit cells', 'Blank down']); + cy.waitForDialogPanel(); + cy.confirmDialogPanel(); + + // ensure notification and cell content + cy.assertNotificationContainingText('Blank down 3 cells'); + cy.assertCellEquals(0, 'b', '2b'); + cy.assertCellEquals(1, 'b', 'also identical'); + cy.assertCellEquals(2, 'b', 'identical'); + cy.assertCellEquals(3, 'b', null); + cy.assertCellEquals(4, 'b', null); + cy.assertCellEquals(5, 'b', null); + }); +}); \ No newline at end of file diff --git a/main/tests/cypress/cypress/integration/project/grid/column/edit-cells/warning-on-fill-down.spec.js b/main/tests/cypress/cypress/integration/project/grid/column/edit-cells/warning-on-fill-down.spec.js new file mode 100644 index 000000000..f3ecbaaff --- /dev/null +++ b/main/tests/cypress/cypress/integration/project/grid/column/edit-cells/warning-on-fill-down.spec.js @@ -0,0 +1,56 @@ +describe(__filename, function () { + it('Ensure cells are filled down', function () { + const fixture = [ + ['a', 'b', 'c'], + + ['0a', '0b', '0c'], + ['1a', null, '1c'], + ['2a', '2b', '2c'], + ['3a', null, '3c'], + ['4a', null, '4c'], + ['5a', '5b', '5c'], + ]; + + cy.loadAndVisitProject(fixture); + + //Create Pending Sort + cy.columnActionClick('b', ['Sort']); + cy.waitForDialogPanel(); + cy.confirmDialogPanel(); + + //Verify Sort occurred + cy.assertCellEquals(0, 'b', '0b'); + cy.assertCellEquals(1, 'b', '2b'); + cy.assertCellEquals(2, 'b', '5b'); + cy.assertCellEquals(3, 'b', null); + cy.assertCellEquals(4, 'b', null); + cy.assertCellEquals(5, 'b', null); + + // click, then cancel dialog + cy.columnActionClick('b', ['Edit cells', 'Fill down']); + cy.waitForDialogPanel(); + cy.cancelDialogPanel(); + + //Verify fill down did not occur + cy.assertCellEquals(0, 'b', '0b'); + cy.assertCellEquals(1, 'b', '2b'); + cy.assertCellEquals(2, 'b', '5b'); + cy.assertCellEquals(3, 'b', null); + cy.assertCellEquals(4, 'b', null); + cy.assertCellEquals(5, 'b', null); + + // click, then confirm dialog + cy.columnActionClick('b', ['Edit cells', 'Fill down']); + cy.waitForDialogPanel(); + cy.confirmDialogPanel(); + + // ensure notification and cell content + cy.assertNotificationContainingText('Fill down 3 cells in column b'); + cy.assertCellEquals(0, 'b', '0b'); // untouched + cy.assertCellEquals(1, 'b', '0b'); // filled + cy.assertCellEquals(2, 'b', '2b'); // untouched + cy.assertCellEquals(3, 'b', '2b'); // filled + cy.assertCellEquals(4, 'b', '2b'); // filled + cy.assertCellEquals(5, 'b', '5b'); // untouched + }); +}); \ No newline at end of file diff --git a/main/tests/cypress/cypress/support/commands.js b/main/tests/cypress/cypress/support/commands.js index 9cdfeca5e..34af6bb8d 100644 --- a/main/tests/cypress/cypress/support/commands.js +++ b/main/tests/cypress/cypress/support/commands.js @@ -307,6 +307,16 @@ Cypress.Commands.add('confirmDialogPanel', () => { cy.get('body > .dialog-container > .dialog-frame').should('not.exist'); }); +/** + * Click on the Cancel button of a dialog panel + */ + Cypress.Commands.add('cancelDialogPanel', () => { + cy.get( + 'body > .dialog-container > .dialog-frame .dialog-footer button[bind="cancelButton"]' + ).click(); + cy.get('body > .dialog-container > .dialog-frame').should('not.exist'); + }); + /** * Will click on a menu entry for a given column name */ diff --git a/main/webapp/modules/core/langs/translation-en.json b/main/webapp/modules/core/langs/translation-en.json index e896e5162..aa4597e82 100644 --- a/main/webapp/modules/core/langs/translation-en.json +++ b/main/webapp/modules/core/langs/translation-en.json @@ -453,6 +453,8 @@ "core-views/remove-sort": "Remove sort", "core-views/sort-by": "Sort by", "core-views/sort-cell": "Sort cell values as", + "core-views/warn-of-pending-sort": "There is a sort pending. The data visible on screen may not reflect the data this operation will act on.", + "core-views/warning": "Warning", "core-views/pos-blank": "Position blanks and errors", "core-views/text": "text", "core-views/case-sensitive": "case-sensitive", diff --git a/main/webapp/modules/core/scripts/views/data-table/data-table-view.js b/main/webapp/modules/core/scripts/views/data-table/data-table-view.js index 74313699d..515d997ee 100644 --- a/main/webapp/modules/core/scripts/views/data-table/data-table-view.js +++ b/main/webapp/modules/core/scripts/views/data-table/data-table-view.js @@ -910,12 +910,26 @@ DataTableView.prototype._createMenuForAllColumns = function(elmt) { { label: $.i18n('core-views/fill-down'), id: "core/fill-down", - click: doAllFillDown + click: function () { + if (self._getSortingCriteriaCount() > 0) { + self._createPendingSortWarningDialog(doAllFillDown); + } + else { + doAllFillDown(); + } + } }, { label: $.i18n('core-views/blank-down'), id: "core/blank-down", - click: doAllBlankDown + click: function () { + if (self._getSortingCriteriaCount() > 0) { + self._createPendingSortWarningDialog(doAllBlankDown); + } + else { + doAllBlankDown(); + } + } } ] }, @@ -1117,3 +1131,29 @@ DataTableView.promptExpressionOnVisibleRows = function(column, title, expression onDone ); }; + +//This function takes a function as a parameter and creates a dialog window +//If the ok button is pressed, the function is executed +//If the cancel button is pressed instead, the window is dismissed and the function is not executed +DataTableView.prototype._createPendingSortWarningDialog = function(func) { + var frame = $(DOM.loadHTML("core", "scripts/views/data-table/warn-of-pending-sort.html")); + var elmts = DOM.bind(frame); + + elmts.or_views_warning.text($.i18n('core-views/warn-of-pending-sort')); + elmts.dialogHeader.text($.i18n('core-views/warning')); + elmts.okButton.html($.i18n('core-buttons/ok')); + elmts.cancelButton.text($.i18n('core-buttons/cancel')); + + var level = DialogSystem.showDialog(frame); + var dismiss = function() { DialogSystem.dismissLevel(level - 1); }; + + elmts.cancelButton.click( function () { + dismiss(); + }); + + elmts.okButton.click( function () { + func(); + dismiss(); + }); + +}; diff --git a/main/webapp/modules/core/scripts/views/data-table/menu-edit-cells.js b/main/webapp/modules/core/scripts/views/data-table/menu-edit-cells.js index 1828ea11a..84ca9a53a 100644 --- a/main/webapp/modules/core/scripts/views/data-table/menu-edit-cells.js +++ b/main/webapp/modules/core/scripts/views/data-table/menu-edit-cells.js @@ -468,12 +468,26 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) { { id: "core/fill-down", label: $.i18n('core-views/fill-down'), - click: doFillDown + click: function () { + if (columnHeaderUI._dataTableView._getSortingCriteriaCount() > 0) { + columnHeaderUI._dataTableView._createPendingSortWarningDialog(doFillDown); + } + else { + doFillDown(); + } + } }, { id: "core/blank-down", label: $.i18n('core-views/blank-down'), - click: doBlankDown + click: function () { + if (columnHeaderUI._dataTableView._getSortingCriteriaCount() > 0) { + columnHeaderUI._dataTableView._createPendingSortWarningDialog(doBlankDown); + } + else { + doBlankDown(); + } + } }, {}, { diff --git a/main/webapp/modules/core/scripts/views/data-table/warn-of-pending-sort.html b/main/webapp/modules/core/scripts/views/data-table/warn-of-pending-sort.html new file mode 100644 index 000000000..5cb4a77fe --- /dev/null +++ b/main/webapp/modules/core/scripts/views/data-table/warn-of-pending-sort.html @@ -0,0 +1,17 @@ +
+ |