feat(studio): allow moving imports into an existing page instead of creating ones
CI / check (push) Successful in 2m31s
CI / deploy (push) Successful in 1m19s
CI / publish-container (push) Successful in 45s

Adds a second mode to the organize-imports dialog: instead of creating
one new page per approved group (which could produce dozens of tiny
pages), the user can pick an existing destination page and have every
approved item moved into it.  No catalog page is created in this mode.

- organizeImportFurni: groups accept destinationPageId; when set, the
  existing page is reused, new offers append after its current highest
  order, moved offers keep their original name, and the real page
  caption is used for logging and results
- OrganizeImportsDialog: mode toggle (create pages / move into page),
  searchable destination picker via /api/admin/catalog/tree?search=,
  name/icon/layout editors hidden in move mode, button shows a move
  count, and the success toast reports moved/added instead of pages
- en + nl translations for the new mode, destination, and move keys
This commit is contained in:
openhands committed 2026-09-11 20:44:26 +02:00
1 parent 61c7519bea
commit caeb4eb0b3
4 files changed
+395 -148

No files matched your search

+63 -25
View File
@@ -355,6 +355,8 @@ export interface OrganizeImportGroup {
caption: string;
pageLayout: string;
iconImage: number;
/** When set, items are moved into this existing page instead of creating one. */
destinationPageId?: number | null;
items: Array<{
itemId: number;
catalogItemId: number | null;
@@ -420,25 +422,54 @@ export async function organizeImportFurni(input: {
let totalAdded = 0;
for (const group of groups) {
const pageId = Number(
await createPageCommand("normal", {
caption: group.caption,
parentId: input.parentId,
pageLayout: group.pageLayout || "default_3x3",
captionSave: group.caption.slice(0, 25),
iconImage: group.iconImage ?? 0,
iconColor: 0,
minRank: 1,
orderNum: 0,
visible: "1",
enabled: "1",
clubOnly: "0",
vipOnly: "0",
pageHeadline: "",
pageTeaser: "",
includes: "",
}),
);
// Either create a fresh page or reuse an existing destination.
const destinationPageId = group.destinationPageId
? Number(group.destinationPageId)
: null;
if (destinationPageId != null && !Number.isFinite(destinationPageId)) {
return {
ok: false as const,
error: "Invalid destination page id",
};
}
const pageId =
destinationPageId ??
Number(
await createPageCommand("normal", {
caption: group.caption,
parentId: input.parentId,
pageLayout: group.pageLayout || "default_3x3",
captionSave: group.caption.slice(0, 25),
iconImage: group.iconImage ?? 0,
iconColor: 0,
minRank: 1,
orderNum: 0,
visible: "1",
enabled: "1",
clubOnly: "0",
vipOnly: "0",
pageHeadline: "",
pageTeaser: "",
includes: "",
}),
);
let destinationCaption: string | null = null;
if (destinationPageId) {
const [captionRows] = (await db.execute(sql`
SELECT caption FROM catalog_pages WHERE id = ${destinationPageId}
`)) as unknown as [Array<{ caption: string }>, unknown];
destinationCaption = captionRows[0]?.caption ?? null;
}
const caption =
destinationCaption ?? group.caption ?? `Category ${pageId}`;
// Existing destinations append after their current offers; freshly
// created pages start at order 1.
const [maxOrder] = (await db.execute(sql`
SELECT COALESCE(MAX(order_number), 0) AS maxOrder
FROM catalog_items WHERE page_id = ${pageId}
`)) as unknown as [{ maxOrder: number }, unknown];
let nextOrder = Number(maxOrder?.maxOrder ?? 0) + 1;
const baseIds = [...new Set(group.items.map((r) => r.itemId))];
const bases = await db
@@ -475,7 +506,6 @@ export async function organizeImportFurni(input: {
}
}
let nextOrder = 1;
let moved = 0;
let added = 0;
@@ -529,11 +559,17 @@ export async function organizeImportFurni(input: {
}
if (moveIds.length > 0) {
// Preserve existing offer names when moving into an existing
// destination; freshly created pages get the base item's name.
const nameUpdate =
destinationPageId == null
? sql`, catalog_name = CASE id ${sql.raw(moveCaseName.join(" "))} END`
: sql``;
await db.execute(sql`
UPDATE catalog_items
SET page_id = ${pageId},
order_number = CASE id ${sql.raw(moveCaseOrder.join(" "))} END,
catalog_name = CASE id ${sql.raw(moveCaseName.join(" "))} END
order_number = CASE id ${sql.raw(moveCaseOrder.join(" "))} END
${nameUpdate}
WHERE id IN (${sql.join(
moveIds.map((id) => sql`${id}`),
sql`, `,
@@ -543,12 +579,14 @@ export async function organizeImportFurni(input: {
await logStaffActivity({
staffId: staff.id,
action: "catalog_page_create",
description: `Organized import into page #${pageId} "${group.caption}" (${moved} moved, ${added} added)`,
action: destinationPageId
? "catalog_items_bulk_update"
: "catalog_page_create",
description: `Organized import into page #${pageId} "${caption}" (${moved} moved, ${added} added)`,
targetType: "catalog_page",
targetId: pageId,
});
created.push({ pageId, caption: group.caption, moved, added });
created.push({ pageId, caption, moved, added });
totalMoved += moved;
totalAdded += added;
}