From fead8200910b5ce611c52c2543796c6d83401fc3 Mon Sep 17 00:00:00 2001 From: Rodolfo Ruiz Date: Thu, 4 Sep 2025 20:47:53 -0600 Subject: [PATCH] chore: add Material column and show the Parent array --- src/private/categories/Categories.jsx | 28 ++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/private/categories/Categories.jsx b/src/private/categories/Categories.jsx index 40d512f..bb5eab8 100644 --- a/src/private/categories/Categories.jsx +++ b/src/private/categories/Categories.jsx @@ -34,7 +34,24 @@ export default function Categories() { try { const data = await api.getAll(); const list = Array.isArray(data) ? data : []; - setRows(list); + + // Build a map of parentId -> array of child tagNames + const parentToChildren = {}; + for (const item of list) { + const parents = Array.isArray(item?.parentTagId) ? item.parentTagId : []; + for (const pid of parents) { + if (!parentToChildren[pid]) parentToChildren[pid] = []; + if (item?.tagName) parentToChildren[pid].push(item.tagName); + } + } + + // Enrich each row with `material` (children whose parentTagId includes this _id) + const enriched = list.map((r) => ({ + ...r, + material: Array.isArray(parentToChildren[r?._id]) ? parentToChildren[r._id].join(', ') : '', + })); + + setRows(enriched); } catch (e) { console.error('Failed to load categories:', e); setRows([]); @@ -148,28 +165,33 @@ export default function Categories() { { field: 'tagName', headerName: 'Name', flex: 1.2, minWidth: 180 }, { field: 'slug', headerName: 'Slug', flex: 1.0, minWidth: 160 }, { field: 'icon', headerName: 'Icon', flex: 0.7, minWidth: 120 }, + // New computed column + { field: 'material', headerName: 'Material', flex: 1.2, minWidth: 200 }, + // Hidden audit columns { field: 'createdAt', headerName: 'Created Date', flex: 1.0, minWidth: 180, + hide: true, valueFormatter: (p) => { const v = p?.value; return v ? new Date(v).toLocaleString() : '—'; }, }, - { field: 'createdBy', headerName: 'Created By', flex: 0.9, minWidth: 160 }, + { field: 'createdBy', headerName: 'Created By', flex: 0.9, minWidth: 160, hide: true }, { field: 'updatedAt', headerName: 'Updated Date', flex: 1.0, minWidth: 180, + hide: true, valueFormatter: (p) => { const v = p?.value; return v ? new Date(v).toLocaleString() : '—'; }, }, - { field: 'updatedBy', headerName: 'Updated By', flex: 0.9, minWidth: 160 }, + { field: 'updatedBy', headerName: 'Updated By', flex: 0.9, minWidth: 160, hide: true }, { field: 'status', headerName: 'Status', flex: 0.7, minWidth: 120 }, ];