"use client" import { useMemo, useState } from "react" import { ChevronRight, Folder, Plus, X } from "lucide-react" import { Button } from "@/components/ui/button" import { Checkbox } from "@/components/ui/checkbox" import { Label } from "@/components/ui/label" import { useDriveList } from "@/lib/api/hooks/use-drive-queries" import type { ApiTokenDriveScope } from "@/lib/api/types" import { displayFileName } from "@/lib/drive/display-file-name" import { normalizeDriveFolderPath } from "@/lib/drive/drive-sidebar-tree" import { cn } from "@/lib/utils" export function ApiTokenDriveScopeEditor({ scope, onChange, enabled, className, }: { scope: ApiTokenDriveScope onChange: (scope: ApiTokenDriveScope) => void enabled: boolean className?: string }) { const [browsePath, setBrowsePath] = useState("/") const list = useDriveList(browsePath, 1, "", enabled && !scope.all_folders) const folders = useMemo( () => (list.data?.files ?? []).filter((f) => f.type === "directory"), [list.data?.files] ) const crumbs = useMemo(() => { const normalized = normalizeDriveFolderPath(browsePath) if (normalized === "/") return [{ path: "/", label: "Mon Drive" }] const parts = normalized.slice(1).split("/") const out: { path: string; label: string }[] = [{ path: "/", label: "Mon Drive" }] for (let i = 0; i < parts.length; i++) { const path = "/" + parts.slice(0, i + 1).join("/") out.push({ path, label: displayFileName(parts[i]!) }) } return out }, [browsePath]) if (!enabled) return null function addFolder(path: string) { const normalized = normalizeDriveFolderPath(path) if (scope.folder_paths.includes(normalized)) return onChange({ all_folders: false, folder_paths: [...scope.folder_paths, normalized], }) } function removeFolder(path: string) { onChange({ all_folders: false, folder_paths: scope.folder_paths.filter((p) => p !== path), }) } return (
Périmètre Drive — dossiers {!scope.all_folders && (
{scope.folder_paths.length > 0 && (
    {scope.folder_paths.map((path) => (
  • {path}
  • ))}
)}
{crumbs.map((crumb, index) => ( {index > 0 && } ))}
{list.isLoading ? (

Chargement…

) : folders.length > 0 ? (
    {folders.map((folder) => (
  • ))}
) : null}
)}
) }