From eeb7d43e9eca66c8e3418e89492848589ee20aa3 Mon Sep 17 00:00:00 2001
From: geireann <geireann.lindfield@gmail.com>
Date: Thu, 24 Aug 2023 15:48:26 -0400
Subject: speedups for dataviz

---
 .../views/nodes/DataVizBox/components/TableBox.tsx    | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

(limited to 'src/client/views/nodes/DataVizBox/components/TableBox.tsx')

diff --git a/src/client/views/nodes/DataVizBox/components/TableBox.tsx b/src/client/views/nodes/DataVizBox/components/TableBox.tsx
index 70483ac6f..e1c5aa125 100644
--- a/src/client/views/nodes/DataVizBox/components/TableBox.tsx
+++ b/src/client/views/nodes/DataVizBox/components/TableBox.tsx
@@ -33,9 +33,11 @@ interface TableBoxProps {
 export class TableBox extends React.Component<TableBoxProps> {
     // filters all data to just display selected data if brushed (created from an incoming link)
     @computed get _tableData() {
-        if (this.incomingLinks.length! <= 0) return this.props.pairs;
-        var guids = StrListCast(this.props.layoutDoc.dataViz_rowGuids);
-        return this.props.pairs?.filter(pair => this.incomingLinks[0]!.dataViz_selectedRows && StrListCast(this.incomingLinks[0].dataViz_selectedRows).includes(guids[this.props.pairs.indexOf(pair)]));
+        if (this.incomingLinks.length <= 0) return this.props.pairs;
+        return this.props.pairs?.filter(pair => StrListCast(this.incomingLinks[0]?.dataViz_selectedRows).includes(this.rowGuids[this.props.pairs.indexOf(pair)]));
+    }
+    @computed get rowGuids() {
+        return  StrListCast(this.props.layoutDoc.dataViz_rowGuids)
     }
 
     @computed get incomingLinks() {
@@ -47,9 +49,6 @@ export class TableBox extends React.Component<TableBoxProps> {
     }
 
     @computed get columns() {
-        if (!this.props.layoutDoc.dataViz_rowGuids) this.props.layoutDoc.dataViz_rowGuids = new List<string>();
-        const guids = Cast(this.props.layoutDoc.dataViz_rowGuids, listSpec('string'), null);
-        if (guids.length == 0) this.props.pairs.map(row => guids.push(Utils.GenerateGuid()));
         return this._tableData.length ? Array.from(Object.keys(this._tableData[0])).filter(header => header != '' && header != undefined) : [];
     }
 
@@ -59,9 +58,9 @@ export class TableBox extends React.Component<TableBoxProps> {
         const selected = Cast(this.props.layoutDoc.dataViz_selectedRows, listSpec('string'), null);
         const incomingSelected = this.incomingLinks.length ? StrListCast(this.incomingLinks[0].dataViz_selectedRows) : undefined;
         if (incomingSelected) {
-            selected.map(guid => {
-                if (!incomingSelected.includes(guid)) selected.splice(selected.indexOf(guid), 1);
-            }); // filters through selected to remove guids that were removed in the incoming data
+            const newsel = selected.filter(guid => incomingSelected.includes(guid));// filters through selected to remove guids that were removed in the incoming data
+            selected.length = 0;
+            selected.push(...newsel);
         }
     }
 
@@ -145,7 +144,7 @@ export class TableBox extends React.Component<TableBoxProps> {
                         <tbody>
                             {this._tableData?.map((p, i) => {
                                 var containsData = false;
-                                var guid = StrListCast(this.props.layoutDoc.dataViz_rowGuids)![this.props.pairs.indexOf(p)];
+                                var guid = this.rowGuids[this.props.pairs.indexOf(p)];
                                 this.columns.map(col => {
                                     if (p[col] != '' && p[col] != null && p[col] != undefined) containsData = true;
                                 });
-- 
cgit v1.2.3-70-g09d2

