import { useMemo, useState } from "react"; import { useProfiles, useScripts } from "../../api/hooks.js"; import { FormInput } from "../FormControls.jsx"; import { ScriptIcon } from "../ScriptIcon.jsx"; import { scriptTags } from "../../lib/script.js"; export function AddScriptDialog({ open, onClose, onPick, owner }) { const { data: scripts = [], isLoading } = useScripts(); const { data: profiles = [], isLoading: profilesLoading } = useProfiles( owner || undefined, { enabled: open && Boolean(owner) }, ); const [q, setQ] = useState(""); const [tab, setTab] = useState("scripts"); const filteredScripts = useMemo(() => { const term = q.trim().toLowerCase(); const list = scripts.map((s) => ({ name: typeof s === "string" ? s : s.name, description: typeof s === "string" ? "" : s.meta?.description ?? "", meta: typeof s === "string" ? null : s.meta, metaError: typeof s === "string" ? null : s.metaError, hasIcon: typeof s === "string" ? undefined : s.hasIcon, tags: typeof s === "string" ? [] : scriptTags(s.meta), })); if (!term) return list; return list.filter( (s) => s.name.toLowerCase().includes(term) || s.description.toLowerCase().includes(term) || s.tags.some((t) => t.toLowerCase().includes(term)), ); }, [scripts, q]); const filteredProfiles = useMemo(() => { const term = q.trim().toLowerCase(); if (!term) return profiles; return profiles.filter( (p) => p.name.toLowerCase().includes(term) || String(p.script ?? "").toLowerCase().includes(term) || String(p.description ?? "").toLowerCase().includes(term), ); }, [profiles, q]); if (!open) return null; return (

Add step

setQ(e.target.value)} autoFocus /> {tab === "scripts" ? (
  • {isLoading ? (
  • ) : ( filteredScripts.map((s) => (
  • )) )}
) : (
    {!owner ? (
  • Save the workflow with an owner first.
  • ) : profilesLoading ? (
  • ) : filteredProfiles.length === 0 ? (
  • No profiles for this owner.
  • ) : ( filteredProfiles.map((p) => (
  • )) )}
)}
); }