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 <paul.derscheid@lmscloud.de>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Paul Derscheid 2026-07-30 08:53:01 +00:00 committed by Lucas Gass
parent bf55b2bc3b
commit 93fa7e817b
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
2 changed files with 53 additions and 5 deletions

View File

@ -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 {

View File

@ -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");