From 93fa7e817b683c79dc3b50e7f04eb2bcb11e1fec Mon Sep 17 00:00:00 2001 From: Paul Derscheid Date: Thu, 30 Jul 2026 08:53:01 +0000 Subject: [PATCH] Bug 43174: (QA follow-up) Restore user choices on redraw independent of search state To test: - cypress run --spec t/cypress/integration/KohaTable/PatronSearch_spec.ts - cypress run --spec t/cypress/integration/KohaTable/KohaTable_spec.ts Signed-off-by: Paul Derscheid Signed-off-by: Lucas Gass --- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 12 +++-- .../integration/KohaTable/KohaTable_spec.ts | 46 +++++++++++++++++++ 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 4208f5edeb..a8714fbf6c 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -1332,6 +1332,13 @@ function _dt_save_restore_state(table_settings, external_filter_nodes = {}) { data.user_choices = kohaTableUserChoices[tableId] || {}; }; let stateLoadParams = function (settings, data) { + // The user choices are part of the column state, which is saved on + // every draw. They must be restored even when the search state is not. + if (data.user_choices) { + const tableId = settings.nTable.id; + kohaTableUserChoices[tableId] = data.user_choices; + } + if (!$("#" + settings.nTable.id).data("loaded_from_state")) return; if (data.external_filters) { @@ -1365,11 +1372,6 @@ function _dt_save_restore_state(table_settings, external_filter_nodes = {}) { } }); } - - if (data.user_choices) { - const tableId = settings.nTable.id; - kohaTableUserChoices[tableId] = data.user_choices; - } }; return { diff --git a/t/cypress/integration/KohaTable/KohaTable_spec.ts b/t/cypress/integration/KohaTable/KohaTable_spec.ts index f7e72f1f4f..b135708d7e 100644 --- a/t/cypress/integration/KohaTable/KohaTable_spec.ts +++ b/t/cypress/integration/KohaTable/KohaTable_spec.ts @@ -206,6 +206,52 @@ describe("kohaTable (using REST API)", () => { }); }); + it("User choices are kept in the state - Save state is ON, search state is OFF", () => { + const state_key = "DataTables_admin_libraries_libraries"; + + build_libraries().then(() => { + cy.visit("/cgi-bin/koha/admin/branches.pl"); + + cy.mock_table_settings({ + default_save_state: 1, + default_save_state_search: 0, + }); + + // Hide "Code" + cy.get(`#${table_id}_wrapper .buttons-colvis`).click(); + cy.get(`#${table_id}_wrapper .dt-button-collection`) + .contains("Code") + .click(); + + cy.window().then(win => { + const state = JSON.parse( + win.localStorage.getItem(state_key) + ); + expect(state.user_choices).to.deep.equal({ 1: false }); + }); + + // The state is saved on every draw, the user choices must not + // be dropped by the draws of the next page load + cy.visit("/cgi-bin/koha/admin/branches.pl"); + + cy.mock_table_settings({ + default_save_state: 1, + default_save_state_search: 0, + }); + + cy.get(`#${table_id}_wrapper .dt-info`).contains( + `Showing 1 to ${RESTdefaultPageSize} of ${baseTotalCount} entries` + ); + + cy.window().then(win => { + const state = JSON.parse( + win.localStorage.getItem(state_key) + ); + expect(state.user_choices).to.deep.equal({ 1: false }); + }); + }); + }); + it("One column hidden, feature is off {visibility_condition: false} - Save state is ON", () => { build_libraries().then(() => { cy.visit("/cgi-bin/koha/admin/branches.pl");