fix: preserve widget drafts and connection groups
This commit is contained in:
1 parent
48042a08ff
commit
29c94be821
12 files changed
+258
-79
No files matched your search
@@ -1,4 +1,8 @@
|
||||
import { getWidgetConnectionBindingNames, isWidgetConnectionCompatible } from "@homarr/custom-widgets/package";
|
||||
import {
|
||||
getWidgetConnectionBindingNames,
|
||||
isWidgetConnectionCompatible,
|
||||
mergeWidgetConnectionBindings,
|
||||
} from "@homarr/custom-widgets/package";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { parse, stringify } from "superjson";
|
||||
import { z } from "zod/v4";
|
||||
@@ -58,7 +62,11 @@ export async function prepareWidgetMigration(
|
||||
const issues = validateCustomWidgetOptions(source.options, configuration);
|
||||
if (issues.length)
|
||||
throw new TRPCError({ code: "PRECONDITION_FAILED", message: `Placement ${placement.id}: ${issues[0]?.message}` });
|
||||
const mergedBindings = { ...bindings, ...placement.packageOptions.connectionBindings };
|
||||
const mergedBindings = mergeWidgetConnectionBindings(
|
||||
source.connections,
|
||||
bindings,
|
||||
placement.packageOptions.connectionBindings,
|
||||
);
|
||||
for (const [name, requirement] of Object.entries(source.connections)) {
|
||||
const names = getWidgetConnectionBindingNames(name, requirement, mergedBindings);
|
||||
if (!names.length && !requirement.optional)
|
||||
|
||||
@@ -6,7 +6,11 @@ import { isRecord } from "@homarr/common";
|
||||
import { eq } from "@homarr/db";
|
||||
import { boards, customWidgetArtifacts, customWidgetInstallations, items } from "@homarr/db/schema";
|
||||
import { getCustomWidgetDefaultOptions, validateCustomWidgetOptions } from "@homarr/custom-widgets/core";
|
||||
import { customWidgetArtifactSchema, customWidgetPackageSchema } from "@homarr/custom-widgets/package";
|
||||
import {
|
||||
customWidgetArtifactSchema,
|
||||
customWidgetPackageSchema,
|
||||
mergeWidgetConnectionBindings,
|
||||
} from "@homarr/custom-widgets/package";
|
||||
import type { CustomWidgetArtifact, CustomWidgetPackage } from "@homarr/custom-widgets/package";
|
||||
|
||||
import { throwIfActionForbiddenAsync } from "../../board/board-access";
|
||||
@@ -105,7 +109,11 @@ export async function resolvePackagePlacement(ctx: PackageContext, itemId: strin
|
||||
const issues = validateCustomWidgetOptions(source.options, configuration);
|
||||
if (issues.length > 0)
|
||||
throw new TRPCError({ code: "PRECONDITION_FAILED", message: "Widget configuration needs repair" });
|
||||
const bindings = { ...parseBindings(installation.bindings), ...options.connectionBindings };
|
||||
const bindings = mergeWidgetConnectionBindings(
|
||||
source.connections,
|
||||
parseBindings(installation.bindings),
|
||||
options.connectionBindings,
|
||||
);
|
||||
return { item, installation, artifact, source, configuration, bindings };
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user