Skip to content

Externalize selected value in redux to avoid selected state switch#1384

Merged
abcampo-iry merged 1 commit intomainfrom
issues/1146-state-is-not-shared-between-mobile-desktop
Mar 27, 2026
Merged

Externalize selected value in redux to avoid selected state switch#1384
abcampo-iry merged 1 commit intomainfrom
issues/1146-state-is-not-shared-between-mobile-desktop

Conversation

@abcampo-iry
Copy link
Copy Markdown
Contributor

@abcampo-iry abcampo-iry commented Mar 16, 2026

Closes: https://github.com/RaspberryPiFoundation/digital-editor-issues/issues/1146

This we way avoid that when it changes between mobile and desktop it looses previous state.
The PR moves the "memory" of which sidebar tab is selected into the global Redux store.

  • The sidebar It checks selectedSidebarOption first. If it's undefined, it falls back to a "default" option (like "instructions" or "file").
  • When a user clicks a tab, the updateOption function now calls dispatch -> setSidebarOption
  • It adds a (safety / paranoid check) optionIsAvailable to ensure that if the sidebar tries to open a tab that doesn't exist in the current context, it reverts to a default.
Screen.Recording.2026-03-16.at.13.00.25.mov

Adds also test to cover this.

Copilot AI review requested due to automatic review settings March 16, 2026 09:19
@abcampo-iry abcampo-iry temporarily deployed to previews/1384/merge March 16, 2026 09:19 — with GitHub Actions Inactive
@abcampo-iry abcampo-iry marked this pull request as draft March 16, 2026 09:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR externalizes the currently selected sidebar panel into Redux so the user’s sidebar selection is preserved when switching between desktop and mobile layouts (e.g., across responsive breakpoints).

Changes:

  • Add selectedSidebarOption and setSidebarOption to EditorSlice.
  • Update Sidebar to initialize/persist the selected panel via Redux instead of purely local state.
  • Add a regression test to ensure the selected sidebar panel remains active after resizing across the mobile breakpoint.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/redux/EditorSlice.js Adds Redux state + action to persist selected sidebar option.
src/components/Menus/Sidebar/Sidebar.jsx Reads/writes selected option from Redux and adjusts default/validation logic.
src/components/WebComponentProject/WebComponentProject.test.js Adds breakpoint-resize regression test; introduces a “real store” render helper.
src/components/Mobile/MobileProject/MobileProject.test.js Removes some sidebar rendering tests (likely superseded by the new integration-style resize test).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@abcampo-iry abcampo-iry temporarily deployed to previews/1384/merge March 16, 2026 09:48 — with GitHub Actions Inactive
@abcampo-iry abcampo-iry force-pushed the issues/1146-state-is-not-shared-between-mobile-desktop branch from 1aee796 to 51a282b Compare March 16, 2026 10:06
@abcampo-iry abcampo-iry temporarily deployed to previews/1384/merge March 16, 2026 10:06 — with GitHub Actions Inactive
@abcampo-iry abcampo-iry marked this pull request as ready for review March 16, 2026 11:34
@abcampo-iry abcampo-iry force-pushed the issues/1146-state-is-not-shared-between-mobile-desktop branch from 51a282b to de09de5 Compare March 19, 2026 10:30
@abcampo-iry abcampo-iry temporarily deployed to previews/1384/merge March 19, 2026 10:30 — with GitHub Actions Inactive
@jamiebenstead jamiebenstead requested a review from Copilot March 24, 2026 10:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Moves the “selected sidebar tab” state from local component state into the global Redux store so the selection persists when the UI switches between desktop (Project) and mobile (MobileProject) layouts.

Changes:

  • Add selectedSidebarOption to editor Redux state and introduce setSidebarOption action.
  • Update Sidebar to initialize from Redux selection (with default fallback) and persist updates back to Redux.
  • Add a WebComponentProject test that verifies the selected sidebar panel survives resizing across the mobile breakpoint (and that null persists a collapsed sidebar).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/redux/EditorSlice.js Adds persisted selectedSidebarOption state and setSidebarOption action to editor Redux slice.
src/components/Menus/Sidebar/Sidebar.jsx Reads/writes selected sidebar option to Redux and validates availability against current sidebar options.
src/components/WebComponentProject/WebComponentProject.test.js Adds real-store test coverage for persisting sidebar selection across desktop/mobile layout switches.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@abcampo-iry abcampo-iry force-pushed the issues/1146-state-is-not-shared-between-mobile-desktop branch from de09de5 to 2a4c02c Compare March 24, 2026 18:30
@abcampo-iry abcampo-iry temporarily deployed to previews/1384/merge March 24, 2026 18:30 — with GitHub Actions Inactive
@jamiebenstead jamiebenstead requested a review from Copilot March 27, 2026 09:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@jamiebenstead jamiebenstead left a comment

Choose a reason for hiding this comment

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

LGTM

Store the selected sidebar option in Redux so desktop and mobile share the same panel state.
Preserve collapsed state and keep the default panel in sync when instructions appear after mount.
@abcampo-iry abcampo-iry force-pushed the issues/1146-state-is-not-shared-between-mobile-desktop branch from 2a4c02c to a316165 Compare March 27, 2026 11:28
@abcampo-iry abcampo-iry merged commit 4daa7f1 into main Mar 27, 2026
7 checks passed
@abcampo-iry abcampo-iry deleted the issues/1146-state-is-not-shared-between-mobile-desktop branch March 27, 2026 12:48
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.

3 participants