Skip to content

Commit 9019ea5

Browse files
NicolappsConvex, Inc.
authored andcommitted
Show the Convex logo in embedded dashboard (#38350)
GitOrigin-RevId: f5dd8bfc1fc6c3aff0a7776daf20e69eb8460b58
1 parent f7ebf81 commit 9019ea5

File tree

2 files changed

+108
-35
lines changed

2 files changed

+108
-35
lines changed

npm-packages/dashboard-common/src/elements/Sidebar.tsx

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,14 @@ export function Sidebar({
2929
items,
3030
collapsed,
3131
setCollapsed,
32+
header,
3233
}: {
3334
collapsed: boolean;
3435
setCollapsed: (collapsed: boolean) => void;
3536
items: SidebarGroup[];
37+
header?: ReactNode;
3638
}) {
37-
const router = useRouter();
38-
39-
const path = router.pathname
40-
.replace("/t/[team]/[project]/[deploymentName]", "")
41-
.split("/")
42-
.filter((i) => !!i);
43-
const currentPage = path[0] ?? null;
44-
39+
const currentPage = useCurrentPage();
4540
const { width } = useWindowSize();
4641

4742
return (
@@ -57,33 +52,38 @@ export function Sidebar({
5752
{ [`min-w-[130px]`]: !collapsed },
5853
)}
5954
>
60-
<div className="flex gap-1 sm:flex-col sm:divide-x-0 sm:divide-y">
61-
{items.map((group) => (
62-
<div key={group.key} className="flex gap-1 sm:flex-col sm:py-2">
63-
{group.items.map((item) => (
64-
<div className="relative h-[1.875rem]" key={item.key}>
65-
<SidebarLink
66-
{...omit(item, "key")}
67-
collapsed={collapsed}
68-
isActive={currentPage === item.key}
69-
disabled={item.disabled}
70-
small
71-
tip={
72-
item.tooltip
73-
? item.tooltip
74-
: collapsed
75-
? item.label
76-
: undefined
77-
}
78-
tipSide={width > 640 ? "right" : "bottom"}
79-
>
80-
{item.label}
81-
</SidebarLink>
82-
</div>
83-
))}
84-
</div>
85-
))}
55+
<div className="flex gap-1 sm:flex-col">
56+
{header}
57+
58+
<div className="flex gap-1 sm:flex-col sm:divide-x-0 sm:divide-y">
59+
{items.map((group) => (
60+
<div key={group.key} className="flex gap-1 sm:flex-col sm:py-2">
61+
{group.items.map((item) => (
62+
<div className="relative h-[1.875rem]" key={item.key}>
63+
<SidebarLink
64+
{...omit(item, "key")}
65+
collapsed={collapsed}
66+
isActive={currentPage === item.key}
67+
disabled={item.disabled}
68+
small
69+
tip={
70+
item.tooltip
71+
? item.tooltip
72+
: collapsed
73+
? item.label
74+
: undefined
75+
}
76+
tipSide={width > 640 ? "right" : "bottom"}
77+
>
78+
{item.label}
79+
</SidebarLink>
80+
</div>
81+
))}
82+
</div>
83+
))}
84+
</div>
8685
</div>
86+
8787
<Button
8888
variant="unstyled"
8989
onClick={() => setCollapsed(!collapsed)}
@@ -215,3 +215,13 @@ export function sidebarLinkClassNames(props: {
215215
: null,
216216
);
217217
}
218+
219+
export function useCurrentPage() {
220+
const router = useRouter();
221+
222+
const path = router.pathname
223+
.replace("/t/[team]/[project]/[deploymentName]", "")
224+
.split("/")
225+
.filter((i) => !!i);
226+
return path[0] ?? null;
227+
}

npm-packages/dashboard-common/src/layouts/DeploymentDashboardLayout.tsx

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ import { DeploymentInfoContext } from "@common/lib/deploymentContext";
1616
import { useGlobalLocalStorage } from "@common/lib/useGlobalLocalStorage";
1717
import { useCollapseSidebarState } from "@common/lib/useCollapseSidebarState";
1818
import { PulseIcon } from "@common/elements/icons";
19-
import { Sidebar } from "@common/elements/Sidebar";
19+
import { Sidebar, useCurrentPage } from "@common/elements/Sidebar";
2020
import { FunctionRunnerWrapper } from "@common/features/functionRunner/components/FunctionRunnerWrapper";
2121
import { FunctionsProvider } from "@common/lib/functions/FunctionsProvider";
2222
import { useIsGlobalRunnerShown } from "@common/features/functionRunner/lib/functionRunner";
2323
import { useIsCloudDeploymentInSelfHostedDashboard } from "@common/lib/useIsCloudDeploymentInSelfHostedDashboard";
24+
import { Tooltip } from "@ui/Tooltip";
25+
import Image from "next/image";
2426

2527
type LayoutProps = {
2628
children: JSX.Element;
@@ -121,6 +123,11 @@ export function DeploymentDashboardLayout({
121123
collapsed={!!collapsed}
122124
setCollapsed={setCollapsed}
123125
items={sidebarItems}
126+
header={
127+
process.env.NEXT_PUBLIC_HIDE_HEADER ? (
128+
<EmbeddedConvexLogo collapsed={!!collapsed} />
129+
) : undefined
130+
}
124131
/>
125132
<div
126133
className={classNames(
@@ -181,3 +188,59 @@ function PauseBanner() {
181188
</div>
182189
);
183190
}
191+
192+
function EmbeddedConvexLogo({ collapsed }: { collapsed: boolean }) {
193+
const currentPage = useCurrentPage();
194+
const { deploymentName } = useIsCloudDeploymentInSelfHostedDashboard();
195+
196+
const href = deploymentName
197+
? `https://dashboard.convex.dev/d/${deploymentName}/${currentPage ?? ""}`
198+
: "https://dashboard.convex.dev";
199+
200+
return (
201+
<>
202+
{/* Vertical layout on small screens */}
203+
<div className="mr-2 sm:hidden">
204+
<Tooltip tip="Convex" side="bottom" wrapsButton>
205+
<a
206+
className="flex h-full items-center"
207+
href={href}
208+
target="_blank"
209+
rel="noreferrer"
210+
>
211+
<Image
212+
src="/convex-logo-only.svg"
213+
width="24"
214+
height="24"
215+
alt="Convex logo"
216+
/>
217+
</a>
218+
</Tooltip>
219+
</div>
220+
221+
{/* Horizontal layout on larger screens, with some text when not collapsed */}
222+
<div className="hidden sm:block">
223+
<Tooltip tip={collapsed && "Convex"} side="bottom" wrapsButton>
224+
<a
225+
href={href}
226+
target="_blank"
227+
rel="noreferrer"
228+
className={
229+
collapsed
230+
? "flex w-full justify-center"
231+
: "flex items-center gap-2 px-1.5 py-0.5"
232+
}
233+
>
234+
<Image
235+
src="/convex-logo-only.svg"
236+
width={collapsed ? 24 : 18}
237+
height={collapsed ? 24 : 18}
238+
alt="Convex logo"
239+
/>
240+
{!collapsed && <div className="text-sm font-medium">Convex</div>}
241+
</a>
242+
</Tooltip>
243+
</div>
244+
</>
245+
);
246+
}

0 commit comments

Comments
 (0)