mirror of
https://github.com/fosrl/pangolin.git
synced 2026-07-11 16:32:10 +02:00
command palette tweaks
This commit is contained in:
+16
-13
@@ -1519,7 +1519,7 @@
|
|||||||
"navbar": "Navigation Menu",
|
"navbar": "Navigation Menu",
|
||||||
"navbarDescription": "Main navigation menu for the application",
|
"navbarDescription": "Main navigation menu for the application",
|
||||||
"navbarDocsLink": "Documentation",
|
"navbarDocsLink": "Documentation",
|
||||||
"commandPaletteTitle": "Command palette",
|
"commandPaletteTitle": "Command Palette",
|
||||||
"commandPaletteDescription": "Search for pages, organizations, resources, and actions",
|
"commandPaletteDescription": "Search for pages, organizations, resources, and actions",
|
||||||
"commandPaletteSearchPlaceholder": "Search pages, resources, actions...",
|
"commandPaletteSearchPlaceholder": "Search pages, resources, actions...",
|
||||||
"commandPaletteNoResults": "No results found.",
|
"commandPaletteNoResults": "No results found.",
|
||||||
@@ -1529,17 +1529,18 @@
|
|||||||
"commandPaletteSites": "Sites",
|
"commandPaletteSites": "Sites",
|
||||||
"commandPaletteResources": "Resources",
|
"commandPaletteResources": "Resources",
|
||||||
"commandPaletteUsers": "Users",
|
"commandPaletteUsers": "Users",
|
||||||
"commandPaletteClients": "Machine clients",
|
"commandPaletteClients": "Machine Clients",
|
||||||
"commandPaletteActions": "Actions",
|
"commandPaletteActions": "Actions",
|
||||||
"commandPaletteCreateSite": "Create site",
|
"commandPaletteCreateSite": "Create Site",
|
||||||
"commandPaletteCreateProxyResource": "Create public resource",
|
"commandPaletteCreateProxyResource": "Create Public Resource",
|
||||||
"commandPaletteCreateUser": "Create user",
|
"commandPaletteCreatePrivateResource": "Create Private Resource",
|
||||||
"commandPaletteCreateApiKey": "Create API key",
|
"commandPaletteCreateUser": "Create User",
|
||||||
"commandPaletteCreateMachineClient": "Create machine client",
|
"commandPaletteCreateApiKey": "Create API Key",
|
||||||
"commandPaletteCreateAlertRule": "Create alert rule",
|
"commandPaletteCreateMachineClient": "Create Machine Client",
|
||||||
"commandPaletteCreateIdentityProvider": "Create identity provider",
|
"commandPaletteCreateAlertRule": "Create Alert Rule",
|
||||||
"commandPaletteToggleTheme": "Toggle theme",
|
"commandPaletteCreateIdentityProvider": "Create Identity Provider",
|
||||||
"commandPaletteChooseOrganization": "Choose organization",
|
"commandPaletteToggleTheme": "Toggle Theme",
|
||||||
|
"commandPaletteChooseOrganization": "Choose Organization",
|
||||||
"commandPaletteShortcutMac": "⌘K",
|
"commandPaletteShortcutMac": "⌘K",
|
||||||
"commandPaletteShortcutWindows": "Ctrl K",
|
"commandPaletteShortcutWindows": "Ctrl K",
|
||||||
"otpErrorEnable": "Unable to enable 2FA",
|
"otpErrorEnable": "Unable to enable 2FA",
|
||||||
@@ -1620,7 +1621,7 @@
|
|||||||
"sidebarBillingAndLicenses": "Billing & Licenses",
|
"sidebarBillingAndLicenses": "Billing & Licenses",
|
||||||
"sidebarLogsAnalytics": "Analytics",
|
"sidebarLogsAnalytics": "Analytics",
|
||||||
"commandSites": "Sites",
|
"commandSites": "Sites",
|
||||||
"commandActionModeInfo": "Type \">\" to open action mode",
|
"commandActionModeInfo": "Type \">\" To Open Action Mode",
|
||||||
"commandResources": "Resources",
|
"commandResources": "Resources",
|
||||||
"commandProxyResources": "Public Resources",
|
"commandProxyResources": "Public Resources",
|
||||||
"commandClientResources": "Private Resources",
|
"commandClientResources": "Private Resources",
|
||||||
@@ -1655,6 +1656,8 @@
|
|||||||
"commandBilling": "Billing",
|
"commandBilling": "Billing",
|
||||||
"commandEnterpriseLicenses": "Licenses",
|
"commandEnterpriseLicenses": "Licenses",
|
||||||
"commandSettings": "Settings",
|
"commandSettings": "Settings",
|
||||||
|
"commandLauncher": "Launcher",
|
||||||
|
"commandResourceLauncher": "Resource Launcher",
|
||||||
"commandSearchResults": "Search Results",
|
"commandSearchResults": "Search Results",
|
||||||
"alertingTitle": "Alerting",
|
"alertingTitle": "Alerting",
|
||||||
"alertingDescription": "Define sources, triggers, and actions for notifications",
|
"alertingDescription": "Define sources, triggers, and actions for notifications",
|
||||||
@@ -3262,7 +3265,7 @@
|
|||||||
"editInternalResourceDialogAddUsers": "Add Users",
|
"editInternalResourceDialogAddUsers": "Add Users",
|
||||||
"editInternalResourceDialogAddClients": "Add Clients",
|
"editInternalResourceDialogAddClients": "Add Clients",
|
||||||
"editInternalResourceDialogDestinationLabel": "Destination",
|
"editInternalResourceDialogDestinationLabel": "Destination",
|
||||||
"editInternalResourceDialogDestinationDescription": "Choose where this resource runs and how clients reach it. Selecting multiple sites will create a high availability resource that can be accessed from any of the selected sites.",
|
"editInternalResourceDialogDestinationDescription": "Choose where this resource runs and how clients reach it",
|
||||||
"internalResourceFormMultiSiteRoutingHelp": "Selecting multiple sites enables resilient routing and failover for high availability.",
|
"internalResourceFormMultiSiteRoutingHelp": "Selecting multiple sites enables resilient routing and failover for high availability.",
|
||||||
"internalResourceFormMultiSiteRoutingHelpLearnMore": "Learn more",
|
"internalResourceFormMultiSiteRoutingHelpLearnMore": "Learn more",
|
||||||
"editInternalResourceDialogPortRestrictionsDescription": "Restrict access to specific TCP/UDP ports or allow/block all ports.",
|
"editInternalResourceDialogPortRestrictionsDescription": "Restrict access to specific TCP/UDP ports or allow/block all ports.",
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import { Layout } from "@app/components/Layout";
|
import { Layout } from "@app/components/Layout";
|
||||||
import ResourceLauncher from "@app/components/resource-launcher/ResourceLauncher";
|
import ResourceLauncher from "@app/components/resource-launcher/ResourceLauncher";
|
||||||
|
import { commandBarNavSections } from "@app/app/navigation";
|
||||||
import { internal } from "@app/lib/api";
|
import { internal } from "@app/lib/api";
|
||||||
import { authCookieHeader } from "@app/lib/api/cookies";
|
import { authCookieHeader } from "@app/lib/api/cookies";
|
||||||
import { fetchLauncherPageData } from "@app/lib/launcherServerData";
|
import { fetchLauncherPageData } from "@app/lib/launcherServerData";
|
||||||
import { verifySession } from "@app/lib/auth/verifySession";
|
import { verifySession } from "@app/lib/auth/verifySession";
|
||||||
|
import { pullEnv } from "@app/lib/pullEnv";
|
||||||
import UserProvider from "@app/providers/UserProvider";
|
import UserProvider from "@app/providers/UserProvider";
|
||||||
import { ListUserOrgsResponse } from "@server/routers/org";
|
import { ListUserOrgsResponse } from "@server/routers/org";
|
||||||
import { GetOrgOverviewResponse } from "@server/routers/org/getOrgOverview";
|
import { GetOrgOverviewResponse } from "@server/routers/org/getOrgOverview";
|
||||||
@@ -57,6 +59,8 @@ export default async function OrgPage(props: OrgPageProps) {
|
|||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
const isAdminOrOwner = Boolean(overview?.isAdmin || overview?.isOwner);
|
const isAdminOrOwner = Boolean(overview?.isAdmin || overview?.isOwner);
|
||||||
|
const env = pullEnv();
|
||||||
|
const primaryOrg = orgs.find((o) => o.orgId === orgId)?.isPrimaryOrg;
|
||||||
|
|
||||||
const searchParams = new URLSearchParams(await props.searchParams);
|
const searchParams = new URLSearchParams(await props.searchParams);
|
||||||
const launcherData = overview
|
const launcherData = overview
|
||||||
@@ -73,6 +77,9 @@ export default async function OrgPage(props: OrgPageProps) {
|
|||||||
orgId={orgId}
|
orgId={orgId}
|
||||||
orgs={orgs}
|
orgs={orgs}
|
||||||
navItems={[]}
|
navItems={[]}
|
||||||
|
commandNavItems={commandBarNavSections(env, {
|
||||||
|
isPrimaryOrg: primaryOrg
|
||||||
|
})}
|
||||||
showSidebar={false}
|
showSidebar={false}
|
||||||
launcherMode
|
launcherMode
|
||||||
showViewAsAdmin={isAdminOrOwner}
|
showViewAsAdmin={isAdminOrOwner}
|
||||||
|
|||||||
+12
-1
@@ -15,6 +15,7 @@ import {
|
|||||||
GlobeLock,
|
GlobeLock,
|
||||||
KeyRound,
|
KeyRound,
|
||||||
Laptop,
|
Laptop,
|
||||||
|
LayoutGrid,
|
||||||
Link as LinkIcon,
|
Link as LinkIcon,
|
||||||
Logs,
|
Logs,
|
||||||
MonitorUp,
|
MonitorUp,
|
||||||
@@ -49,7 +50,7 @@ export const orgLangingNavItems: SidebarNavItem[] = [
|
|||||||
{
|
{
|
||||||
title: "sidebarAccount",
|
title: "sidebarAccount",
|
||||||
href: "/{orgId}",
|
href: "/{orgId}",
|
||||||
icon: <User className="size-4 flex-none" />
|
icon: <LayoutGrid className="size-4 flex-none" />
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -360,6 +361,16 @@ export const commandBarNavSections = (
|
|||||||
env?: Env,
|
env?: Env,
|
||||||
options?: OrgNavSectionsOptions
|
options?: OrgNavSectionsOptions
|
||||||
): CommandBarNavSection[] => [
|
): CommandBarNavSection[] => [
|
||||||
|
{
|
||||||
|
heading: "commandLauncher",
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
title: "commandResourceLauncher",
|
||||||
|
href: "/{orgId}",
|
||||||
|
icon: <LayoutGrid className="size-4 flex-none" />
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
heading: "network",
|
heading: "network",
|
||||||
items: [
|
items: [
|
||||||
|
|||||||
@@ -105,8 +105,11 @@ export function LayoutHeader({
|
|||||||
|
|
||||||
{showTopBar && (
|
{showTopBar && (
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
<CommandPaletteTrigger />
|
|
||||||
<ThemeSwitcher />
|
<ThemeSwitcher />
|
||||||
|
<CommandPaletteTrigger
|
||||||
|
orgId={orgId}
|
||||||
|
orgs={orgs}
|
||||||
|
/>
|
||||||
<ProfileIcon />
|
<ProfileIcon />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import {
|
|||||||
import { useUserContext } from "@app/hooks/useUserContext";
|
import { useUserContext } from "@app/hooks/useUserContext";
|
||||||
import { cn } from "@app/lib/cn";
|
import { cn } from "@app/lib/cn";
|
||||||
import { ListUserOrgsResponse } from "@server/routers/org";
|
import { ListUserOrgsResponse } from "@server/routers/org";
|
||||||
import { Menu, Server, Settings, SquareMousePointer } from "lucide-react";
|
import { Menu, Server, Settings, LayoutGrid } from "lucide-react";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { usePathname } from "next/navigation";
|
import { usePathname } from "next/navigation";
|
||||||
@@ -151,7 +151,7 @@ export function LayoutMobileMenu({
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<span className="flex-shrink-0 w-5 h-5 flex items-center justify-center text-muted-foreground mr-3">
|
<span className="flex-shrink-0 w-5 h-5 flex items-center justify-center text-muted-foreground mr-3">
|
||||||
<SquareMousePointer className="h-4 w-4" />
|
<LayoutGrid className="h-4 w-4" />
|
||||||
</span>
|
</span>
|
||||||
<span className="flex-1">
|
<span className="flex-1">
|
||||||
{t(
|
{t(
|
||||||
@@ -207,7 +207,11 @@ export function LayoutMobileMenu({
|
|||||||
{showTopBar && (
|
{showTopBar && (
|
||||||
<div className="ml-auto flex items-center justify-end">
|
<div className="ml-auto flex items-center justify-end">
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
<CommandPaletteTrigger variant="mobile" />
|
<CommandPaletteTrigger
|
||||||
|
variant="mobile"
|
||||||
|
orgId={orgId}
|
||||||
|
orgs={orgs}
|
||||||
|
/>
|
||||||
<ThemeSwitcher />
|
<ThemeSwitcher />
|
||||||
<ProfileIcon />
|
<ProfileIcon />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ import { ListUserOrgsResponse } from "@server/routers/org";
|
|||||||
import {
|
import {
|
||||||
ArrowRight,
|
ArrowRight,
|
||||||
ExternalLink,
|
ExternalLink,
|
||||||
|
LayoutGrid,
|
||||||
PanelRightOpen,
|
PanelRightOpen,
|
||||||
Server,
|
Server
|
||||||
SquareMousePointer
|
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import dynamic from "next/dynamic";
|
import dynamic from "next/dynamic";
|
||||||
@@ -186,7 +186,7 @@ export function LayoutSidebar({
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<span className="flex-shrink-0 w-5 h-5 flex items-center justify-center text-muted-foreground">
|
<span className="flex-shrink-0 w-5 h-5 flex items-center justify-center text-muted-foreground">
|
||||||
<SquareMousePointer className="h-4 w-4" />
|
<LayoutGrid className="h-4 w-4" />
|
||||||
</span>
|
</span>
|
||||||
</Link>
|
</Link>
|
||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
@@ -195,7 +195,9 @@ export function LayoutSidebar({
|
|||||||
sideOffset={8}
|
sideOffset={8}
|
||||||
>
|
>
|
||||||
<p>
|
<p>
|
||||||
{t("resourceSidebarLauncherTitle")}
|
{t(
|
||||||
|
"resourceSidebarLauncherTitle"
|
||||||
|
)}
|
||||||
</p>
|
</p>
|
||||||
</TooltipContent>
|
</TooltipContent>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
@@ -208,7 +210,7 @@ export function LayoutSidebar({
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<span className="flex-shrink-0 mr-3 w-5 h-5 flex items-center justify-center text-muted-foreground">
|
<span className="flex-shrink-0 mr-3 w-5 h-5 flex items-center justify-center text-muted-foreground">
|
||||||
<SquareMousePointer className="h-4 w-4" />
|
<LayoutGrid className="h-4 w-4" />
|
||||||
</span>
|
</span>
|
||||||
<span className="flex-1">
|
<span className="flex-1">
|
||||||
{t("resourceSidebarLauncherTitle")}
|
{t("resourceSidebarLauncherTitle")}
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ import {
|
|||||||
CommandList,
|
CommandList,
|
||||||
CommandSeparator
|
CommandSeparator
|
||||||
} from "@app/components/ui/command";
|
} from "@app/components/ui/command";
|
||||||
|
import { Button } from "@app/components/ui/button";
|
||||||
import { cn } from "@app/lib/cn";
|
import { cn } from "@app/lib/cn";
|
||||||
|
import { useMediaQuery } from "@app/hooks/useMediaQuery";
|
||||||
import { ListUserOrgsResponse } from "@server/routers/org";
|
import { ListUserOrgsResponse } from "@server/routers/org";
|
||||||
import {
|
import {
|
||||||
ChevronRightIcon,
|
ChevronRightIcon,
|
||||||
@@ -22,7 +24,8 @@ import {
|
|||||||
LaptopIcon,
|
LaptopIcon,
|
||||||
PlugIcon,
|
PlugIcon,
|
||||||
ServerIcon,
|
ServerIcon,
|
||||||
UserIcon
|
UserIcon,
|
||||||
|
X
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
@@ -34,6 +37,7 @@ import React, {
|
|||||||
useMemo,
|
useMemo,
|
||||||
useState
|
useState
|
||||||
} from "react";
|
} from "react";
|
||||||
|
import { useCanUseCommandPalette } from "./useCanUseCommandPalette";
|
||||||
import { useCommandPaletteActions } from "./useCommandPaletteActions";
|
import { useCommandPaletteActions } from "./useCommandPaletteActions";
|
||||||
import { useCommandPaletteNavigation } from "./useCommandPaletteNavigation";
|
import { useCommandPaletteNavigation } from "./useCommandPaletteNavigation";
|
||||||
import { useCommandPaletteSearch } from "./useCommandPaletteSearch";
|
import { useCommandPaletteSearch } from "./useCommandPaletteSearch";
|
||||||
@@ -57,6 +61,7 @@ export function CommandPalette({ orgId, orgs, navItems }: CommandPaletteProps) {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { open, setOpen } = useCommandPalette();
|
const { open, setOpen } = useCommandPalette();
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
|
const isDesktop = useMediaQuery("(min-width: 768px)");
|
||||||
|
|
||||||
const isActionMode = search.startsWith(">");
|
const isActionMode = search.startsWith(">");
|
||||||
|
|
||||||
@@ -134,6 +139,20 @@ export function CommandPalette({ orgId, orgs, navItems }: CommandPaletteProps) {
|
|||||||
value={search}
|
value={search}
|
||||||
onValueChange={setSearch}
|
onValueChange={setSearch}
|
||||||
isLoading={!isActionMode && shouldSearch && isLoading}
|
isLoading={!isActionMode && shouldSearch && isLoading}
|
||||||
|
trailing={
|
||||||
|
!isDesktop ? (
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="size-8 shrink-0"
|
||||||
|
aria-label={t("close")}
|
||||||
|
onClick={() => handleOpenChange(false)}
|
||||||
|
>
|
||||||
|
<X className="size-4" />
|
||||||
|
</Button>
|
||||||
|
) : undefined
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<CommandList className="max-h-118 min-h-0 h-(--cmdk-list-height) scroll-pb-4 scroll-pt-2 transition-[height] duration-250 ease-in-out">
|
<CommandList className="max-h-118 min-h-0 h-(--cmdk-list-height) scroll-pb-4 scroll-pt-2 transition-[height] duration-250 ease-in-out">
|
||||||
<CommandEmpty>{t("commandPaletteNoResults")}</CommandEmpty>
|
<CommandEmpty>{t("commandPaletteNoResults")}</CommandEmpty>
|
||||||
@@ -427,13 +446,14 @@ function isEditableTarget(target: EventTarget | null) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function CommandPaletteProvider({
|
function CommandPaletteProviderInner({
|
||||||
children,
|
children,
|
||||||
orgId,
|
orgId,
|
||||||
orgs,
|
orgs,
|
||||||
navItems
|
navItems
|
||||||
}: CommandPaletteProviderProps) {
|
}: CommandPaletteProviderProps) {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
const canUseCommandPalette = useCanUseCommandPalette(orgId, orgs);
|
||||||
|
|
||||||
const toggle = useCallback(() => {
|
const toggle = useCallback(() => {
|
||||||
setOpen((current) => !current);
|
setOpen((current) => !current);
|
||||||
@@ -449,6 +469,10 @@ export function CommandPaletteProvider({
|
|||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!canUseCommandPalette) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
function onKeyDown(event: KeyboardEvent) {
|
function onKeyDown(event: KeyboardEvent) {
|
||||||
if (
|
if (
|
||||||
event.key.toLowerCase() !== "k" ||
|
event.key.toLowerCase() !== "k" ||
|
||||||
@@ -467,12 +491,18 @@ export function CommandPaletteProvider({
|
|||||||
|
|
||||||
document.addEventListener("keydown", onKeyDown);
|
document.addEventListener("keydown", onKeyDown);
|
||||||
return () => document.removeEventListener("keydown", onKeyDown);
|
return () => document.removeEventListener("keydown", onKeyDown);
|
||||||
}, [open, toggle]);
|
}, [canUseCommandPalette, open, toggle]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CommandPaletteContext value={contextValue}>
|
<CommandPaletteContext value={contextValue}>
|
||||||
{children}
|
{children}
|
||||||
<CommandPalette orgId={orgId} orgs={orgs} navItems={navItems} />
|
{canUseCommandPalette ? (
|
||||||
|
<CommandPalette orgId={orgId} orgs={orgs} navItems={navItems} />
|
||||||
|
) : null}
|
||||||
</CommandPaletteContext>
|
</CommandPaletteContext>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function CommandPaletteProvider(props: CommandPaletteProviderProps) {
|
||||||
|
return <CommandPaletteProviderInner {...props} />;
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,11 +6,15 @@ import { cn } from "@app/lib/cn";
|
|||||||
import { Search } from "lucide-react";
|
import { Search } from "lucide-react";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
|
import { ListUserOrgsResponse } from "@server/routers/org";
|
||||||
import { useCommandPalette } from "./CommandPalette";
|
import { useCommandPalette } from "./CommandPalette";
|
||||||
|
import { useCanUseCommandPalette } from "./useCanUseCommandPalette";
|
||||||
|
|
||||||
type CommandPaletteTriggerProps = {
|
type CommandPaletteTriggerProps = {
|
||||||
variant?: "header" | "mobile";
|
variant?: "header" | "mobile";
|
||||||
className?: string;
|
className?: string;
|
||||||
|
orgId?: string;
|
||||||
|
orgs?: ListUserOrgsResponse["orgs"];
|
||||||
};
|
};
|
||||||
|
|
||||||
function useIsMac() {
|
function useIsMac() {
|
||||||
@@ -25,11 +29,18 @@ function useIsMac() {
|
|||||||
|
|
||||||
export function CommandPaletteTrigger({
|
export function CommandPaletteTrigger({
|
||||||
variant = "header",
|
variant = "header",
|
||||||
className
|
className,
|
||||||
|
orgId,
|
||||||
|
orgs
|
||||||
}: CommandPaletteTriggerProps) {
|
}: CommandPaletteTriggerProps) {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
const { setOpen } = useCommandPalette();
|
const { setOpen } = useCommandPalette();
|
||||||
const isMac = useIsMac();
|
const isMac = useIsMac();
|
||||||
|
const canUseCommandPalette = useCanUseCommandPalette(orgId, orgs);
|
||||||
|
|
||||||
|
if (!canUseCommandPalette) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (variant === "mobile") {
|
if (variant === "mobile") {
|
||||||
return (
|
return (
|
||||||
@@ -49,13 +60,13 @@ export function CommandPaletteTrigger({
|
|||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className={cn(
|
className={cn(
|
||||||
"hidden h-9 w-56 justify-start gap-2 px-3 text-muted-foreground md:flex lg:w-64",
|
"relative hidden h-9 w-56 justify-start pl-8 pr-3 text-muted-foreground md:flex lg:w-64",
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
aria-label={t("commandPaletteTitle")}
|
aria-label={t("commandPaletteTitle")}
|
||||||
onClick={() => setOpen(true)}
|
onClick={() => setOpen(true)}
|
||||||
>
|
>
|
||||||
<Search className="size-4 shrink-0 opacity-50" />
|
<Search className="absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
||||||
<span className="flex-1 truncate text-left text-sm font-normal">
|
<span className="flex-1 truncate text-left text-sm font-normal">
|
||||||
{t("commandPaletteSearchPlaceholder")}
|
{t("commandPaletteSearchPlaceholder")}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useUserContext } from "@app/hooks/useUserContext";
|
||||||
|
import { ListUserOrgsResponse } from "@server/routers/org";
|
||||||
|
import { usePathname } from "next/navigation";
|
||||||
|
|
||||||
|
export function useCanUseCommandPalette(
|
||||||
|
orgId?: string,
|
||||||
|
orgs?: ListUserOrgsResponse["orgs"]
|
||||||
|
) {
|
||||||
|
const pathname = usePathname();
|
||||||
|
const { user } = useUserContext();
|
||||||
|
|
||||||
|
if (pathname?.startsWith("/admin")) {
|
||||||
|
return user.serverAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!orgId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentOrg = orgs?.find((org) => org.orgId === orgId);
|
||||||
|
return Boolean(currentOrg?.isAdmin || currentOrg?.isOwner);
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
BellRing,
|
BellRing,
|
||||||
Building2,
|
Building2,
|
||||||
Globe,
|
Globe,
|
||||||
|
GlobeLock,
|
||||||
KeyRound,
|
KeyRound,
|
||||||
MonitorUp,
|
MonitorUp,
|
||||||
Plus,
|
Plus,
|
||||||
@@ -86,6 +87,12 @@ export function useCommandPaletteActions(
|
|||||||
icon: <Globe className="size-4" />,
|
icon: <Globe className="size-4" />,
|
||||||
href: `/${orgId}/settings/resources/proxy/create`
|
href: `/${orgId}/settings/resources/proxy/create`
|
||||||
});
|
});
|
||||||
|
actions.push({
|
||||||
|
id: "create-private-resource",
|
||||||
|
label: t("commandPaletteCreatePrivateResource"),
|
||||||
|
icon: <GlobeLock className="size-4" />,
|
||||||
|
href: `/${orgId}/settings/resources/private/create`
|
||||||
|
});
|
||||||
actions.push({
|
actions.push({
|
||||||
id: "create-machine-client",
|
id: "create-machine-client",
|
||||||
label: t("commandPaletteCreateMachineClient"),
|
label: t("commandPaletteCreateMachineClient"),
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ export function useCommandPaletteSearch({
|
|||||||
return privateResourcesQuery.data.map((resource) => ({
|
return privateResourcesQuery.data.map((resource) => ({
|
||||||
id: `site-resource-${resource.siteResourceId}`,
|
id: `site-resource-${resource.siteResourceId}`,
|
||||||
name: resource.name,
|
name: resource.name,
|
||||||
href: `/${orgId}/settings/resources/private?query=${resource.name}`
|
href: `/${orgId}/settings/resources/private/${resource.niceId}`
|
||||||
}));
|
}));
|
||||||
}, [orgId, privateResourcesQuery.data]);
|
}, [orgId, privateResourcesQuery.data]);
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,21 @@ import {
|
|||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle
|
DialogTitle
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
|
import {
|
||||||
|
Sheet,
|
||||||
|
SheetContent,
|
||||||
|
SheetDescription,
|
||||||
|
SheetHeader,
|
||||||
|
SheetTitle
|
||||||
|
} from "@/components/ui/sheet";
|
||||||
|
import { useMediaQuery } from "@app/hooks/useMediaQuery";
|
||||||
import { cn } from "@app/lib/cn";
|
import { cn } from "@app/lib/cn";
|
||||||
|
|
||||||
|
const desktop = "(min-width: 768px)";
|
||||||
|
|
||||||
|
const commandSurfaceClassName =
|
||||||
|
"transition duration-150 mt-0 [&_[cmdk-group-heading]]:text-muted-foreground **:data-[slot=command-input-wrapper]:h-12 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5";
|
||||||
|
|
||||||
function Command({
|
function Command({
|
||||||
className,
|
className,
|
||||||
...props
|
...props
|
||||||
@@ -35,6 +48,7 @@ function CommandDialog({
|
|||||||
children,
|
children,
|
||||||
className,
|
className,
|
||||||
showCloseButton = true,
|
showCloseButton = true,
|
||||||
|
commandProps,
|
||||||
...props
|
...props
|
||||||
}: React.ComponentProps<typeof Dialog> & {
|
}: React.ComponentProps<typeof Dialog> & {
|
||||||
title?: string;
|
title?: string;
|
||||||
@@ -43,6 +57,35 @@ function CommandDialog({
|
|||||||
showCloseButton?: boolean;
|
showCloseButton?: boolean;
|
||||||
commandProps?: React.ComponentProps<typeof Command>;
|
commandProps?: React.ComponentProps<typeof Command>;
|
||||||
}) {
|
}) {
|
||||||
|
const isDesktop = useMediaQuery(desktop);
|
||||||
|
|
||||||
|
const command = (
|
||||||
|
<Command {...commandProps} className={commandSurfaceClassName}>
|
||||||
|
{children}
|
||||||
|
</Command>
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!isDesktop) {
|
||||||
|
return (
|
||||||
|
<Sheet open={props.open} onOpenChange={props.onOpenChange}>
|
||||||
|
<SheetContent
|
||||||
|
side="top"
|
||||||
|
className={cn(
|
||||||
|
"flex max-h-[85dvh] w-full flex-col gap-0 overflow-hidden rounded-none border-x-0 p-0 pt-[env(safe-area-inset-top,0px)]",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
onOpenAutoFocus={(event) => event.preventDefault()}
|
||||||
|
>
|
||||||
|
<SheetHeader className="sr-only">
|
||||||
|
<SheetTitle>{title}</SheetTitle>
|
||||||
|
<SheetDescription>{description}</SheetDescription>
|
||||||
|
</SheetHeader>
|
||||||
|
{command}
|
||||||
|
</SheetContent>
|
||||||
|
</Sheet>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog {...props}>
|
<Dialog {...props}>
|
||||||
<DialogHeader className="sr-only">
|
<DialogHeader className="sr-only">
|
||||||
@@ -51,16 +94,11 @@ function CommandDialog({
|
|||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<DialogContent
|
<DialogContent
|
||||||
className={cn(
|
className={cn(
|
||||||
"overflow-hidden p-0 place-items-start",
|
"overflow-hidden p-0 place-items-start md:top-[clamp(1.5rem,12vh,200px)] md:max-h-[calc(100dvh-clamp(1.5rem,12vh,200px)-1.5rem)] md:translate-y-0",
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<Command
|
{command}
|
||||||
{...props.commandProps}
|
|
||||||
className="transition duration-150 mt-0 [&_[cmdk-group-heading]]:text-muted-foreground **:data-[slot=command-input-wrapper]:h-12 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5"
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</Command>
|
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
@@ -69,9 +107,11 @@ function CommandDialog({
|
|||||||
function CommandInput({
|
function CommandInput({
|
||||||
className,
|
className,
|
||||||
isLoading,
|
isLoading,
|
||||||
|
trailing,
|
||||||
...props
|
...props
|
||||||
}: React.ComponentProps<typeof CommandPrimitive.Input> & {
|
}: React.ComponentProps<typeof CommandPrimitive.Input> & {
|
||||||
isLoading?: boolean;
|
isLoading?: boolean;
|
||||||
|
trailing?: React.ReactNode;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -86,11 +126,12 @@ function CommandInput({
|
|||||||
<CommandPrimitive.Input
|
<CommandPrimitive.Input
|
||||||
data-slot="command-input"
|
data-slot="command-input"
|
||||||
className={cn(
|
className={cn(
|
||||||
"placeholder:text-muted-foreground flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50",
|
"placeholder:text-muted-foreground flex h-10 min-w-0 flex-1 rounded-md bg-transparent py-3 text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50",
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
|
{trailing ? <div className="shrink-0">{trailing}</div> : null}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user