Harden catalog admin: fix translate/quick-add, RCON sync, and confirm UX.
Local Build and Deploy / deploy (push) Successful in 1m18s
Local Build and Deploy / deploy (push) Successful in 1m18s
Restore broken Quick Add search, correct Translate saves to items_base and FurnitureData, reparent page deletes, sync RCON on create/toggle/BC mutations, and replace native confirms/prompts with dialogs. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
de9f837da1
commit
b52e25578d
20 files changed
+557
-216
No files matched your search
@@ -118,45 +118,93 @@ export async function updateCatalogItem({
|
||||
export async function translateCatalogItems({
|
||||
items,
|
||||
}: {
|
||||
/** `id` is items_base.id (not catalog_items.id) */
|
||||
items: Array<{ id: number; publicName: string; description: string }>;
|
||||
}) {
|
||||
await requirePermission(PERMS.CATALOG_EDIT);
|
||||
const { invalidateFurniDataCache } = await import(
|
||||
"@/lib/services/catalog-items-loader"
|
||||
);
|
||||
const { patchFurniEntryNames } = await import("@/lib/services/furni-data");
|
||||
|
||||
let namesUpdated = 0;
|
||||
let descriptionsUpdated = 0;
|
||||
let furniDataUpdated = 0;
|
||||
const _furniDataInserted = 0;
|
||||
const furniPatches: Array<{
|
||||
classname: string;
|
||||
itemType: string;
|
||||
name?: string;
|
||||
description?: string;
|
||||
spriteId?: number;
|
||||
createIfMissing?: boolean;
|
||||
}> = [];
|
||||
|
||||
for (const item of items) {
|
||||
const existing = await prisma.catalogItems.findUnique({
|
||||
const base = await prisma.itemsBase.findUnique({
|
||||
where: { id: item.id },
|
||||
select: { catalogName: true },
|
||||
select: {
|
||||
id: true,
|
||||
publicName: true,
|
||||
itemName: true,
|
||||
type: true,
|
||||
spriteId: true,
|
||||
},
|
||||
});
|
||||
if (!existing) continue;
|
||||
if (!base) continue;
|
||||
|
||||
if (item.publicName && item.publicName !== existing.catalogName) {
|
||||
await prisma.catalogItems.update({
|
||||
where: { id: item.id },
|
||||
data: { catalogName: item.publicName },
|
||||
const nextName = item.publicName?.trim() ?? "";
|
||||
const nextDesc = item.description ?? "";
|
||||
const nameChanged = nextName !== "" && nextName !== (base.publicName ?? "");
|
||||
|
||||
if (nameChanged) {
|
||||
await prisma.itemsBase.update({
|
||||
where: { id: base.id },
|
||||
data: { publicName: nextName },
|
||||
});
|
||||
// Sync catalogName for catalog rows that reference this base item
|
||||
const idStr = String(base.id);
|
||||
const related = await prisma.catalogItems.findMany({
|
||||
where: {
|
||||
OR: [
|
||||
{ itemIds: idStr },
|
||||
{ itemIds: { startsWith: `${idStr};` } },
|
||||
{ itemIds: { contains: `;${idStr};` } },
|
||||
{ itemIds: { endsWith: `;${idStr}` } },
|
||||
],
|
||||
},
|
||||
select: { id: true, catalogName: true },
|
||||
});
|
||||
for (const row of related) {
|
||||
if (row.catalogName !== nextName) {
|
||||
await prisma.catalogItems.update({
|
||||
where: { id: row.id },
|
||||
data: { catalogName: nextName },
|
||||
});
|
||||
}
|
||||
}
|
||||
namesUpdated++;
|
||||
}
|
||||
|
||||
if (item.description) {
|
||||
const baseItem = await prisma.itemsBase.findFirst({
|
||||
where: { itemName: existing.catalogName },
|
||||
select: { id: true, publicName: true },
|
||||
if (nextDesc !== "" || nameChanged) {
|
||||
descriptionsUpdated += nextDesc !== "" ? 1 : 0;
|
||||
furniPatches.push({
|
||||
classname: base.itemName,
|
||||
itemType: base.type || "s",
|
||||
name: nextName || base.publicName || base.itemName,
|
||||
description: nextDesc,
|
||||
spriteId: base.spriteId,
|
||||
createIfMissing: true,
|
||||
});
|
||||
if (baseItem) {
|
||||
await prisma.itemsBase.update({
|
||||
where: { id: baseItem.id },
|
||||
data: { publicName: item.publicName || baseItem.publicName },
|
||||
});
|
||||
furniDataUpdated++;
|
||||
}
|
||||
descriptionsUpdated++;
|
||||
}
|
||||
}
|
||||
|
||||
const furniResult =
|
||||
furniPatches.length > 0
|
||||
? await patchFurniEntryNames(furniPatches)
|
||||
: { updated: 0, inserted: 0 };
|
||||
if (furniResult.updated > 0 || furniResult.inserted > 0) {
|
||||
invalidateFurniDataCache();
|
||||
}
|
||||
|
||||
await rcon.updateCatalog();
|
||||
revalidatePath("/admin/catalog");
|
||||
return {
|
||||
@@ -164,8 +212,8 @@ export async function translateCatalogItems({
|
||||
data: {
|
||||
namesUpdated,
|
||||
descriptionsUpdated,
|
||||
furniDataUpdated,
|
||||
furniDataInserted: 0,
|
||||
furniDataUpdated: furniResult.updated,
|
||||
furniDataInserted: furniResult.inserted,
|
||||
updated: items.length,
|
||||
},
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user