Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
feat(SKY-9828): polish browser profile selector + table search (#6000)
Celal Zamanoğlu7c65968cb1e4
diff --git a/skyvern-frontend/src/routes/browserProfiles/BrowserProfilesList.tsx b/skyvern-frontend/src/routes/browserProfiles/BrowserProfilesList.tsxindex b4ffb98f2..c5686ba22 100644--- a/skyvern-frontend/src/routes/browserProfiles/BrowserProfilesList.tsx+++ b/skyvern-frontend/src/routes/browserProfiles/BrowserProfilesList.tsx@@ -23,7 +23,11 @@ import { cn } from "@/util/utils";import { BrowserProfileItem } from "./BrowserProfileItem";-function BrowserProfilesList() {+type Props = {+ searchKey?: string;+};++function BrowserProfilesList({ searchKey }: Props = {}) {const [searchParams, setSearchParams] = useSearchParams();const page = searchParams.get("page") ? Number(searchParams.get("page")) : 1;const itemsPerPage = searchParams.get("page_size")@@ -55,11 +59,13 @@ function BrowserProfilesList() {} = useBrowserProfilesQuery({page,page_size: itemsPerPage,+ searchKey,});const { data: nextPageProfiles } = useBrowserProfilesQuery({page: page + 1,page_size: itemsPerPage,+ searchKey,enabled: (profiles?.length ?? 0) === itemsPerPage,});@@ -93,12 +99,20 @@ function BrowserProfilesList() {}const pageItems = profiles ?? [];+ const hasSearch = Boolean(searchKey && searchKey.length > 0);if (pageItems.length === 0 && page === 1) {return (<div className="rounded-md border border-slate-700 bg-slate-elevation1 p-6 text-sm text-slate-300">- No browser profiles yet. Profiles are created via the API/SDK, or when a- credential test or workflow run saves its persistent browser session.+ {hasSearch ? (+ <>No browser profiles match “{searchKey}”.</>+ ) : (+ <>+ No browser profiles yet. Profiles are created via the API/SDK, or+ when a credential test or workflow run saves its persistent browser+ session.+ </>+ )}</div>);}diff --git a/skyvern-frontend/src/routes/browserProfiles/BrowserProfilesPage.tsx b/skyvern-frontend/src/routes/browserProfiles/BrowserProfilesPage.tsxindex 1ba9890ac..005a46b09 100644--- a/skyvern-frontend/src/routes/browserProfiles/BrowserProfilesPage.tsx+++ b/skyvern-frontend/src/routes/browserProfiles/BrowserProfilesPage.tsx@@ -1,14 +1,37 @@+import { useState } from "react";+import { useSearchParams } from "react-router-dom";+import { useDebounce } from "use-debounce";++import { TableSearchInput } from "@/components/TableSearchInput";+import { BrowserProfilesList } from "./BrowserProfilesList";const subHeaderText ="Manage saved browser profiles used by your workflow runs.";function BrowserProfilesPage() {+ const [searchParams, setSearchParams] = useSearchParams();+ const [search, setSearch] = useState("");+ const [debouncedSearch] = useDebounce(search, 250);+return (<div className="space-y-5"><h1 className="text-2xl">Browser Profiles</h1><div className="w-96 text-sm text-slate-300">{subHeaderText}</div>- <BrowserProfilesList />+ <div className="flex justify-between">+ <TableSearchInput+ value={search}+ onChange={(value) => {+ setSearch(value);+ const params = new URLSearchParams(searchParams);+ params.set("page", "1");+ setSearchParams(params, { replace: true });+ }}+ placeholder="Search browser profiles..."+ className="w-48 lg:w-72"+ />+ </div>+ <BrowserProfilesList searchKey={debouncedSearch} /></div>);}diff --git a/skyvern-frontend/src/routes/workflows/components/BrowserProfileSelector.tsx b/skyvern-frontend/src/routes/workflows/components/BrowserProfileSelector.tsxindex 2f3920d14..ef6b22b4a 100644--- a/skyvern-frontend/src/routes/workflows/components/BrowserProfileSelector.tsx+++ b/skyvern-frontend/src/routes/workflows/components/BrowserProfileSelector.tsx@@ -1,73 +1,271 @@-import {- CustomSelectItem,- Select,- SelectContent,- SelectItem,- SelectItemText,- SelectSeparator,- SelectTrigger,- SelectValue,-} from "@/components/ui/select";+import { ChevronDownIcon, ReloadIcon } from "@radix-ui/react-icons";+import { useEffect, useMemo, useRef, useState } from "react";+import { useDebounce } from "use-debounce";+import { Skeleton } from "@/components/ui/skeleton";-import { useBrowserProfilesQuery } from "../hooks/useBrowserProfilesQuery";+import { useBrowserProfileQuery } from "@/routes/browserProfiles/hooks/useBrowserProfileQuery";+import { cn, handleInfiniteScroll } from "@/util/utils";++import { useInfiniteBrowserProfilesQuery } from "../hooks/useInfiniteBrowserProfilesQuery";-const NONE_VALUE = "__none__";+const PAGE_SIZE = 20;type Props = {value: string | null;onChange: (value: string | null) => void;placeholder?: string;+ compact?: boolean;};-function BrowserProfileSelector({ value, onChange, placeholder }: Props) {- const { data: profiles, isLoading, isError } = useBrowserProfilesQuery();+function BrowserProfileSelector({+ value,+ onChange,+ placeholder,+ compact = false,+}: Props) {+ const triggerHeightClass = compact ? "h-9" : "h-10";+ const triggerInnerPaddingClass = compact ? "px-3 py-1" : "px-3 py-2";+ const [open, setOpen] = useState(false);+ const [searchQuery, setSearchQuery] = useState("");+ const [debouncedSearch] = useDebounce(searchQuery, 300);+ const containerRef = useRef<HTMLDivElement>(null);+ const inputRef = useRef<HTMLInputElement>(null);+ const dropdownRef = useRef<HTMLDivElement>(null);+ const isTyping = searchQuery !== debouncedSearch;- if (isLoading) {- return <Skeleton className="h-10 w-full" />;- }+ useEffect(() => {+ const el = dropdownRef.current;+ if (!el) return;+ const handler = (e: WheelEvent) => {+ e.stopPropagation();+ };+ el.addEventListener("wheel", handler, { passive: false });+ return () => el.removeEventListener("wheel", handler);+ }, [open]);++ const {+ data,+ fetchNextPage,+ hasNextPage,+ isFetchingNextPage,+ isFetching,+ isError,+ } = useInfiniteBrowserProfilesQuery({+ page_size: PAGE_SIZE,+ searchKey: debouncedSearch,+ enabled: open,+ });++ const profiles = useMemo(+ () => data?.pages.flatMap((page) => page) ?? [],+ [data],+ );++ const hasValue = Boolean(value && value !== "");++ const profileInList = useMemo(+ () =>+ hasValue+ ? profiles.find((profile) => profile.browser_profile_id === value)+ : undefined,+ [hasValue, profiles, value],+ );++ // Fall back to a single-profile fetch when the saved value isn't in the+ // current paginated results (e.g., the user opens an existing workflow with+ // a profile selected that lives on a later page).+ const { data: selectedProfile } = useBrowserProfileQuery(+ hasValue && !profileInList ? (value ?? undefined) : undefined,+ );++ const selectedDisplay = profileInList ?? selectedProfile;++ // Reset the previous search whenever the dropdown is reopened so the user+ // always starts from the unfiltered list.+ useEffect(() => {+ if (!open) {+ setSearchQuery("");+ }+ }, [open]);++ const handleToggle = () => {+ if (open) {+ setOpen(false);+ } else {+ setOpen(true);+ setTimeout(() => inputRef.current?.focus(), 0);+ }+ };++ const handleSelect = (profileId: string | null) => {+ onChange(profileId);+ setOpen(false);+ };++ const triggerLabel = hasValue+ ? (selectedDisplay?.name ?? value ?? "")+ : (placeholder ?? "Select a browser profile");if (isError) {return (- <Select disabled>- <SelectTrigger>- <SelectValue placeholder="Failed to load browser profiles" />- </SelectTrigger>- </Select>+ <div+ className={cn(+ "flex w-full cursor-not-allowed items-center rounded-md border border-input bg-transparent text-sm opacity-50 shadow-sm",+ triggerHeightClass,+ )}+ >+ <div+ className={cn(+ "min-w-0 flex-1 truncate text-left",+ triggerInnerPaddingClass,+ )}+ >+ <span className="text-muted-foreground">+ Failed to load browser profiles+ </span>+ </div>+ <div className="flex items-center pr-2">+ <ChevronDownIcon className="size-4 text-slate-500" />+ </div>+ </div>);}- const selectValue = value === null || value === "" ? NONE_VALUE : value;-return (- <Select- value={selectValue}- onValueChange={(next) => {- onChange(next === NONE_VALUE ? null : next);+ <div+ ref={containerRef}+ className="nopan relative"+ onBlur={(e) => {+ if (!containerRef.current?.contains(e.relatedTarget as Node)) {+ setOpen(false);+ }}}>- <SelectTrigger>- <SelectValue placeholder={placeholder ?? "Select a browser profile"} />- </SelectTrigger>- <SelectContent>- <SelectItem value={NONE_VALUE}>None</SelectItem>- {profiles && profiles.length > 0 && <SelectSeparator />}- {profiles?.map((profile) => (- <CustomSelectItem- key={profile.browser_profile_id}- value={profile.browser_profile_id}+ <div+ role="button"+ tabIndex={0}+ className={cn(+ "flex w-full cursor-pointer items-center rounded-md border border-input bg-transparent text-sm shadow-sm",+ triggerHeightClass,+ )}+ onClick={handleToggle}+ onKeyDown={(e) => {+ if (e.key === "Enter" || e.key === " ") {+ e.preventDefault();+ handleToggle();+ }+ }}+ >+ <div+ className={cn(+ "min-w-0 flex-1 truncate text-left",+ triggerInnerPaddingClass,+ )}+ >+ {hasValue ? (+ <span className="text-slate-200">{triggerLabel}</span>+ ) : (+ <span className="text-muted-foreground">{triggerLabel}</span>+ )}+ </div>+ <div className="flex items-center pr-2">+ <ChevronDownIcon+ className={`size-4 text-slate-500 transition-transform ${open ? "rotate-180" : ""}`}+ />+ </div>+ </div>++ {open && (+ <div+ ref={dropdownRef}+ className="absolute z-50 mt-1 w-full overflow-hidden rounded-md border border-slate-600 bg-slate-800 shadow-lg"+ onMouseDown={(e) => e.preventDefault()}+ >+ <div className="border-b border-slate-600 px-3 py-2">+ <input+ ref={inputRef}+ type="text"+ value={searchQuery}+ onChange={(e) => setSearchQuery(e.target.value)}+ placeholder="Search browser profiles..."+ className="w-full bg-transparent text-sm text-slate-200 placeholder:text-muted-foreground focus-visible:outline-none"+ />+ </div>+ <div+ className="max-h-[300px] overflow-y-auto"+ onScroll={(e) =>+ handleInfiniteScroll(+ e,+ fetchNextPage,+ hasNextPage,+ isFetchingNextPage,+ )+ }>- <div className="space-y-1">- <p className="text-sm font-medium">- <SelectItemText>{profile.name}</SelectItemText>- </p>- {profile.description && (- <p className="text-xs text-slate-400">{profile.description}</p>- )}- </div>- </CustomSelectItem>- ))}- </SelectContent>- </Select>+ <button+ type="button"+ onMouseDown={(e) => e.preventDefault()}+ onClick={() => handleSelect(null)}+ className={`flex w-full items-center px-3 py-2 text-left text-sm transition-colors hover:bg-slate-700 ${+ !hasValue ? "bg-slate-700" : ""+ }`}+ >+ <span className="text-slate-200">None</span>+ </button>+ {(isFetching || isTyping) && profiles.length === 0 ? (+ <>+ {Array.from({ length: 5 }).map((_, index) => (+ <div+ key={`skeleton-${index}`}+ className="flex w-full flex-col gap-1 px-3 py-2"+ >+ <Skeleton className="h-3.5 w-3/4" />+ <Skeleton className="h-3 w-1/2" />+ </div>+ ))}+ </>+ ) : profiles.length === 0 ? (+ <div className="px-3 py-3 text-xs text-slate-500">+ {debouncedSearch+ ? `No browser profiles match "${debouncedSearch}".`+ : "No browser profiles found."}+ </div>+ ) : (+ <>+ {profiles.map((profile) => {+ const isSelected = value === profile.browser_profile_id;+ return (+ <button+ key={profile.browser_profile_id}+ type="button"+ onMouseDown={(e) => e.preventDefault()}+ onClick={() => handleSelect(profile.browser_profile_id)}+ className={`flex w-full flex-col gap-0.5 px-3 py-2 text-left text-sm transition-colors hover:bg-slate-700 ${+ isSelected ? "bg-slate-700" : ""+ }`}+ >+ <span className="font-medium text-slate-200">+ {profile.name}+ </span>+ {profile.description && (+ <span className="truncate text-xs text-slate-400">+ {profile.description}+ </span>+ )}+ </button>+ );+ })}+ {isFetchingNextPage && (+ <div className="flex items-center justify-center py-2">+ <ReloadIcon className="h-3 w-3 animate-spin text-slate-400" />+ </div>+ )}+ </>+ )}+ </div>+ </div>+ )}+ </div>);}diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/StartNode/StartNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/StartNode/StartNode.tsxindex 75717faad..261b90403 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/StartNode/StartNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/StartNode/StartNode.tsx@@ -481,6 +481,7 @@ function StartNode({ id, data, parentId }: NodeProps<StartNode>) {onChange={(value) => {update({ browserProfileId: value });}}+ compact/></div><div className="space-y-2">diff --git a/skyvern-frontend/src/routes/workflows/hooks/useBrowserProfilesQuery.ts b/skyvern-frontend/src/routes/workflows/hooks/useBrowserProfilesQuery.tsindex 59ffb91cd..7159fbe21 100644--- a/skyvern-frontend/src/routes/workflows/hooks/useBrowserProfilesQuery.ts+++ b/skyvern-frontend/src/routes/workflows/hooks/useBrowserProfilesQuery.ts@@ -13,14 +13,21 @@ type Props = UseQueryOptions & {includeDeleted?: boolean;page?: number;page_size?: number;+ searchKey?: string;};function useBrowserProfilesQuery(props: Props = {}) {- const { includeDeleted = false, page, page_size, ...queryOptions } = props;+ const {+ includeDeleted = false,+ page,+ page_size,+ searchKey,+ ...queryOptions+ } = props;const credentialGetter = useCredentialGetter();return useQuery<QueryReturnType>({- queryKey: ["browserProfiles", includeDeleted, page, page_size],+ queryKey: ["browserProfiles", includeDeleted, page, page_size, searchKey],queryFn: async () => {const client = await getClient(credentialGetter, "sans-api-v1");const params = new URLSearchParams();@@ -33,6 +40,9 @@ function useBrowserProfilesQuery(props: Props = {}) {if (page_size !== undefined) {params.set("page_size", String(page_size));}+ if (searchKey) {+ params.set("search_key", searchKey);+ }return client.get("/browser_profiles", { params }).then((res) => res.data);diff --git a/skyvern-frontend/src/routes/workflows/hooks/useInfiniteBrowserProfilesQuery.ts b/skyvern-frontend/src/routes/workflows/hooks/useInfiniteBrowserProfilesQuery.tsnew file mode 100644index 000000000..e3ecc5d1f--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/hooks/useInfiniteBrowserProfilesQuery.ts@@ -0,0 +1,46 @@+import { getClient } from "@/api/AxiosClient";+import { BrowserProfileApiResponse } from "@/api/types";+import { useCredentialGetter } from "@/hooks/useCredentialGetter";+import { useInfiniteQuery } from "@tanstack/react-query";++interface UseInfiniteBrowserProfilesQueryParams {+ page_size?: number;+ searchKey?: string;+ enabled?: boolean;+}++function useInfiniteBrowserProfilesQuery(+ params?: UseInfiniteBrowserProfilesQueryParams,+) {+ const credentialGetter = useCredentialGetter();+ const pageSize = params?.page_size ?? 20;+ const searchKey = params?.searchKey ?? "";++ return useInfiniteQuery<Array<BrowserProfileApiResponse>>({+ queryKey: ["browserProfiles-infinite", searchKey, pageSize],+ queryFn: async ({ pageParam = 1 }) => {+ const client = await getClient(credentialGetter, "sans-api-v1");+ const searchParams = new URLSearchParams();+ searchParams.append("page", String(pageParam));+ searchParams.append("page_size", String(pageSize));+ if (searchKey) {+ searchParams.append("search_key", searchKey);+ }+ return client+ .get<Array<BrowserProfileApiResponse>>("/browser_profiles", {+ params: searchParams,+ })+ .then((response) => response.data);+ },+ getNextPageParam: (lastPage, allPages) => {+ if (lastPage.length === pageSize) {+ return allPages.length + 1;+ }+ return undefined;+ },+ initialPageParam: 1,+ enabled: params?.enabled ?? true,+ });+}++export { useInfiniteBrowserProfilesQuery };