Fix Visual Manager empty categories: seed roots, harden tree API.
Local Build and Deploy / deploy (push) Successful in 56s
Local Build and Deploy / deploy (push) Successful in 56s
Seed root tabs from SSR, load the full tree without CLEAR_TREE races, coerce parent ids, and tolerate catalog_items page_id type mismatches so category pages actually appear. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
385cefd0fa
commit
1d8efefce4
6 files changed
+285
-187
No files matched your search
@@ -142,12 +142,35 @@ function reducer(
|
||||
case "SET_FULL_TREE": {
|
||||
const nodes = new Map<number, TreeNodeData>();
|
||||
const childrenMap = new Map<number, number[]>();
|
||||
for (const n of action.nodes) {
|
||||
nodes.set(n.id, n);
|
||||
for (const raw of action.nodes) {
|
||||
const id = Number(raw.id);
|
||||
const parentId = Number(raw.parentId);
|
||||
if (!Number.isFinite(id)) continue;
|
||||
const n: TreeNodeData = {
|
||||
...raw,
|
||||
id,
|
||||
parentId: Number.isFinite(parentId) ? parentId : -1,
|
||||
enabled: String(raw.enabled ?? "0"),
|
||||
visible: String(raw.visible ?? "0"),
|
||||
childCount: Number(raw.childCount) || 0,
|
||||
itemCount: Number(raw.itemCount) || 0,
|
||||
iconImage: Number(raw.iconImage) || 0,
|
||||
iconColor: Number(raw.iconColor) || 0,
|
||||
orderNum: Number(raw.orderNum) || 0,
|
||||
};
|
||||
nodes.set(id, n);
|
||||
const siblings = childrenMap.get(n.parentId) || [];
|
||||
siblings.push(n.id);
|
||||
siblings.push(id);
|
||||
childrenMap.set(n.parentId, siblings);
|
||||
}
|
||||
// Roots may be parent_id -1 or 0 — mirror both keys so tabs resolve children.
|
||||
const underNeg1 = childrenMap.get(-1) || [];
|
||||
const under0 = childrenMap.get(0) || [];
|
||||
if (underNeg1.length || under0.length) {
|
||||
const merged = [...new Set([...underNeg1, ...under0])];
|
||||
childrenMap.set(-1, merged);
|
||||
childrenMap.set(0, merged);
|
||||
}
|
||||
for (const [parentId, ids] of childrenMap) {
|
||||
ids.sort(
|
||||
(a, b) =>
|
||||
|
||||
Reference in new issue
Block a user