-
Notifications
You must be signed in to change notification settings - Fork 960
feat(desktop): focus neighbor workspace after v2 delete #3401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...DashboardSidebar/utils/getDeleteFocusTargetWorkspaceId/getDeleteFocusTargetWorkspaceId.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| export function getDeleteFocusTargetWorkspaceId( | ||
| flattenedWorkspaceIds: readonly string[], | ||
| deletedWorkspaceId: string, | ||
| ): string | null { | ||
| const index = flattenedWorkspaceIds.indexOf(deletedWorkspaceId); | ||
| if (index === -1) return null; | ||
| return ( | ||
| flattenedWorkspaceIds[index - 1] ?? flattenedWorkspaceIds[index + 1] ?? null | ||
| ); | ||
| } |
1 change: 1 addition & 0 deletions
1
...ted/_dashboard/components/DashboardSidebar/utils/getDeleteFocusTargetWorkspaceId/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { getDeleteFocusTargetWorkspaceId } from "./getDeleteFocusTargetWorkspaceId"; |
76 changes: 76 additions & 0 deletions
76
...omponents/DashboardSidebar/utils/getFlattenedV2WorkspaceIds/getFlattenedV2WorkspaceIds.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import type { AppCollections } from "renderer/routes/_authenticated/providers/CollectionsProvider/collections"; | ||
|
|
||
| type TopLevelItem = | ||
| | { kind: "workspace"; tabOrder: number; workspaceId: string } | ||
| | { kind: "section"; tabOrder: number; sectionId: string }; | ||
|
|
||
| export function getFlattenedV2WorkspaceIds( | ||
| collections: Pick< | ||
| AppCollections, | ||
| "v2SidebarProjects" | "v2SidebarSections" | "v2WorkspaceLocalState" | ||
| >, | ||
| ): string[] { | ||
| const projects = Array.from( | ||
| collections.v2SidebarProjects.state.values(), | ||
| ).sort((left, right) => left.tabOrder - right.tabOrder); | ||
| const allSections = Array.from(collections.v2SidebarSections.state.values()); | ||
| const allWorkspaces = Array.from( | ||
| collections.v2WorkspaceLocalState.state.values(), | ||
| ); | ||
|
|
||
| const result: string[] = []; | ||
|
|
||
| for (const project of projects) { | ||
| const projectWorkspaces = allWorkspaces.filter( | ||
| (workspace) => workspace.sidebarState.projectId === project.projectId, | ||
| ); | ||
| const projectSections = allSections.filter( | ||
| (section) => section.projectId === project.projectId, | ||
| ); | ||
|
|
||
| const topLevelItems: TopLevelItem[] = []; | ||
| for (const workspace of projectWorkspaces) { | ||
| if (workspace.sidebarState.sectionId == null) { | ||
| topLevelItems.push({ | ||
| kind: "workspace", | ||
| tabOrder: workspace.sidebarState.tabOrder, | ||
| workspaceId: workspace.workspaceId, | ||
| }); | ||
| } | ||
| } | ||
| for (const section of projectSections) { | ||
| topLevelItems.push({ | ||
| kind: "section", | ||
| tabOrder: section.tabOrder, | ||
| sectionId: section.sectionId, | ||
| }); | ||
| } | ||
| topLevelItems.sort((left, right) => { | ||
| if (left.tabOrder !== right.tabOrder) { | ||
| return left.tabOrder - right.tabOrder; | ||
| } | ||
| if (left.kind === right.kind) return 0; | ||
| return left.kind === "section" ? -1 : 1; | ||
| }); | ||
|
|
||
| for (const item of topLevelItems) { | ||
| if (item.kind === "workspace") { | ||
| result.push(item.workspaceId); | ||
| continue; | ||
| } | ||
| const sectionWorkspaces = projectWorkspaces | ||
| .filter( | ||
| (workspace) => workspace.sidebarState.sectionId === item.sectionId, | ||
| ) | ||
| .sort( | ||
| (left, right) => | ||
| left.sidebarState.tabOrder - right.sidebarState.tabOrder, | ||
| ); | ||
| for (const workspace of sectionWorkspaces) { | ||
| result.push(workspace.workspaceId); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } |
1 change: 1 addition & 0 deletions
1
...nticated/_dashboard/components/DashboardSidebar/utils/getFlattenedV2WorkspaceIds/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { getFlattenedV2WorkspaceIds } from "./getFlattenedV2WorkspaceIds"; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
deletePromiseIIFE chainsremoveWorkspaceFromSidebarand the navigation call after the server mutate. If the mutate succeeds butnavigateToV2Workspace(ornavigate({ to: "/" })) throws,deletePromiserejects andtoast.promisewill display:…even though the workspace was already deleted on the server and removed from the sidebar. In practice, in-app TanStack Router navigations almost never throw, so the risk is very low — but if it does happen the user could believe the workspace still exists and retry the delete unnecessarily.
One option is to isolate the navigation so its failure doesn't propagate to the promise used by
toast.promise: