Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
improvement(ui): use real links for notifications, navbar and product switcher (#8934)
Andrew Huang110e749d74a8
diff --git a/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsx b/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsxindex 18a459ad81..4e03c854c7 100644--- a/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsx+++ b/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsx@@ -415,15 +415,10 @@ export const Navbar = () => {><NavbarSwitcher open={isOrgSelectOpen} onOpenChange={setIsOrgSelectOpen}><div className="group flex min-w-0 cursor-pointer items-center gap-2 overflow-hidden text-sm text-foreground transition-all duration-100">- <button+ <Link+ to="/organizations/$orgId/projects"+ params={{ orgId: currentOrg.id }}className="flex cursor-pointer items-center gap-x-2 truncate whitespace-nowrap"- type="button"- onClick={() => {- navigate({- to: "/organizations/$orgId/projects",- params: { orgId: currentOrg.id }- });- }}>{isSubOrganization ? (<SubOrgIcon@@ -452,7 +447,7 @@ export const Navbar = () => {{isSubOrganization ? "Sub" : "Org"}</Badge>)}- </button>+ </Link>{subscription.cardDeclined && !isProjectScope && !isSubOrganization && (<Tooltip><TooltipTrigger asChild>@@ -517,20 +512,20 @@ export const Navbar = () => {<Tooltip><TooltipTrigger asChild><IconButton+ asChildvariant="ghost-muted"size="xs"- aria-label="Sub-Organization Settings"className="-mr-1 size-5"- onClick={() => {- setIsOrgSelectOpen(false);- navigate({- to: "/organizations/$orgId/settings",- params: { orgId: rootOrg.id },- search: { selectedTab: "tab-sub-organizations" }- });- }}>- <Settings className="size-3.5!" />+ <Link+ to="/organizations/$orgId/settings"+ params={{ orgId: rootOrg.id }}+ search={{ selectedTab: "tab-sub-organizations" }}+ aria-label="Sub-Organization Settings"+ onClick={() => setIsOrgSelectOpen(false)}+ >+ <Settings className="size-3.5!" />+ </Link></IconButton></TooltipTrigger><TooltipContent>Sub-Organization Settings</TooltipContent>diff --git a/frontend/src/layouts/OrganizationLayout/components/NavBar/Notification.tsx b/frontend/src/layouts/OrganizationLayout/components/NavBar/Notification.tsxindex 6ef415b491..796b62304c 100644--- a/frontend/src/layouts/OrganizationLayout/components/NavBar/Notification.tsx+++ b/frontend/src/layouts/OrganizationLayout/components/NavBar/Notification.tsx@@ -1,18 +1,45 @@+import { MouseEvent } from "react";import Markdown from "react-markdown";import { formatDistance } from "date-fns";import { Trash2 } from "lucide-react";import { twMerge } from "tailwind-merge";-import { IconButton, Tooltip, TooltipContent, TooltipTrigger } from "@app/components/v3";+import {+ DropdownMenuItem,+ IconButton,+ rowLinkClassName,+ Tooltip,+ TooltipContent,+ TooltipTrigger+} from "@app/components/v3";import { isCriticalNotification, TUserNotification } from "@app/hooks/api/notifications/types";type Props = {notification: TUserNotification;+ href?: string;+ onOpen: (event: MouseEvent<HTMLElement>) => void;+ onAuxOpen: () => void;onDelete: (notificationId: string) => void;};-export const Notification = ({ notification, onDelete }: Props) => {+export const Notification = ({ notification, href, onOpen, onAuxOpen, onDelete }: Props) => {const isCritical = isCriticalNotification(notification.type);+ const titleClassName = twMerge(+ rowLinkClassName,+ "static min-w-0 rounded-none p-0 text-left text-sm leading-5 font-medium text-foreground focus:bg-transparent"+ );+ const titleWithTooltip = (+ <Tooltip delayDuration={300}>+ <TooltipTrigger asChild>+ <span className="relative z-10 block truncate">+ <Markdown components={{ p: "span" }}>{notification.title}</Markdown>+ </span>+ </TooltipTrigger>+ <TooltipContent className="z-[var(--z-index-tooltip)]">+ <Markdown>{notification.title}</Markdown>+ </TooltipContent>+ </Tooltip>+ );return (<div@@ -35,17 +62,28 @@ export const Notification = ({ notification, onDelete }: Props) => {/></div>)}- <Tooltip delayDuration={300}>- <TooltipTrigger asChild>- <span className="overflow-hidden text-sm leading-5 font-medium text-ellipsis whitespace-nowrap text-foreground">- <Markdown components={{ p: "span" }}>{notification.title}</Markdown>- </span>- </TooltipTrigger>- <TooltipContent className="z-[var(--z-index-tooltip)]">- <Markdown>{notification.title}</Markdown>- </TooltipContent>- </Tooltip>- <div className="relative ml-auto shrink-0 pl-7">+ <DropdownMenuItem+ asChild+ className={titleClassName}+ onSelect={(event) => event.preventDefault()}+ >+ {href ? (+ <a+ href={href}+ onClick={onOpen}+ onAuxClick={(event) => {+ if (event.button === 1) onAuxOpen();+ }}+ >+ {titleWithTooltip}+ </a>+ ) : (+ <button type="button" onClick={onOpen}>+ {titleWithTooltip}+ </button>+ )}+ </DropdownMenuItem>+ <div className="pointer-events-none relative ml-auto shrink-0 pl-7"><span className="inline-block text-xs leading-5 whitespace-nowrap text-muted transition-transform group-focus-within:-translate-x-7 group-hover:-translate-x-7 [@media(hover:none)]:-translate-x-7">{formatDistance(notification.createdAt, new Date())} ago</span>@@ -53,7 +91,7 @@ export const Notification = ({ notification, onDelete }: Props) => {aria-label="Delete notification"variant="ghost-muted"size="2xs"- className="absolute -top-0.5 right-0 opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100 [@media(hover:none)]:opacity-100"+ className="pointer-events-auto absolute -top-0.5 right-0 z-10 opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100 [@media(hover:none)]:opacity-100"onClick={(e) => {e.stopPropagation();onDelete(notification.id);@@ -65,7 +103,7 @@ export const Notification = ({ notification, onDelete }: Props) => {</div></div>{notification.body && (- <div className="w-full overflow-hidden text-xs break-words text-accent">+ <div className="w-full overflow-hidden text-xs break-words text-accent [&_a]:relative [&_a]:z-10"><Markdown>{notification.body}</Markdown></div>)}diff --git a/frontend/src/layouts/OrganizationLayout/components/NavBar/NotificationDropdown.tsx b/frontend/src/layouts/OrganizationLayout/components/NavBar/NotificationDropdown.tsxindex 6863fde7e5..3325265380 100644--- a/frontend/src/layouts/OrganizationLayout/components/NavBar/NotificationDropdown.tsx+++ b/frontend/src/layouts/OrganizationLayout/components/NavBar/NotificationDropdown.tsx@@ -1,4 +1,4 @@-import { useMemo, useRef, useState } from "react";+import { MouseEvent, useMemo, useRef, useState } from "react";import { useRouter } from "@tanstack/react-router";import { Bell, BellIcon } from "lucide-react";@@ -47,18 +47,40 @@ export const NotificationDropdown = () => {// Links are stored server-side and may be site-relative or absolute, and may carry a query string. Passing them// straight to `to` would resolve them against the current path and swallow the search params, so normalize to a// path + search + hash and let the router parse it via `href`.- const openNotificationLink = (link: string) => {- const { pathname, search, hash } = new URL(link, window.location.origin);- router.navigate({ href: `${pathname}${search}${hash}` });+ const getNotificationHref = (link: string) => {+ try {+ const { pathname, search, hash } = new URL(link, window.location.origin);+ return `${pathname}${search}${hash}`;+ } catch {+ return undefined;+ }};- const handleNotificationOpen = (notification: TUserNotification) => {+ const markNotificationRead = (notification: TUserNotification) => {if (!notification.isRead) {updateNotification({ notificationId: notification.id, isRead: true });}- if (notification.link) {- openNotificationLink(notification.link);+ };++ const handleNotificationOpen = (+ event: MouseEvent<HTMLElement>,+ notification: TUserNotification,+ href?: string+ ) => {+ markNotificationRead(notification);+ if (+ !href ||+ event.defaultPrevented ||+ event.button !== 0 ||+ event.metaKey ||+ event.ctrlKey ||+ event.shiftKey ||+ event.altKey+ ) {+ return;}+ event.preventDefault();+ router.navigate({ href });};const unreadCount = useMemo(@@ -143,20 +165,21 @@ export const NotificationDropdown = () => {)}{!isLoading && notifications && notifications.length > 0 && (<div className="flex w-full flex-col">- {visibleNotifications?.map((notification) => (- <div- role="button"- tabIndex={0}- key={notification.id}- onClick={() => handleNotificationOpen(notification)}- onKeyDown={(e) => {- if (e.key !== "Enter") return;- handleNotificationOpen(notification);- }}- >- <Notification notification={notification} onDelete={deleteNotification} />- </div>- ))}+ {visibleNotifications?.map((notification) => {+ const href = notification.link+ ? getNotificationHref(notification.link)+ : undefined;+ return (+ <Notification+ key={notification.id}+ notification={notification}+ href={href}+ onOpen={(event) => handleNotificationOpen(event, notification, href)}+ onAuxOpen={() => markNotificationRead(notification)}+ onDelete={deleteNotification}+ />+ );+ })}{hasMoreNotifications && (<DropdownMenuItemonSelect={(e) => {diff --git a/frontend/src/layouts/OrganizationLayout/components/OrgSidebar/ProjectNav.tsx b/frontend/src/layouts/OrganizationLayout/components/OrgSidebar/ProjectNav.tsxindex fb9d5c1bde..077ac7579b 100644--- a/frontend/src/layouts/OrganizationLayout/components/OrgSidebar/ProjectNav.tsx+++ b/frontend/src/layouts/OrganizationLayout/components/OrgSidebar/ProjectNav.tsx@@ -169,31 +169,28 @@ export const ProjectNav = () => {><SidebarGroup className="flex-1"><SidebarGroupLabel asChild>- <button- className="cursor-pointer hover:bg-foreground/[0.025]"- type="button"- onClick={() => {- if (intermediateAvailable) {- navigate({- to: "/organizations/$orgId/projects/$type",- params: {- orgId: currentOrg.id,- type: projectTypeToUrlSlug(currentProject.type)- }- });- return;- }- navigate({- // eslint-disable-next-line @typescript-eslint/no-explicit-any- to: "/organizations/$orgId/projects" as any,- // eslint-disable-next-line @typescript-eslint/no-explicit-any- params: { orgId: currentOrg.id } as any- });- }}- >- <ChevronLeft />- <span>{projectLabel}</span>- </button>+ {intermediateAvailable ? (+ <Link+ className="cursor-pointer hover:bg-foreground/[0.025]"+ to="/organizations/$orgId/projects/$type"+ params={{+ orgId: currentOrg.id,+ type: projectTypeToUrlSlug(currentProject.type)+ }}+ >+ <ChevronLeft />+ <span>{projectLabel}</span>+ </Link>+ ) : (+ <Link+ className="cursor-pointer hover:bg-foreground/[0.025]"+ to="/organizations/$orgId/projects"+ params={{ orgId: currentOrg.id }}+ >+ <ChevronLeft />+ <span>{projectLabel}</span>+ </Link>+ )}</SidebarGroupLabel><NavComponent onSubmenuOpen={handleSubmenuOpen} />{showProductSettings && (diff --git a/frontend/src/layouts/ProjectLayout/components/TypeSelect/TypeSelect.tsx b/frontend/src/layouts/ProjectLayout/components/TypeSelect/TypeSelect.tsxindex ad733b3f91..c6a90a8aa9 100644--- a/frontend/src/layouts/ProjectLayout/components/TypeSelect/TypeSelect.tsx+++ b/frontend/src/layouts/ProjectLayout/components/TypeSelect/TypeSelect.tsx@@ -1,16 +1,23 @@import { useMemo, useState } from "react";-import { useLocation, useNavigate, useParams } from "@tanstack/react-router";+import { Link, useLocation, useNavigate, useParams } from "@tanstack/react-router";import { Check } from "lucide-react";import { PreviewBadge } from "@app/components/agent-vault/PreviewBadge";import { CertManagerNotConfiguredModal } from "@app/components/projects/CertManagerNotConfiguredModal";-import { Command, CommandGroup, CommandItem, CommandList } from "@app/components/v3";+import {+ Command,+ CommandGroup,+ CommandItem,+ CommandItemLink,+ CommandList+} from "@app/components/v3";import { useOrganization } from "@app/context";import {resolveCertManagerProjectId,setCertManagerActiveProjectCookie} from "@app/helpers/certManagerActiveProject";import {+ getInstancePinningLink,getOrgScopedProductFromPath,getProjectHomePage,getProjectLucideIcon,@@ -46,13 +53,16 @@ const ORG_PRODUCT_PAGE_PATH_RE = /^\/organizations\/[^/]+\/projects\/([^/]+)\//;const TypeSelectInner = ({currentType,- currentProjectName+ currentProjectName,+ currentProjectId}: {currentType: ProjectType;currentProjectName?: string;+ currentProjectId?: string;}) => {const [open, setOpen] = useState(false);const [isCertManagerSetupOpen, setIsCertManagerSetupOpen] = useState(false);+ const [selectedValue, setSelectedValue] = useState("");const navigate = useNavigate();const { currentOrg } = useOrganization();const { data: projects = [] } = useGetUserProjects();@@ -77,6 +87,26 @@ const TypeSelectInner = ({[currentOrg.id, projects, certManagerInstance?.activeProjectId]);+ const getProductLink = (type: ProjectType) => {+ const orgId = currentOrg?.id || "";+ if (type === currentType && currentProjectId) {+ const pinnedPath = type === ProjectType.CertificateManager ? "overview" : "data-sources";+ const pinnedLink = getInstancePinningLink(orgId, { id: currentProjectId, type }, pinnedPath);+ if (pinnedLink) return pinnedLink;+ }+ if (type === ProjectType.CertificateManager) {+ if (!certManagerTargetProjectId) return null;+ return getInstancePinningLink(orgId, { id: certManagerTargetProjectId, type }, "overview");+ }+ if (isOrgScopedProduct(type)) {+ return { to: getProjectHomePage(type, []), params: { orgId } } as const;+ }+ return {+ to: "/organizations/$orgId/projects/$type",+ params: { orgId, type: projectTypeToUrlSlug(type) }+ } as const;+ };+const navigateToCertManager = () => {if (isCertManagerInstancePending) return;if (certManagerTargetProjectId) {@@ -118,43 +148,46 @@ const TypeSelectInner = ({const typeTitle = getProjectTitle(currentType);const pillLabel = currentProjectName ?? typeTitle;const ProductIcon = getProjectLucideIcon(currentType);+ const pillLink = getProductLink(currentType);+ const pillClassName =+ "group grid min-w-min cursor-pointer grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-x-2 overflow-hidden text-sm text-foreground-inverse";+ const pillContent = (+ <>+ <ProductIcon className="h-[14px] w-[14px] shrink-0" />+ <span className="truncate">{pillLabel}</span>+ <ProductPlanBadge type={currentType} />+ </>+ );return (<NavbarBlock className="min-w-16">- <NavbarSwitcher open={open} onOpenChange={setOpen}>- <button- type="button"- onClick={() => {- if (currentType === ProjectType.CertificateManager) {- navigateToCertManager();- } else if (isOrgScopedProduct(currentType)) {- navigate({- to: getProjectHomePage(currentType, []),- params: { orgId: currentOrg?.id || "" }- });- } else {- navigate({- to: "/organizations/$orgId/projects/$type",- params: { orgId: currentOrg?.id || "", type: projectTypeToUrlSlug(currentType) }- });- }- }}- className="group grid min-w-min cursor-pointer grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-x-2 overflow-hidden text-sm text-foreground-inverse"- >- <ProductIcon className="h-[14px] w-[14px] shrink-0" />- <span className="truncate">{pillLabel}</span>- <ProductPlanBadge type={currentType} />- </button>+ <NavbarSwitcher+ open={open}+ onOpenChange={(nextOpen) => {+ if (nextOpen) setSelectedValue("");+ setOpen(nextOpen);+ }}+ >+ {pillLink ? (+ <Link {...pillLink} className={pillClassName}>+ {pillContent}+ </Link>+ ) : (+ <button type="button" onClick={navigateToCertManager} className={pillClassName}>+ {pillContent}+ </button>+ )}<PreviewBadge type={currentType} /><NavbarSwitcherTrigger aria-label="switch-product-type" /><NavbarSwitcherContent className="w-80">- <Command>+ <Command value={selectedValue} onValueChange={setSelectedValue}><CommandList><CommandGroup heading="Products">{PRODUCT_TYPES.map((type) => {const isCertManager = type === ProjectType.CertificateManager;const count = projectCountsByType[type] || 0;const ItemIcon = getProjectLucideIcon(type);+ const itemLink = getProductLink(type);return (<CommandItem@@ -166,7 +199,16 @@ const TypeSelectInner = ({<Check className={currentType === type ? "opacity-100" : "opacity-0"} /><ItemIcon className="h-4 w-4 shrink-0" /><div className="flex min-w-0 flex-1 items-center justify-between">- <span className="truncate text-sm">{getProjectTitle(type)}</span>+ {itemLink ? (+ <CommandItemLink+ {...itemLink}+ onFocus={() => setSelectedValue(getProjectTitle(type))}+ >+ {getProjectTitle(type)}+ </CommandItemLink>+ ) : (+ <span className="truncate text-sm">{getProjectTitle(type)}</span>+ )}{!isCertManager && count > 1 && (<span className="text-xs text-muted">{count}</span>)}@@ -217,6 +259,7 @@ export const TypeSelect = () => {<TypeSelectInnercurrentType={ProjectType.CertificateManager}currentProjectName={isLegacyCertManagerProject ? project?.name : undefined}+ currentProjectId={isLegacyCertManagerProject ? project?.id : undefined}/>);}@@ -231,6 +274,7 @@ export const TypeSelect = () => {<TypeSelectInnercurrentType={ProjectType.SecretScanning}currentProjectName={isLegacySecretScanningProject ? project?.name : undefined}+ currentProjectId={isLegacySecretScanningProject ? project?.id : undefined}/>);}