feat(studio): allow moving imports into an existing page instead of creating ones
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:
1 parent
61c7519bea
commit
caeb4eb0b3
4 files changed
+260
-13
No files matched your search
+45
-7
@@ -355,6 +355,8 @@ export interface OrganizeImportGroup {
|
|||||||
caption: string;
|
caption: string;
|
||||||
pageLayout: string;
|
pageLayout: string;
|
||||||
iconImage: number;
|
iconImage: number;
|
||||||
|
/** When set, items are moved into this existing page instead of creating one. */
|
||||||
|
destinationPageId?: number | null;
|
||||||
items: Array<{
|
items: Array<{
|
||||||
itemId: number;
|
itemId: number;
|
||||||
catalogItemId: number | null;
|
catalogItemId: number | null;
|
||||||
@@ -420,7 +422,19 @@ export async function organizeImportFurni(input: {
|
|||||||
let totalAdded = 0;
|
let totalAdded = 0;
|
||||||
|
|
||||||
for (const group of groups) {
|
for (const group of groups) {
|
||||||
const pageId = Number(
|
// 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", {
|
await createPageCommand("normal", {
|
||||||
caption: group.caption,
|
caption: group.caption,
|
||||||
parentId: input.parentId,
|
parentId: input.parentId,
|
||||||
@@ -439,6 +453,23 @@ export async function organizeImportFurni(input: {
|
|||||||
includes: "",
|
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 baseIds = [...new Set(group.items.map((r) => r.itemId))];
|
||||||
const bases = await db
|
const bases = await db
|
||||||
@@ -475,7 +506,6 @@ export async function organizeImportFurni(input: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let nextOrder = 1;
|
|
||||||
let moved = 0;
|
let moved = 0;
|
||||||
let added = 0;
|
let added = 0;
|
||||||
|
|
||||||
@@ -529,11 +559,17 @@ export async function organizeImportFurni(input: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (moveIds.length > 0) {
|
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`
|
await db.execute(sql`
|
||||||
UPDATE catalog_items
|
UPDATE catalog_items
|
||||||
SET page_id = ${pageId},
|
SET page_id = ${pageId},
|
||||||
order_number = CASE id ${sql.raw(moveCaseOrder.join(" "))} END,
|
order_number = CASE id ${sql.raw(moveCaseOrder.join(" "))} END
|
||||||
catalog_name = CASE id ${sql.raw(moveCaseName.join(" "))} END
|
${nameUpdate}
|
||||||
WHERE id IN (${sql.join(
|
WHERE id IN (${sql.join(
|
||||||
moveIds.map((id) => sql`${id}`),
|
moveIds.map((id) => sql`${id}`),
|
||||||
sql`, `,
|
sql`, `,
|
||||||
@@ -543,12 +579,14 @@ export async function organizeImportFurni(input: {
|
|||||||
|
|
||||||
await logStaffActivity({
|
await logStaffActivity({
|
||||||
staffId: staff.id,
|
staffId: staff.id,
|
||||||
action: "catalog_page_create",
|
action: destinationPageId
|
||||||
description: `Organized import into page #${pageId} "${group.caption}" (${moved} moved, ${added} added)`,
|
? "catalog_items_bulk_update"
|
||||||
|
: "catalog_page_create",
|
||||||
|
description: `Organized import into page #${pageId} "${caption}" (${moved} moved, ${added} added)`,
|
||||||
targetType: "catalog_page",
|
targetType: "catalog_page",
|
||||||
targetId: pageId,
|
targetId: pageId,
|
||||||
});
|
});
|
||||||
created.push({ pageId, caption: group.caption, moved, added });
|
created.push({ pageId, caption, moved, added });
|
||||||
totalMoved += moved;
|
totalMoved += moved;
|
||||||
totalAdded += added;
|
totalAdded += added;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
@@ -2209,6 +2209,16 @@
|
|||||||
"desc": "Imported furniture is grouped into suggested pages. Review each group, then create the pages you approve.",
|
"desc": "Imported furniture is grouped into suggested pages. Review each group, then create the pages you approve.",
|
||||||
"selectAll": "Select all",
|
"selectAll": "Select all",
|
||||||
"deselectAll": "Deselect all",
|
"deselectAll": "Deselect all",
|
||||||
|
"mode": "Mode",
|
||||||
|
"modeCreate": "Create new pages",
|
||||||
|
"modeMove": "Move into an existing page",
|
||||||
|
"destination": "Destination page",
|
||||||
|
"destinationChosen": "selected",
|
||||||
|
"destinationSearchPlaceholder": "Search pages by name…",
|
||||||
|
"noDestResults": "No pages found",
|
||||||
|
"destinationHint": "All approved groups are moved into this page — no new page is created.",
|
||||||
|
"chooseDestination": "Pick a destination page first",
|
||||||
|
"move": "Move {count, plural, one {1 item} other {# items}}",
|
||||||
"name": "Name",
|
"name": "Name",
|
||||||
"icon": "Icon",
|
"icon": "Icon",
|
||||||
"layout": "Layout",
|
"layout": "Layout",
|
||||||
|
|||||||
@@ -1977,6 +1977,16 @@
|
|||||||
"desc": "Geïmporteerde meubels worden gegroepeerd in voorgestelde pagina's. Bekijk elke groep en maak alleen de pagina's aan die je goedkeurt.",
|
"desc": "Geïmporteerde meubels worden gegroepeerd in voorgestelde pagina's. Bekijk elke groep en maak alleen de pagina's aan die je goedkeurt.",
|
||||||
"selectAll": "Alles selecteren",
|
"selectAll": "Alles selecteren",
|
||||||
"deselectAll": "Alles deselecteren",
|
"deselectAll": "Alles deselecteren",
|
||||||
|
"mode": "Modus",
|
||||||
|
"modeCreate": "Nieuwe pagina's aanmaken",
|
||||||
|
"modeMove": "Verplaatsen naar bestaande pagina",
|
||||||
|
"destination": "Doelpagina",
|
||||||
|
"destinationChosen": "geselecteerd",
|
||||||
|
"destinationSearchPlaceholder": "Zoek pagina's op naam…",
|
||||||
|
"noDestResults": "Geen pagina's gevonden",
|
||||||
|
"destinationHint": "Alle goedgekeurde groepen worden naar deze pagina verplaatst — er wordt geen nieuwe pagina aangemaakt.",
|
||||||
|
"chooseDestination": "Kies eerst een doelpagina",
|
||||||
|
"move": "{count, plural, one {1 item verplaatsen} other {# items verplaatsen}}",
|
||||||
"name": "Naam",
|
"name": "Naam",
|
||||||
"icon": "Icoon",
|
"icon": "Icoon",
|
||||||
"layout": "Indeling",
|
"layout": "Indeling",
|
||||||
|
|||||||
Reference in new issue
Block a user