Skip to content

Commit

Permalink
feat: metrics ui component (unkeyed#2745)
Browse files Browse the repository at this point in the history
* feat: metrics ui component

* fix: fmt

* fix: permission metric component

* fix: manual fmt

* fix: manual fmt

* fix: manual fmt

* fix: border-border in some other places

---------

Co-authored-by: Oğuzhan Olguncu <21091016+ogzhanolguncu@users.noreply.github.com>
  • Loading branch information
Flo4604 and ogzhanolguncu authored Dec 13, 2024
1 parent bc34781 commit 580c165
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { StackedColumnChart } from "@/components/dashboard/charts";
import { EmptyPlaceholder } from "@/components/dashboard/empty-placeholder";
import { Badge } from "@/components/ui/badge";
import { Card, CardContent, CardHeader } from "@/components/ui/card";
import { Metric } from "@/components/ui/metric";
import { Separator } from "@/components/ui/separator";
import { getTenantId } from "@/lib/auth";
import { clickhouse } from "@/lib/clickhouse";
Expand Down Expand Up @@ -143,10 +144,7 @@ export default async function APIKeyDetailPage(props: {
...ratelimitedOverTime.map((d) => ({ ...d, category: "Ratelimited" })),
...usageExceededOverTime.map((d) => ({ ...d, category: "Usage Exceeded" })),
...disabledOverTime.map((d) => ({ ...d, category: "Disabled" })),
...insufficientPermissionsOverTime.map((d) => ({
...d,
category: "Insufficient Permissions",
})),
...insufficientPermissionsOverTime.map((d) => ({ ...d, category: "Insufficient Permissions" })),
...expiredOverTime.map((d) => ({ ...d, category: "Expired" })),
...forbiddenOverTime.map((d) => ({ ...d, category: "Forbidden" })),
];
Expand Down Expand Up @@ -337,7 +335,7 @@ export default async function APIKeyDetailPage(props: {
{Intl.NumberFormat().format(transientPermissionIds.size)} Permissions
</Badge>
</div>
<div className="flex items-center gap-2">
<div className="flex items-center gap-2 border-border">
<CreateNewRole
trigger={<Button>Create New Role</Button>}
permissions={key.workspace.permissions}
Expand Down Expand Up @@ -405,12 +403,3 @@ function prepareInterval(interval: Interval) {
}
}
}

const Metric: React.FC<{ label: string; value: React.ReactNode }> = ({ label, value }) => {
return (
<div className="flex flex-col items-start justify-between h-full px-4 py-2">
<p className="text-sm text-content-subtle">{label}</p>
<div className="text-2xl font-semibold leading-none tracking-tight">{value}</div>
</div>
);
};
10 changes: 1 addition & 9 deletions apps/dashboard/app/(app)/apis/[apiId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AreaChart, StackedColumnChart } from "@/components/dashboard/charts";
import { EmptyPlaceholder } from "@/components/dashboard/empty-placeholder";
import { Card, CardContent, CardHeader } from "@/components/ui/card";
import { Metric } from "@/components/ui/metric";
import { Separator } from "@/components/ui/separator";
import { getTenantId } from "@/lib/auth";
import { clickhouse } from "@/lib/clickhouse";
Expand Down Expand Up @@ -321,12 +322,3 @@ function prepareInterval(interval: Interval) {
}
}
}

const Metric: React.FC<{ label: string; value: string }> = ({ label, value }) => {
return (
<div className="flex flex-col items-start justify-between h-full px-4 py-2">
<p className="text-sm text-content-subtle">{label}</p>
<div className="text-2xl font-semibold leading-none tracking-tight">{value}</div>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const UpdateIpWhitelist: React.FC<Props> = ({ api, workspace }) => {
/>
</div>
) : (
<Alert className="flex items-center justify-between opacity-100">
<Alert className="flex items-center justify-between opacity-100 border-border">
<div>
<AlertTitle>Enterprise Feature</AlertTitle>
<AlertDescription>
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/(app)/apis/create-api-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const CreateApiButton = ({ ...rest }: React.ButtonHTMLAttributes<HTMLButt
Create New API
</Button>
</DialogTrigger>
<DialogContent className="w-11/12 max-sm: ">
<DialogContent className="border-border w-11/12 max-sm: ">
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)}>
<FormField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const Metric: React.FC<{ label: string; value?: string; Icon: LucideIcon }> = ({
Icon,
}) => {
return (
<div className="flex items-center gap-4 px-4 py-2 border rounded-lg">
<div className="flex items-center gap-4 px-4 py-2 border rounded-lg border-border">
<Icon className="w-6 h-6 text-primary" />
<div className="flex flex-col items-start justify-center">
<p className="text-sm text-content-subtle">{label}</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const CreateNewPermission: React.FC<Props> = ({ trigger }) => {
return (
<Dialog open={open} onOpenChange={handleDialogOpenChange}>
<DialogTrigger asChild>{trigger}</DialogTrigger>
<DialogContent>
<DialogContent className="border-border">
<DialogHeader>
<DialogTitle>Create a new permission</DialogTitle>
<DialogDescription>Permissions allow your key to do certain actions.</DialogDescription>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const CreateNewRole: React.FC<Props> = ({ trigger }) => {
return (
<Dialog open={open} onOpenChange={handleDialogOpenChange}>
<DialogTrigger asChild>{trigger}</DialogTrigger>
<DialogContent>
<DialogContent className="border-border">
<DialogHeader>
<DialogTitle>Create a new role</DialogTitle>
<DialogDescription>Roles group permissions together.</DialogDescription>
Expand Down
10 changes: 1 addition & 9 deletions apps/dashboard/app/(app)/ratelimits/[namespaceId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CopyButton } from "@/components/dashboard/copy-button";
import { EmptyPlaceholder } from "@/components/dashboard/empty-placeholder";
import { Card, CardContent, CardHeader } from "@/components/ui/card";
import { Code } from "@/components/ui/code";
import { Metric } from "@/components/ui/metric";
import { Separator } from "@/components/ui/separator";
import { getTenantId } from "@/lib/auth";
import { clickhouse } from "@/lib/clickhouse";
Expand Down Expand Up @@ -291,12 +292,3 @@ function prepareInterval(interval: Interval) {
}
}
}

const Metric: React.FC<{ label: string; value: string }> = ({ label, value }) => {
return (
<div className="flex flex-col items-start justify-center px-4 py-2">
<p className="text-sm text-content-subtle">{label}</p>
<div className="text-2xl font-semibold leading-none tracking-tight">{value}</div>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const CreateNamespaceButton = ({
Create new namespace
</Button>
</DialogTrigger>
<DialogContent className="w-11/12 max-sm: ">
<DialogContent className="border-border w-11/12 max-sm: ">
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)}>
<FormField
Expand Down
13 changes: 1 addition & 12 deletions apps/dashboard/app/(app)/settings/root-keys/[keyId]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Metric } from "@/components/ui/metric";
import { getTenantId } from "@/lib/auth";
import { clickhouse } from "@/lib/clickhouse";
import { db } from "@/lib/db";
Expand Down Expand Up @@ -65,18 +66,6 @@ export default async function Layout({ children, params: { keyId } }: Props) {
);
}

const Metric: React.FC<{
label: React.ReactNode;
value: React.ReactNode;
}> = ({ label, value }) => {
return (
<div className="flex flex-col items-start justify-center px-4 py-2">
<p className="text-sm text-content-subtle">{label}</p>
<div className="text-sm leading-none tracking-tight ">{value}</div>
</div>
);
};

const LastUsed: React.FC<{ workspaceId: string; keySpaceId: string; keyId: string }> = async ({
workspaceId,
keySpaceId,
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/(app)/settings/user/update-theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const Option: React.FC<{ theme: string; icon: LucideIcon }> = (props) => {
type="button"
onClick={() => setTheme(props.theme)}
className={cn(
"border text-sm rounded-md hover:border-primary flex items-center justify-center gap-2 h-8 p-2 ",
"border text-sm rounded-md hover:border-primary flex items-center justify-center gap-2 h-8 p-2 border-border ",
{
"bg-primary text-primary-foreground border-primary": props.theme === theme,
},
Expand Down
13 changes: 1 addition & 12 deletions apps/dashboard/app/ratelimit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { PageHeader } from "@/components/dashboard/page-header";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Metric } from "@/components/ui/metric";
import {
Select,
SelectContent,
Expand Down Expand Up @@ -272,15 +273,3 @@ export default function RatelimitPage() {
</div>
);
}

const Metric: React.FC<{
label: React.ReactNode;
value: React.ReactNode;
}> = ({ label, value }) => {
return (
<div className="flex flex-col items-start justify-center px-4 py-2">
<p className="text-sm text-content-subtle">{label}</p>
<div className="text-2xl font-semibold leading-none tracking-tight">{value}</div>
</div>
);
};
17 changes: 17 additions & 0 deletions apps/dashboard/components/ui/metric.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type * as React from "react";

interface MetricProps {
label: string;
value: string | React.ReactNode;
}

const Metric: React.FC<MetricProps> = ({ label, value }) => {
return (
<div className="flex flex-col items-start justify-center px-4 py-2 border-border">
<p className="text-sm text-content-subtle">{label}</p>
<div className="text-2xl font-semibold leading-none tracking-tight">{value}</div>
</div>
);
};

export { Metric };

0 comments on commit 580c165

Please sign in to comment.