fix: resolve layout type errors in organize-imports-dialog
This commit is contained in:
1 parent
caeb4eb0b3
commit
683fee3bd9
2 files changed
+106
-49
No files matched your search
@@ -1,4 +1,8 @@
|
|||||||
import { sql } from "drizzle-orm";
|
import { sql } from "drizzle-orm";
|
||||||
|
import {
|
||||||
|
groupSuggestedCategories,
|
||||||
|
type SugFurniEntry,
|
||||||
|
} from "@/features/catalog/domain/organize";
|
||||||
import {
|
import {
|
||||||
getImportedCategoryPageIds,
|
getImportedCategoryPageIds,
|
||||||
getImportedRootCaption,
|
getImportedRootCaption,
|
||||||
@@ -193,9 +197,55 @@ export const GET = withAdmin(
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 5) Group on the server so the client only ever sees compact, ready-made
|
||||||
|
// categories instead of a giant raw item array.
|
||||||
|
type SugFurniEntryExtra = SugFurniEntry & {
|
||||||
|
alreadyPlaced?: boolean;
|
||||||
|
catalogItemId?: number;
|
||||||
|
spriteId?: number;
|
||||||
|
sourcePageCaption?: string;
|
||||||
|
itemId?: number;
|
||||||
|
};
|
||||||
|
// Map to the extended shape so groupSuggestedCategories accepts it,
|
||||||
|
// then we can use the extra fields in the returned groups.
|
||||||
|
const sugItems = items.map((it) => ({
|
||||||
|
id: it.itemId,
|
||||||
|
itemName: it.itemName,
|
||||||
|
publicName: it.publicName,
|
||||||
|
type: it.type,
|
||||||
|
spriteId: it.spriteId,
|
||||||
|
interactionType: it.interactionType,
|
||||||
|
alreadyPlaced: it.alreadyPlaced,
|
||||||
|
catalogItemId: it.catalogItemId,
|
||||||
|
})) as SugFurniEntryExtra[];
|
||||||
|
const groups = groupSuggestedCategories(sugItems).map((g) => {
|
||||||
|
const moved = g.items.filter((i) => i.alreadyPlaced).length;
|
||||||
|
return {
|
||||||
|
name: g.name,
|
||||||
|
icon: g.icon,
|
||||||
|
layout: g.layout?.layout ?? null,
|
||||||
|
total: g.items.length,
|
||||||
|
moved,
|
||||||
|
added: g.items.length - moved,
|
||||||
|
thumbs: g.items.slice(0, 12).map((i) => ({
|
||||||
|
itemName: i.itemName,
|
||||||
|
publicName: i.publicName,
|
||||||
|
spriteId: i.spriteId,
|
||||||
|
alreadyPlaced: i.alreadyPlaced,
|
||||||
|
sourcePageCaption: i.sourcePageCaption,
|
||||||
|
})),
|
||||||
|
items: g.items.map((i) => ({
|
||||||
|
itemId: i.itemId,
|
||||||
|
catalogItemId: i.catalogItemId,
|
||||||
|
alreadyPlaced: i.alreadyPlaced,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
const importRootPageId = pageIds[0] ?? null;
|
const importRootPageId = pageIds[0] ?? null;
|
||||||
return apiOk({
|
return apiOk({
|
||||||
items,
|
groups,
|
||||||
|
groupCount: groups.length,
|
||||||
total: items.length,
|
total: items.length,
|
||||||
importRootPageId,
|
importRootPageId,
|
||||||
importRootCaption: await getImportedRootCaption(),
|
importRootCaption: await getImportedRootCaption(),
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user