fix(custom-widgets): refine v2 authoring

This commit is contained in:
Thomas Camlong committed 2026-07-20 14:14:53 +02:00
1 parent b050c267b6
commit f9863b8402
124 files changed
+2089 -913

No files matched your search

@@ -9,8 +9,6 @@ CREATE TABLE `custom_widget_definition` (
`requests` text NOT NULL,
`options_schema` text NOT NULL,
`default_options` text NOT NULL,
`state_schema` text,
`default_state` text,
`template` text NOT NULL,
`enabled` boolean DEFAULT true NOT NULL,
`created_at` timestamp DEFAULT (now()) NOT NULL,
@@ -593,20 +593,6 @@
"notNull": true,
"autoincrement": false
},
"state_schema": {
"name": "state_schema",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"default_state": {
"name": "default_state",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"template": {
"name": "template",
"type": "text",
@@ -9,8 +9,6 @@ CREATE TABLE "custom_widget_definition" (
"requests" text NOT NULL,
"options_schema" text NOT NULL,
"default_options" text NOT NULL,
"state_schema" text,
"default_state" text,
"template" text NOT NULL,
"enabled" boolean DEFAULT true NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
@@ -550,18 +550,6 @@
"primaryKey": false,
"notNull": true
},
"state_schema": {
"name": "state_schema",
"type": "text",
"primaryKey": false,
"notNull": false
},
"default_state": {
"name": "default_state",
"type": "text",
"primaryKey": false,
"notNull": false
},
"template": {
"name": "template",
"type": "text",
+35 -1
View File
@@ -1,6 +1,7 @@
import SuperJSON from "superjson";
import { createId, objectKeys } from "@homarr/common";
import { BUNDLED_CUSTOM_WIDGETS, customWidgetDefinitionSchema } from "@homarr/custom-widgets/core";
import {
createDocumentationLink,
credentialsAdminGroup,
@@ -15,7 +16,7 @@ import type { WidgetKind } from "@homarr/definitions";
import { defaultServerSettings, defaultServerSettingsKeys } from "@homarr/server-settings";
import type { Database } from "..";
import { eq } from "..";
import { eq, inArray } from "..";
import { getMaxGroupPositionAsync, placeAllWidgetsAsync } from "../queries";
import {
getServerSettingByKeyAsync,
@@ -26,6 +27,7 @@ import {
import {
apps,
boards,
customWidgetDefinitions,
groupMembers,
groupPermissions,
groups,
@@ -57,6 +59,7 @@ export const seedDataAsync = async (db: Database) => {
await seedDefaultIntegrationsAsync(db);
await seedDefaultAppsAsync(db);
await seedDefaultBoardAsync(db);
await seedDefaultCustomWidgetsAsync(db);
await seedBoardWidgetsAsync(db);
if (isTruthyEnv(process.env.DEMO_MODE)) {
@@ -552,6 +555,37 @@ const seedDemoUserAsync = async (db: Database) => {
);
};
const seedDefaultCustomWidgetsAsync = async (db: Database) => {
const seedIds = BUNDLED_CUSTOM_WIDGETS.map(({ id }) => id);
const existing = await db.query.customWidgetDefinitions.findMany({
columns: { id: true },
where: inArray(customWidgetDefinitions.id, seedIds),
});
const existingIds = new Set(existing.map(({ id }) => id));
const values = BUNDLED_CUSTOM_WIDGETS.filter(({ id }) => !existingIds.has(id)).map(({ id, widget }) => {
const definition = customWidgetDefinitionSchema.parse(widget);
return {
id,
name: definition.name,
description: definition.description ?? null,
iconUrl: definition.iconUrl ?? null,
sources: SuperJSON.stringify(definition.sources),
requests: SuperJSON.stringify(definition.requests),
optionsSchema: SuperJSON.stringify(definition.optionsSchema),
defaultOptions: SuperJSON.stringify(definition.defaultOptions),
template: definition.template,
enabled: false,
creatorId: null,
};
});
if (values.length === 0) {
console.log("Skipping seeding of bundled custom widgets because they already exist");
return;
}
await db.insert(customWidgetDefinitions).values(values);
console.log(`Created ${values.length} bundled custom widgets through seeding process`);
};
const seedBoardWidgetsAsync = async (db: Database) => {
const existingItems = await db.$count(items);
if (existingItems > 0) {
@@ -10,8 +10,6 @@ CREATE TABLE `custom_widget_definition` (
`requests` text NOT NULL,
`options_schema` text NOT NULL,
`default_options` text NOT NULL,
`state_schema` text,
`default_state` text,
`template` text NOT NULL,
`enabled` integer DEFAULT true NOT NULL,
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
@@ -574,20 +574,6 @@
"notNull": true,
"autoincrement": false
},
"state_schema": {
"name": "state_schema",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"default_state": {
"name": "default_state",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"template": {
"name": "template",
"type": "text",
-2
View File
@@ -508,8 +508,6 @@ export const customWidgetDefinitions = mysqlTable("custom_widget_definition", {
requests: text().notNull(),
optionsSchema: text().notNull(),
defaultOptions: text().notNull(),
stateSchema: text(),
defaultState: text(),
template: text().notNull(),
enabled: boolean().notNull().default(true),
createdAt: timestamp({ mode: "date" }).notNull().defaultNow(),
-2
View File
@@ -507,8 +507,6 @@ export const customWidgetDefinitions = pgTable("custom_widget_definition", {
requests: text().notNull(),
optionsSchema: text().notNull(),
defaultOptions: text().notNull(),
stateSchema: text(),
defaultState: text(),
template: text().notNull(),
enabled: boolean().notNull().default(true),
createdAt: timestamp({ mode: "date" }).notNull().defaultNow(),
-2
View File
@@ -493,8 +493,6 @@ export const customWidgetDefinitions = sqliteTable("custom_widget_definition", {
requests: text().notNull(),
optionsSchema: text().notNull(),
defaultOptions: text().notNull(),
stateSchema: text(),
defaultState: text(),
template: text().notNull(),
enabled: int({ mode: "boolean" }).notNull().default(true),
createdAt: int({ mode: "timestamp" })