Open in dashboard: searchable Command list

This commit is contained in:
2026-10-12 22:07:17 +02:00
parent 530a4b602e
commit a93f865e91
@@ -9,6 +9,14 @@ import {
dashboardsQueryOptions, dashboardsQueryOptions,
} from "@/components/Dashboard/queries" } from "@/components/Dashboard/queries"
import { Button } from "@/components/ui/button" import { Button } from "@/components/ui/button"
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
} from "@/components/ui/command"
import { import {
Popover, Popover,
PopoverContent, PopoverContent,
@@ -78,39 +86,46 @@ export function OpenInDashboard({
Open in dashboard Open in dashboard
</Button> </Button>
</PopoverTrigger> </PopoverTrigger>
<PopoverContent align="end" className="w-64 p-1"> <PopoverContent align="end" className="w-64 p-0">
{flow && !hasResults && ( <Command>
<button <CommandInput placeholder="Search dashboards" />
type="button" <CommandList>
onClick={() => generate.mutate(flow)} <CommandEmpty>
{dashboards.length
? "No dashboard by that name."
: "No dashboards yet."}
</CommandEmpty>
{flow && !hasResults ? (
<CommandGroup>
<CommandItem
value={`build results ${flow}`}
onSelect={() => generate.mutate(flow)}
disabled={generate.isPending} disabled={generate.isPending}
className="w-full rounded-md px-2 py-1.5 text-left text-sm hover:bg-accent disabled:opacity-50"
> >
{generate.isPending {generate.isPending
? "Building…" ? "Building…"
: `Build a results dashboard for ${flow}`} : `Build a results dashboard for ${flow}`}
</button> </CommandItem>
)} </CommandGroup>
) : null}
<CommandGroup>
{dashboards.map((one) => ( {dashboards.map((one) => (
<button <CommandItem
key={one.name} key={one.name}
type="button" value={`${one.name} ${one.title}`}
onClick={() => show(one.name)} onSelect={() => show(one.name)}
className="w-full rounded-md px-2 py-1.5 text-left text-sm hover:bg-accent"
> >
{one.title || one.name} {one.title || one.name}
{one.name === results && ( {one.name === results ? (
<span className="ml-2 text-muted-foreground text-xs"> <span className="ml-2 text-xs text-muted-foreground">
results results
</span> </span>
)} ) : null}
</button> </CommandItem>
))} ))}
{dashboards.length === 0 && !flow && ( </CommandGroup>
<p className="px-2 py-1.5 text-muted-foreground text-sm"> </CommandList>
No dashboards yet. </Command>
</p>
)}
</PopoverContent> </PopoverContent>
</Popover> </Popover>
) )