Skip to content

Commit 3998f16

Browse files
committed
dev-demo: add dashboard plugin
1 parent 8d99e5d commit 3998f16

5 files changed

Lines changed: 82 additions & 1 deletion

File tree

dev-demo/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import BackgroundJobsPlugin from '../plugins/adminforth-background-jobs/index.js
2424

2525
import auditLogsResource from "./resources/auditLogs.js"
2626
import sessionsResource from "./resources/agent_resources/sessions.js";
27+
import dashboardConfigsResource from './resources/dashboard_configs.js';
2728
import turnsResource from './resources/agent_resources/turns.js';
2829
import { FICTIONAL_CAR_BRANDS, FICTIONAL_CAR_MODELS_BY_BRAND, ENGINE_TYPES, BODY_TYPES } from './custom/cars_data.js';
2930
import passkeysResource from './resources/passkeys.js';
@@ -139,7 +140,8 @@ export const admin = new AdminForth({
139140
translations,
140141
background_jobs_resource,
141142
sessionsResource,
142-
turnsResource
143+
turnsResource,
144+
dashboardConfigsResource,
143145
],
144146
menu: [
145147
{ type: 'heading', label: 'SYSTEM' },
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- CreateTable
2+
CREATE TABLE "dashboard_configs" (
3+
"id" TEXT NOT NULL PRIMARY KEY,
4+
"slug" TEXT NOT NULL,
5+
"label" TEXT NOT NULL,
6+
"revision" INTEGER NOT NULL,
7+
"config" JSONB NOT NULL
8+
);
9+
10+
-- CreateIndex
11+
CREATE UNIQUE INDEX "dashboard_configs_slug_key" ON "dashboard_configs"("slug");
12+
13+
-- CreateIndex
14+
CREATE INDEX "dashboard_configs_slug_idx" ON "dashboard_configs"("slug");

dev-demo/migrations/prisma/sqlite/schema.prisma

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,13 @@ model turns {
127127
response String?
128128
dubbug String?
129129
}
130+
131+
model dashboard_configs {
132+
id String @id
133+
slug String @unique
134+
label String
135+
revision Int
136+
config Json
137+
138+
@@index([slug])
139+
}

dev-demo/resources/adminuser.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import AdminForthAdapterS3Storage from '../../adapters/adminforth-storage-adapte
99
import AdminForthAdapterGoogleOauth2 from '../../adapters/adminforth-oauth-adapter-google/index.js';
1010
import OpenSignupPlugin from '../../plugins/adminforth-open-signup/index.js';
1111
import OAuthPlugin from '../../plugins/adminforth-oauth/index.js';
12+
import DashboardPlugin from '../../plugins/adminforth-dashboard/index.js';
1213
import KeyValueAdapterRam from '../../adapters/adminforth-key-value-adapter-ram/index.js';
1314
import AdminForthAgent from '../../plugins/adminforth-agent/index.js';
1415
import CompletionAdapterOpenAIResponses from '../../adapters/adminforth-completion-adapter-openai-responses/index.js';
@@ -259,6 +260,9 @@ export default {
259260
debugField: 'dubbug',
260261
},
261262
}),
263+
new DashboardPlugin({
264+
dashboardConfigsResourceId: 'dashboard_configs',
265+
}),
262266
],
263267
hooks: {
264268
create: {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { randomUUID } from 'crypto';
2+
import { AdminForthDataTypes } from 'adminforth';
3+
import type { AdminForthResourceInput } from 'adminforth';
4+
5+
export default {
6+
dataSource: 'sqlite',
7+
table: 'dashboard_configs',
8+
resourceId: 'dashboard_configs',
9+
label: 'Dashboard Configs',
10+
recordLabel: (record) => record.label,
11+
columns: [
12+
{
13+
name: 'id',
14+
primaryKey: true,
15+
type: AdminForthDataTypes.STRING,
16+
fillOnCreate: () => randomUUID(),
17+
showIn: {
18+
list: false,
19+
edit: false,
20+
create: false,
21+
show: true,
22+
filter: false,
23+
},
24+
},
25+
{
26+
name: 'slug',
27+
type: AdminForthDataTypes.STRING,
28+
label: 'Slug',
29+
},
30+
{
31+
name: 'label',
32+
type: AdminForthDataTypes.STRING,
33+
label: 'Label',
34+
},
35+
{
36+
name: 'revision',
37+
type: AdminForthDataTypes.INTEGER,
38+
label: 'Revision',
39+
fillOnCreate: () => 1,
40+
showIn: {
41+
edit: false,
42+
create: false,
43+
},
44+
},
45+
{
46+
name: 'config',
47+
type: AdminForthDataTypes.JSON,
48+
label: 'Config',
49+
},
50+
],
51+
} as AdminForthResourceInput;

0 commit comments

Comments
 (0)