From 64d8094c459a8818151d48f4f1d75b070dc745d2 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Mon, 21 Sep 2020 12:46:29 -0400
Subject: switched schema view to set dataDocs by default

---
 src/client/views/collections/CollectionSchemaCells.tsx | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

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

diff --git a/src/client/views/collections/CollectionSchemaCells.tsx b/src/client/views/collections/CollectionSchemaCells.tsx
index 18ae260e8..3d472b791 100644
--- a/src/client/views/collections/CollectionSchemaCells.tsx
+++ b/src/client/views/collections/CollectionSchemaCells.tsx
@@ -71,6 +71,7 @@ export class CollectionSchemaCell extends React.Component<CellProps> {
     @observable protected _isEditing: boolean = false;
     protected _focusRef = React.createRef<HTMLDivElement>();
     protected _rowDoc = this.props.rowProps.original;
+    protected _rowDataDoc = Doc.GetProto(this.props.rowProps.original);
     protected _dropDisposer?: DragManager.DragDropDisposer;
     @observable contents: string = "";
 
@@ -126,11 +127,11 @@ export class CollectionSchemaCell extends React.Component<CellProps> {
     private drop = (e: Event, de: DragManager.DropEvent) => {
         if (de.complete.docDragData) {
             if (de.complete.docDragData.draggedDocuments.length === 1) {
-                this._rowDoc[this.renderFieldKey] = de.complete.docDragData.draggedDocuments[0];
+                this._rowDataDoc[this.renderFieldKey] = de.complete.docDragData.draggedDocuments[0];
             }
             else {
                 const coll = Docs.Create.SchemaDocument([new SchemaHeaderField("title", "#f1efeb")], de.complete.docDragData.draggedDocuments, {});
-                this._rowDoc[this.renderFieldKey] = coll;
+                this._rowDataDoc[this.renderFieldKey] = coll;
             }
             e.stopPropagation();
         }
@@ -164,8 +165,7 @@ export class CollectionSchemaCell extends React.Component<CellProps> {
     @computed get renderFieldKey() { return CollectionSchemaCell.resolvedFieldKey(this.props.rowProps.column.id!, this.props.rowProps.original); }
     onItemDown = async (e: React.PointerEvent) => {
         if (this.props.Document._searchDoc) {
-            const doc = Doc.GetProto(this._rowDoc);
-            const aliasdoc = await SearchUtil.GetAliasesOfDocument(doc);
+            const aliasdoc = await SearchUtil.GetAliasesOfDocument(this._rowDataDoc);
             const targetContext = aliasdoc.length <= 0 ? undefined : Cast(aliasdoc[0].context, Doc, null);
             DocumentManager.Instance.jumpToDocument(this._rowDoc, false, () => undefined, targetContext);
         }
@@ -238,10 +238,10 @@ export class CollectionSchemaCell extends React.Component<CellProps> {
                                     let retVal = false;
                                     if (value.startsWith(":=") || value.startsWith("=:=")) {
                                         const script = value.substring(value.startsWith("=:=") ? 3 : 2);
-                                        retVal = this.props.setComputed(script, value.startsWith(":=") ? Doc.GetProto(this.props.Document) : this.props.Document, this.renderFieldKey, this.props.row, this.props.col);
+                                        retVal = this.props.setComputed(script, value.startsWith(":=") ? this._rowDataDoc : this._rowDoc, this.renderFieldKey, this.props.row, this.props.col);
                                     } else {
                                         const script = CompileScript(value, { requiredType: type, typecheck: false, editable: true, addReturn: true, params: { this: Doc.name, $r: "number", $c: "number", $: "any" } });
-                                        script.compiled && (retVal = this.applyToDoc(this._rowDoc, this.props.row, this.props.col, script.run));
+                                        script.compiled && (retVal = this.applyToDoc(this._rowDataDoc, this.props.row, this.props.col, script.run));
                                     }
                                     if (retVal) {
                                         this._isEditing = false; // need to set this here. otherwise, the assignment of the field will invalidate & cause render() to be called with the wrong value for 'editing'
@@ -253,8 +253,8 @@ export class CollectionSchemaCell extends React.Component<CellProps> {
                                     const script = CompileScript(value, { requiredType: type, typecheck: false, editable: true, addReturn: true, params: { this: Doc.name, $r: "number", $c: "number", $: "any" } });
                                     script.compiled && DocListCast(field).
                                         forEach((doc, i) => value.startsWith(":=") ?
-                                            this.props.setComputed(value.substring(2), doc, this.renderFieldKey, i, this.props.col) :
-                                            this.applyToDoc(doc, i, this.props.col, script.run));
+                                            this.props.setComputed(value.substring(2), Doc.GetProto(doc), this.renderFieldKey, i, this.props.col) :
+                                            this.applyToDoc(Doc.GetProto(doc), i, this.props.col, script.run));
                                 }}
                             />
                             :
-- 
cgit v1.2.3-70-g09d2


From 51aab84bc8814ea1be6aed3eca02da3ec00a280b Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Mon, 21 Sep 2020 15:07:33 -0400
Subject: fixed fill down for schema cols with ctrl-enter.  fixed gathering
 facet values in FilterBox

---
 .../views/collections/CollectionSchemaCells.tsx    |  2 +-
 src/client/views/nodes/FilterBox.tsx               | 48 +++++++++++++++++-----
 2 files changed, 39 insertions(+), 11 deletions(-)

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

diff --git a/src/client/views/collections/CollectionSchemaCells.tsx b/src/client/views/collections/CollectionSchemaCells.tsx
index 3d472b791..2443bd34e 100644
--- a/src/client/views/collections/CollectionSchemaCells.tsx
+++ b/src/client/views/collections/CollectionSchemaCells.tsx
@@ -251,7 +251,7 @@ export class CollectionSchemaCell extends React.Component<CellProps> {
                                 })}
                                 OnFillDown={async (value: string) => {
                                     const script = CompileScript(value, { requiredType: type, typecheck: false, editable: true, addReturn: true, params: { this: Doc.name, $r: "number", $c: "number", $: "any" } });
-                                    script.compiled && DocListCast(field).
+                                    script.compiled && DocListCast(this.props.Document[this.props.fieldKey]).
                                         forEach((doc, i) => value.startsWith(":=") ?
                                             this.props.setComputed(value.substring(2), Doc.GetProto(doc), this.renderFieldKey, i, this.props.col) :
                                             this.applyToDoc(Doc.GetProto(doc), i, this.props.col, script.run));
diff --git a/src/client/views/nodes/FilterBox.tsx b/src/client/views/nodes/FilterBox.tsx
index 748af89ef..805745f4a 100644
--- a/src/client/views/nodes/FilterBox.tsx
+++ b/src/client/views/nodes/FilterBox.tsx
@@ -19,6 +19,7 @@ import { SearchBox } from "../search/SearchBox";
 import { FieldView, FieldViewProps } from './FieldView';
 import './FilterBox.scss';
 import { Scripting } from "../../util/Scripting";
+import { values } from "lodash";
 const higflyout = require("@hig/flyout");
 export const { anchorPoints } = higflyout;
 export const Flyout = higflyout.default;
@@ -49,6 +50,39 @@ export class FilterBox extends ViewBoxBaseComponent<FieldViewProps, FilterBoxDoc
         this.allDocs.forEach(doc => SearchBox.documentKeys(doc).filter(key => keys.add(key)));
         return Array.from(keys.keys()).filter(key => key[0] === "#" || key.indexOf("lastModified") !== -1 || (key[0] === key[0].toUpperCase() && !key.startsWith("_") && !key.startsWith("acl")) || noviceFields.includes(key)).sort();
     }
+
+    gatherFieldValues(dashboard: Doc, facetKey: string) {
+        const childDocs = DocListCast((dashboard.data as any)[0].data);
+        const valueSet = new Set<string>();
+        let rtFields = 0;
+        childDocs.forEach((d) => {
+            const facetVal = d[facetKey];
+            if (facetVal instanceof RichTextField) rtFields++;
+            valueSet.add(Field.toString(facetVal as Field));
+            const fieldKey = Doc.LayoutFieldKey(d);
+            const annos = !Field.toString(Doc.LayoutField(d) as Field).includes("CollectionView");
+            const data = d[annos ? fieldKey + "-annotations" : fieldKey];
+            if (data !== undefined) {
+                let subDocs = DocListCast(data);
+                if (subDocs.length > 0) {
+                    let newarray: Doc[] = [];
+                    while (subDocs.length > 0) {
+                        newarray = [];
+                        subDocs.forEach((t) => {
+                            const facetVal = t[facetKey];
+                            if (facetVal instanceof RichTextField) rtFields++;
+                            valueSet.add(Field.toString(facetVal as Field));
+                            const fieldKey = Doc.LayoutFieldKey(t);
+                            const annos = !Field.toString(Doc.LayoutField(t) as Field).includes("CollectionView");
+                            DocListCast(t[annos ? fieldKey + "-annotations" : fieldKey]).forEach((newdoc) => newarray.push(newdoc));
+                        });
+                        subDocs = newarray;
+                    }
+                }
+            }
+        });
+        return { strings: Array.from(valueSet.keys()), rtFields };
+    }
     /**
      * Responds to clicking the check box in the flyout menu
      */
@@ -73,17 +107,11 @@ export class FilterBox extends ViewBoxBaseComponent<FieldViewProps, FilterBoxDoc
             }
         } else {
             const allCollectionDocs = DocListCast((targetDoc.data as any)[0].data);
-            var rtfields = 0;
-            const facetValues = Array.from(allCollectionDocs.reduce((set, child) => {
-                const field = child[facetHeader] as Field;
-                const fieldStr = Field.toString(field);
-                if (field instanceof RichTextField || (typeof (field) === "string" && fieldStr.split(" ").length > 2)) rtfields++;
-                return set.add(fieldStr);
-            }, new Set<string>()));
+            const facetValues = this.gatherFieldValues(targetDoc, facetHeader);
 
             let nonNumbers = 0;
             let minVal = Number.MAX_VALUE, maxVal = -Number.MAX_VALUE;
-            facetValues.map(val => {
+            facetValues.strings.map(val => {
                 const num = Number(val);
                 if (Number.isNaN(num)) {
                     nonNumbers++;
@@ -93,13 +121,13 @@ export class FilterBox extends ViewBoxBaseComponent<FieldViewProps, FilterBoxDoc
                 }
             });
             let newFacet: Opt<Doc>;
-            if (facetHeader === "text" || rtfields / allCollectionDocs.length > 0.1) {
+            if (facetHeader === "text" || facetValues.rtfields / allCollectionDocs.length > 0.1) {
                 newFacet = Docs.Create.TextDocument("", { _width: 100, _height: 25, _stayInCollection: true, _hideContextMenu: true, treeViewExpandedView: "layout", title: facetHeader, treeViewOpen: true, forceActive: true, ignoreClick: true });
                 Doc.GetProto(newFacet).type = DocumentType.COL; // forces item to show an open/close button instead ofa checkbox
                 newFacet._textBoxPadding = 4;
                 const scriptText = `setDocFilter(this?.target, "${facetHeader}", text, "match")`;
                 newFacet.onTextChanged = ScriptField.MakeScript(scriptText, { this: Doc.name, text: "string" });
-            } else if (facetHeader !== "tags" && nonNumbers / facetValues.length < .1) {
+            } else if (facetHeader !== "tags" && nonNumbers / facetValues.strings.length < .1) {
                 newFacet = Docs.Create.SliderDocument({ title: facetHeader, _stayInCollection: true, _hideContextMenu: true, treeViewExpandedView: "layout", treeViewOpen: true });
                 const newFacetField = Doc.LayoutFieldKey(newFacet);
                 const ranged = Doc.readDocRangeFilter(targetDoc, facetHeader);
-- 
cgit v1.2.3-70-g09d2

