[loggi-qmb] Fix: drag-and-drop reorder in Customize modal duplicates charts #118

Closed
opened 2026-02-21 20:02:59 +01:00 by matthias · 0 comments
Owner

Bead ID: loggi-qmb
Type: bug
Priority: P1
Status: closed
Close reason: Fixed two bugs: (1) Changed onEnd selector from querySelectorAll('[data-plot-id]') to querySelectorAll(':scope > [data-plot-id]') so it only matches wrapper divs, not nested inputs. (2) Added deduplication in getOrderedPlotIds() using a Set to gracefully handle previously corrupted saved orders.


Why

Dragging to reorder charts in the Customize modal causes every chart to appear twice in the stats grid.

Root cause

In openPlotCustomize(), the onEnd SortableJS handler uses:

const items = list.querySelectorAll('[data-plot-id]');

This selector matches both the wrapper <div data-plot-id="..."> and the nested <input data-plot-id="..."> inside each list item, so the saved order array contains every plot ID twice. When renderStatsGrid iterates over this doubled array, it builds each chart card twice.

What

Change the selector in the onEnd handler to only match direct children of the list (the wrapper divs), not the nested inputs. Use :scope > [data-plot-id] or list.children.

Verify that getOrderedPlotIds() also deduplicates gracefully (it currently doesn't — filter preserves duplicates).

Acceptance criteria

  • Reordering via drag-and-drop saves each plot ID exactly once
  • No duplicate chart cards appear after reordering
  • Existing saved orders with duplicates are handled gracefully (deduplicated on load)

Where

  • app/static/js/stats.jsonEnd handler (~L300), getOrderedPlotIds() (~L115)
**Bead ID:** `loggi-qmb` **Type:** bug **Priority:** P1 **Status:** closed **Close reason:** Fixed two bugs: (1) Changed onEnd selector from querySelectorAll('[data-plot-id]') to querySelectorAll(':scope > [data-plot-id]') so it only matches wrapper divs, not nested inputs. (2) Added deduplication in getOrderedPlotIds() using a Set to gracefully handle previously corrupted saved orders. --- ## Why Dragging to reorder charts in the Customize modal causes every chart to appear twice in the stats grid. ## Root cause In `openPlotCustomize()`, the `onEnd` SortableJS handler uses: ```js const items = list.querySelectorAll('[data-plot-id]'); ``` This selector matches **both** the wrapper `<div data-plot-id="...">` and the nested `<input data-plot-id="...">` inside each list item, so the saved order array contains every plot ID twice. When `renderStatsGrid` iterates over this doubled array, it builds each chart card twice. ## What Change the selector in the `onEnd` handler to only match direct children of the list (the wrapper divs), not the nested inputs. Use `:scope > [data-plot-id]` or `list.children`. Verify that `getOrderedPlotIds()` also deduplicates gracefully (it currently doesn't — `filter` preserves duplicates). ## Acceptance criteria - Reordering via drag-and-drop saves each plot ID exactly once - No duplicate chart cards appear after reordering - Existing saved orders with duplicates are handled gracefully (deduplicated on load) ## Where - `app/static/js/stats.js` — `onEnd` handler (~L300), `getOrderedPlotIds()` (~L115)
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
matthias/loggi#118
No description provided.