Skip to content

Commit 770c4ae

Browse files
committed
add info to show history
1 parent 93a8de7 commit 770c4ae

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

apps/web/app/routes/ws/settings/general.tsx

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useState } from "react";
2+
import prettyMilliseconds from "pretty-ms";
23
import { toast } from "sonner";
34

45
import { trpc } from "~/api/trpc";
@@ -19,6 +20,14 @@ import {
1920
FieldLabel,
2021
} from "~/components/ui/field";
2122
import { Input } from "~/components/ui/input";
23+
import {
24+
Table,
25+
TableBody,
26+
TableCell,
27+
TableHead,
28+
TableHeader,
29+
TableRow,
30+
} from "~/components/ui/table";
2231
import { useWorkspace } from "~/components/WorkspaceProvider";
2332

2433
export default function GeneralSettingsPage() {
@@ -30,10 +39,19 @@ export default function GeneralSettingsPage() {
3039
slug?: string;
3140
}>({});
3241

42+
const utils = trpc.useUtils();
43+
const saveHistoryQuery = trpc.workspace.saveHistory.useQuery({
44+
workspaceId: workspace.id,
45+
});
46+
3347
const saveWorkspace = trpc.workspace.save.useMutation({
3448
onSuccess: () => {
3549
toast.success("Workspace saved sucessfully");
50+
void utils.workspace.saveHistory.invalidate({
51+
workspaceId: workspace.id,
52+
});
3653
},
54+
3755
onError: (error: unknown) => {
3856
const message =
3957
error instanceof Error ? error.message : "Failed to update workspace";
@@ -178,7 +196,7 @@ export default function GeneralSettingsPage() {
178196

179197
<Card>
180198
<CardHeader>
181-
<CardTitle>Workspace Information</CardTitle>
199+
<CardTitle>State</CardTitle>
182200
<CardDescription>
183201
Update your workspace name and URL slug
184202
</CardDescription>
@@ -189,6 +207,35 @@ export default function GeneralSettingsPage() {
189207
>
190208
Force Save Workspace
191209
</Button>
210+
211+
<div className="mt-5 max-h-[500px] overflow-y-auto rounded-md border bg-muted/50">
212+
<Table>
213+
<TableHeader>
214+
<TableRow>
215+
<TableHead>Timestamp</TableHead>
216+
<TableHead>Partition</TableHead>
217+
<TableHead>Offset</TableHead>
218+
<TableHead>Num Partitions</TableHead>
219+
<TableHead>Path</TableHead>
220+
</TableRow>
221+
</TableHeader>
222+
<TableBody className="font-mono text-xs">
223+
{saveHistoryQuery.data?.map(({ workspace_snapshot }) => (
224+
<TableRow key={workspace_snapshot.id}>
225+
<TableCell>
226+
{prettyMilliseconds(
227+
Date.now() - workspace_snapshot.timestamp.getTime(),
228+
)}
229+
</TableCell>
230+
<TableCell>{workspace_snapshot.partition}</TableCell>
231+
<TableCell>{workspace_snapshot.offset}</TableCell>
232+
<TableCell>{workspace_snapshot.numPartitions}</TableCell>
233+
<TableCell>{workspace_snapshot.path}</TableCell>
234+
</TableRow>
235+
))}
236+
</TableBody>
237+
</Table>
238+
</div>
192239
</CardContent>
193240
</Card>
194241
</div>

packages/trpc/src/routes/workspace.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
11
import { TRPCError } from "@trpc/server";
22
import { z } from "zod";
33

4-
import { eq, takeFirst, takeFirstOrNull } from "@ctrlplane/db";
4+
import { desc, eq, takeFirst, takeFirstOrNull } from "@ctrlplane/db";
55
import * as schema from "@ctrlplane/db/schema";
66
import { Event, sendGoEvent } from "@ctrlplane/events";
77
import { Permission } from "@ctrlplane/validators/auth";
88

99
import { protectedProcedure, router } from "../trpc.js";
1010

1111
export const workspaceRouter = router({
12+
saveHistory: protectedProcedure
13+
.input(z.object({ workspaceId: z.uuid() }))
14+
.query(async ({ ctx, input }) => {
15+
const snapshots = await ctx.db
16+
.select()
17+
.from(schema.workspace)
18+
.innerJoin(
19+
schema.workspaceSnapshot,
20+
eq(schema.workspace.id, schema.workspaceSnapshot.workspaceId),
21+
)
22+
.where(eq(schema.workspace.id, input.workspaceId))
23+
.limit(500)
24+
.orderBy(desc(schema.workspaceSnapshot.timestamp));
25+
26+
return snapshots;
27+
}),
28+
1229
save: protectedProcedure
1330
.input(z.object({ workspaceId: z.uuid() }))
1431
.mutation(async ({ input }) => {

0 commit comments

Comments
 (0)