From 791ca5ff760aa320c596da0d2cdee16d198aeeb6 Mon Sep 17 00:00:00 2001
From: srichman333 <sarah_n_richman@brown.edu>
Date: Mon, 4 Dec 2023 18:49:31 -0500
Subject: dataviz as schema live updates

---
 .../collectionFreeForm/CollectionFreeFormView.tsx            | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

(limited to 'src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx')

diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index 3a1ea766a..d53049e04 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -1976,9 +1976,11 @@ ScriptingGlobals.add(function sendToBack(doc: Doc) {
 });
 ScriptingGlobals.add(function datavizFromSchema(doc: Doc) {
     SelectionManager.Views().forEach(view => {
-        var keys = Cast(view.layoutDoc.schema_columnKeys, listSpec('string'))?.filter(key => key!="text");
-        const defaultColumnKeys: string[] = ['title', 'type', 'author', 'author_date'];
-        if (!keys) keys = Cast(view.layoutDoc.schema_columnKeys, listSpec('string'), defaultColumnKeys);;
+        if (!view.layoutDoc.schema_columnKeys){
+            view.layoutDoc.schema_columnKeys = new List<string>(['title', 'type', 'author', 'author_date'])
+        }
+        const keys = Cast(view.layoutDoc.schema_columnKeys, listSpec('string'))?.filter(key => key!="text");
+        if (!keys) return;
 
         const children = DocListCast(view.rootDoc[Doc.LayoutFieldKey(view.rootDoc)]);
         let csvRows = [];
@@ -2000,8 +2002,10 @@ ScriptingGlobals.add(function datavizFromSchema(doc: Doc) {
         DocUtils.uploadFileToDoc(file, {}, loading);
 
         if (view.ComponentView?.addDocument) {
+          //  loading.dataViz_fromSchema = true;
+            loading.dataViz_asSchema = view.layoutDoc;
             SchemaCSVPopUp.Instance.setView(view);
-            SchemaCSVPopUp.Instance.setTarget(view.rootDoc);
+            SchemaCSVPopUp.Instance.setTarget(view.layoutDoc);
             SchemaCSVPopUp.Instance.setDataVizDoc(loading);
             SchemaCSVPopUp.Instance.setVisible(true);
         }
-- 
cgit v1.2.3-70-g09d2

