From 6398cdece520d8ee2b969886ee6e2bbaa4ce16c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Mon, 8 Jun 2026 18:56:16 +0200 Subject: [PATCH] refactor(settings): reuse the tested tile-reorder helper for pill sort Swap the hand-rolled per-group slot substitution for the same pure, total-order rebuildTilesWithReorderedVitals helper the inline edit mode uses, so the pill-sort control renumbers tile order identically and stays in lockstep with the overview arrange surface. --- .../settings/insights-pill-order-section.tsx | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/components/settings/insights-pill-order-section.tsx b/src/components/settings/insights-pill-order-section.tsx index 186042d10..20ab000fd 100644 --- a/src/components/settings/insights-pill-order-section.tsx +++ b/src/components/settings/insights-pill-order-section.tsx @@ -28,7 +28,10 @@ import { useTranslations } from "@/lib/i18n/context"; import { useAuth } from "@/hooks/use-auth"; import { queryKeys } from "@/lib/query-keys"; import { useInsightsLayoutQuery } from "@/hooks/use-insights-layout"; -import { reorderById } from "@/lib/insights-layout-reorder"; +import { + reorderById, + rebuildTilesWithReorderedVitals, +} from "@/lib/insights-layout-reorder"; import { type InsightsLayout, type InsightsTileConfig, @@ -167,21 +170,14 @@ export function InsightsPillOrderSection({ id }: { id?: string }) { const reordered = reorderById(subset, String(active.id), String(over.id)); const reorderedIds = reordered.map((r) => r.id); - setDraftTiles((tiles) => { - // Substitute this group's slots in their new relative order, leaving - // every other tile (and its order) untouched. Walk the tile list and, - // at each group-member slot, take the next id from the reordered list. - let cursor = 0; - return tiles.map((tile) => { - if (!groupMemberIds.has(tile.id)) return tile; - const nextId = reorderedIds[cursor++]; - const replacement = tiles.find((tt) => tt.id === nextId); - // Keep this slot's `order` and `visible`; swap the id into position. - return replacement - ? { ...replacement, order: tile.order } - : tile; - }); - }); + // Substitute this group's slots in their new relative order through the + // same tested, total-order helper the inline edit mode uses, leaving every + // other tile's relative order untouched (QA M2). + setDraftTiles((tiles) => + rebuildTilesWithReorderedVitals(tiles, reorderedIds, (id) => + groupMemberIds.has(id), + ), + ); } const dirty = useMemo(() => {