From c7fb21e2be5f0969b14bf4ca5b30d531d3acc197 Mon Sep 17 00:00:00 2001 From: Chung Zhi Xuan Date: Fri, 2 Feb 2024 16:37:41 +0800 Subject: [PATCH] Make stock count display tidier --- .../cms/src/admin/utils/RenderCellFactory.tsx | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/apps/cms/src/admin/utils/RenderCellFactory.tsx b/apps/cms/src/admin/utils/RenderCellFactory.tsx index 1216fcc9..9000c172 100644 --- a/apps/cms/src/admin/utils/RenderCellFactory.tsx +++ b/apps/cms/src/admin/utils/RenderCellFactory.tsx @@ -72,25 +72,37 @@ export class RenderCellFactory { ); return ImageComponentCell; } + if (key === "stock") { - const ObjectComponent: React.FC<{ data: string }> = ({ data }) => ( -
- {Object.entries(data).map(([subKey, value], index) => ( -
- {subKey}:{" "} - - {typeof value === 'object' ? JSON.stringify(value, null, 2) : String(value)} - + const StockTableComponent: React.FC<{ data: StockData }> = ({ data }) => ( +
+ {Object.entries(data).map(([color, sizes], index) => ( +
+ {color} +
+ {Object.entries(sizes).map(([size, quantity], sizeIndex) => ( + + {size}: {quantity} {sizeIndex % 2 !== 0 &&
}{" "} + {/* Add line break after every two sizes */} +
+ ))} +
))}
); - const ObjectComponentCell = (row, data: string) => ( - + const StockTableComponentCell = (row, data: StockData) => ( + ); - return ObjectComponentCell; - + return StockTableComponentCell; } + + interface StockData { + [color: string]: { + [size: string]: number; + }; + } + if (typeof element[key] == "object") { const DateComponent: React.FC<{ children?: React.ReactNode }> = ({ children,