Repository navigation
fix(desktop): select the agent tab when opening a CLI-created workspace #9488
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
Open
aaronrosenthal
wants to merge
2
commits into
ParadevAI:main
Choose a base branch
from
aaronrosenthal:fix-setup-tab-order-62c0eccd
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
44 changes: 44 additions & 0 deletions
44
.../_dashboard/v2-workspace/$workspaceId/utils/adoptTerminalPanes/adoptTerminalPanes.test.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,44 @@ | ||
| import { describe, expect, it } from "bun:test"; | ||
| import { createWorkspaceStore } from "@superset/panes"; | ||
| import type { PaneViewerData } from "../../types"; | ||
| import { adoptTerminalPanes } from "./adoptTerminalPanes"; | ||
|
|
||
| function tabTerminalIds(store: ReturnType<typeof emptyStore>) { | ||
| return store | ||
| .getState() | ||
| .tabs.map( | ||
| (tab) => | ||
| (Object.values(tab.panes)[0]?.data as { terminalId: string }) | ||
| .terminalId, | ||
| ); | ||
| } | ||
|
|
||
| function activeTerminalId(store: ReturnType<typeof emptyStore>) { | ||
| const state = store.getState(); | ||
| const tab = state.tabs.find((t) => t.id === state.activeTabId); | ||
| return (Object.values(tab?.panes ?? {})[0]?.data as { terminalId: string }) | ||
| ?.terminalId; | ||
| } | ||
|
|
||
| function emptyStore() { | ||
| return createWorkspaceStore<PaneViewerData>({ | ||
| initialState: { version: 1, tabs: [], activeTabId: null }, | ||
| }); | ||
| } | ||
|
|
||
| describe("adoptTerminalPanes", () => { | ||
| it("selects the oldest terminal when the layout was empty", () => { | ||
| const store = emptyStore(); | ||
| adoptTerminalPanes(store, ["agent", "setup"]); | ||
| expect(tabTerminalIds(store)).toEqual(["agent", "setup"]); | ||
| expect(activeTerminalId(store)).toBe("agent"); | ||
| }); | ||
|
|
||
| it("keeps the tab the user already had selected", () => { | ||
| const store = emptyStore(); | ||
| adoptTerminalPanes(store, ["existing"]); | ||
| adoptTerminalPanes(store, ["agent", "setup"]); | ||
| expect(tabTerminalIds(store)).toEqual(["existing", "agent", "setup"]); | ||
| expect(activeTerminalId(store)).toBe("existing"); | ||
| }); | ||
| }); |
31 changes: 31 additions & 0 deletions
31
...cated/_dashboard/v2-workspace/$workspaceId/utils/adoptTerminalPanes/adoptTerminalPanes.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,31 @@ | ||
| import type { WorkspaceStore } from "@superset/panes"; | ||
| import type { StoreApi } from "zustand/vanilla"; | ||
| import type { PaneViewerData } from "../../types"; | ||
| import { | ||
| findTerminalPaneLocation, | ||
| focusOrAddTerminalPane, | ||
| } from "../focusTerminalPane"; | ||
|
|
||
| /** | ||
| * Give each terminal a tab, oldest first, without moving the selection off a | ||
| * tab the user already has. In an empty layout the oldest terminal is | ||
| * selected: the host starts an independent agent before the setup terminal. | ||
| */ | ||
| export function adoptTerminalPanes( | ||
| store: StoreApi<WorkspaceStore<PaneViewerData>>, | ||
| oldestFirstTerminalIds: readonly string[], | ||
| ): void { | ||
| const [firstTerminalId] = oldestFirstTerminalIds; | ||
| if (firstTerminalId === undefined) return; | ||
|
|
||
| const previousActiveTabId = store.getState().activeTabId; | ||
| for (const terminalId of oldestFirstTerminalIds) { | ||
| focusOrAddTerminalPane(store, terminalId, { focus: false }); | ||
| } | ||
|
|
||
| const state = store.getState(); | ||
| const selectedTabId = | ||
| previousActiveTabId ?? | ||
| findTerminalPaneLocation(state, firstTerminalId)?.tabId; | ||
| if (selectedTabId) state.setActiveTab(selectedTabId); | ||
| } |
1 change: 1 addition & 0 deletions
1
...tes/_authenticated/_dashboard/v2-workspace/$workspaceId/utils/adoptTerminalPanes/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 { adoptTerminalPanes } from "./adoptTerminalPanes"; |
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.
Script executed:
Repository: ParadevAI/Paradev
Length of output: 17397
Script executed:
Repository: ParadevAI/Paradev
Length of output: 15043
Script executed:
Repository: ParadevAI/Paradev
Length of output: 36686
Script executed:
Repository: ParadevAI/Paradev
Length of output: 35660
Script executed:
Repository: ParadevAI/Paradev
Length of output: 16474
Script executed:
Repository: ParadevAI/Paradev
Length of output: 29791
Script executed:
Repository: ParadevAI/Paradev
Length of output: 17746
Web query:
ECMAScript Array.prototype.sort stable sorting equal comparator result specificationResult:
Preserve tied session order when selecting the oldest tab.
If the agent and setup sessions receive the same
createdAt, reversing the stable sort can put setup first. An empty workspace then selects setup instead of the earlier agent. Sort oldest-first without reversing tied sessions.