Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

remove tree picker

adilson6c26487288f3
diff --git a/backend/src/server/routes/v1/app-connection-routers/gitlab-connection-router.ts b/backend/src/server/routes/v1/app-connection-routers/gitlab-connection-router.ts
index 3190293162..ab5f4040bc 100644
--- a/backend/src/server/routes/v1/app-connection-routers/gitlab-connection-router.ts
+++ b/backend/src/server/routes/v1/app-connection-routers/gitlab-connection-router.ts
@@ -10,7 +10,6 @@ import {
TGitLabProject,
UpdateGitLabConnectionSchema
} from "@app/services/app-connection/gitlab";
-import { TGitLabGroupTreeItem } from "@app/services/app-connection/gitlab/gitlab-connection-types";
import { AuthMode } from "@app/services/auth/auth-type";
import { registerAppConnectionEndpoints } from "./app-connection-endpoints";
@@ -102,103 +101,4 @@ export const registerGitLabConnectionRouter = async (server: FastifyZodProvider)
return groups;
}
});
-
- server.route({
- method: "GET",
- url: `/:connectionId/groups/root`,
- config: {
- rateLimit: readLimit
- },
- schema: {
- operationId: "listGitLabRootGroups",
- params: z.object({
- connectionId: z.string().uuid()
- }),
- response: {
- 200: z
- .object({
- id: z.string(),
- name: z.string(),
- fullPath: z.string()
- })
- .array()
- }
- },
- onRequest: verifyAuth([AuthMode.JWT]),
- handler: async (req) => {
- const { connectionId } = req.params;
- const groups: TGitLabGroupTreeItem[] = await server.services.appConnection.gitlab.listRootGroups(
- connectionId,
- req.permission
- );
- return groups;
- }
- });
-
- server.route({
- method: "GET",
- url: `/:connectionId/groups/:groupId/subgroups`,
- config: {
- rateLimit: readLimit
- },
- schema: {
- operationId: "listGitLabGroupSubgroups",
- params: z.object({
- connectionId: z.string().uuid(),
- groupId: z.string().min(1)
- }),
- response: {
- 200: z
- .object({
- id: z.string(),
- name: z.string(),
- fullPath: z.string()
- })
- .array()
- }
- },
- onRequest: verifyAuth([AuthMode.JWT]),
- handler: async (req) => {
- const { connectionId, groupId } = req.params;
- const subgroups: TGitLabGroupTreeItem[] = await server.services.appConnection.gitlab.listSubgroups(
- connectionId,
- groupId,
- req.permission
- );
- return subgroups;
- }
- });
-
- server.route({
- method: "GET",
- url: `/:connectionId/groups/:groupId/projects`,
- config: {
- rateLimit: readLimit
- },
- schema: {
- operationId: "listGitLabGroupProjects",
- params: z.object({
- connectionId: z.string().uuid(),
- groupId: z.string().min(1)
- }),
- response: {
- 200: z
- .object({
- id: z.string(),
- name: z.string()
- })
- .array()
- }
- },
- onRequest: verifyAuth([AuthMode.JWT]),
- handler: async (req) => {
- const { connectionId, groupId } = req.params;
- const projects: TGitLabProject[] = await server.services.appConnection.gitlab.listGroupProjects(
- connectionId,
- groupId,
- req.permission
- );
- return projects;
- }
- });
};
diff --git a/backend/src/services/app-connection/gitlab/gitlab-connection-fns.ts b/backend/src/services/app-connection/gitlab/gitlab-connection-fns.ts
index 83769e8c2c..736b1ef6f6 100644
--- a/backend/src/services/app-connection/gitlab/gitlab-connection-fns.ts
+++ b/backend/src/services/app-connection/gitlab/gitlab-connection-fns.ts
@@ -15,13 +15,10 @@ import { TKmsServiceFactory } from "@app/services/kms/kms-service";
import { TAppConnectionDALFactory } from "../app-connection-dal";
import { GitLabAccessTokenType, GitLabConnectionMethod } from "./gitlab-connection-enums";
-import {
- TGitLabConnection,
- TGitLabConnectionConfig,
- TGitLabGroup,
- TGitLabGroupTreeItem,
- TGitLabProject
-} from "./gitlab-connection-types";
+import { TGitLabConnection, TGitLabConnectionConfig, TGitLabGroup, TGitLabProject } from "./gitlab-connection-types";
+
+// Cap provider list calls to the first page; users narrow further via server-side search.
+const SEARCH_ITEMS_LIMIT = 20;
interface GitLabOAuthTokenResponse {
access_token: string;
@@ -356,6 +353,9 @@ export const listGitLabProjects = async ({
appConnection.method === GitLabConnectionMethod.OAuth
);
const projects = await client.Projects.all({
+ pagination: "offset",
+ perPage: SEARCH_ITEMS_LIMIT,
+ maxPages: 1,
...(search ? { search } : {}),
archived: false,
includePendingDelete: false,
@@ -401,6 +401,9 @@ export const listGitLabGroups = async ({
try {
const groups = await client.Groups.all({
+ pagination: "offset",
+ perPage: SEARCH_ITEMS_LIMIT,
+ maxPages: 1,
orderBy: "name",
sort: "asc",
minAccessLevel: 50,
@@ -429,78 +432,3 @@ export const listGitLabGroups = async ({
});
}
};
-
-export const listGitLabRootGroups = async (params: TNavigationParams): Promise<TGitLabGroupTreeItem[]> => {
- const client = await getNavigationClient(params);
- if (!client) return [];
-
- try {
- const groups = await client.Groups.all({
- topLevelOnly: true,
- orderBy: "name",
- sort: "asc",
- minAccessLevel: 20
- });
-
- return groups.map((g) => ({ id: g.id.toString(), name: g.name, fullPath: g.fullPath }));
- } catch (error: unknown) {
- if (error instanceof GitbeakerRequestError) {
- throw new BadRequestError({
- message: `Failed to fetch GitLab groups: ${error.message ?? "Unknown error"}${error.cause?.description && error.message !== "Unauthorized" ? `. Cause: ${error.cause.description}` : ""}`
- });
- }
- if (error instanceof InternalServerError) throw error;
- throw new InternalServerError({ message: "Unable to fetch GitLab root groups" });
- }
-};
-
-export const listGitLabSubgroups = async (
- groupId: string,
- params: TNavigationParams
-): Promise<TGitLabGroupTreeItem[]> => {
- const client = await getNavigationClient(params);
- if (!client) return [];
-
- try {
- const subgroups = await client.Groups.allSubgroups(Number(groupId), {
- orderBy: "name",
- sort: "asc",
- minAccessLevel: 20
- });
-
- return subgroups.map((g) => ({ id: g.id.toString(), name: g.name, fullPath: g.fullPath }));
- } catch (error: unknown) {
- if (error instanceof GitbeakerRequestError) {
- throw new BadRequestError({
- message: `Failed to fetch GitLab subgroups: ${error.message ?? "Unknown error"}${error.cause?.description && error.message !== "Unauthorized" ? `. Cause: ${error.cause.description}` : ""}`
- });
- }
- if (error instanceof InternalServerError) throw error;
- throw new InternalServerError({ message: "Unable to fetch GitLab subgroups" });
- }
-};
-
-export const listGitLabGroupProjects = async (
- groupId: string,
- params: TNavigationParams
-): Promise<TGitLabProject[]> => {
- const client = await getNavigationClient(params);
- if (!client) return [];
-
- try {
- const projects = await client.Groups.allProjects(Number(groupId), {
- archived: false,
- includeSubgroups: false
- });
-
- return projects.map((p) => ({ id: p.id.toString(), name: p.pathWithNamespace }));
- } catch (error: unknown) {
- if (error instanceof GitbeakerRequestError) {
- throw new BadRequestError({
- message: `Failed to fetch GitLab group projects: ${error.message ?? "Unknown error"}${error.cause?.description && error.message !== "Unauthorized" ? `. Cause: ${error.cause.description}` : ""}`
- });
- }
- if (error instanceof InternalServerError) throw error;
- throw new InternalServerError({ message: "Unable to fetch GitLab group projects" });
- }
-};
diff --git a/backend/src/services/app-connection/gitlab/gitlab-connection-service.ts b/backend/src/services/app-connection/gitlab/gitlab-connection-service.ts
index 35254613c5..314ba9052d 100644
--- a/backend/src/services/app-connection/gitlab/gitlab-connection-service.ts
+++ b/backend/src/services/app-connection/gitlab/gitlab-connection-service.ts
@@ -4,13 +4,7 @@ import { TKmsServiceFactory } from "@app/services/kms/kms-service";
import { TAppConnectionDALFactory } from "../app-connection-dal";
import { AppConnection } from "../app-connection-enums";
-import {
- listGitLabGroupProjects,
- listGitLabGroups,
- listGitLabProjects,
- listGitLabRootGroups,
- listGitLabSubgroups
-} from "./gitlab-connection-fns";
+import { listGitLabGroups, listGitLabProjects } from "./gitlab-connection-fns";
import { TGitLabConnection } from "./gitlab-connection-types";
type TGetAppConnectionFunc = (
@@ -46,46 +40,8 @@ export const gitlabConnectionService = (
}
};
- const listRootGroups = async (connectionId: string, actor: OrgServiceActor) => {
- try {
- const appConnection = await getAppConnection(AppConnection.GitLab, connectionId, actor);
- return await listGitLabRootGroups({ appConnection, appConnectionDAL, kmsService });
- } catch (error) {
- logger.error(error, `Failed to list root groups for GitLab connection ${connectionId}`);
- return [];
- }
- };
-
- const listSubgroups = async (connectionId: string, groupId: string, actor: OrgServiceActor) => {
- try {
- const appConnection = await getAppConnection(AppConnection.GitLab, connectionId, actor);
- const subgroups = await listGitLabSubgroups(groupId, {
- appConnection,
- appConnectionDAL,
- kmsService
- });
- return subgroups;
- } catch (error) {
- logger.error(error, `Failed to list subgroups for GitLab group ${groupId}`);
- return [];
- }
- };
-
- const listGroupProjects = async (connectionId: string, groupId: string, actor: OrgServiceActor) => {
- try {
- const appConnection = await getAppConnection(AppConnection.GitLab, connectionId, actor);
- return await listGitLabGroupProjects(groupId, { appConnection, appConnectionDAL, kmsService });
- } catch (error) {
- logger.error(error, `Failed to list projects for GitLab group ${groupId}`);
- return [];
- }
- };
-
return {
listProjects,
- listGroups,
- listRootGroups,
- listSubgroups,
- listGroupProjects
+ listGroups
};
};
diff --git a/backend/src/services/app-connection/gitlab/gitlab-connection-types.ts b/backend/src/services/app-connection/gitlab/gitlab-connection-types.ts
index 10d6d8aa59..347f637de2 100644
--- a/backend/src/services/app-connection/gitlab/gitlab-connection-types.ts
+++ b/backend/src/services/app-connection/gitlab/gitlab-connection-types.ts
@@ -56,9 +56,3 @@ export interface TGitLabGroup {
fullName: string;
fullPath: string;
}
-
-export type TGitLabGroupTreeItem = {
- id: string;
- name: string;
- fullPath: string;
-};
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/GitLabProjectPicker.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/GitLabProjectPicker.tsx
deleted file mode 100644
index 95a7335452..0000000000
--- a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/GitLabProjectPicker.tsx
+++ /dev/null
@@ -1,360 +0,0 @@
-import { useState } from "react";
-import { Box, Folder, Search, User, X } from "lucide-react";
-
-import {
- BrowserRow,
- IconButton,
- InlineEmpty,
- Input,
- ListSkeleton,
- SectionHeading,
- TREE_PICKER_SCROLL_CLASS,
- TreePicker,
- TTreePickerDataSource,
- TTreePickerItem,
- TTreePickerPathEntry
-} from "@app/components/v3";
-import { cn } from "@app/components/v3/utils";
-import {
- useGitLabConnectionListGroupProjects,
- useGitLabConnectionListGroups,
- useGitLabConnectionListProjects,
- useGitLabConnectionListRootGroups,
- useGitLabConnectionListSubgroups
-} from "@app/hooks/api/appConnections/gitlab";
-import { useDebounce } from "@app/hooks/useDebounce";
-
-const SEARCH_ITEMS_LIMIT = 25;
-
-type TabKey = "groups" | "yours";
-
-type GitLabProjectPickerProps = {
- connectionId: string;
- selectedProjectId: string;
- isError?: boolean;
- onChange: (project: { id: string; name: string }) => void;
-};
-
-const SegmentedButton = ({
- icon,
- label,
- isActive,
- count,
- onClick
-}: {
- icon: React.ReactNode;
- label: string;
- isActive: boolean;
- count?: number;
- onClick: () => void;
-}) => (
- <button
- type="button"
- aria-pressed={isActive}
- onClick={onClick}
- className={cn(
- "flex h-7 min-w-0 flex-1 items-center justify-center gap-1.5 rounded px-2.5 text-xs font-medium transition-colors",
- "@md/picker:inline-flex @md/picker:flex-none @md/picker:shrink-0 @md/picker:justify-start",
- "[&_svg]:size-3.5 [&_svg]:shrink-0",
- isActive
- ? "border border-primary/25 bg-primary/10 text-foreground"
- : "border border-transparent text-accent hover:bg-foreground/5 hover:text-foreground"
- )}
- >
- {icon}
- <span className="min-w-0 truncate">{label}</span>
- {count != null && (
- <span
- className={cn(
- "rounded-sm px-1 text-[10px] leading-tight font-medium",
- isActive ? "bg-primary/15 text-foreground" : "bg-foreground/10 text-muted"
- )}
- >
- {count}
- </span>
- )}
- </button>
-);
-
-const PersonalProjectsList = ({
- isLoading,
- projects,
- selectedProjectId,
- onSelect,
- isSearching,
- searchQuery
-}: {
- isLoading: boolean;
- projects: TTreePickerItem[];
- selectedProjectId: string;
- onSelect: (project: TTreePickerItem) => void;
- isSearching: boolean;
- searchQuery: string;
-}) => {
- if (isLoading) return <ListSkeleton />;
-
- if (projects.length === 0) {
- return isSearching ? (
- <InlineEmpty
- title={`No projects match "${searchQuery}".`}
- description="Try a partial name."
- />
- ) : (
- <InlineEmpty
- title="No personal projects."
- description="Projects you create outside of a group will show up here."
- />
- );
- }
-
- return (
- <div className="flex flex-col gap-0.5 p-1">
- {projects.map((project) => (
- <BrowserRow
- key={project.id}
- icon={<Box />}
- label={project.name}
- isSelected={project.id === selectedProjectId}
- onClick={() => onSelect(project)}
- />
- ))}
- </div>
- );
-};
-
-const SearchResultsList = ({
- query,
- isLoading,
- groups,
- projects,
- selectedProjectId,
- onSelectGroup,
- onSelectProject
-}: {
- query: string;
- isLoading: boolean;
- groups: { id: string; fullPath: string }[];
- projects: TTreePickerItem[];
- selectedProjectId: string;
- onSelectGroup: (group: { id: string; fullPath: string }) => void;
- onSelectProject: (project: TTreePickerItem) => void;
-}) => {
- if (isLoading) return <ListSkeleton />;
-
- if (groups.length === 0 && projects.length === 0) {
- return (
- <InlineEmpty
- title={`No groups or projects match "${query}".`}
- description="Try a partial name or browse groups."
- />
- );
- }
-
- return (
- <div className="flex flex-col">
- {groups.length > 0 && (
- <>
- <SectionHeading>Groups</SectionHeading>
- <div className="flex flex-col gap-0.5 p-1">
- {groups.map((group) => (
- <BrowserRow
- key={group.id}
- icon={<Folder className="text-folder" />}
- label={<span className="font-mono text-xs">{group.fullPath}</span>}
- showChevron
- onClick={() => onSelectGroup(group)}
- />
- ))}
- </div>
- </>
- )}
- {projects.length > 0 && (
- <>
- <SectionHeading>Projects</SectionHeading>
- <div className="flex flex-col gap-0.5 p-1">
- {projects.map((project) => (
- <BrowserRow
- key={project.id}
- icon={<Box />}
- label={<span className="font-mono text-xs">{project.name}</span>}
- isSelected={project.id === selectedProjectId}
- onClick={() => onSelectProject(project)}
- />
- ))}
- </div>
- </>
- )}
- </div>
- );
-};
-
-export const GitLabProjectPicker = ({
- connectionId,
- selectedProjectId,
- isError,
- onChange
-}: GitLabProjectPickerProps) => {
- const [tab, setTab] = useState<TabKey>("groups");
- const [path, setPath] = useState<TTreePickerPathEntry[]>([]);
- const [search, setSearch] = useState("");
- const [debouncedSearch] = useDebounce(search.trim(), 300);
-
- const hasConnection = Boolean(connectionId);
- const isSearching = debouncedSearch.length > 0;
-
- const treeDataSource: TTreePickerDataSource = {
- useRootContainers: (opts) => useGitLabConnectionListRootGroups(connectionId, opts),
- useSubContainers: (groupId, opts) =>
- useGitLabConnectionListSubgroups(connectionId, groupId, opts),
- useContainerItems: (groupId, opts) =>
- useGitLabConnectionListGroupProjects(connectionId, groupId, opts)
- };
-
- const rootGroupsQuery = useGitLabConnectionListRootGroups(connectionId, {
- enabled: hasConnection
- });
-
- const personalProjectsQuery = useGitLabConnectionListProjects(connectionId, undefined, {
- enabled: hasConnection
- });
-
- const projectSearchQuery = useGitLabConnectionListProjects(connectionId, debouncedSearch, {
- enabled: hasConnection && tab === "groups" && isSearching
- });
-
- const groupNameSearchQuery = useGitLabConnectionListGroups(connectionId, debouncedSearch, {
- enabled: hasConnection && tab === "groups" && isSearching
- });
-
- const handleTabChange = (next: TabKey) => {
- if (next === tab) return;
- setTab(next);
- setSearch("");
- setPath([]);
- };
-
- const handleProjectSelect = (project: { id: string; name: string }) => {
- onChange({ id: project.id, name: project.name });
- };
-
- const handleSearchGroupSelect = (group: { id: string; fullPath: string }) => {
- setSearch("");
- setPath([{ id: group.id, name: group.fullPath }]);
- };
-
- const normalizedSearch = debouncedSearch.toLowerCase();
- const personalProjects = personalProjectsQuery.data ?? [];
- const filteredPersonalProjects = personalProjects.filter((project) =>
- project.name.toLowerCase().includes(normalizedSearch)
- );
-
- const searchedProjects = (projectSearchQuery.data ?? [])
- .filter((project) => project.name.toLowerCase().includes(normalizedSearch))
- .map((project) => ({ id: project.id, name: project.name }))
- .slice(0, SEARCH_ITEMS_LIMIT);
-
- return (
- <div
- className={cn(
- "@container/picker flex min-w-0 flex-col gap-2 rounded-md border bg-container",
- isError ? "border-danger" : "border-border"
- )}
- >
- <div className="flex min-w-0 flex-wrap items-center gap-2 border-b border-border p-2">
- <div className="flex w-full items-center gap-0.5 rounded-md border border-border bg-bunker-700/30 p-0.5 @md/picker:inline-flex @md/picker:w-auto @md/picker:shrink-0">
- <SegmentedButton
- icon={<Folder />}
- label="Groups"
- isActive={tab === "groups"}
- count={rootGroupsQuery.data?.length}
- onClick={() => handleTabChange("groups")}
- />
- <SegmentedButton
- icon={<User />}
- label="Projects"
- isActive={tab === "yours"}
- count={personalProjects.length}
- onClick={() => handleTabChange("yours")}
- />
- </div>
- <div className="relative flex min-w-0 flex-1 items-center @md/picker:min-w-[160px]">
- <Search className="pointer-events-none absolute left-2.5 size-3.5 text-muted" />
- <Input
- value={search}
- onChange={(e) => setSearch(e.target.value)}
- placeholder={
- tab === "yours" ? "Search your projects..." : "Search groups & projects..."
- }
- className="h-8 w-full min-w-0 pr-7 pl-8 text-sm"
- disabled={!hasConnection}
- />
- {search.length > 0 && (
- <IconButton
- aria-label="Clear search"
- variant="ghost-muted"
- size="xs"
- className="absolute right-1"
- onClick={() => setSearch("")}
- >
- <X />
- </IconButton>
- )}
- </div>
- </div>
-
- {!hasConnection && (
- <div className={cn(TREE_PICKER_SCROLL_CLASS, "px-3 py-10 text-center text-sm text-muted")}>
- Select a GitLab Connection above to browse projects.
- </div>
- )}
-
- {hasConnection && tab === "groups" && isSearching && (
- <div className={cn(TREE_PICKER_SCROLL_CLASS, "p-1")}>
- <SearchResultsList
- query={debouncedSearch}
- isLoading={projectSearchQuery.isLoading || groupNameSearchQuery.isLoading}
- groups={groupNameSearchQuery.data ?? []}
- projects={searchedProjects}
- selectedProjectId={selectedProjectId}
- onSelectGroup={handleSearchGroupSelect}
- onSelectProject={handleProjectSelect}
- />
- </div>
- )}
-
- {hasConnection && tab === "groups" && !isSearching && (
- <TreePicker
- dataSource={treeDataSource}
- path={path}
- onPathChange={setPath}
- selectedItemId={selectedProjectId}
- onSelectItem={handleProjectSelect}
- rootLabel="Groups"
- subContainersHeading="Subgroups"
- itemsHeading="Projects"
- emptyRoot={{
- title: "No groups available.",
- description: "Your GitLab account isn't a member of any group."
- }}
- emptyContainer={{
- title: "This group is empty.",
- description: "No subgroups or projects available to your token here."
- }}
- />
- )}
-
- {hasConnection && tab === "yours" && (
- <div className={cn(TREE_PICKER_SCROLL_CLASS, "p-1")}>
- <PersonalProjectsList
- isLoading={personalProjectsQuery.isLoading}
- projects={filteredPersonalProjects}
- selectedProjectId={selectedProjectId}
- onSelect={handleProjectSelect}
- isSearching={isSearching}
- searchQuery={debouncedSearch}
- />
- </div>
- )}
- </div>
- );
-};
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/GitLabSyncFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/GitLabSyncFields.tsx
index 6c257b9681..96e7fee61d 100644
--- a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/GitLabSyncFields.tsx
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/GitLabSyncFields.tsx
@@ -1,3 +1,4 @@
+import { useMemo, useState } from "react";
import { Controller, useFormContext, useWatch } from "react-hook-form";
import { SingleValue } from "react-select";
import { Info } from "lucide-react";
@@ -23,39 +24,17 @@ import {
TooltipContent,
TooltipTrigger
} from "@app/components/v3";
-import { TGitLabGroup, useGitLabConnectionListGroups } from "@app/hooks/api/appConnections/gitlab";
+import { useDebounce } from "@app/hooks";
+import {
+ TGitLabGroup,
+ TGitLabProject,
+ useGitLabConnectionListGroups,
+ useGitLabConnectionListProjects
+} from "@app/hooks/api/appConnections/gitlab";
import { SecretSync } from "@app/hooks/api/secretSyncs";
import { GitLabSyncScope } from "@app/hooks/api/secretSyncs/types/gitlab-sync";
import { TSecretSyncForm } from "../schemas";
-import { GitLabProjectPicker } from "./GitLabProjectPicker";
-
-const ProjectPickerField = ({
- connectionId,
- selectedProjectId,
- isError
-}: {
- connectionId: string;
- selectedProjectId: string;
- isError?: boolean;
-}) => {
- const { setValue } = useFormContext<TSecretSyncForm & { destination: SecretSync.GitLab }>();
-
- return (
- <GitLabProjectPicker
- connectionId={connectionId}
- selectedProjectId={selectedProjectId}
- isError={isError}
- onChange={(project) => {
- setValue("destinationConfig.projectId", project.id, {
- shouldDirty: true,
- shouldValidate: true
- });
- setValue("destinationConfig.projectName", project.name, { shouldDirty: true });
- }}
- />
- );
-};
const SecretProtectionOption = ({
title,
@@ -94,18 +73,56 @@ export const GitLabSyncFields = () => {
TSecretSyncForm & { destination: SecretSync.GitLab }
>();
+ const [projectSearch, setProjectSearch] = useState("");
+ const [debouncedProjectSearch] = useDebounce(projectSearch, 300);
+ const [groupSearch, setGroupSearch] = useState("");
+ const [debouncedGroupSearch] = useDebounce(groupSearch, 300);
+
const connectionId = useWatch({ name: "connection.id", control });
const scope = useWatch({ name: "destinationConfig.scope", control });
const shouldMaskSecrets = useWatch({ name: "destinationConfig.shouldMaskSecrets", control });
+ const projectId = useWatch({ name: "destinationConfig.projectId", control });
+ const projectName = useWatch({ name: "destinationConfig.projectName", control });
+ const groupId = useWatch({ name: "destinationConfig.groupId", control });
+ const groupName = useWatch({ name: "destinationConfig.groupName", control });
const { data: groups, isLoading: isGroupsLoading } = useGitLabConnectionListGroups(
connectionId,
- undefined,
+ debouncedGroupSearch || undefined,
{
enabled: Boolean(connectionId) && scope === GitLabSyncScope.Group
}
);
+ const { data: projects, isLoading: isProjectsLoading } = useGitLabConnectionListProjects(
+ connectionId,
+ debouncedProjectSearch || undefined,
+ {
+ enabled: Boolean(connectionId) && scope === GitLabSyncScope.Project
+ }
+ );
+
+ // The provider only returns the first page, so the currently-selected item may not be in the
+ // results. Surface it from the stored name so the selection always renders (e.g. when editing).
+ const groupOptions = useMemo(() => {
+ const results = groups ?? [];
+ if (groupId && groupName && !results.some((group) => group.id === groupId)) {
+ return [
+ { id: groupId, name: groupName, fullName: groupName, fullPath: groupName },
+ ...results
+ ];
+ }
+ return results;
+ }, [groups, groupId, groupName]);
+
+ const projectOptions = useMemo(() => {
+ const results = projects ?? [];
+ if (projectId && projectName && !results.some((project) => project.id === projectId)) {
+ return [{ id: projectId, name: projectName }, ...results];
+ }
+ return results;
+ }, [projects, projectId, projectName]);
+
return (
<FieldGroup>
<SecretSyncConnectionField
@@ -115,6 +132,8 @@ export const GitLabSyncFields = () => {
setValue("destinationConfig.groupId", "");
setValue("destinationConfig.groupName", "");
setValue("destinationConfig.scope", GitLabSyncScope.Project);
+ setProjectSearch("");
+ setGroupSearch("");
}}
/>
@@ -134,6 +153,8 @@ export const GitLabSyncFields = () => {
setValue("destinationConfig.projectName", "");
setValue("destinationConfig.groupId", "");
setValue("destinationConfig.groupName", "");
+ setProjectSearch("");
+ setGroupSearch("");
}}
>
<SelectTrigger className="w-full capitalize" isError={Boolean(error)}>
@@ -166,7 +187,8 @@ export const GitLabSyncFields = () => {
<Info />
</TooltipTrigger>
<TooltipContent className="max-w-md">
- Ensure the group exists in the connection&apos;s GitLab instance URL.
+ Ensure the group exists in the connection&apos;s GitLab instance URL. Only the
+ first results are shown — search by name to find more.
</TooltipContent>
</Tooltip>
</FieldLabel>
@@ -174,18 +196,23 @@ export const GitLabSyncFields = () => {
<FilterableSelect
isLoading={isGroupsLoading && Boolean(connectionId)}
isDisabled={!connectionId}
- value={groups?.find((group) => group.id === value) ?? null}
+ value={groupOptions.find((group) => group.id === value) ?? null}
onChange={(option) => {
- onChange((option as SingleValue<TGitLabGroup>)?.id ?? "");
- setValue(
- "destinationConfig.groupName",
- (option as SingleValue<TGitLabGroup>)?.fullName ?? ""
- );
+ const selected = option as SingleValue<TGitLabGroup>;
+ onChange(selected?.id ?? "");
+ setValue("destinationConfig.groupName", selected?.fullName ?? "", {
+ shouldDirty: true
+ });
}}
- options={groups}
- placeholder="Select a group..."
+ onInputChange={(newValue) => setGroupSearch(newValue)}
+ filterOption={null}
+ options={groupOptions}
+ placeholder="Search for a group..."
getOptionLabel={(option) => option.fullName}
getOptionValue={(option) => option.id}
+ noOptionsMessage={({ inputValue }) =>
+ inputValue ? "No groups found matching your search." : "No groups found."
+ }
/>
<FieldError errors={[error]} />
</FieldContent>
@@ -198,7 +225,7 @@ export const GitLabSyncFields = () => {
<Controller
name="destinationConfig.projectId"
control={control}
- render={({ field: { value }, fieldState: { error } }) => (
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
<Field>
<FieldLabel>
GitLab Project
@@ -208,15 +235,32 @@ export const GitLabSyncFields = () => {
</TooltipTrigger>
<TooltipContent className="max-w-md">
Ensure the project exists in the connection&apos;s GitLab instance URL and the
- connection has access to it.
+ connection has access to it. Only the first results are shown — search by name
+ to find more.
</TooltipContent>
</Tooltip>
</FieldLabel>
<FieldContent>
- <ProjectPickerField
- connectionId={connectionId}
- selectedProjectId={value}
- isError={Boolean(error)}
+ <FilterableSelect
+ isLoading={isProjectsLoading && Boolean(connectionId)}
+ isDisabled={!connectionId}
+ value={projectOptions.find((project) => project.id === value) ?? null}
+ onChange={(option) => {
+ const selected = option as SingleValue<TGitLabProject>;
+ onChange(selected?.id ?? "");
+ setValue("destinationConfig.projectName", selected?.name ?? "", {
+ shouldDirty: true
+ });
+ }}
+ onInputChange={(newValue) => setProjectSearch(newValue)}
+ filterOption={null}
+ options={projectOptions}
+ placeholder="Search for a project..."
+ getOptionLabel={(option) => option.name}
+ getOptionValue={(option) => option.id}
+ noOptionsMessage={({ inputValue }) =>
+ inputValue ? "No projects found matching your search." : "No projects found."
+ }
/>
<FieldError errors={[error]} />
</FieldContent>
diff --git a/frontend/src/components/v3/platform/TreePicker/TreePicker.tsx b/frontend/src/components/v3/platform/TreePicker/TreePicker.tsx
deleted file mode 100644
index 3fb3fac0fc..0000000000
--- a/frontend/src/components/v3/platform/TreePicker/TreePicker.tsx
+++ /dev/null
@@ -1,241 +0,0 @@
-import { ReactNode } from "react";
-import { Box, ChevronLeft, ChevronRight, Folder } from "lucide-react";
-
-import { IconButton } from "@app/components/v3/generic/IconButton";
-import { cn } from "@app/components/v3/utils";
-
-import {
- BrowserRow,
- InlineEmpty,
- ListSkeleton,
- SectionHeading,
- TREE_PICKER_SCROLL_CLASS
-} from "./primitives";
-import { TreePickerProps, TTreePickerContainer, TTreePickerItem } from "./types";
-
-const ContainerList = ({
- containerIcon,
- containers,
- onDrillIn,
- emptyTitle,
- emptyDescription
-}: {
- containerIcon: ReactNode;
- containers: TTreePickerContainer[];
- onDrillIn: (container: TTreePickerContainer) => void;
- emptyTitle: string;
- emptyDescription?: string;
-}) => {
- if (containers.length === 0) {
- return <InlineEmpty title={emptyTitle} description={emptyDescription} />;
- }
-
- return (
- <div className="flex flex-col gap-0.5 p-1">
- {containers.map((container) => (
- <BrowserRow
- key={container.id}
- icon={containerIcon}
- label={container.name}
- meta={
- container.fullPath && container.fullPath !== container.name
- ? container.fullPath
- : undefined
- }
- showChevron
- onClick={() => onDrillIn(container)}
- />
- ))}
- </div>
- );
-};
-
-const ContainerDetailList = ({
- containerIcon,
- itemIcon,
- subContainers,
- items,
- selectedItemId,
- subContainersHeading,
- itemsHeading,
- onDrillIn,
- onSelectItem,
- emptyTitle,
- emptyDescription
-}: {
- containerIcon: ReactNode;
- itemIcon: ReactNode;
- subContainers: TTreePickerContainer[];
- items: TTreePickerItem[];
- selectedItemId: string;
- subContainersHeading: string;
- itemsHeading: string;
- onDrillIn: (container: TTreePickerContainer) => void;
- onSelectItem: (item: TTreePickerItem) => void;
- emptyTitle: string;
- emptyDescription?: string;
-}) => {
- if (subContainers.length === 0 && items.length === 0) {
- return <InlineEmpty title={emptyTitle} description={emptyDescription} />;
- }
-
- return (
- <div className="flex flex-col">
- {subContainers.length > 0 && (
- <>
- <SectionHeading>{subContainersHeading}</SectionHeading>
- <div className="flex flex-col gap-0.5 p-1">
- {subContainers.map((subContainer) => (
- <BrowserRow
- key={subContainer.id}
- icon={containerIcon}
- label={subContainer.name}
- meta={subContainer.fullPath}
- showChevron
- onClick={() => onDrillIn(subContainer)}
- />
- ))}
- </div>
- </>
- )}
- {items.length > 0 && (
- <>
- <SectionHeading>{itemsHeading}</SectionHeading>
- <div className="flex flex-col gap-0.5 p-1">
- {items.map((item) => (
- <BrowserRow
- key={item.id}
- icon={itemIcon}
- label={item.name}
- meta={item.meta}
- isSelected={item.id === selectedItemId}
- onClick={() => onSelectItem(item)}
- />
- ))}
- </div>
- </>
- )}
- </div>
- );
-};
-
-export const TreePicker = ({
- dataSource,
- path,
- onPathChange,
- selectedItemId,
- onSelectItem,
- disabled = false,
- rootLabel,
- subContainersHeading = "Folders",
- itemsHeading = "Items",
- emptyRoot,
- emptyContainer,
- containerIcon = <Folder className="text-folder" />,
- itemIcon = <Box />
-}: TreePickerProps) => {
- const isEnabled = !disabled;
- const current = path[path.length - 1] ?? null;
-
- const rootContainersQuery = dataSource.useRootContainers({ enabled: isEnabled });
-
- const subContainersQuery = dataSource.useSubContainers(current?.id ?? "", {
- enabled: isEnabled && Boolean(current)
- });
-
- const containerItemsQuery = dataSource.useContainerItems(current?.id ?? "", {
- enabled: isEnabled && Boolean(current)
- });
-
- const handleDrillIn = (container: TTreePickerContainer) => {
- onPathChange([...path, { id: container.id, name: container.name }]);
- };
-
- const isLoading = current
- ? subContainersQuery.isLoading || containerItemsQuery.isLoading
- : rootContainersQuery.isLoading;
-
- return (
- <div className="flex min-w-0 flex-col">
- {path.length > 0 && (
- <div className="flex min-w-0 items-center gap-2 border-b border-border px-2 py-1.5">
- <IconButton
- aria-label="Back"
- variant="ghost-muted"
- size="xs"
- onClick={() => onPathChange(path.slice(0, -1))}
- >
- <ChevronLeft />
- </IconButton>
- <nav
- aria-label="breadcrumb"
- className="flex min-w-0 flex-1 items-center gap-1 overflow-hidden text-xs"
- >
- <button
- type="button"
- onClick={() => onPathChange([])}
- className="shrink-0 cursor-pointer whitespace-nowrap text-muted hover:text-foreground"
- >
- {rootLabel}
- </button>
- {path.map((entry, index) => {
- const isLast = index === path.length - 1;
- return (
- <span key={entry.id} className="inline-flex min-w-0 items-center gap-1">
- <ChevronRight className="size-3 shrink-0 text-muted/70" />
- {isLast ? (
- <span aria-current="page" className="truncate text-foreground">
- {entry.name}
- </span>
- ) : (
- <button
- type="button"
- onClick={() => onPathChange(path.slice(0, index + 1))}
- className="cursor-pointer truncate text-muted hover:text-foreground"
- >
- {entry.name}
- </button>
- )}
- </span>
- );
- })}
- </nav>
- </div>
- )}
-
- <div className={cn(TREE_PICKER_SCROLL_CLASS, "p-1")}>
- {(() => {
- if (isLoading) return <ListSkeleton />;
-
- if (!current) {
- return (
- <ContainerList
- containerIcon={containerIcon}
- containers={rootContainersQuery.data ?? []}
- onDrillIn={handleDrillIn}
- emptyTitle={emptyRoot.title}
- emptyDescription={emptyRoot.description}
- />
- );
- }
-
- return (
- <ContainerDetailList
- containerIcon={containerIcon}
- itemIcon={itemIcon}
- subContainers={subContainersQuery.data ?? []}
- items={containerItemsQuery.data ?? []}
- selectedItemId={selectedItemId}
- subContainersHeading={subContainersHeading}
- itemsHeading={itemsHeading}
- onDrillIn={handleDrillIn}
- onSelectItem={onSelectItem}
- emptyTitle={emptyContainer.title}
- emptyDescription={emptyContainer.description}
- />
- );
- })()}
- </div>
- </div>
- );
-};
diff --git a/frontend/src/components/v3/platform/TreePicker/index.ts b/frontend/src/components/v3/platform/TreePicker/index.ts
deleted file mode 100644
index 99ae86e573..0000000000
--- a/frontend/src/components/v3/platform/TreePicker/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export * from "./primitives";
-export * from "./TreePicker";
-export * from "./types";
diff --git a/frontend/src/components/v3/platform/TreePicker/primitives.tsx b/frontend/src/components/v3/platform/TreePicker/primitives.tsx
deleted file mode 100644
index 99f31d9c3c..0000000000
--- a/frontend/src/components/v3/platform/TreePicker/primitives.tsx
+++ /dev/null
@@ -1,67 +0,0 @@
-import { ReactNode } from "react";
-import { Check, ChevronRight } from "lucide-react";
-
-import { Empty, EmptyDescription, EmptyTitle } from "@app/components/v3/generic/Empty";
-import { Skeleton } from "@app/components/v3/generic/Skeleton";
-import { cn } from "@app/components/v3/utils";
-
-// Shared scroll-region height so every view block (tree, search, personal) lines up.
-export const TREE_PICKER_SCROLL_CLASS = "max-h-[320px] min-h-[260px] overflow-y-auto";
-
-export const ListSkeleton = () => (
- <div className="flex flex-col gap-1 p-1">
- {Array.from({ length: 5 }).map((_, i) => (
- // eslint-disable-next-line react/no-array-index-key
- <Skeleton key={i} className="h-8 w-full" />
- ))}
- </div>
-);
-
-export const SectionHeading = ({ children }: { children: ReactNode }) => (
- <div className="px-2 pt-2 pb-1 text-[10px] font-medium tracking-wider text-muted uppercase">
- {children}
- </div>
-);
-
-export const InlineEmpty = ({ title, description }: { title: string; description?: string }) => (
- <Empty className="border-0 bg-transparent p-6 shadow-none">
- <EmptyTitle>{title}</EmptyTitle>
- {description && <EmptyDescription>{description}</EmptyDescription>}
- </Empty>
-);
-
-export const BrowserRow = ({
- icon,
- label,
- meta,
- isSelected = false,
- showChevron = false,
- onClick
-}: {
- icon: ReactNode;
- label: ReactNode;
- meta?: ReactNode;
- isSelected?: boolean;
- showChevron?: boolean;
- onClick: () => void;
-}) => (
- <button
- type="button"
- onClick={onClick}
- className={cn(
- "group flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-sm transition-colors",
- "[&_svg]:size-3.5 [&_svg]:shrink-0",
- isSelected
- ? "bg-primary/10 text-foreground"
- : "text-accent hover:bg-foreground/5 hover:text-foreground"
- )}
- >
- <span className={cn("inline-flex shrink-0", isSelected ? "text-primary" : "text-muted")}>
- {icon}
- </span>
- <span className="min-w-0 flex-1 truncate">{label}</span>
- {meta != null && <span className="shrink-0 text-xs text-muted">{meta}</span>}
- {showChevron && <ChevronRight className="text-muted" />}
- {isSelected && !showChevron && <Check className="text-primary" />}
- </button>
-);
diff --git a/frontend/src/components/v3/platform/TreePicker/types.ts b/frontend/src/components/v3/platform/TreePicker/types.ts
deleted file mode 100644
index 3072e99ff2..0000000000
--- a/frontend/src/components/v3/platform/TreePicker/types.ts
+++ /dev/null
@@ -1,45 +0,0 @@
-import { ReactNode } from "react";
-
-export type TTreePickerContainer = { id: string; name: string; fullPath?: string };
-export type TTreePickerItem = { id: string; name: string; meta?: string };
-export type TTreePickerPathEntry = { id: string; name: string };
-
-type QueryOpts = { enabled: boolean };
-
-// Minimal subset of a React Query result the picker reads; a UseQueryResult satisfies it
-// structurally, so passthrough adapters can return query results directly.
-export type TTreePickerQueryResult<T> = {
- data: T | undefined;
- isLoading: boolean;
- isFetching?: boolean;
-};
-
-export type TTreePickerDataSource = {
- useRootContainers: (opts: QueryOpts) => TTreePickerQueryResult<TTreePickerContainer[]>;
- useSubContainers: (
- containerId: string,
- opts: QueryOpts
- ) => TTreePickerQueryResult<TTreePickerContainer[]>;
- useContainerItems: (
- containerId: string,
- opts: QueryOpts
- ) => TTreePickerQueryResult<TTreePickerItem[]>;
-};
-
-type EmptyCopy = { title: string; description?: string };
-
-export type TreePickerProps = {
- dataSource: TTreePickerDataSource;
- path: TTreePickerPathEntry[];
- onPathChange: (path: TTreePickerPathEntry[]) => void;
- selectedItemId: string;
- onSelectItem: (item: { id: string; name: string }) => void;
- disabled?: boolean;
- rootLabel: string;
- subContainersHeading?: string;
- itemsHeading?: string;
- emptyRoot: EmptyCopy;
- emptyContainer: EmptyCopy;
- containerIcon?: ReactNode;
- itemIcon?: ReactNode;
-};
diff --git a/frontend/src/components/v3/platform/index.ts b/frontend/src/components/v3/platform/index.ts
index d9567da35b..bdb3389b35 100644
--- a/frontend/src/components/v3/platform/index.ts
+++ b/frontend/src/components/v3/platform/index.ts
@@ -6,4 +6,3 @@ export * from "./PasswordGenerator";
export * from "./ScopeIcons";
export * from "./SecretInput";
export * from "./SecretPathInput";
-export * from "./TreePicker";
diff --git a/frontend/src/hooks/api/appConnections/gitlab/queries.tsx b/frontend/src/hooks/api/appConnections/gitlab/queries.tsx
index 35217541ed..fa110340bd 100644
--- a/frontend/src/hooks/api/appConnections/gitlab/queries.tsx
+++ b/frontend/src/hooks/api/appConnections/gitlab/queries.tsx
@@ -3,20 +3,14 @@ import { useQuery, UseQueryOptions } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { appConnectionKeys } from "../queries";
-import { TGitLabGroup, TGitLabGroupTreeItem, TGitLabProject } from "./types";
+import { TGitLabGroup, TGitLabProject } from "./types";
const gitlabConnectionKeys = {
all: [...appConnectionKeys.all, "gitlab"] as const,
listProjects: (connectionId: string, search?: string) =>
[...gitlabConnectionKeys.all, "projects", connectionId, search ?? ""] as const,
listGroups: (connectionId: string, search?: string) =>
- [...gitlabConnectionKeys.all, "groups", connectionId, search ?? ""] as const,
- listRootGroups: (connectionId: string) =>
- [...gitlabConnectionKeys.all, "groups", "root", connectionId] as const,
- listSubgroups: (connectionId: string, groupId: string) =>
- [...gitlabConnectionKeys.all, "subgroups", connectionId, groupId] as const,
- listGroupProjects: (connectionId: string, groupId: string) =>
- [...gitlabConnectionKeys.all, "group-projects", connectionId, groupId] as const
+ [...gitlabConnectionKeys.all, "groups", connectionId, search ?? ""] as const
};
export const useGitLabConnectionListProjects = (
@@ -72,80 +66,3 @@ export const useGitLabConnectionListGroups = (
...options
});
};
-
-export const useGitLabConnectionListRootGroups = (
- connectionId: string,
- options?: Omit<
- UseQueryOptions<
- TGitLabGroupTreeItem[],
- unknown,
- TGitLabGroupTreeItem[],
- ReturnType<typeof gitlabConnectionKeys.listRootGroups>
- >,
- "queryKey" | "queryFn"
- >
-) => {
- return useQuery({
- queryKey: gitlabConnectionKeys.listRootGroups(connectionId),
- queryFn: async () => {
- const { data } = await apiRequest.get<TGitLabGroupTreeItem[]>(
- `/api/v1/app-connections/gitlab/${connectionId}/groups/root`
- );
-
- return data;
- },
- ...options
- });
-};
-
-export const useGitLabConnectionListSubgroups = (
- connectionId: string,
- groupId: string,
- options?: Omit<
- UseQueryOptions<
- TGitLabGroupTreeItem[],
- unknown,
- TGitLabGroupTreeItem[],
- ReturnType<typeof gitlabConnectionKeys.listSubgroups>
- >,
- "queryKey" | "queryFn"
- >
-) => {
- return useQuery({
- queryKey: gitlabConnectionKeys.listSubgroups(connectionId, groupId),
- queryFn: async () => {
- const { data } = await apiRequest.get<TGitLabGroupTreeItem[]>(
- `/api/v1/app-connections/gitlab/${connectionId}/groups/${groupId}/subgroups`
- );
-
- return data;
- },
- ...options
- });
-};
-
-export const useGitLabConnectionListGroupProjects = (
- connectionId: string,
- groupId: string,
- options?: Omit<
- UseQueryOptions<
- TGitLabProject[],
- unknown,
- TGitLabProject[],
- ReturnType<typeof gitlabConnectionKeys.listGroupProjects>
- >,
- "queryKey" | "queryFn"
- >
-) => {
- return useQuery({
- queryKey: gitlabConnectionKeys.listGroupProjects(connectionId, groupId),
- queryFn: async () => {
- const { data } = await apiRequest.get<TGitLabProject[]>(
- `/api/v1/app-connections/gitlab/${connectionId}/groups/${groupId}/projects`
- );
-
- return data;
- },
- ...options
- });
-};
diff --git a/frontend/src/hooks/api/appConnections/gitlab/types.ts b/frontend/src/hooks/api/appConnections/gitlab/types.ts
index e67fb2b93c..87bdbfafe9 100644
--- a/frontend/src/hooks/api/appConnections/gitlab/types.ts
+++ b/frontend/src/hooks/api/appConnections/gitlab/types.ts
@@ -10,12 +10,6 @@ export type TGitLabGroup = {
fullPath: string;
};
-export type TGitLabGroupTreeItem = {
- id: string;
- name: string;
- fullPath: string;
-};
-
export enum GitLabAccessTokenType {
Personal = "personal",
Project = "project",