-
Notifications
You must be signed in to change notification settings - Fork 126
🤖 feat: add project switcher to the scratch creation page #3817
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
8 commits
Select commit
Hold shift + click to select a range
ae43f6d
🤖 feat: add project switcher to the scratch creation page
ibetitsmike b35bed7
review: use persisted-state helpers and pin mobile1 viewport in scrat…
ibetitsmike 819fc09
fix: self-heal DOM harness at file boundaries so module-eval env dete…
ibetitsmike d4b5f16
fix: exclude bun-only domIsolation test from jest integration run
ibetitsmike 39a073f
fix: restore leaked bun module mocks after suites and deracify TGL me…
ibetitsmike 6ff5420
fix: sweep Dialog mock.module leaks with a shared restore helper and …
ibetitsmike ba5b99d
fix: render TGL context menu inline in unit test instead of Radix portal
ibetitsmike 487a0be
fix: use alias module paths in TGL menu mock so the suite restore res…
ibetitsmike 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
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
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
87 changes: 87 additions & 0 deletions
87
src/browser/components/ScratchPage/ScratchPage.stories.tsx
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,87 @@ | ||
| import { userEvent, waitFor } from "@storybook/test"; | ||
|
|
||
| import { appMeta, AppWithMocks, type AppStory } from "@/browser/stories/meta.js"; | ||
| import { createMockORPCClient } from "@/browser/stories/mocks/orpc"; | ||
| import { updatePersistedState } from "@/browser/hooks/usePersistedState"; | ||
| import { LEFT_SIDEBAR_COLLAPSED_KEY } from "@/common/constants/storage"; | ||
|
|
||
| // Integration: stories render the full app so the sidebar's "New scratch chat" | ||
| // entry can navigate to the real scratch creation route. | ||
| export default { | ||
| ...appMeta, | ||
| title: "Components/ScratchPage", | ||
| }; | ||
|
|
||
| /** | ||
| * With multiple projects configured, the scratch header must show "Scratch" | ||
| * as the current scope and offer the project switcher: on mobile the sidebar | ||
| * auto-collapses after navigation and is otherwise the only way to reach a | ||
| * project's creation page. | ||
| */ | ||
| export const ScratchCreationWithProjects: AppStory = { | ||
| // Mirrors the Pixel phone variant so local viewing reproduces the mobile flow | ||
| // the story covers; the test-runner ignores globals and plays at desktop width. | ||
| globals: { | ||
| viewport: { value: "mobile1", isRotated: false }, | ||
| }, | ||
| parameters: { | ||
| pixel: { | ||
| matrix: { themes: ["dark", "light"], viewports: ["laptop", "phone"] }, | ||
| }, | ||
| }, | ||
| render: () => ( | ||
| <AppWithMocks | ||
| setup={() => { | ||
| // Start expanded so the play function can click the sidebar entry | ||
| // even in mobile viewport modes. | ||
| updatePersistedState(LEFT_SIDEBAR_COLLAPSED_KEY, false); | ||
| return createMockORPCClient({ | ||
| projects: new Map([ | ||
| ["/Users/dev/frontend-app", { workspaces: [] }], | ||
| ["/Users/dev/backend-api", { workspaces: [] }], | ||
| ]), | ||
| workspaces: [], | ||
| }); | ||
| }} | ||
| /> | ||
| ), | ||
| play: async ({ canvasElement }: { canvasElement: HTMLElement }) => { | ||
| const storyRoot = document.getElementById("storybook-root") ?? canvasElement; | ||
|
|
||
| try { | ||
| const newScratchButton = await waitFor( | ||
| () => { | ||
| // Guard: a previous story's play-function may have left the sidebar | ||
| // collapsed via localStorage. | ||
| if (document.documentElement.dataset.leftSidebarCollapsed === "true") { | ||
| const expandBtn = storyRoot.querySelector<HTMLElement>("[aria-label='Expand sidebar']"); | ||
| if (expandBtn) expandBtn.click(); | ||
| throw new Error("Sidebar collapsed: expanding"); | ||
| } | ||
| const el = storyRoot.querySelector<HTMLElement>("[aria-label='New scratch chat']"); | ||
| if (!el) throw new Error("New scratch chat button not found"); | ||
| return el; | ||
| }, | ||
| { timeout: 10_000 } | ||
| ); | ||
| await userEvent.click(newScratchButton); | ||
|
|
||
| await waitFor( | ||
| () => { | ||
| const group = storyRoot.querySelector("[data-component='ScratchProjectGroup']"); | ||
| if (!group) throw new Error("Scratch project header not found"); | ||
| const selector = group.querySelector("[data-testid='project-selector']"); | ||
| if (!selector) throw new Error("Project switcher not found on scratch page"); | ||
| if (!(selector.textContent ?? "").includes("Scratch")) { | ||
| throw new Error("Project switcher does not show the Scratch scope"); | ||
| } | ||
| }, | ||
| { timeout: 10_000 } | ||
| ); | ||
| } finally { | ||
| // Remove the sidebar-state override so later stories start from the | ||
| // default expanded-on-desktop state even if assertions fail. | ||
| updatePersistedState(LEFT_SIDEBAR_COLLAPSED_KEY, null); | ||
| } | ||
| }, | ||
| }; | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { | ||
| Select as RadixSelect, | ||
| SelectContent, | ||
| SelectItem, | ||
| SelectTrigger, | ||
| SelectValue, | ||
| } from "@/browser/components/SelectPrimitive/SelectPrimitive"; | ||
| import { Tooltip, TooltipTrigger, TooltipContent } from "@/browser/components/Tooltip/Tooltip"; | ||
|
|
||
| interface CreationProjectSelectProps { | ||
| selected: string; | ||
| selectedLabel: string; | ||
| tooltip?: string; | ||
| options: Array<{ value: string; label: string }>; | ||
| onChange: (value: string) => void; | ||
| } | ||
|
|
||
| /** | ||
| * Current-scope heading for creation composers: a project switcher when there | ||
| * is more than one choice, otherwise a static heading. Shared by the project | ||
| * creation header (CreationControls) and the scratch creation header. | ||
| */ | ||
| export function CreationProjectSelect(props: CreationProjectSelectProps) { | ||
| const tooltip = props.tooltip ?? props.selected; | ||
| if (props.options.length <= 1) { | ||
| return ( | ||
| <Tooltip> | ||
| <TooltipTrigger asChild> | ||
| <h2 className="text-foreground shrink-0 text-lg font-semibold">{props.selectedLabel}</h2> | ||
| </TooltipTrigger> | ||
| <TooltipContent align="start">{tooltip}</TooltipContent> | ||
| </Tooltip> | ||
| ); | ||
| } | ||
| return ( | ||
| <RadixSelect value={props.selected} onValueChange={props.onChange}> | ||
| <Tooltip> | ||
| <TooltipTrigger asChild> | ||
| <SelectTrigger | ||
| aria-label="Select project" | ||
| data-testid="project-selector" | ||
| className="text-foreground hover:bg-toggle-bg/70 h-7 w-auto max-w-[280px] shrink-0 border-transparent bg-transparent px-0 text-lg font-semibold shadow-none" | ||
| > | ||
| {/* Explicit child instead of Radix's <SelectValue/> mirror of the | ||
| matched <SelectItem/> text, so unmatched values still render | ||
| the caller's label rather than falling back to nothing. */} | ||
| <SelectValue placeholder={props.selectedLabel}>{props.selectedLabel}</SelectValue> | ||
| </SelectTrigger> | ||
| </TooltipTrigger> | ||
| <TooltipContent align="start">{tooltip}</TooltipContent> | ||
| </Tooltip> | ||
| <SelectContent> | ||
| {props.options.map((option) => ( | ||
| <SelectItem key={option.value} value={option.value}> | ||
| {option.label} | ||
| </SelectItem> | ||
| ))} | ||
| </SelectContent> | ||
| </RadixSelect> | ||
| ); | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.