From 60a4ccfe2ab6337c064da8a303336f1872f5e9a6 Mon Sep 17 00:00:00 2001
From: Nathan-SR <144961007+Nathan-SR@users.noreply.github.com>
Date: Wed, 12 Jun 2024 21:16:17 -0400
Subject: cell value parser for highlighting cells used in equation works; need
 to implement actual VU

---
 .../collectionSchema/CollectionSchemaView.tsx      | 48 +++++++++++++++++++---
 1 file changed, 43 insertions(+), 5 deletions(-)

(limited to 'src/client/views/collections/collectionSchema/CollectionSchemaView.tsx')

diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
index affa70a62..4d959e42c 100644
--- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
+++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
@@ -39,6 +39,7 @@ import { listSpec } from '../../../../fields/Schema';
 import { GetEffectiveAcl } from '../../../../fields/util';
 import { ContextMenuProps } from '../../ContextMenuItem';
 import { truncate } from 'lodash';
+import { DocumentManager } from '../../../util/DocumentManager';
 
 const { SCHEMA_NEW_NODE_HEIGHT } = require('../../global/globalCssVariables.module.scss'); // prettier-ignore
 
@@ -481,6 +482,39 @@ export class CollectionSchemaView extends CollectionSubView() {
             cellEles.slice(-1)[0].style.borderBottom = edgeStyle;
         });
 
+    getCellElement = (doc: Doc, fieldKey: string) => {
+        const index = this.columnKeys.indexOf(fieldKey);
+        console.log(doc.title)
+        const cell = this._rowEles.get(doc).children[1].children[index];
+        return cell;
+    }
+
+    findCellRefs = (text: string) => {
+        const pattern = /(this|d(\d+))\.(\w+)/g;
+        interface Match { docRef: string; field: string; }
+
+        const matches: Match[] = [];
+        let match: RegExpExecArray | null;
+
+        while ((match = pattern.exec(text)) !== null) {
+            const docRef = match[1] === 'this' ? match[1] : match[2]; 
+        matches.push({ docRef, field: match[3] });
+        }
+
+        const cells: Array<any> = [];
+        matches.forEach((match: Match) => {
+            const {docRef, field} = match;
+            const doc = DocumentManager.Instance.DocumentViews[Number(docRef)].Document;
+            if (this.columnKeys.includes(field)) {cells.push(this.getCellElement(doc, field))}
+        })
+
+        console.log(cells);
+
+        return cells;
+    }
+
+
+
     @action
     addRowRef = (doc: Doc, ref: HTMLDivElement) => this._rowEles.set(doc, ref);
 
@@ -1012,22 +1046,26 @@ export class CollectionSchemaView extends CollectionSubView() {
         }
     };
 
-    displayedSubCollectionDocs = (doc: Doc) => {
+    subCollectionDocs = (doc: Doc, displayed: boolean) => {
         const childDocs = DocListCast(doc[Doc.LayoutFieldKey(doc)]);
-        const displayedCollections = childDocs.filter(d => d.type === 'collection' && d._childrenSharedWithSchema);
+        let collections: Array<Doc> = [];
+        if (displayed) collections = childDocs.filter(d => d.type === 'collection' && d._childrenSharedWithSchema);
+        else collections = childDocs.filter(d => d.type === 'collection' && !d._childrenSharedWithSchema);
         let toReturn: Doc[] = [...childDocs];
-        displayedCollections.forEach(d => toReturn = toReturn.concat(this.displayedSubCollectionDocs(d)));
+        collections.forEach(d => toReturn = toReturn.concat(this.subCollectionDocs(d, displayed)));
         return toReturn;
     }
-    
+
     @computed get docs() {
         let docsFromChildren: Doc[] = [];
+
         const displayedCollections = this.childDocs.filter(d => d.type === 'collection' && d._childrenSharedWithSchema);
         displayedCollections.forEach(d => {
-            let docsNotAlreadyDisplayed = this.displayedSubCollectionDocs(d).filter(dc => !this._docs.includes(dc));
+            let docsNotAlreadyDisplayed = this.subCollectionDocs(d, true).filter(dc => !this._docs.includes(dc));
             docsFromChildren = docsFromChildren.concat(docsNotAlreadyDisplayed);
         });
         let docs = this._docs.concat(docsFromChildren);
+
         return docs;
     }
     
-- 
cgit v1.2.3-70-g09d2

