Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ui version to sidebar footer #1063

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 43 additions & 30 deletions ui/admin/app/components/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import {
BotIcon,
BoxesIcon,
InfoIcon,
KeyIcon,
MessageSquare,
PuzzleIcon,
SettingsIcon,
User,
WebhookIcon,
Wrench,
} from "lucide-react";
import { Link, useLocation } from "react-router";
import { $path } from "safe-routes";
import useSWR from "swr";

import { VersionApiService } from "~/lib/service/api/versionApiService";
import { cn } from "~/lib/utils";

import { TypographyMuted, TypographySmall } from "~/components/Typography";
import { ObotLogo } from "~/components/branding/ObotLogo";
import { Button } from "~/components/ui/button";
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "~/components/ui/popover";
import { Separator } from "~/components/ui/separator";
import {
Sidebar,
SidebarContent,
Expand Down Expand Up @@ -131,39 +135,48 @@ export function AppSidebar() {
</SidebarGroupContent>
</SidebarGroup>
</SidebarContent>
<SidebarFooter>
<VersionInfo />
</SidebarFooter>
</Sidebar>
);
}

// disabling this because this will inevitably be used in the future
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function AppSidebarFooter() {
function VersionInfo() {
const { state } = useSidebar();
return (
<SidebarFooter
className={cn(
"pb-4 bg-background",
state === "collapsed" ? "" : "px-2"
)}
>
<Popover>
<PopoverTrigger asChild>
<SidebarMenuButton className="w-full flex items-center">
<SettingsIcon className="mr-2" /> Settings
</SidebarMenuButton>
</PopoverTrigger>
<PopoverContent side="right" align="end">
<Button variant="secondary" asChild className="w-full">
<Link
to={$path("/oauth-apps")}
className="flex items-center p-2 hover:bg-accent rounded-md"
>
<KeyIcon className="mr-2 h-4 w-4" />
<span>Manage OAuth Apps</span>
</Link>
</Button>
</PopoverContent>
</Popover>
</SidebarFooter>
const getVersion = useSWR(VersionApiService.getVersion.key(), () =>
VersionApiService.getVersion()
);

const { data: version } = getVersion;
const versionEntries = Object.entries(version ?? {});
return version?.obot ? (
<Popover>
<PopoverTrigger asChild>
<Button
variant="ghost"
size="sm"
startContent={<InfoIcon />}
className="text-muted-foreground"
>
{state !== "collapsed" ? version.obot : null}
</Button>
</PopoverTrigger>
<PopoverContent className="w-fit min-w-44 p-2">
<div>
{versionEntries.map(([key, value], index) =>
value ? (
<div key={key}>
<TypographyMuted>{key}:</TypographyMuted>
<TypographySmall>{value}</TypographySmall>
{index !== versionEntries.length - 1 && (
<Separator className="my-2" />
)}
</div>
) : null
)}
</div>
</PopoverContent>
</Popover>
) : null;
}
4 changes: 4 additions & 0 deletions ui/admin/app/lib/model/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type Version = {
obot: string;
[key: string]: string;
};
1 change: 1 addition & 0 deletions ui/admin/app/lib/routers/apiRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export const ApiRoutes = {
buildUrl(`/webhooks/${webhookId}`),
invoke: (webhookId: string) => buildUrl(`/webhooks/${webhookId}`),
},
version: () => buildUrl("/version"),
};

/** revalidates the cache for all routes that match the filter callback
Expand Down
17 changes: 17 additions & 0 deletions ui/admin/app/lib/service/api/versionApiService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Version } from "~/lib/model/version";
import { ApiRoutes } from "~/lib/routers/apiRoutes";
import { request } from "~/lib/service/api/primitives";

async function getVersion() {
const res = await request<Version>({
url: ApiRoutes.version().url,
errorMessage: "Failed to fetch app version.",
});

return res.data;
}
getVersion.key = () => ({ url: ApiRoutes.version().path }) as const;

export const VersionApiService = {
getVersion,
};