feat(studio): improve organize imports UX with validation limits and translations
CI / check (push) Failing after 30s
CI / deploy (push) Skipped
CI / publish-container (push) Skipped

This commit is contained in:
openhands committed 2026-09-12 19:24:55 +02:00
1 parent d2572757cd
commit 8707c0d8fe
3 files changed
+84 -23

No files matched your search

@@ -1,6 +1,7 @@
"use client"; "use client";
import { import {
ArrowRight,
Eye, Eye,
Folder, Folder,
FolderTree, FolderTree,
@@ -304,6 +305,10 @@ export function OrganizeImportsDialog({
const handleCreate = async () => { const handleCreate = async () => {
if (isCreating) return; if (isCreating) return;
if (totalSelected > 1000) {
toast.error(t("errorMaxItems"));
return;
}
if (moveMode && destinationPageId == null) { if (moveMode && destinationPageId == null) {
toast.error(t("chooseDestination")); toast.error(t("chooseDestination"));
return; return;
@@ -325,11 +330,20 @@ export function OrganizeImportsDialog({
credits: freeMode ? 0 : credits, credits: freeMode ? 0 : credits,
points: freeMode ? 0 : points, points: freeMode ? 0 : points,
pointsType: freeMode ? 0 : pointsType, pointsType: freeMode ? 0 : pointsType,
amount: 1,
})), })),
}; };
}); });
// Frontend validation for group count
const MAX_GROUPS = 50;
if (payload.length > MAX_GROUPS) {
toast.error(t("errorMaxGroups", { count: MAX_GROUPS }));
return;
}
if (payload.length === 0 || payload.some((g) => !g.caption)) { if (payload.length === 0 || payload.some((g) => !g.caption)) {
toast.error("Every approved page needs a name"); toast.error(t("errorNoName"));
return; return;
} }
setIsCreating(true); setIsCreating(true);
@@ -341,20 +355,28 @@ export function OrganizeImportsDialog({
const moved = created.reduce((sum, c) => sum + c.moved, 0); const moved = created.reduce((sum, c) => sum + c.moved, 0);
const added = created.reduce((sum, c) => sum + c.added, 0); const added = created.reduce((sum, c) => sum + c.added, 0);
toast.success( toast.success(
`Moved ${moved} offer${moved === 1 ? "" : "s"}${ t("successMove", {
added > 0 ? `, added ${added} new` : "" moved,
} to "${destinationCaption ?? "page"}"`, added,
destination: destinationCaption ?? "page",
}),
); );
} else { } else {
const moved = created.reduce((sum, c) => sum + c.moved, 0);
const added = created.reduce((sum, c) => sum + c.added, 0);
toast.success( toast.success(
`Created ${created.length} page${created.length === 1 ? "" : "s"}`, t("successCreate", {
count: created.length,
moved,
added,
}),
); );
} }
onOpenChange(false); onOpenChange(false);
router.refresh(); router.refresh();
} catch (error) { } catch (error) {
console.error("[OrganizeImports] create failed:", error); console.error("[OrganizeImports] create failed:", error);
toast.error("Failed to organize imports"); toast.error(t("errorFailed"));
} finally { } finally {
setIsCreating(false); setIsCreating(false);
} }
@@ -365,15 +387,21 @@ export function OrganizeImportsDialog({
<Dialog open={open} onOpenChange={onOpenChange}> <Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="flex h-[90vh] max-h-[90vh] w-[800px] max-w-[95vw] flex-col overflow-hidden p-0"> <DialogContent className="flex h-[90vh] max-h-[90vh] w-[800px] max-w-[95vw] flex-col overflow-hidden p-0">
<DialogHeader className="flex-none border-b px-4 py-3"> <DialogHeader className="flex-none border-b px-4 py-3">
<DialogTitle className="flex items-center gap-2 text-sm font-semibold"> <DialogTitle className="flex items-center gap-2 text-sm font-semibold">
<FolderTree className="h-4 w-4" /> <FolderTree className="h-4 w-4" />
{t("title")} {t("title")}
{totalSelected > 0 && !loading && ( {totalSelected > 0 && !loading && (
<Badge variant="secondary" className="text-[10px]"> <Badge variant="secondary" className="text-[10px]">
{t("itemsBadge", { count: totalSelected })} {t("itemsBadge", { count: totalSelected })}
</Badge> </Badge>
)} )}
</DialogTitle> <div className="flex-1 text-[10px] text-muted-foreground ml-2">
{moveMode
? t("tipMove")
: t("tipCreate")}
</div>
<p className="text-xs text-muted-foreground ml-2">{t("limitHint")}</p>
</DialogTitle>
</DialogHeader> </DialogHeader>
<div className="flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto p-4"> <div className="flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto p-4">
@@ -460,22 +488,24 @@ export function OrganizeImportsDialog({
type="button" type="button"
variant={!moveMode ? "default" : "outline"} variant={!moveMode ? "default" : "outline"}
size="sm" size="sm"
className="h-6 px-2 text-[10px]" className={cn("h-7 px-3 text-[11px] gap-1.5", !moveMode && "ring-2 ring-primary ring-offset-1")}
onClick={() => { onClick={() => {
setMoveMode(false); setMoveMode(false);
setDestinationPageId(null); setDestinationPageId(null);
setDestinationCaption(null); setDestinationCaption(null);
}} }}
> >
<Plus className="h-3.5 w-3.5" />
{t("modeCreate")} {t("modeCreate")}
</Button> </Button>
<Button <Button
type="button" type="button"
variant={moveMode ? "default" : "outline"} variant={moveMode ? "default" : "outline"}
size="sm" size="sm"
className="h-6 px-2 text-[10px]" className={cn("h-7 px-3 text-[11px] gap-1.5", moveMode && "ring-2 ring-primary ring-offset-1")}
onClick={() => setMoveMode(true)} onClick={() => setMoveMode(true)}
> >
<ArrowRight className="h-3.5 w-3.5" />
{t("modeMove")} {t("modeMove")}
</Button> </Button>
</div> </div>
@@ -656,7 +686,7 @@ export function OrganizeImportsDialog({
{/* Batch Actions Bar */} {/* Batch Actions Bar */}
<div className="flex flex-wrap items-center gap-2 border-t pt-2.5"> <div className="flex flex-wrap items-center gap-2 border-t pt-2.5">
<span className="text-[10px] font-medium text-muted-foreground"> <span className="text-[10px] font-medium text-muted-foreground">
Batch: {t("batchLabel")}
</span> </span>
<Select <Select
value={batchLayout} value={batchLayout}
@@ -673,7 +703,7 @@ export function OrganizeImportsDialog({
<SelectContent> <SelectContent>
{CATALOG_LAYOUTS.map((l) => ( {CATALOG_LAYOUTS.map((l) => (
<SelectItem key={l} value={l} className="text-xs"> <SelectItem key={l} value={l} className="text-xs">
{l} {l === "default_3x3" ? t("layoutFallbackDefault3x3") : l}
</SelectItem> </SelectItem>
))} ))}
</SelectContent> </SelectContent>
@@ -936,8 +966,11 @@ export function OrganizeImportsDialog({
{thumb.alreadyPlaced ? ( {thumb.alreadyPlaced ? (
<span className="max-w-14 truncate text-[8px] text-muted-foreground"> <span className="max-w-14 truncate text-[8px] text-muted-foreground">
{thumb.sourcePageCaption {thumb.sourcePageCaption
? thumb.sourcePageCaption.replace(/^Imp /, "") ? thumb.sourcePageCaption.replace(
: "moved"} new RegExp(`^${t("impPrefix")}`),
"",
)
: t("isMoved")}
</span> </span>
) : ( ) : (
<span className="max-w-14 truncate text-[8px] text-muted-foreground"> <span className="max-w-14 truncate text-[8px] text-muted-foreground">
+15 -1
View File
@@ -2251,7 +2251,21 @@
"searchGroups": "Filter import groups...", "searchGroups": "Filter import groups...",
"visualPreview": "Preview", "visualPreview": "Preview",
"resetAll": "Reset overrides", "resetAll": "Reset overrides",
"onlyUnplaced": "Only show unplaced items" "onlyUnplaced": "Only show unplaced items",
"errorMaxItems": "Max 1000 items per run. Reduce selection.",
"errorMaxGroups": "Max {count} groups per run. Reduce selection.",
"errorNoName": "Every approved page needs a name",
"tipMove": "Tip: Pick a destination page below to move furniture.",
"tipCreate": "Tip: Pick this mode to create new pages.",
"limitHint": "Max 1000 items and 50 groups per run.",
"errorFailed": "Failed to organize imports",
"successMove": "Moved {moved} offer{moved, plural, one {} other {s}}{added, plural, =0 {} other {, added {added} new}} to \"{destination}\"",
"successCreate": "Created {count, plural, one {1 page} other {# pages}} with {moved} moved and {added} added furniture",
"batchLabel": "Batch:",
"layoutFallbackDefault3x3": "3x3",
"itemsUnit": "items",
"impPrefix": "Imp ",
"isMoved": "moved"
} }
}, },
"bulk": { "bulk": {
+15 -1
View File
@@ -2013,7 +2013,21 @@
"searchGroups": "Filter importgroepen...", "searchGroups": "Filter importgroepen...",
"visualPreview": "Voorbeeld", "visualPreview": "Voorbeeld",
"resetAll": "Wijzigingen herstellen", "resetAll": "Wijzigingen herstellen",
"onlyUnplaced": "Toon alleen ongeplaatste items" "onlyUnplaced": "Toon alleen ongeplaatste items",
"errorMaxItems": "Maximaal 1000 items per run. Verlaag de selectie.",
"errorMaxGroups": "Maximaal {count} groepen per run. Verlaag de selectie.",
"errorNoName": "Elke goedgekeurde pagina heeft een naam nodig",
"tipMove": "Tip: Kies de doelpagina in het vak hieronder om meubels te verplaatsen.",
"tipCreate": "Tip: Kies deze modus om nieuwe pagina's aan te maken.",
"limitHint": "Maximaal 1000 items en 50 groepen per run.",
"errorFailed": "Kon imports niet organiseren",
"successMove": "{moved} item{moved, plural, one { verplaatst} other {s verplaatst}}{added, plural, =0 {} other {, {added} nieuw toegevoegd}} naar \"{destination}\"",
"successCreate": "{count, plural, one {1 pagina} other {# pagina's}} aangemaakt met {moved} verplaatste en {added} toegevoegde meubels",
"batchLabel": "Batch:",
"layoutFallbackDefault3x3": "3x3",
"itemsUnit": "items",
"impPrefix": "Imp ",
"isMoved": "verplaatst"
} }
}, },
"bulk": { "bulk": {