From 8ff112c527f6563740f3665064b1e40ea390f087 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Thu, 20 Nov 2025 13:37:34 +0100 Subject: [PATCH] Fix inconsistent selection counter after deleting a row from a grid view ref https://www.woltlab.com/community/thread/314897-grid-bulk-interactions-z%C3%A4hler-wird-nicht-zur%C3%BCckgesetzt/ --- ts/WoltLabSuite/Core/Component/GridView.ts | 1 + ts/WoltLabSuite/Core/Component/GridView/Selection.ts | 10 ++++++++++ ts/WoltLabSuite/Core/Component/GridView/State.ts | 4 ++++ ts/WoltLabSuite/Core/Component/ListView.ts | 1 + ts/WoltLabSuite/Core/Component/ListView/Selection.ts | 10 ++++++++++ ts/WoltLabSuite/Core/Component/ListView/State.ts | 4 ++++ .../files/js/WoltLabSuite/Core/Component/GridView.js | 1 + .../WoltLabSuite/Core/Component/GridView/Selection.js | 8 ++++++++ .../js/WoltLabSuite/Core/Component/GridView/State.js | 3 +++ .../files/js/WoltLabSuite/Core/Component/ListView.js | 1 + .../WoltLabSuite/Core/Component/ListView/Selection.js | 8 ++++++++ .../js/WoltLabSuite/Core/Component/ListView/State.js | 3 +++ 12 files changed, 54 insertions(+) diff --git a/ts/WoltLabSuite/Core/Component/GridView.ts b/ts/WoltLabSuite/Core/Component/GridView.ts index 252278ed9c..6ebd60d7a6 100644 --- a/ts/WoltLabSuite/Core/Component/GridView.ts +++ b/ts/WoltLabSuite/Core/Component/GridView.ts @@ -111,6 +111,7 @@ export class GridView { this.#table.addEventListener("interaction:remove", (event) => { (event.target as HTMLElement).remove(); + this.#state.removeSelection(parseInt((event.target as HTMLElement).dataset.objectId!)); this.#checkEmptyTable(); }); diff --git a/ts/WoltLabSuite/Core/Component/GridView/Selection.ts b/ts/WoltLabSuite/Core/Component/GridView/Selection.ts index bea7826728..a7e54c07b2 100644 --- a/ts/WoltLabSuite/Core/Component/GridView/Selection.ts +++ b/ts/WoltLabSuite/Core/Component/GridView/Selection.ts @@ -274,6 +274,16 @@ export class Selection extends EventTarget { this.#updateSelectionBar(); } + removeSelection(objectId: number): void { + const selectedIds = this.getSelectedIds(); + if (selectedIds.indexOf(objectId) !== -1) { + selectedIds.splice(selectedIds.indexOf(objectId), 1); + window.localStorage.setItem(this.#getStorageKey(), JSON.stringify(selectedIds)); + } + + this.#change(); + } + #initBulkInteractions(): void { if (!this.#bulkInteractionButton) { return; diff --git a/ts/WoltLabSuite/Core/Component/GridView/State.ts b/ts/WoltLabSuite/Core/Component/GridView/State.ts index c6760fa8fc..40e2390bbe 100644 --- a/ts/WoltLabSuite/Core/Component/GridView/State.ts +++ b/ts/WoltLabSuite/Core/Component/GridView/State.ts @@ -199,6 +199,10 @@ export class State extends EventTarget { this.#selection.resetSelection(); } + removeSelection(objectId: number): void { + this.#selection.removeSelection(objectId); + } + refreshSelection(): void { this.#selection.refresh(); } diff --git a/ts/WoltLabSuite/Core/Component/ListView.ts b/ts/WoltLabSuite/Core/Component/ListView.ts index fc77d26662..063d2fef28 100644 --- a/ts/WoltLabSuite/Core/Component/ListView.ts +++ b/ts/WoltLabSuite/Core/Component/ListView.ts @@ -115,6 +115,7 @@ export class ListView { this.#viewElement.addEventListener("interaction:remove", (event) => { (event.target as HTMLElement).remove(); + this.#state.removeSelection(parseInt((event.target as HTMLElement).dataset.objectId!)); this.#checkEmptyList(); }); diff --git a/ts/WoltLabSuite/Core/Component/ListView/Selection.ts b/ts/WoltLabSuite/Core/Component/ListView/Selection.ts index 91bda0f450..7a0dc15ffc 100644 --- a/ts/WoltLabSuite/Core/Component/ListView/Selection.ts +++ b/ts/WoltLabSuite/Core/Component/ListView/Selection.ts @@ -274,6 +274,16 @@ export class Selection extends EventTarget { this.#updateSelectionBar(); } + removeSelection(objectId: number): void { + const selectedIds = this.getSelectedIds(); + if (selectedIds.indexOf(objectId) !== -1) { + selectedIds.splice(selectedIds.indexOf(objectId), 1); + window.localStorage.setItem(this.#getStorageKey(), JSON.stringify(selectedIds)); + } + + this.#change(); + } + #initBulkInteractions(): void { if (!this.#bulkInteractionButton) { return; diff --git a/ts/WoltLabSuite/Core/Component/ListView/State.ts b/ts/WoltLabSuite/Core/Component/ListView/State.ts index 8da24c7ac0..c787951c7d 100644 --- a/ts/WoltLabSuite/Core/Component/ListView/State.ts +++ b/ts/WoltLabSuite/Core/Component/ListView/State.ts @@ -220,6 +220,10 @@ export class State extends EventTarget { this.#selection.resetSelection(); } + removeSelection(objectId: number): void { + this.#selection.removeSelection(objectId); + } + refreshSelection(): void { this.#selection.refresh(); } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/GridView.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/GridView.js index 305db65135..708ad81a01 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/GridView.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/GridView.js @@ -74,6 +74,7 @@ define(["require", "exports", "tslib", "../Api/GridViews/GetRow", "../Api/GridVi }); this.#table.addEventListener("interaction:remove", (event) => { event.target.remove(); + this.#state.removeSelection(parseInt(event.target.dataset.objectId)); this.#checkEmptyTable(); }); this.#table.addEventListener("interaction:reset-selection", () => { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/GridView/Selection.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/GridView/Selection.js index 7e6af3e61b..45d0e73508 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/GridView/Selection.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/GridView/Selection.js @@ -223,6 +223,14 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Core", "WoltLabSuite/C window.localStorage.removeItem(this.#getStorageKey()); this.#updateSelectionBar(); } + removeSelection(objectId) { + const selectedIds = this.getSelectedIds(); + if (selectedIds.indexOf(objectId) !== -1) { + selectedIds.splice(selectedIds.indexOf(objectId), 1); + window.localStorage.setItem(this.#getStorageKey(), JSON.stringify(selectedIds)); + } + this.#change(); + } #initBulkInteractions() { if (!this.#bulkInteractionButton) { return; diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/GridView/State.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/GridView/State.js index b344de2327..0f5ec89bb1 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/GridView/State.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/GridView/State.js @@ -144,6 +144,9 @@ define(["require", "exports", "tslib", "./Filter", "./Selection", "./Sorting"], resetSelection() { this.#selection.resetSelection(); } + removeSelection(objectId) { + this.#selection.removeSelection(objectId); + } refreshSelection() { this.#selection.refresh(); } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/ListView.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/ListView.js index 5736f97591..0b1f2fb078 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/ListView.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/ListView.js @@ -77,6 +77,7 @@ define(["require", "exports", "tslib", "./ListView/State", "../Dom/Change/Listen }); this.#viewElement.addEventListener("interaction:remove", (event) => { event.target.remove(); + this.#state.removeSelection(parseInt(event.target.dataset.objectId)); this.#checkEmptyList(); }); this.#viewElement.addEventListener("interaction:reset-selection", () => { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/ListView/Selection.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/ListView/Selection.js index 3ad7b4994d..d32b4562c7 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/ListView/Selection.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/ListView/Selection.js @@ -223,6 +223,14 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Core", "WoltLabSuite/C window.localStorage.removeItem(this.#getStorageKey()); this.#updateSelectionBar(); } + removeSelection(objectId) { + const selectedIds = this.getSelectedIds(); + if (selectedIds.indexOf(objectId) !== -1) { + selectedIds.splice(selectedIds.indexOf(objectId), 1); + window.localStorage.setItem(this.#getStorageKey(), JSON.stringify(selectedIds)); + } + this.#change(); + } #initBulkInteractions() { if (!this.#bulkInteractionButton) { return; diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/ListView/State.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/ListView/State.js index 09b2371f2d..e6a5f0ba90 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/ListView/State.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/ListView/State.js @@ -152,6 +152,9 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Helper/Selector", "./F resetSelection() { this.#selection.resetSelection(); } + removeSelection(objectId) { + this.#selection.removeSelection(objectId); + } refreshSelection() { this.#selection.refresh(); }