Skip to content

Commit 4f3b591

Browse files
committed
feat(database): add Database route with loader and editor functionality
1 parent 0d53f40 commit 4f3b591

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

packages/workshop-app/app/routes/admin+/_layout.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ export default function AdminLayout() {
3434
Diff Viewer
3535
</Link>
3636
</li>
37+
<li>
38+
<Link className="underline" to="db">
39+
Database
40+
</Link>
41+
</li>
3742
<li>
3843
<Link className="underline" to="cache">
3944
Cache Management
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { loadJSON } from '@epic-web/workshop-utils/data-storage.server'
2+
import { readDb } from '@epic-web/workshop-utils/db.server'
3+
import { Icon } from '#app/components/icons.tsx'
4+
import { SimpleTooltip } from '#app/components/ui/tooltip.tsx'
5+
import { ensureUndeployed } from '#app/utils/misc.js'
6+
import { LaunchEditor } from '../launch-editor.tsx'
7+
import { type Route } from './+types/db.ts'
8+
9+
export async function loader() {
10+
ensureUndeployed()
11+
const db = await readDb()
12+
const { path: filepath } = await loadJSON()
13+
14+
return { db, filepath }
15+
}
16+
17+
export default function DbRoute({ loaderData }: Route.ComponentProps) {
18+
const { db, filepath } = loaderData
19+
return (
20+
<main>
21+
<h1 className="text-2xl font-bold">Database</h1>
22+
<div className="prose mt-4">
23+
{/* @ts-expect-error 🤷‍♂️ no idea */}
24+
<callout-danger>
25+
<strong>Warning:</strong> Editing the database directly can corrupt
26+
your data. Be very careful!
27+
{/* @ts-expect-error 🤷‍♂️ no idea */}
28+
</callout-danger>
29+
</div>
30+
<LaunchEditor
31+
file={filepath}
32+
className="flex max-w-full items-center gap-2"
33+
>
34+
<SimpleTooltip content="Open the database file in your editor">
35+
<Icon name="Files" className="h-4 w-4" title="Open in editor" />
36+
</SimpleTooltip>
37+
<span className="truncate" title={filepath}>
38+
{filepath}
39+
</span>
40+
</LaunchEditor>
41+
<pre className="mt-4 max-h-[400px] w-full overflow-auto rounded border bg-gray-900 p-4 text-sm text-white">
42+
{JSON.stringify(db, null, 2)}
43+
</pre>
44+
</main>
45+
)
46+
}

packages/workshop-utils/src/db.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export async function deleteDb() {
129129
}
130130
}
131131

132-
async function readDb() {
132+
export async function readDb() {
133133
if (process.env.EPICSHOP_DEPLOYED) return null
134134

135135
const maxRetries = 3

0 commit comments

Comments
 (0)