From e616be2e4219a38e28e9ec224ca0c8ccb9845bf7 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 16 Jun 2026 14:20:59 +0200 Subject: [PATCH] Bug 41604: Hide column if the feature is disabled Example: supplier_report on the basket page Signed-off-by: Jason Robb Signed-off-by: Victor Grousset/tuxayo Signed-off-by: Lucas Gass --- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 20 ++++++++++-- .../integration/KohaTable/KohaTable_spec.ts | 32 +++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 7929210b73..faae338b88 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -1530,13 +1530,27 @@ function update_search_description( options ); - settings["buttons"] = _dt_buttons({ settings, table_settings }); - if (add_filters) { settings["orderCellsTop"] = true; } if (table_settings) { + // Deal with visibility_condition + // Column must be hidden and cannot be toggled if condition is false + table_settings.columns = table_settings.columns.map(c => { + if ( + c.visibility_condition !== undefined && + !c.visibility_condition + ) { + return { + ...c, + is_hidden: true, + cannot_be_toggled: true, + }; + } + return c; + }); + let state_settings = _dt_save_restore_state( table_settings, external_filter_nodes @@ -1562,6 +1576,8 @@ function update_search_description( } } + settings["buttons"] = _dt_buttons({ settings, table_settings }); + var default_column_defs = [ { targets: ["string-sort"], type: "string" }, { targets: ["anti-the"], type: "anti-the" }, diff --git a/t/cypress/integration/KohaTable/KohaTable_spec.ts b/t/cypress/integration/KohaTable/KohaTable_spec.ts index 8fab186b15..f7e72f1f4f 100644 --- a/t/cypress/integration/KohaTable/KohaTable_spec.ts +++ b/t/cypress/integration/KohaTable/KohaTable_spec.ts @@ -206,6 +206,38 @@ describe("kohaTable (using REST API)", () => { }); }); + 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"); + + cy.mock_table_settings({ + default_save_state: 1, + columns: { + library_code: { + is_hidden: true, + visibility_condition: false, + }, + }, + }); + + cy.get("@columns").then(columns => { + cy.get(`#${table_id} th`).should( + "have.length", + columns.length - 1 + ); + cy.get(`#${table_id} th`).contains("Name"); + cy.get(`#${table_id} th`) + .contains("Code") + .should("not.exist"); + cy.get(`#${table_id}_wrapper .buttons-colvis`).click(); + // The feature is off, the column cannot be displayed + cy.get(`#${table_id}_wrapper .dt-button-collection`) + .contains("Code") + .should("not.exist"); + }); + }); + }); + it("Force visibility of one column", () => { build_libraries().then(() => { cy.visit("/cgi-bin/koha/admin/branches.pl");