feat(workshop): rebuild install and publish as pages

Replace the stacked install modals (browse -> details -> import review)
with page-based flows so the primary action is always reachable:

- /manage/custom-widgets/workshop browses submissions as a card grid
  with large previews, sitting in a tab next to the installed widgets
- /manage/custom-widgets/workshop/[id] merges the listing, security
  review and source setup onto one page with a sticky install footer
- /manage/custom-widgets/publish/[id] replaces the publish modal
- /manage/workshop redirects; its navbar entry is gone
- the Custom CSS picker collapses from three modals to one

Extract useCustomWidgetImport and ImportReviewContent so the Workshop
page and the file/clipboard dialog share one import pipeline.

Votes now show the viewer's own choice filled Reddit-style, backed by a
new user-votes query, and screenshots get a zoomable lightbox.

Rework the installed list onto ManageCollectionItem: show the widget
description, replace the cryptic "JSX - 2" badge with plain request and
origin facts, and swap the toggle and bare pencil for a status badge,
a labelled Edit button and a menu entry for enable/disable.

Fixes found while reviewing:

- importing could run twice and duplicate a widget; guard on pending and
  succeeded, and return to the installed list instead of the heavy edit
  form
- a background refetch of the submission (window focus, or the
  invalidation a vote triggers) reset the source setup and silently wiped
  part-typed credentials; key the reset on the sources, not the object
- breadcrumbs raised MISSING_MESSAGE for unmapped dynamic segments; fall
  back to the raw segment via t.has
- publishing had no in-flight guard and could post duplicate listings
- tooltips on disabled vote and report controls never fired, making the
  sign-in hint unreachable
This commit is contained in:
Thomas Camlong committed 2026-08-17 01:14:38 +02:00
1 parent 50537d077c
commit 206905ea2d
38 files changed
+2303 -1700

No files matched your search

@@ -6,17 +6,42 @@ import { describe, expect, test } from "vitest";
const languageDirectory = resolve(import.meta.dirname, "../../../translation/src/lang");
describe("Workshop navigation translations", () => {
test("defines the navbar and breadcrumb label in the source locale", async () => {
test("defines the breadcrumb labels for the Custom Widgets sub-routes", async () => {
const messages = JSON.parse(await readFile(resolve(languageDirectory, "en.json"), "utf8")) as {
management?: { navbar?: { items?: { workshop?: unknown } } };
navigationStructure?: { manage?: { workshop?: { label?: unknown } } };
navigationStructure?: {
manage?: {
workshop?: unknown;
"custom-widgets"?: {
workshop?: { label?: unknown };
publish?: { label?: unknown };
};
};
};
customWidget?: { page?: { tabs?: Record<string, unknown> } };
workshop?: Record<string, unknown>;
};
expect(messages.management?.navbar?.items?.workshop).toBe("Workshop");
expect(messages.navigationStructure?.manage?.workshop?.label).toBe("Workshop");
// The Workshop is reached through the Custom Widgets tabs, not its own navbar entry.
expect(messages.management?.navbar?.items?.workshop).toBeUndefined();
expect(messages.navigationStructure?.manage?.workshop).toBeUndefined();
expect(messages.navigationStructure?.manage?.["custom-widgets"]?.workshop?.label).toBe("Workshop");
expect(messages.navigationStructure?.manage?.["custom-widgets"]?.publish?.label).toBe("Publish to Workshop");
expect(messages.customWidget?.page?.tabs).toMatchObject({
installed: "Installed",
workshop: "Workshop",
ariaLabel: expect.any(String),
});
expect(messages.workshop).toMatchObject({
communityMember: "Community member",
outdated: "Outdated",
install: "Install",
back: expect.any(String),
listAriaLabel: expect.any(String),
installReviewTitle: expect.any(String),
emptyFilteredDescription: expect.any(String),
importCssConfirm: expect.any(String),
reportCount: expect.any(String),
reportWarning: expect.any(String),
reportVisibility: expect.any(String),
@@ -31,7 +56,19 @@ describe("Workshop navigation translations", () => {
inappropriate: expect.any(String),
other: expect.any(String),
}),
publish: expect.objectContaining({ invalidScreenshot: expect.any(String) }),
publish: expect.objectContaining({
invalidScreenshot: expect.any(String),
}),
});
});
test("drops the message keys that only existed for the stacked install modals", async () => {
const messages = JSON.parse(await readFile(resolve(languageDirectory, "en.json"), "utf8")) as {
workshop?: Record<string, unknown>;
};
for (const key of ["installDialog", "continueInstall", "confirmInstallTitle", "backToWidget", "inspectCss"]) {
expect(messages.workshop).not.toHaveProperty(key);
}
});
});
@@ -1,24 +1,11 @@
import type { ReactNode } from "react";
import {
Alert,
Badge,
Box,
Button,
Code,
Group,
Modal,
Paper,
SimpleGrid,
Stack,
Text,
} from "@mantine/core";
import { Alert, Badge, Box, Button, Code, Group, Modal, Paper, SimpleGrid, Stack, Text } from "@mantine/core";
import type { ModalProps } from "@mantine/core";
import { IconAlertTriangle } from "@tabler/icons-react";
import type { ImportReview } from "../core/import";
export interface ImportReviewMessages {
title: string;
export interface ImportReviewContentMessages {
description: string;
name: string;
origin: string;
@@ -28,9 +15,13 @@ export interface ImportReviewMessages {
permissions: string;
actionWarningTitle: string;
actionWarningDescription: string;
permission(permission: string): string;
}
export interface ImportReviewMessages extends ImportReviewContentMessages {
title: string;
cancel: string;
confirm: string;
permission(permission: string): string;
}
export interface ImportReviewDialogProps {
@@ -75,6 +66,71 @@ function ImportFact({ label, value }: { label: string; value: string }) {
);
}
export interface ImportReviewContentProps {
review: ImportReview;
messages: ImportReviewContentMessages;
children?: ReactNode;
}
/**
* The security facts a user has to review before a custom widget is installed.
* Shared by the import modal and the Workshop install page so both read identically.
*/
export function ImportReviewContent({ review, messages, children }: ImportReviewContentProps) {
return (
<Stack gap="md">
<Text size="sm" c="dimmed">
{messages.description}
</Text>
<SimpleGrid cols={{ base: 1, sm: 2 }} spacing="xs">
<ImportFact label={messages.name} value={review.name} />
<ImportFact label={messages.origin} value={review.origins.join(", ")} />
<ImportFact label={messages.authentication} value={review.authTypes.join(", ")} />
<ImportFact label={messages.networkScope} value={review.networkScopes.join(", ")} />
</SimpleGrid>
<SimpleGrid cols={{ base: 1, sm: 2 }} spacing="md">
<div>
<Text size="sm" fw={600} mb={6}>
{messages.methods}
</Text>
<Group gap={6}>
{review.methods.map((method) => (
<Badge
key={method}
color={method === "DELETE" ? "red" : method === "GET" ? "blue" : "orange"}
variant="light"
>
{method}
</Badge>
))}
</Group>
</div>
<div>
<Text size="sm" fw={600} mb={6}>
{messages.permissions}
</Text>
<Group gap={6}>
{review.permissions.map((permission) => (
<Badge key={permission} color="gray" variant="light">
{messages.permission(permission)}
</Badge>
))}
</Group>
</div>
</SimpleGrid>
{review.hasActions && (
<Alert color="yellow" icon={<IconAlertTriangle size={16} />}>
<Text size="sm" fw={600}>
{messages.actionWarningTitle}
</Text>
<Text size="sm">{messages.actionWarningDescription}</Text>
</Alert>
)}
{children}
</Stack>
);
}
export function ImportReviewDialog({
opened,
review,
@@ -103,56 +159,9 @@ export function ImportReviewDialog({
{review && (
<>
<Box p="lg" style={{ flex: 1, minHeight: 0, overflowY: "auto" }}>
<Stack gap="md">
<Text size="sm" c="dimmed">
{messages.description}
</Text>
<SimpleGrid cols={{ base: 1, sm: 2 }} spacing="xs">
<ImportFact label={messages.name} value={review.name} />
<ImportFact label={messages.origin} value={review.origins.join(", ")} />
<ImportFact label={messages.authentication} value={review.authTypes.join(", ")} />
<ImportFact label={messages.networkScope} value={review.networkScopes.join(", ")} />
</SimpleGrid>
<SimpleGrid cols={{ base: 1, sm: 2 }} spacing="md">
<div>
<Text size="sm" fw={600} mb={6}>
{messages.methods}
</Text>
<Group gap={6}>
{review.methods.map((method) => (
<Badge
key={method}
color={method === "DELETE" ? "red" : method === "GET" ? "blue" : "orange"}
variant="light"
>
{method}
</Badge>
))}
</Group>
</div>
<div>
<Text size="sm" fw={600} mb={6}>
{messages.permissions}
</Text>
<Group gap={6}>
{review.permissions.map((permission) => (
<Badge key={permission} color="gray" variant="light">
{messages.permission(permission)}
</Badge>
))}
</Group>
</div>
</SimpleGrid>
{review.hasActions && (
<Alert color="yellow" icon={<IconAlertTriangle size={16} />}>
<Text size="sm" fw={600}>
{messages.actionWarningTitle}
</Text>
<Text size="sm">{messages.actionWarningDescription}</Text>
</Alert>
)}
<ImportReviewContent review={review} messages={messages}>
{children}
</Stack>
</ImportReviewContent>
</Box>
<Box
px="lg"
+53 -47
View File
@@ -831,7 +831,12 @@
"list": {
"title": "Custom Widgets",
"noResults": "No custom widgets yet. Create your first one!",
"noDescription": "No description",
"loading": "Loading...",
"enabled": "Enabled",
"disabled": "Disabled",
"disabledDescription": "This widget stays configured but will not load on any board.",
"requestCount": "{count, plural, one {# request} other {# requests}}",
"invalidDefinition": "Invalid definition",
"invalidDefinitionDescription": "This stored widget no longer matches the current Custom Widget schema. Delete it and recreate or import a valid definition.",
"migrationRequired": "Migration required",
@@ -846,6 +851,11 @@
},
"edit": {
"title": "Edit Custom Widget"
},
"tabs": {
"ariaLabel": "Custom widget sections",
"installed": "Installed",
"workshop": "Workshop"
}
},
"action": {
@@ -1382,69 +1392,68 @@
}
},
"workshop": {
"installSuccess": "Custom widget installed",
"installSuccessDescription": "Add its credentials, test the requests, and save when it is ready.",
"installError": "Could not install widget",
"installErrorDescription": "The Workshop submission is not a valid Custom JSX v2 widget.",
"title": "Workshop",
"importFromWorkshop": "Import from Workshop",
"browseWorkshop": "Browse Workshop",
"openCommunity": "Open Workshop",
"manageSubmissionsTitle": "Manage submissions on Workshop",
"manageSubmissionsDescription": "Publishing starts in Homarr, but updates, reports, outdated status, and deletion are managed directly on the Workshop website. Sign in there and select Yours to find your submissions.",
"description": "Community Custom JSX v2 widgets. Inspect the source and network capabilities before installing.",
"descriptionCss": "Community Custom CSS themes. Preview every rule before importing it into a board.",
"securityNotice": "Workshop widgets can call their declared API sources and perform declared actions with credentials you configure locally. Secrets are never included.",
"securityNoticeCss": "Community CSS can change the appearance and usability of a board. Review it before importing; nothing is saved until you save board settings.",
"signIn": "Sign in with GitHub",
"signInError": "GitHub sign-in failed. Check that the Workshop OAuth provider is configured and that popups are allowed.",
"signOut": "Sign out",
"openOnWorkshop": "Open {title} on the Workshop website",
"back": "Back to Workshop",
"cancel": "Cancel",
"search": "Search widgets",
"searchCss": "Search CSS themes",
"sort": "Sort",
"sortTop": "Top rated",
"sortNewest": "Newest",
"listAriaLabel": "Workshop widgets",
"listAriaLabelCss": "Workshop CSS themes",
"empty": "No widgets match this search.",
"emptyDescription": "Community widgets published to the Workshop show up here.",
"emptyFilteredTitle": "No widgets match this search",
"emptyFilteredDescription": "No Workshop widget matches \"{search}\".",
"clearSearch": "Clear search",
"emptyCss": "No CSS themes match this search.",
"unavailableTitle": "Homarr Workshop seems to be unavailable",
"unavailable": "The community service may be temporarily down. Try again in a moment. Your installed widgets are unaffected.",
"retry": "Try again",
"empty": "No widgets match this search.",
"emptyCss": "No CSS themes match this search.",
"loadError": "This submission could not be loaded.",
"noDescription": "No description",
"author": "by {name}",
"communityMember": "Community member",
"comments": "{count, plural, one {# comment} other {# comments}}",
"viewDetails": "View details",
"voteSummary": "{upvotes, plural, one {# upvote} other {# upvotes}}, {downvotes, plural, one {# downvote} other {# downvotes}}",
"outdated": "Outdated",
"outdatedWarning": "The author marked this submission as outdated. Review it carefully before importing.",
"reportCount": "{count, plural, one {# report} other {# reports}}",
"reportWarning": "{count, plural, one {This submission has # open community report.} other {This submission has # open community reports.}} It remains installable, but you should review its content first.",
"reportVisibility": "Report details are visible only to this submission's author and Workshop admins.",
"screenshotAlt": "{title} screenshot {count, number}",
"upvote": "Upvote, {count, plural, one {# vote} other {# votes}}",
"downvote": "Downvote, {count, plural, one {# vote} other {# votes}}",
"score": "Score: {count, number}",
"inspectCss": "Inspect CSS",
"upvote": "Upvote",
"downvote": "Downvote",
"voteError": "The vote could not be saved.",
"signIn": "Sign in with GitHub",
"signInError": "GitHub sign-in failed. Check that the Workshop OAuth provider is configured and that popups are allowed.",
"signOut": "Sign out",
"signInHint": "Sign in to vote or report. Installing does not require a Workshop account.",
"securityNotice": "Workshop widgets can call their declared API sources and perform declared actions with credentials you configure locally. Secrets are never included.",
"securityNoticeCss": "Community CSS can change the appearance and usability of a board. Review it before importing; nothing is saved until you save board settings.",
"install": "Install",
"installReviewTitle": "Review before installing",
"installError": "This widget cannot be installed",
"installErrorDescription": "The Workshop submission is not a valid Custom JSX v2 widget.",
"useCss": "Import CSS",
"importCss": "Import CSS from Workshop",
"importCssConfirm": "Replace the current custom CSS with \"{title}\"? Nothing is saved until you save the board settings.",
"screenshotAlt": "{title} screenshot {count, number}",
"zoomScreenshot": "View full size",
"previousScreenshot": "Previous screenshot",
"nextScreenshot": "Next screenshot",
"technicalDetails": "Technical details",
"sourceCode": "Workshop entry",
"loadError": "This submission could not be loaded.",
"sources": "Declared API sources",
"requests": "Declared queries and actions",
"noRequests": "This widget does not declare network requests.",
"export": "Export",
"report": "Report",
"install": "Install widget",
"continueInstall": "Continue installation",
"confirmInstallTitle": "Confirm widget installation",
"confirmInstallDescription": "Confirm where this widget connects and add any credentials required by your Homarr installation.",
"backToWidget": "Back to widget",
"useCss": "Import CSS",
"signInHint": "Sign in to vote or report. Installing does not require a Workshop account.",
"reportTitle": "Report submission",
"reportReason": "Reason",
"reportExplanation": "What should the Workshop moderators know?",
"reportSend": "Send report",
"reportSent": "Report sent",
"reportSentDescription": "Workshop moderators can now review this submission.",
"reportCount": "{count, plural, one {# report} other {# reports}}",
"reportWarning": "{count, plural, one {This submission has # open community report.} other {This submission has # open community reports.}} It remains installable, but you should review its content first.",
"reportVisibility": "Report details are visible only to this submission's author and Workshop admins.",
"reportCategory": {
"outdated": "Outdated or no longer working",
"malicious": "Malicious",
@@ -1453,7 +1462,6 @@
"inappropriate": "Inappropriate",
"other": "Other"
},
"voteError": "The vote could not be saved.",
"publish": {
"title": "Publish to Workshop",
"introTitle": "Share this widget with the community",
@@ -1462,7 +1470,6 @@
"listingDetailsDescription": "These details appear publicly alongside the exported widget definition.",
"success": "Published immediately. Community members can now install and report this widget.",
"successTitle": "Your widget is live",
"manageTitle": "Continue on Workshop",
"manageDescription": "Open the submission to update its listing, review reports, mark it outdated, or delete it. Submission management is handled directly on the Workshop website.",
"viewSubmission": "View and manage submission",
"done": "Done",
@@ -1481,10 +1488,7 @@
"publicationNote": "Publishing is immediate. You can manage the submission afterward on Workshop.",
"definitionChanged": "The widget changed while publication was being prepared. Review its private source URLs again, then retry.",
"error": "Publication failed"
},
"installDialog": "Install from Workshop",
"installed": "Widget installed",
"installedDescription": "{name} is ready to configure."
}
},
"integration": {
"page": {
@@ -5970,7 +5974,6 @@
"apps": "Apps",
"integrations": "Integrations",
"customWidgets": "Custom Widgets",
"workshop": "Workshop",
"searchEngies": "Search engines",
"medias": "Medias",
"users": {
@@ -7350,11 +7353,14 @@
"flow": {
"label": "Flow"
}
},
"workshop": {
"label": "Workshop"
},
"publish": {
"label": "Publish to Workshop"
}
},
"workshop": {
"label": "Workshop"
},
"users": {
"label": "Users",
"create": {
+16 -1
View File
@@ -657,6 +657,8 @@ export const workshopQueryKeys = {
] as const,
comments: (backend: WorkshopBackend, submission: string) =>
[...workshopQueryKeys.all, "comments", backend.baseUrl, submission] as const,
userVotes: (backend: WorkshopBackend) =>
[...workshopQueryKeys.all, "user-votes", backend.baseUrl, backend.currentUser?.id ?? "anonymous"] as const,
};
export const workshopListQueryOptions = (backend: WorkshopBackend, options: WorkshopListOptions = {}) =>
@@ -683,6 +685,14 @@ export const workshopReportSummariesQueryOptions = (backend: WorkshopBackend, su
enabled: submission.length > 0,
});
/** The votes the signed-in user already cast, so controls can render their own choice. */
export const workshopUserVotesQueryOptions = (backend: WorkshopBackend) =>
queryOptions({
queryKey: workshopQueryKeys.userVotes(backend),
queryFn: () => backend.listVotesForCurrentUser(),
enabled: backend.currentUser !== null,
});
export const workshopCommentsQueryOptions = (backend: WorkshopBackend, submission: string) =>
queryOptions({
queryKey: workshopQueryKeys.comments(backend, submission),
@@ -771,12 +781,17 @@ export function useWorkshopCommentsQuery(backend: WorkshopBackend, submission: s
return useQuery(workshopCommentsQueryOptions(backend, submission));
}
export function useWorkshopUserVotesQuery(backend: WorkshopBackend) {
return useQuery(workshopUserVotesQueryOptions(backend));
}
function useWorkshopInvalidation(backend: WorkshopBackend) {
const queryClient = useQueryClient();
return {
lists: () => queryClient.invalidateQueries({ queryKey: workshopQueryKeys.lists(backend.baseUrl) }),
details: () => queryClient.invalidateQueries({ queryKey: workshopQueryKeys.details(backend.baseUrl) }),
detail: (id: string) => queryClient.invalidateQueries({ queryKey: workshopQueryKeys.detail(backend, id) }),
userVotes: () => queryClient.invalidateQueries({ queryKey: workshopQueryKeys.userVotes(backend) }),
removeDetail: (id: string) => queryClient.removeQueries({ queryKey: workshopQueryKeys.detail(backend, id) }),
reports: () => queryClient.invalidateQueries({ queryKey: workshopQueryKeys.reports(backend) }),
reportSummaries: (submission: string) =>
@@ -814,7 +829,7 @@ export function useWorkshopVoteMutation(backend: WorkshopBackend) {
const invalidation = useWorkshopInvalidation(backend);
return useMutation({
...workshopVoteMutationOptions(backend),
onSuccess: async () => Promise.all([invalidation.lists(), invalidation.details()]),
onSuccess: async () => Promise.all([invalidation.lists(), invalidation.details(), invalidation.userVotes()]),
});
}