From 71d18a4958fb892b49ed56cc0332542aefee8b63 Mon Sep 17 00:00:00 2001 From: Gordon Smith Date: Fri, 29 Nov 2024 07:16:27 +0000 Subject: [PATCH] fix: Nested datasets not rendering correctly Signed-off-by: Gordon Smith --- packages/dgrid/index.html | 30 +++++++-------------------- packages/dgrid/src/RowFormatter.ts | 19 +++++++++++------ packages/eclwatch/.vscode/launch.json | 2 +- packages/eclwatch/index.html | 7 ++++--- packages/eclwatch/package.json | 2 +- 5 files changed, 26 insertions(+), 34 deletions(-) diff --git a/packages/dgrid/index.html b/packages/dgrid/index.html index 1ffc41f3cc..32c2d30cb6 100644 --- a/packages/dgrid/index.html +++ b/packages/dgrid/index.html @@ -33,31 +33,15 @@

ESM Quick Test

diff --git a/packages/dgrid/src/RowFormatter.ts b/packages/dgrid/src/RowFormatter.ts index 177184d042..c497c98577 100644 --- a/packages/dgrid/src/RowFormatter.ts +++ b/packages/dgrid/src/RowFormatter.ts @@ -1,4 +1,3 @@ - function entitiesEncode(str) { return String(str).replace(/&/g, "&").replace(//g, ">").replace(/"/g, """); } @@ -17,6 +16,10 @@ function safeEncode(item) { return item; } +function isArray(obj: any): obj is any[] { + return obj instanceof Array; +} + const LINE_SPLITTER = "

"; const LINE_SPLITTER2 = "
"; @@ -78,9 +81,13 @@ export class RowFormatter { for (const column of columns) { if (column.children && row[column.leafID]) { let childDepth = 0; - for (const childRow of row[column.leafID]) { - if (childRow instanceof Array) { - } + let childRows = []; + if (isArray(row[column.leafID])) { + childRows = row[column.leafID]; + } else if (isArray(row[column.leafID].Row)) { + childRows = row[column.leafID].Row; + } + for (const childRow of childRows) { childDepth += this.calcDepth(column.children, childRow); } maxChildDepth = Math.max(maxChildDepth, childDepth); @@ -92,8 +99,8 @@ export class RowFormatter { formatCell(column: ColumnType, cell, maxChildDepth) { if (column.children) { let childDepth = 0; - if (!(cell instanceof Array)) { - if (cell instanceof Object && cell.Row instanceof Array) { // Push fix in comms? + if (!isArray(cell)) { + if (isArray(cell.Row)) { cell = cell.Row; } else { cell = [cell]; diff --git a/packages/eclwatch/.vscode/launch.json b/packages/eclwatch/.vscode/launch.json index f41798cc0a..f763cb8e25 100644 --- a/packages/eclwatch/.vscode/launch.json +++ b/packages/eclwatch/.vscode/launch.json @@ -33,7 +33,7 @@ "name": "index.html", "request": "launch", "type": "msedge", - "url": "http://localhost:5173/index.html", + "url": "http://localhost:5520/index.html", "runtimeArgs": [ "--disable-web-security" ], diff --git a/packages/eclwatch/index.html b/packages/eclwatch/index.html index 10baeaa82f..b64aa2b93b 100644 --- a/packages/eclwatch/index.html +++ b/packages/eclwatch/index.html @@ -30,15 +30,16 @@

ESM Quick Test

diff --git a/packages/eclwatch/package.json b/packages/eclwatch/package.json index 3727279e25..55b3d3aaae 100644 --- a/packages/eclwatch/package.json +++ b/packages/eclwatch/package.json @@ -23,7 +23,7 @@ "scripts": { "clean": "rimraf --glob lib* types dist *.tsbuildinfo .turbo", "bundle": "vite build", - "bundle-watch": "vite", + "bundle-watch": "vite --port 5520", "gen-types": "tsc --project tsconfig.json", "gen-types-watch": "npm run gen-types -- --watch", "build": "run-p gen-types bundle",