From c0a9db92ef13556a6fe158dbae0cfb86e9ac341a Mon Sep 17 00:00:00 2001 From: Fred KISSIE Date: Tue, 16 Jun 2026 19:28:22 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20update=20command=20bar=20UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command-palette/CommandPalette.tsx | 110 +++++++++++------- src/components/ui/command.tsx | 13 ++- 2 files changed, 77 insertions(+), 46 deletions(-) diff --git a/src/components/command-palette/CommandPalette.tsx b/src/components/command-palette/CommandPalette.tsx index f0c022430..726d1c999 100644 --- a/src/components/command-palette/CommandPalette.tsx +++ b/src/components/command-palette/CommandPalette.tsx @@ -1,5 +1,9 @@ "use client"; +import type { + CommandBarNavSection, + SidebarNavSection +} from "@app/app/navigation"; import { CommandDialog, CommandEmpty, @@ -9,13 +13,9 @@ import { CommandList, CommandSeparator } from "@app/components/ui/command"; -import type { - CommandBarNavSection, - SidebarNavSection -} from "@app/app/navigation"; -import { Badge } from "@app/components/ui/badge"; +import { cn } from "@app/lib/cn"; import { ListUserOrgsResponse } from "@server/routers/org"; -import { Loader2 } from "lucide-react"; +import { useTranslations } from "next-intl"; import { useRouter } from "next/navigation"; import React, { createContext, @@ -25,13 +25,10 @@ import React, { useMemo, useState } from "react"; -import { useTranslations } from "next-intl"; import { useCommandPaletteActions } from "./useCommandPaletteActions"; import { useCommandPaletteNavigation } from "./useCommandPaletteNavigation"; -import { useCommandPaletteOrganizations } from "./useCommandPaletteOrganizations"; import { useCommandPaletteSearch } from "./useCommandPaletteSearch"; -import { useUserContext } from "@app/hooks/useUserContext"; -import { cn } from "@app/lib/cn"; +import { search } from "jmespath"; type CommandPaletteProps = { orgId?: string; @@ -52,14 +49,16 @@ export function CommandPalette({ orgId, orgs, navItems }: CommandPaletteProps) { const { open, setOpen } = useCommandPalette(); const [search, setSearch] = useState(""); + const isActionMode = search.startsWith(">"); + const navigationGroups = useCommandPaletteNavigation(navItems); // const organizations = useCommandPaletteOrganizations(orgs); const actions = useCommandPaletteActions(orgId, orgs); const { shouldSearch, sites, resources, users, machineClients, isLoading } = useCommandPaletteSearch({ orgId, - query: search, - enabled: open + query: search.substring(1), + enabled: open && isActionMode }); const handleOpenChange = useCallback( @@ -96,9 +95,24 @@ export function CommandPalette({ orgId, orgs, navItems }: CommandPaletteProps) { className="max-w-2xl **:data-[slot=command-input-wrapper]:h-15" commandProps={{ loop: true, - filter(value, search) { - if (value.toLowerCase().includes(search.toLowerCase())) + filter(value, query) { + let search = query; + if (query.startsWith(">")) { + search = query.substring(1); + + console.log({ + search, + value + }); + } + + if ( + value + .toLowerCase() + .includes(search.trim().toLowerCase()) + ) { return 1; + } return 0; } }} @@ -107,8 +121,9 @@ export function CommandPalette({ orgId, orgs, navItems }: CommandPaletteProps) { placeholder={t("commandPaletteSearchPlaceholder")} value={search} onValueChange={setSearch} + // isLoading /> - + {t("commandPaletteNoResults")} - {navigationGroups.map((group, groupIndex) => ( - - {groupIndex > 0 && } - 0 && - "[&_[cmdk-group-heading]]:pt-3" - )} - > - {group.items.map((item, itemIndex) => ( - - runCommand(() => router.push(item.href)) - } - className="h-9" + {!isActionMode && + navigationGroups.map((group, groupIndex) => { + console.log({ + groupIndex, + groupHeading: group.heading + }); + return ( + + {groupIndex > 0 && } + 0 && + "[&_[cmdk-group-heading]]:pt-3" + )} > - {item.icon} - {item.title} - - ))} - - - ))} + {group.items.map((item) => ( + + runCommand(() => + router.push(item.href) + ) + } + className="h-9" + > + {item.icon} + {item.title} + + ))} + + + ); + })} {/* {organizations.length > 1 && ( <> @@ -282,7 +306,7 @@ export function CommandPalette({ orgId, orgs, navItems }: CommandPaletteProps) { )} */} - {/* {actions.length > 0 && ( + {isActionMode && actions.length > 0 && ( <> - )} */} + )} ); diff --git a/src/components/ui/command.tsx b/src/components/ui/command.tsx index f4b9e1bfe..efd1c35f5 100644 --- a/src/components/ui/command.tsx +++ b/src/components/ui/command.tsx @@ -2,7 +2,7 @@ import * as React from "react"; import { Command as CommandPrimitive } from "cmdk"; -import { SearchIcon } from "lucide-react"; +import { LoaderIcon, SearchIcon } from "lucide-react"; import { Dialog, @@ -68,14 +68,21 @@ function CommandDialog({ function CommandInput({ className, + isLoading, ...props -}: React.ComponentProps) { +}: React.ComponentProps & { + isLoading?: boolean; +}) { return (
- + {isLoading ? ( + + ) : ( + + )}