Skip to content

refactor(dashboard): immutable state updates, drag-drop hook, and granular contexts#497

Merged
aldbr merged 2 commits into
DIRACGrid:mainfrom
aldbr:split/3-dashboard-contexts
Jul 15, 2026
Merged

refactor(dashboard): immutable state updates, drag-drop hook, and granular contexts#497
aldbr merged 2 commits into
DIRACGrid:mainfrom
aldbr:split/3-dashboard-contexts

Conversation

@aldbr

@aldbr aldbr commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Part of #494 (stack 3/5). Stacked on #496 — until it merges, review the last commit only (refactor(dashboard)).

Dashboard/drawer refactor and context granularity:

  • splits the monolithic applications context into three purpose-built contexts — AppList / Dashboard / CurrentApp — so components only re-render for the state they actually read (previously, dragging or renaming a drawer item re-rendered every running application);
  • extracts drag-and-drop into a useDashboardDragDrop hook (stable-ref pattern, drop targets no longer re-register on every render) and the context menu into DrawerContextMenu;
  • makes all dashboard state updates immutable — the previous code pushed into arrays held by React state (one dialog only opened by accident of an unrelated re-render) and keyed drag-reorderable lists by index;
  • rebuilds the hooks on the granular contexts (useAppList, useDashboard, useApplicationId, useCurrentApplication).

Note for extension authors: useApplicationTitle/useApplicationType are removed; state restored from storage is now structurally validated before use.

🤖 Generated with Claude Code

@ryuwd ryuwd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see mainly small things or things that can be deferred to issues for later, otherwise LGTM

P.S. some things I discussed with an LLM and the LLM explained better than me so I added some of the explanations from there but take with a grain of salt and feel free to defer those to later

Comment thread packages/diracx-web-components/src/components/DashboardLayout/DrawerItem.tsx Outdated
@aldbr
aldbr force-pushed the split/3-dashboard-contexts branch from 8698cbc to 8e25460 Compare July 15, 2026 06:37
aldbr and others added 2 commits July 15, 2026 09:10
…nular contexts

Split the monolithic ApplicationsContext tuple into three purpose-built
contexts (AppListContext, DashboardContext, CurrentAppContext) so
components subscribe only to the state they read, and rework the
dashboard layout around them:

- extract drag-and-drop monitoring into a useDashboardDragDrop hook and
  the context menu into a DrawerContextMenu component; DashboardDrawer
  now updates dashboard state immutably (no in-place mutation of groups)
- rewrite hooks/application.tsx around the granular contexts
  (useAppList, useDashboard, useApplicationId, useCurrentApplication)
  and drop useApplicationTitle/useApplicationType
- memoize NavigationProvider and OIDCConfigurationProvider values
- ProfileButton loses the dead About entry; ThemeToggleButton,
  Import/ExportButton, ApplicationDialog and ApplicationSelector are
  adapted to the new contexts
- contexts/index.ts now exports the granular contexts explicitly
  (ApplicationsContext is gone); Dashboard stories/tests updated
useDashboardDragDrop no longer takes userDashboard or mirrors it in a
ref. reorderSections receives the source/destination group titles from
the drop event and looks the groups up inside the setUserDashboard
functional updater, where React hands it the freshest state. This drops
the ref, its sync effect, and the userDashboard parameter, and removes
the (practically unreachable) window where a drop could read a stale
dashboard between a state commit and the ref update. The destination
index is copied into a local so the updater stays pure under StrictMode.

Draft addressing review comment C6.1 — kept as its own commit for review.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@aldbr
aldbr force-pushed the split/3-dashboard-contexts branch from 41492a5 to 329cbaf Compare July 15, 2026 07:14
@aldbr
aldbr requested a review from ryuwd July 15, 2026 07:28

@ryuwd ryuwd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for addressing the comments

@aldbr
aldbr merged commit bc95278 into DIRACGrid:main Jul 15, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Quality pass: library packaging, Job Monitor performance, state correctness, test coverage

2 participants