"use client"; import type { AutoFormInputComponentProps } from "../ui/auto-form/types"; import fetcher from "@/components/fetcher"; import { Button } from "@/components/ui/button"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "@/components/ui/command"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { ScrollArea } from "@/components/ui/scroll-area"; import { cn } from "@/lib/utils"; import { findAllDeployments } from "@/server/curdDeploments"; import { Check, ChevronsUpDown } from "lucide-react"; import * as React from "react"; import useSWR from "swr"; export function SnapshotPickerView({ field, }: Pick) { return (
{field.value && (
              {JSON.stringify(field.value, null, 2)}
            
)}
); } function SnapshotPresetPicker({ field, }: Pick) { const [open, setOpen] = React.useState(false); const [selected, setSelected] = React.useState(null); const [frameworks, setFramework] = React.useState< { id: string; label: string; value: string; }[] >(); React.useEffect(() => { findAllDeployments().then((a) => { console.log(a); const frameworks = a .map((item) => { if ( item.deployments.length == 0 || item.deployments[0].version.snapshot == null ) return null; return { id: item.deployments[0].version.id, label: `${item.name} - ${item.deployments[0].environment}`, value: JSON.stringify(item.deployments[0].version.snapshot), }; }) .filter((item): item is NonNullable => item != null); setFramework(frameworks); }); }, []); function findItem(value: string) { return frameworks?.find((item) => item.id === value); } return ( No framework found. {frameworks?.map((framework) => ( { setSelected(currentValue); const json = frameworks?.find((item) => item.id === currentValue) ?.value ?? null; field.onChange(json ? JSON.parse(json) : null); setOpen(false); }} > {framework.label} ))} ); } type CustomNodeList = { custom_nodes: { author: string; title: string; reference: string; files: string[]; install_type: string; description: string; }[]; }; function CustomNodesSelector({ field, }: Pick) { const [open, setOpen] = React.useState(false); const customNodeList = field.value.git_custom_nodes ?? ({} as Record< string, { hash: string; disabled: boolean; } >); const { data, error, isLoading } = useSWR( "https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/custom-node-list.json", fetcher ); const keys = React.useMemo( () => Object.keys(customNodeList), [customNodeList, data] ); function findItem(value: string) { // console.log(keys, value.toLowerCase()); const included = keys.includes(value.toLowerCase()); return included; } return ( No custom nodes found. {data && data.custom_nodes?.map((framework, index) => ( { let nodeList: Record< string, { hash: string; disabled: boolean; } >; const x = customNodeList; if (x[currentValue]) { const newNodeList = { ...x }; delete newNodeList[currentValue]; nodeList = newNodeList; } else { nodeList = { [currentValue]: { hash: "latest", disabled: false, }, ...x, }; } field.onChange({ ...field.value, git_custom_nodes: nodeList, }); }} > {framework.title} ))} ); }