fix: address release v2 review findings (#6708)
This commit is contained in:
1 parent
a002b91add
commit
7da2e10064
39 files changed
+500
-769
No files matched your search
@@ -1,5 +1,16 @@
|
||||
import type { QueryKey } from "@tanstack/react-query";
|
||||
|
||||
const isRecord = (value: unknown): value is Record<string, unknown> => typeof value === "object" && value !== null;
|
||||
|
||||
interface ForbiddenTrpcError {
|
||||
data: { code: "FORBIDDEN" };
|
||||
}
|
||||
|
||||
export const isTrpcForbiddenError = (error: unknown): error is ForbiddenTrpcError => {
|
||||
if (!isRecord(error) || !isRecord(error.data)) return false;
|
||||
return error.data.code === "FORBIDDEN";
|
||||
};
|
||||
|
||||
// RSC-prefetched data must survive the hydration pass without an immediate
|
||||
// duplicate fetch. Widget-specific intervals still control live refreshes.
|
||||
export const queryCacheDefaultStaleTimeMs = 30_000;
|
||||
@@ -8,6 +19,7 @@ export const queryCacheDefaultGcTimeMs = 1000 * 60 * 5;
|
||||
export const queryCacheMetadataStaleTimeMs = 1000 * 60 * 5;
|
||||
|
||||
const widgetDataQueryPaths = new Set(["app.byId", "app.byIds", "docker.getContainers", "integration.byIds"]);
|
||||
const persistenceExcludedWidgetPaths = new Set(["widget.customApi.getData", "widget.customApi.queryRequest"]);
|
||||
// Beszel system stats are large time-series payloads and were deliberately kept out of
|
||||
// the persisted cache in #6289; live stats come from an SSE subscription instead.
|
||||
const excludedWidgetPaths = new Set(["widget.app.ping", "widget.beszel.getSystemStats"]);
|
||||
@@ -66,3 +78,11 @@ export const isWidgetDataQueryKey = (queryKey: QueryKey) => {
|
||||
|
||||
return isWidgetDataTrpcPath(path.join("."));
|
||||
};
|
||||
|
||||
export const isPersistableDashboardQueryKey = (queryKey: QueryKey) => {
|
||||
const path = getTrpcPathFromQueryKey(queryKey);
|
||||
if (!path) return false;
|
||||
|
||||
const joinedPath = path.join(".");
|
||||
return isWidgetDataTrpcPath(joinedPath) && !persistenceExcludedWidgetPaths.has(joinedPath);
|
||||
};
|
||||
@@ -86,9 +86,14 @@ interface BoardItemPlacementRectangle {
|
||||
}
|
||||
|
||||
const boardItemPlacementTails = new Map<string, Promise<void>>();
|
||||
const maxManageOverviewPreviewRows = 12;
|
||||
const defaultManageOverviewPreviewRows = 12;
|
||||
const maxManageOverviewPreviewRows = 48;
|
||||
const manageOverviewInputSchema = z
|
||||
.object({ fullPreview: z.boolean().default(false), userId: z.string().optional() })
|
||||
.object({
|
||||
fullPreview: z.boolean().default(false),
|
||||
previewRowLimit: z.number().int().min(1).max(maxManageOverviewPreviewRows).optional(),
|
||||
userId: z.string().optional(),
|
||||
})
|
||||
.optional();
|
||||
|
||||
const serializeBoardItemPlacementAsync = async <T>(boardId: string, operation: () => Promise<T>) => {
|
||||
@@ -311,6 +316,8 @@ export const boardRouter = createTRPCRouter({
|
||||
const { boardIds, currentUser, groupMemberships } = await getBoardAccessContextAsync(ctx.db, userId);
|
||||
const groupPermissionWhere = getBoardGroupPermissionWhere(groupMemberships);
|
||||
const canViewAllBoards = getCanViewAllBoards(groupMemberships);
|
||||
let previewRowLimit = input?.previewRowLimit ?? defaultManageOverviewPreviewRows;
|
||||
if (input?.fullPreview) previewRowLimit = maxManageOverviewPreviewRows;
|
||||
|
||||
const dbBoards = await ctx.db.query.boards.findMany({
|
||||
columns: {
|
||||
@@ -388,7 +395,7 @@ export const boardRouter = createTRPCRouter({
|
||||
inArray(itemLayouts.sectionId, rootSectionIds),
|
||||
gte(itemLayouts.xOffset, 0),
|
||||
gte(itemLayouts.yOffset, 0),
|
||||
input?.fullPreview ? undefined : lt(itemLayouts.yOffset, maxManageOverviewPreviewRows),
|
||||
lt(itemLayouts.yOffset, previewRowLimit),
|
||||
gt(itemLayouts.width, 0),
|
||||
gt(itemLayouts.height, 0),
|
||||
),
|
||||
@@ -413,7 +420,7 @@ export const boardRouter = createTRPCRouter({
|
||||
inArray(sectionLayouts.parentSectionId, rootSectionIds),
|
||||
gte(sectionLayouts.xOffset, 0),
|
||||
gte(sectionLayouts.yOffset, 0),
|
||||
input?.fullPreview ? undefined : lt(sectionLayouts.yOffset, maxManageOverviewPreviewRows),
|
||||
lt(sectionLayouts.yOffset, previewRowLimit),
|
||||
gt(sectionLayouts.width, 0),
|
||||
gt(sectionLayouts.height, 0),
|
||||
),
|
||||
@@ -448,7 +455,7 @@ export const boardRouter = createTRPCRouter({
|
||||
inArray(itemLayouts.sectionId, previewContainerSectionIds),
|
||||
gte(itemLayouts.xOffset, 0),
|
||||
gte(itemLayouts.yOffset, 0),
|
||||
input?.fullPreview ? undefined : lt(itemLayouts.yOffset, maxManageOverviewPreviewRows),
|
||||
lt(itemLayouts.yOffset, previewRowLimit),
|
||||
gt(itemLayouts.width, 0),
|
||||
gt(itemLayouts.height, 0),
|
||||
),
|
||||
|
||||
@@ -84,15 +84,13 @@ export const getDockerReconciliationAsync = async (db: Database) => {
|
||||
const appAmbiguous =
|
||||
!linkedApp && (exactAppMatches.length > 1 || (exactAppMatches.length === 0 && nameAppMatches.length > 1));
|
||||
const ambiguous = integrationAmbiguous || appAmbiguous;
|
||||
const state: DockerReconciliationState = integrationMoved
|
||||
? "moved"
|
||||
: linked
|
||||
? "linked"
|
||||
: integration || app
|
||||
? "represented"
|
||||
: match
|
||||
? "newRecognized"
|
||||
: "newApp";
|
||||
const state = getReconciliationState({
|
||||
integrationMoved,
|
||||
linked,
|
||||
represented: Boolean(integration || app),
|
||||
recognized: Boolean(match),
|
||||
});
|
||||
const nextAction = getCandidateNextAction(state, integrationAmbiguous, appAmbiguous);
|
||||
|
||||
return {
|
||||
candidateKey: container.resourceId,
|
||||
@@ -103,11 +101,7 @@ export const getDockerReconciliationAsync = async (db: Database) => {
|
||||
match,
|
||||
urlCandidates,
|
||||
state,
|
||||
nextAction: integrationAmbiguous
|
||||
? ("reviewIntegration" as const)
|
||||
: appAmbiguous
|
||||
? ("viewRepresentation" as const)
|
||||
: nextActionForState(state),
|
||||
nextAction,
|
||||
representation: {
|
||||
integration: integration
|
||||
? {
|
||||
@@ -147,87 +141,100 @@ export const getDockerServiceHealthAsync = async (db: Database) => {
|
||||
status: endpoint.status,
|
||||
nextAction: endpoint.status === "unavailable" ? ("checkEndpoint" as const) : ("none" as const),
|
||||
})),
|
||||
services: reconciliation.candidates.map((candidate) => ({
|
||||
key: candidate.candidateKey,
|
||||
identity: {
|
||||
endpointId: candidate.endpointId,
|
||||
nativeId: candidate.nativeId,
|
||||
name: candidate.container.name,
|
||||
integration: candidate.representation.integration,
|
||||
app: candidate.representation.app,
|
||||
},
|
||||
layers: [
|
||||
{ layer: "docker" as const, status: "available" as const, nextAction: "none" as const },
|
||||
{
|
||||
layer: "integrationConfiguration" as const,
|
||||
status: integrationHealthStatus(
|
||||
candidate.state,
|
||||
candidate.match?.kind,
|
||||
Boolean(candidate.representation.integration),
|
||||
),
|
||||
nextAction:
|
||||
candidate.nextAction === "reviewIntegration"
|
||||
? ("reviewIntegration" as const)
|
||||
: candidate.state === "newRecognized"
|
||||
? ("setupIntegration" as const)
|
||||
: ("none" as const),
|
||||
services: reconciliation.candidates.map((candidate) => {
|
||||
const integration = candidate.representation.integration;
|
||||
const app = candidate.representation.app;
|
||||
const itemCount = integration?.itemCount;
|
||||
|
||||
return {
|
||||
key: candidate.candidateKey,
|
||||
identity: {
|
||||
endpointId: candidate.endpointId,
|
||||
nativeId: candidate.nativeId,
|
||||
name: candidate.container.name,
|
||||
integration,
|
||||
app,
|
||||
},
|
||||
{
|
||||
layer: "authentication" as const,
|
||||
status: "notObserved" as const,
|
||||
nextAction: candidate.representation.integration
|
||||
? ("testConnection" as const)
|
||||
: candidate.nextAction === "reviewIntegration"
|
||||
? ("reviewIntegration" as const)
|
||||
: candidate.match
|
||||
? ("setupIntegration" as const)
|
||||
: ("none" as const),
|
||||
},
|
||||
{
|
||||
layer: "apiRequest" as const,
|
||||
status: "notObserved" as const,
|
||||
nextAction: candidate.representation.integration
|
||||
? ("openIntegrationDiagnostics" as const)
|
||||
: ("none" as const),
|
||||
},
|
||||
{
|
||||
layer: "appRepresentation" as const,
|
||||
status: candidate.representation.app ? ("linked" as const) : ("missing" as const),
|
||||
nextAction: candidate.representation.app
|
||||
? ("none" as const)
|
||||
: candidate.representation.signals.ambiguous && candidate.nextAction === "viewRepresentation"
|
||||
? ("viewRepresentation" as const)
|
||||
: ("createApp" as const),
|
||||
},
|
||||
{
|
||||
layer: "widgetConfiguration" as const,
|
||||
status: candidate.representation.integration
|
||||
? candidate.representation.integration.itemCount > 0
|
||||
? ("linked" as const)
|
||||
: ("unused" as const)
|
||||
: ("notApplicable" as const),
|
||||
nextAction:
|
||||
candidate.representation.integration && candidate.representation.integration.itemCount === 0
|
||||
? ("addWidget" as const)
|
||||
: ("none" as const),
|
||||
},
|
||||
{
|
||||
layer: "widgetQuery" as const,
|
||||
status: "notObserved" as const,
|
||||
nextAction:
|
||||
candidate.representation.integration && candidate.representation.integration.itemCount > 0
|
||||
? ("openBoard" as const)
|
||||
: ("none" as const),
|
||||
},
|
||||
],
|
||||
status: candidate.state,
|
||||
nextAction: candidate.nextAction,
|
||||
})),
|
||||
layers: [
|
||||
{ layer: "docker" as const, status: "available" as const, nextAction: "none" as const },
|
||||
{
|
||||
layer: "integrationConfiguration" as const,
|
||||
status: integrationHealthStatus(candidate.state, candidate.match?.kind, Boolean(integration)),
|
||||
nextAction: getIntegrationConfigurationNextAction(candidate.state, candidate.nextAction),
|
||||
},
|
||||
{
|
||||
layer: "authentication" as const,
|
||||
status: "notObserved" as const,
|
||||
nextAction: getAuthenticationNextAction(
|
||||
Boolean(integration),
|
||||
Boolean(candidate.match),
|
||||
candidate.nextAction,
|
||||
),
|
||||
},
|
||||
{
|
||||
layer: "apiRequest" as const,
|
||||
status: "notObserved" as const,
|
||||
nextAction: integration ? ("openIntegrationDiagnostics" as const) : ("none" as const),
|
||||
},
|
||||
{
|
||||
layer: "appRepresentation" as const,
|
||||
status: app ? ("linked" as const) : ("missing" as const),
|
||||
nextAction: getAppRepresentationNextAction(
|
||||
Boolean(app),
|
||||
candidate.representation.signals.ambiguous,
|
||||
candidate.nextAction,
|
||||
),
|
||||
},
|
||||
{
|
||||
layer: "widgetConfiguration" as const,
|
||||
status: getWidgetConfigurationStatus(itemCount),
|
||||
nextAction: itemCount === 0 ? ("addWidget" as const) : ("none" as const),
|
||||
},
|
||||
{
|
||||
layer: "widgetQuery" as const,
|
||||
status: "notObserved" as const,
|
||||
nextAction: itemCount !== undefined && itemCount > 0 ? ("openBoard" as const) : ("none" as const),
|
||||
},
|
||||
],
|
||||
status: candidate.state,
|
||||
nextAction: candidate.nextAction,
|
||||
};
|
||||
}),
|
||||
};
|
||||
};
|
||||
|
||||
const normalizeName = (value: string) => value.trim().toLowerCase();
|
||||
|
||||
interface ReconciliationStateInput {
|
||||
integrationMoved: boolean;
|
||||
linked: boolean;
|
||||
represented: boolean;
|
||||
recognized: boolean;
|
||||
}
|
||||
|
||||
const getReconciliationState = ({
|
||||
integrationMoved,
|
||||
linked,
|
||||
represented,
|
||||
recognized,
|
||||
}: ReconciliationStateInput): DockerReconciliationState => {
|
||||
if (integrationMoved) return "moved";
|
||||
if (linked) return "linked";
|
||||
if (represented) return "represented";
|
||||
if (recognized) return "newRecognized";
|
||||
return "newApp";
|
||||
};
|
||||
|
||||
const getCandidateNextAction = (
|
||||
state: DockerReconciliationState,
|
||||
integrationAmbiguous: boolean,
|
||||
appAmbiguous: boolean,
|
||||
) => {
|
||||
if (integrationAmbiguous) return "reviewIntegration" as const;
|
||||
if (appAmbiguous) return "viewRepresentation" as const;
|
||||
return nextActionForState(state);
|
||||
};
|
||||
|
||||
const nextActionForState = (state: DockerReconciliationState): DockerReconciliationNextAction => {
|
||||
if (state === "newRecognized") return "setupIntegration";
|
||||
if (state === "newApp") return "createApp";
|
||||
@@ -235,6 +242,42 @@ const nextActionForState = (state: DockerReconciliationState): DockerReconciliat
|
||||
return "viewRepresentation";
|
||||
};
|
||||
|
||||
const getIntegrationConfigurationNextAction = (
|
||||
state: DockerReconciliationState,
|
||||
nextAction: DockerReconciliationNextAction,
|
||||
) => {
|
||||
if (nextAction === "reviewIntegration") return "reviewIntegration" as const;
|
||||
if (state === "newRecognized") return "setupIntegration" as const;
|
||||
return "none" as const;
|
||||
};
|
||||
|
||||
const getAuthenticationNextAction = (
|
||||
hasIntegration: boolean,
|
||||
hasMatch: boolean,
|
||||
nextAction: DockerReconciliationNextAction,
|
||||
) => {
|
||||
if (hasIntegration) return "testConnection" as const;
|
||||
if (nextAction === "reviewIntegration") return "reviewIntegration" as const;
|
||||
if (hasMatch) return "setupIntegration" as const;
|
||||
return "none" as const;
|
||||
};
|
||||
|
||||
const getAppRepresentationNextAction = (
|
||||
hasApp: boolean,
|
||||
ambiguous: boolean,
|
||||
nextAction: DockerReconciliationNextAction,
|
||||
) => {
|
||||
if (hasApp) return "none" as const;
|
||||
if (ambiguous && nextAction === "viewRepresentation") return "viewRepresentation" as const;
|
||||
return "createApp" as const;
|
||||
};
|
||||
|
||||
const getWidgetConfigurationStatus = (itemCount: number | undefined) => {
|
||||
if (itemCount === undefined) return "notApplicable" as const;
|
||||
if (itemCount > 0) return "linked" as const;
|
||||
return "unused" as const;
|
||||
};
|
||||
|
||||
const integrationHealthStatus = (
|
||||
state: DockerReconciliationState,
|
||||
kind: IntegrationKind | undefined,
|
||||
@@ -242,5 +285,6 @@ const integrationHealthStatus = (
|
||||
) => {
|
||||
if (!kind) return "notApplicable" as const;
|
||||
if (state === "moved") return "changed" as const;
|
||||
return hasIntegration ? ("configured" as const) : ("missing" as const);
|
||||
if (hasIntegration) return "configured" as const;
|
||||
return "missing" as const;
|
||||
};
|
||||
@@ -14,6 +14,7 @@ import { dockerRouter } from "../../docker/docker-router";
|
||||
const findDockerContainerAsyncMock = vi.hoisted(() => vi.fn());
|
||||
const hasDockerEndpointCapabilityMock = vi.hoisted(() => vi.fn(() => true));
|
||||
const invalidateDockerCacheMock = vi.hoisted(() => vi.fn());
|
||||
const resetDockerSingletonMock = vi.hoisted(() => vi.fn());
|
||||
const getDockerDataAsyncMock = vi.hoisted(() =>
|
||||
vi.fn<
|
||||
() => Promise<{
|
||||
@@ -62,7 +63,7 @@ vi.mock("@homarr/docker", () => ({
|
||||
},
|
||||
},
|
||||
],
|
||||
reset: () => undefined,
|
||||
reset: resetDockerSingletonMock,
|
||||
},
|
||||
}));
|
||||
vi.mock("@homarr/request-handler/docker", () => ({
|
||||
@@ -501,6 +502,7 @@ test("invalidates the shared Docker inventory on explicit refresh", async () =>
|
||||
await createAdminCaller().refreshInventory();
|
||||
|
||||
expect(invalidateDockerCacheMock).toHaveBeenCalledOnce();
|
||||
expect(resetDockerSingletonMock).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
test("projects persisted service layers without inventing runtime health", async () => {
|
||||
|
||||
@@ -50,7 +50,10 @@ export const immichRouter = createTRPCRouter({
|
||||
)
|
||||
.concat(createImmichIntegrationMiddleware("query"))
|
||||
.query(async ({ ctx, input }) => {
|
||||
if (ctx.integration.kind === "mock") return mockWidgetData.immichAlbums.slice(0, input.limit);
|
||||
if (ctx.integration.kind === "mock") {
|
||||
if (input.limit === undefined) return [...mockWidgetData.immichAlbums];
|
||||
return mockWidgetData.immichAlbums.slice(0, input.limit);
|
||||
}
|
||||
const innerHandler = immichAlbumsRequestHandler.handler(
|
||||
{ ...ctx.integration, kind: "immich" },
|
||||
{
|
||||
|
||||
@@ -6,7 +6,8 @@ import { harnessRoot, normalizeHarnessEnvironmentArgs } from "./commands/harness
|
||||
const harnessCommandNames = new Set(["harness", "local-harness"]);
|
||||
|
||||
function isHarnessInvocation(argv: string[]): boolean {
|
||||
return argv.slice(2).some((argument) => harnessCommandNames.has(argument));
|
||||
const command = argv[2];
|
||||
return command !== undefined && harnessCommandNames.has(command);
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
|
||||
@@ -12,6 +12,11 @@ describe("getUsableWidgetQueryData", () => {
|
||||
expect(getUsableWidgetQueryData({ data, error: new Error("offline") })).toBe(data);
|
||||
});
|
||||
|
||||
test("throws access-denied refetches instead of rendering stale cached data", () => {
|
||||
const error = { data: { code: "FORBIDDEN" } };
|
||||
expect(() => getUsableWidgetQueryData({ data: [{ id: "revoked" }], error })).toThrow(error);
|
||||
});
|
||||
|
||||
test("throws a terminal failure when no usable data exists", () => {
|
||||
const error = new Error("offline");
|
||||
expect(() => getUsableWidgetQueryData({ data: undefined, error })).toThrow(error);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { isTrpcForbiddenError } from "@homarr/api/query-cache";
|
||||
|
||||
interface WidgetQueryState {
|
||||
data: unknown;
|
||||
error: unknown;
|
||||
@@ -9,6 +11,7 @@ interface PendingWidgetQueryState extends WidgetQueryState {
|
||||
|
||||
/** Throws terminal query failures while preserving successful empty values and stale cached data. */
|
||||
export const getUsableWidgetQueryData = <TQuery extends WidgetQueryState>(query: TQuery): TQuery["data"] => {
|
||||
if (isTrpcForbiddenError(query.error)) throw query.error;
|
||||
if (query.error && query.data === undefined) throw query.error;
|
||||
return query.data;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { getAllowedPermissions, getFrameTitle, getSandboxFlags, isSupportedProtocol } from "./component";
|
||||
import { getAllowedPermissions, getFrameTitle, getSandboxFlags } from "./component";
|
||||
|
||||
const permissions = {
|
||||
allowFullScreen: true,
|
||||
@@ -18,12 +18,6 @@ describe("iframe policy", () => {
|
||||
expect(getSandboxFlags(permissions)).toContain("allow-modals");
|
||||
});
|
||||
|
||||
it("accepts only HTTP protocols", () => {
|
||||
expect(isSupportedProtocol("https://example.com")).toBe(true);
|
||||
expect(isSupportedProtocol("javascript:alert(1)")).toBe(false);
|
||||
expect(isSupportedProtocol("not a url")).toBe(false);
|
||||
});
|
||||
|
||||
it("creates a display title without credentials, paths, or query parameters", () => {
|
||||
expect(getFrameTitle("https://user:secret@example.com/private?token=sensitive")).toBe("example.com");
|
||||
});
|
||||
|
||||
@@ -1,26 +1,21 @@
|
||||
"use client";
|
||||
|
||||
import { Box, Stack, Text, Title } from "@mantine/core";
|
||||
import { IconBrowserOff, IconProtocol } from "@tabler/icons-react";
|
||||
import { IconBrowserOff } from "@tabler/icons-react";
|
||||
|
||||
import { objectEntries } from "@homarr/common";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
|
||||
import type { WidgetComponentProps } from "../definition";
|
||||
import { getSafeApplicationUrl } from "../common/application-url";
|
||||
import classes from "./component.module.css";
|
||||
|
||||
export default function IFrameWidget({ options, isEditMode }: WidgetComponentProps<"iframe">) {
|
||||
const t = useI18n("widget.iframe");
|
||||
const { embedUrl, allowScrolling, ...permissions } = options;
|
||||
const safeEmbedUrl = getSafeApplicationUrl(embedUrl);
|
||||
const allowedPermissions = getAllowedPermissions(permissions);
|
||||
const sandboxFlags = getSandboxFlags(permissions);
|
||||
|
||||
if (embedUrl.trim() === "") return <NoUrl />;
|
||||
if (!safeEmbedUrl) {
|
||||
return <UnsupportedProtocol />;
|
||||
}
|
||||
|
||||
return (
|
||||
<Stack h="100%" w="100%" gap={0}>
|
||||
@@ -29,8 +24,8 @@ export default function IFrameWidget({ options, isEditMode }: WidgetComponentPro
|
||||
loading="lazy"
|
||||
style={isEditMode ? { userSelect: "none", pointerEvents: "none" } : undefined}
|
||||
className={classes.iframe}
|
||||
src={safeEmbedUrl}
|
||||
title={getFrameTitle(safeEmbedUrl)}
|
||||
src={embedUrl}
|
||||
title={getFrameTitle(embedUrl)}
|
||||
allow={allowedPermissions}
|
||||
scrolling={allowScrolling ? "yes" : "no"}
|
||||
sandbox={sandboxFlags.join(" ")}
|
||||
@@ -42,12 +37,6 @@ export default function IFrameWidget({ options, isEditMode }: WidgetComponentPro
|
||||
);
|
||||
}
|
||||
|
||||
const supportedProtocols = ["http", "https"];
|
||||
|
||||
export const isSupportedProtocol = (url: string) => {
|
||||
return getSafeApplicationUrl(url) !== undefined;
|
||||
};
|
||||
|
||||
const NoUrl = () => {
|
||||
const t = useI18n("widget.iframe");
|
||||
|
||||
@@ -59,21 +48,6 @@ const NoUrl = () => {
|
||||
);
|
||||
};
|
||||
|
||||
const UnsupportedProtocol = () => {
|
||||
const t = useI18n("widget.iframe");
|
||||
|
||||
return (
|
||||
<Stack align="center" justify="center" h="100%">
|
||||
<IconProtocol />
|
||||
<Title order={4} ta="center">
|
||||
{t("error.unsupportedProtocol", {
|
||||
supportedProtocols: supportedProtocols.map((protocol) => protocol).join(", "),
|
||||
})}
|
||||
</Title>
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
|
||||
export const getAllowedPermissions = (
|
||||
permissions: Omit<WidgetComponentProps<"iframe">["options"], "embedUrl" | "allowScrolling">,
|
||||
) => {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { IconBrowser, IconExternalLink } from "@tabler/icons-react";
|
||||
|
||||
import { createWidgetDefinition } from "../definition";
|
||||
import { getSafeApplicationUrl } from "../common/application-url";
|
||||
import { optionsBuilder } from "../options";
|
||||
|
||||
const createOptions = () =>
|
||||
@@ -23,17 +22,17 @@ export const { definition, componentLoader } = createWidgetDefinition("iframe",
|
||||
supportsAdvancedFocus: false,
|
||||
icon: IconBrowser,
|
||||
contextActions: ({ options }) => {
|
||||
const embedUrl = getSafeApplicationUrl(options.embedUrl);
|
||||
return embedUrl
|
||||
? [
|
||||
{
|
||||
key: "open-iframe",
|
||||
label: "widget.common.openInNewTab.label",
|
||||
icon: IconExternalLink,
|
||||
onClick: () => window.open(embedUrl, "_blank", "noopener,noreferrer"),
|
||||
},
|
||||
]
|
||||
: [];
|
||||
const embedUrl = options.embedUrl;
|
||||
if (typeof embedUrl !== "string" || embedUrl.trim() === "") return [];
|
||||
|
||||
return [
|
||||
{
|
||||
key: "open-iframe",
|
||||
label: "widget.common.openInNewTab.label",
|
||||
icon: IconExternalLink,
|
||||
onClick: () => window.open(embedUrl, "_blank", "noopener,noreferrer"),
|
||||
},
|
||||
];
|
||||
},
|
||||
createOptions,
|
||||
}).withDynamicImport(() => import("./component"));
|
||||
@@ -68,10 +68,14 @@ export interface WidgetEditModalSize {
|
||||
height: number;
|
||||
}
|
||||
|
||||
export interface WidgetPreviewDimensions extends WidgetEditModalSize {
|
||||
scale?: number;
|
||||
}
|
||||
|
||||
interface WidgetEditPreviewResizeOptions {
|
||||
initialSize: WidgetEditModalSize;
|
||||
maximumSize: WidgetEditModalSize;
|
||||
getDimensions?: (size: WidgetEditModalSize) => { width: number; height: number; scale?: number };
|
||||
getDimensions?: (size: WidgetEditModalSize) => WidgetPreviewDimensions;
|
||||
}
|
||||
|
||||
export interface EmbeddedIntegrationEditFormHandle {
|
||||
@@ -99,7 +103,7 @@ export interface WidgetEditModalProps<TSort extends WidgetKind> {
|
||||
onIntegrationSaved?: () => void;
|
||||
onOpenNewIntegration?: (onCreated?: (id: string) => void) => void;
|
||||
previewComponent?: ComponentType<WidgetComponentProps<TSort>>;
|
||||
previewDimensions?: { width: number; height: number; scale?: number };
|
||||
previewDimensions?: WidgetPreviewDimensions;
|
||||
previewResize?: WidgetEditPreviewResizeOptions;
|
||||
previewWrapper?: ComponentType<PropsWithChildren>;
|
||||
}
|
||||
@@ -111,7 +115,7 @@ interface WidgetEditPreviewProps {
|
||||
state: WidgetEditModalState;
|
||||
itemId?: string;
|
||||
boardId?: string;
|
||||
dimensions?: { width: number; height: number; scale?: number };
|
||||
dimensions?: WidgetPreviewDimensions;
|
||||
integrationData: IntegrationSelectOption[];
|
||||
onChangeOptions: (newOptions: Record<string, unknown>) => void;
|
||||
resize?: {
|
||||
@@ -179,7 +183,9 @@ const WidgetEditPreview = ({
|
||||
},
|
||||
}));
|
||||
let componentItemId = itemId;
|
||||
if (kind === "assistant") componentItemId = `widget-preview-${generatedPreviewId}`;
|
||||
if (kind === "assistant" || kind === "timer") {
|
||||
componentItemId = `widget-preview-${generatedPreviewId}`;
|
||||
}
|
||||
const isPendingCustomWidget = kind === "customApi" && !itemId;
|
||||
const previewOpacity = (board?.opacity ?? 100) / 100;
|
||||
const handleResizeValue = (dimension: keyof WidgetEditModalSize, value: string | number) => {
|
||||
|
||||
Reference in new issue
Block a user