Skip to content

Automate browser based workflows with AI

Move New profile to the top of the browser-profile dropdown (#7998)

Celal Zamanoğlu118619373ab3
diff --git a/skyvern-frontend/src/routes/workflows/components/BrowserProfileControl.test.tsx b/skyvern-frontend/src/routes/workflows/components/BrowserProfileControl.test.tsx
new file mode 100644
index 000000000..c746d0be8
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/components/BrowserProfileControl.test.tsx
@@ -0,0 +1,127 @@
+// @vitest-environment jsdom
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import {
+ fireEvent,
+ render,
+ screen,
+ waitFor,
+ within,
+} from "@testing-library/react";
+import type { ReactNode } from "react";
+import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
+
+import type { BrowserProfileApiResponse } from "@/api/types";
+import { BrowserProfileControl } from "./BrowserProfileControl";
+
+const mocks = vi.hoisted(() => ({ useInfiniteBrowserProfilesQuery: vi.fn() }));
+
+vi.mock("../hooks/useInfiniteBrowserProfilesQuery", () => ({
+ useInfiniteBrowserProfilesQuery: mocks.useInfiniteBrowserProfilesQuery,
+}));
+vi.mock("@/routes/browserProfiles/hooks/useBrowserProfileQuery", () => ({
+ useBrowserProfileQuery: () => ({ data: undefined }),
+}));
+vi.mock("@/hooks/useCredentialGetter", () => ({
+ useCredentialGetter: () => null,
+}));
+
+const originalScrollIntoView = Element.prototype.scrollIntoView;
+beforeAll(() => {
+ vi.stubGlobal(
+ "ResizeObserver",
+ class {
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+ },
+ );
+ Element.prototype.scrollIntoView = () => {};
+});
+afterAll(() => {
+ vi.unstubAllGlobals();
+ Element.prototype.scrollIntoView = originalScrollIntoView;
+});
+
+function profile(id: string, name: string): BrowserProfileApiResponse {
+ return {
+ browser_profile_id: id,
+ name,
+ is_managed: false,
+ linked_credential_name: null,
+ deleted_at: null,
+ } as unknown as BrowserProfileApiResponse;
+}
+
+function renderControl() {
+ mocks.useInfiniteBrowserProfilesQuery.mockReturnValue({
+ data: { pages: [[profile("bp_alpha", "Alpha Profile")]] },
+ isFetching: false,
+ });
+ const wrapper = ({ children }: { children: ReactNode }) => (
+ <QueryClientProvider
+ client={
+ new QueryClient({ defaultOptions: { queries: { retry: false } } })
+ }
+ >
+ {children}
+ </QueryClientProvider>
+ );
+ render(
+ <BrowserProfileControl
+ mode="dropdown"
+ profileId={null}
+ onProfileChange={vi.fn()}
+ codeValue=""
+ onCodeChange={vi.fn()}
+ codeMode="none"
+ restingCaption="Fresh browser every run"
+ />,
+ { wrapper },
+ );
+ fireEvent.click(screen.getByRole("combobox"));
+}
+
+const follows = (a: Element, b: Element) =>
+ Boolean(a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING);
+
+describe("BrowserProfileControl dropdown order", () => {
+ it("renders + New profile directly under Auto and above the profile list", () => {
+ renderControl();
+
+ // Scope to the menu — "Auto" also shows on the closed trigger label.
+ const list = within(screen.getByRole("listbox"));
+ const auto = list.getByText("Auto");
+ const create = list.getByText("+ New profile…");
+ const firstProfile = list.getByText("Alpha Profile");
+
+ expect(follows(auto, create)).toBe(true);
+ expect(follows(create, firstProfile)).toBe(true);
+ });
+
+ it("still opens the inline create input from its new position", () => {
+ renderControl();
+
+ fireEvent.click(screen.getByText("+ New profile…"));
+
+ expect(screen.getByPlaceholderText("Profile name")).toBeTruthy();
+ });
+
+ it("drops + New profile below the matches while searching (Auto hides, top match stays the Enter target)", async () => {
+ renderControl();
+
+ fireEvent.change(screen.getByPlaceholderText("Search profiles..."), {
+ target: { value: "al" },
+ });
+
+ await waitFor(() => {
+ const list = within(screen.getByRole("listbox"));
+ expect(list.queryByText("Auto")).toBeNull();
+ expect(
+ follows(
+ list.getByText("Alpha Profile"),
+ list.getByText("+ New profile…"),
+ ),
+ ).toBe(true);
+ });
+ });
+});
diff --git a/skyvern-frontend/src/routes/workflows/components/BrowserProfileControl.tsx b/skyvern-frontend/src/routes/workflows/components/BrowserProfileControl.tsx
index ab35e3126..8fdc101a6 100644
--- a/skyvern-frontend/src/routes/workflows/components/BrowserProfileControl.tsx
+++ b/skyvern-frontend/src/routes/workflows/components/BrowserProfileControl.tsx
@@ -163,6 +163,23 @@ function ProfileDropdown({
setQuery("");
};
+ const searching = debouncedQuery.trim().length > 0;
+ // +New sits under the resting option in the default view; under an active
+ // search the resting option hides, so keep +New at the bottom to leave the
+ // first matching profile as cmdk's default-highlighted (Enter) target.
+ const newProfileGroup = (borderClass: string) => (
+ <CommandGroup className={borderClass}>
+ <CommandItem value="new-profile" onSelect={() => setCreating(true)}>
+ <div className="min-w-0 flex-1">
+ <div className="text-sm font-medium">+ New profile…</div>
+ <div className="whitespace-normal break-words text-xs text-muted-foreground">
+ Created empty — the first run fills it, every run updates it
+ </div>
+ </div>
+ </CommandItem>
+ </CommandGroup>
+ );
+
return (
<div className="min-w-0 space-y-1.5">
<Popover
@@ -252,25 +269,28 @@ function ProfileDropdown({
onValueChange={setQuery}
/>
<CommandList>
- {!debouncedQuery.trim() ? (
- <CommandGroup>
- <CommandItem
- value="auto-profile"
- onSelect={() => pick(null)}
- >
- <div className="min-w-0 flex-1">
- <div className="text-sm font-medium">
- {restingLabel}
- </div>
- <div className="whitespace-normal break-words text-xs text-muted-foreground">
- {restingCaption}
+ {!searching ? (
+ <>
+ <CommandGroup>
+ <CommandItem
+ value="auto-profile"
+ onSelect={() => pick(null)}
+ >
+ <div className="min-w-0 flex-1">
+ <div className="text-sm font-medium">
+ {restingLabel}
+ </div>
+ <div className="whitespace-normal break-words text-xs text-muted-foreground">
+ {restingCaption}
+ </div>
</div>
- </div>
- {profileId === null ? (
- <CheckIcon className="ml-2 size-4 shrink-0" />
- ) : null}
- </CommandItem>
- </CommandGroup>
+ {profileId === null ? (
+ <CheckIcon className="ml-2 size-4 shrink-0" />
+ ) : null}
+ </CommandItem>
+ </CommandGroup>
+ {newProfileGroup("border-b border-border")}
+ </>
) : null}
{profiles.length === 0 ? (
<CommandEmpty>
@@ -323,20 +343,7 @@ function ProfileDropdown({
})}
</CommandGroup>
)}
- <CommandGroup className="border-t border-border">
- <CommandItem
- value="new-profile"
- onSelect={() => setCreating(true)}
- >
- <div className="min-w-0 flex-1">
- <div className="text-sm font-medium">+ New profile…</div>
- <div className="whitespace-normal break-words text-xs text-muted-foreground">
- Created empty — the first run fills it, every run
- updates it
- </div>
- </div>
- </CommandItem>
- </CommandGroup>
+ {searching ? newProfileGroup("border-t border-border") : null}
</CommandList>
</Command>
)}