Skip to content

Commit 5d7916c

Browse files
Drill into TAB_NAVIGATOR in session storage fallback for workspace restore
The session-storage fallback in useRestoreWorkspacesTabOnNavigate searched for WORKSPACE_NAVIGATOR at the root level of the state from getStateFromPath, but getStateFromPath returns state rooted at TAB_NAVIGATOR. This caused the findLast to never find WORKSPACE_NAVIGATOR, falling through to the workspaces list instead of restoring the last workspace sub-page after a refresh. Updated the test mock to match the real getStateFromPath output shape. Co-authored-by: Sobit Neupane <sobitneupane@users.noreply.github.com>
1 parent 8f67bd6 commit 5d7916c

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

src/hooks/useRestoreWorkspacesTabOnNavigate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ function useRestoreWorkspacesTabOnNavigate() {
5555
}
5656

5757
// Fall back to session storage when no workspace route exists anywhere in the navigation tree.
58-
const sessionRoute = getWorkspacesTabStateFromSessionStorage()
58+
// getStateFromPath returns state rooted at TAB_NAVIGATOR, so we must drill into it first.
59+
const sessionTabNavigatorRoute = getWorkspacesTabStateFromSessionStorage()?.routes?.findLast((route) => route.name === NAVIGATORS.TAB_NAVIGATOR);
60+
const sessionRoute = getTabState(sessionTabNavigatorRoute)
5961
?.routes?.findLast((route) => route.name === NAVIGATORS.WORKSPACE_NAVIGATOR)
6062
?.state?.routes?.findLast((route) => isWorkspaceNavigatorRouteName(route.name));
6163
if (sessionRoute) {

tests/unit/hooks/useRestoreWorkspacesTabOnNavigate.test.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,16 +280,23 @@ describe('useRestoreWorkspacesTabOnNavigate', () => {
280280
lastVisitedTabPathUtils.getWorkspacesTabStateFromSessionStorage.mockReturnValue({
281281
routes: [
282282
{
283-
name: NAVIGATORS.WORKSPACE_NAVIGATOR,
283+
name: NAVIGATORS.TAB_NAVIGATOR,
284284
state: {
285285
routes: [
286286
{
287-
name: NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR,
287+
name: NAVIGATORS.WORKSPACE_NAVIGATOR,
288288
state: {
289-
index: 1,
290289
routes: [
291-
{name: SCREENS.WORKSPACE.INITIAL, params: {policyID: fakePolicyID}},
292-
{name: SCREENS.WORKSPACE.WORKFLOWS, params: {policyID: fakePolicyID}},
290+
{
291+
name: NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR,
292+
state: {
293+
index: 1,
294+
routes: [
295+
{name: SCREENS.WORKSPACE.INITIAL, params: {policyID: fakePolicyID}},
296+
{name: SCREENS.WORKSPACE.WORKFLOWS, params: {policyID: fakePolicyID}},
297+
],
298+
},
299+
},
293300
],
294301
},
295302
},

0 commit comments

Comments
 (0)