From 9f24c29df130ce4e206bc655ed7025e58c1517ce Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Thu, 19 Aug 2021 02:22:38 -0400
Subject: changed how treeview cycles between options for expanded views to
 show 'data' and some more adjustments.

---
 src/client/views/collections/TreeView.tsx | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

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

diff --git a/src/client/views/collections/TreeView.tsx b/src/client/views/collections/TreeView.tsx
index 0598be49b..84b2fcef6 100644
--- a/src/client/views/collections/TreeView.tsx
+++ b/src/client/views/collections/TreeView.tsx
@@ -482,10 +482,11 @@ export class TreeView extends React.Component<TreeViewProps> {
             const next = (modes: any[]) => modes[(modes.indexOf(StrCast(this.doc.treeViewExpandedView)) + 1) % modes.length];
             const annos = () => DocListCast(this.doc[this.fieldKey + "-annotations"]).length ? "annotations" : "";
             const links = () => DocListCast(this.doc.links).length ? "links" : "";
-            const children = () => this.childDocs ? this.fieldKey : "";
-            this.doc.treeViewExpandedView = next(this.props.treeView.fileSysMode ?
-                (Doc.UserDoc().noviceMode ? ["layout", "aliases"] : ["layout", "aliases", "fields"]) :
-                (Doc.UserDoc().noviceMode ? [children(), "layout"] : [children(), "fields", "layout", links(), annos()]).filter(mode => mode));
+            const data = () => this.childDocs && !this.props.treeView.dashboardMode ? this.fieldKey : "";
+            const aliases = () => this.props.treeView.dashboardMode ? "" : "aliases";
+            const fields = () => Doc.UserDoc().noviceMode ? "" : "fields";
+            const modes = [data(), "layout", ...(this.props.treeView.fileSysMode ? [aliases(), links(), annos()] : []), fields()];
+            this.doc.treeViewExpandedView = next(modes.filter(mode => mode));
         }
         this.treeViewOpen = true;
     }
-- 
cgit v1.2.3-70-g09d2


From d35d6cb036a4bd78f3df967b3564a0517d1b9843 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Thu, 19 Aug 2021 03:04:36 -0400
Subject: fixed links from sometimes disappearing on refresh.  cleaned up
 cycling through tree view expansion modes

---
 src/client/util/LinkManager.ts            | 13 ++++++++-----
 src/client/views/collections/TreeView.tsx | 26 +++++++++++++++-----------
 2 files changed, 23 insertions(+), 16 deletions(-)

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

diff --git a/src/client/util/LinkManager.ts b/src/client/util/LinkManager.ts
index 933b98a8c..c33dff8d1 100644
--- a/src/client/util/LinkManager.ts
+++ b/src/client/util/LinkManager.ts
@@ -36,9 +36,11 @@ export class LinkManager {
         setTimeout(() => {
             LinkManager.userLinkDBs = [];
             const addLinkToDoc = (link: Doc) => {
-                const a1 = link?.anchor1;
-                const a2 = link?.anchor2;
-                Promise.all([a1, a2]).then(action(() => {
+                const a1Prom = link?.anchor1;
+                const a2Prom = link?.anchor2;
+                Promise.all([a1Prom, a2Prom]).then(action((all) => {
+                    const a1 = all[0];
+                    const a2 = all[1];
                     if (a1 instanceof Doc && a2 instanceof Doc && ((a1.author !== undefined && a2.author !== undefined) || link.author === Doc.CurrentUserEmail)) {
                         Doc.GetProto(a1)[DirectLinksSym].add(link);
                         Doc.GetProto(a2)[DirectLinksSym].add(link);
@@ -110,9 +112,10 @@ export class LinkManager {
 
     relatedLinker = computedFn(function relatedLinker(this: any, anchor: Doc): Doc[] {
         const lfield = Doc.LayoutFieldKey(anchor);
-        return DocListCast(anchor[lfield + "-annotations"]).concat(DocListCast(anchor[lfield + "-annotations-timeline"])).reduce((list, anno) =>
+        const related = DocListCast(anchor[lfield + "-annotations"]).concat(DocListCast(anchor[lfield + "-annotations-timeline"])).reduce((list, anno) =>
             [...list, ...LinkManager.Instance.relatedLinker(anno)],
-            Array.from(Doc.GetProto(anchor)[DirectLinksSym]).slice());// LinkManager.Instance.directLinker(anchor).slice());
+            Array.from(Doc.GetProto(anchor)[DirectLinksSym]).slice());
+        return related;
     }, true);
 
     // returns map of group type to anchor's links in that group type
diff --git a/src/client/views/collections/TreeView.tsx b/src/client/views/collections/TreeView.tsx
index 84b2fcef6..3ee9dbf59 100644
--- a/src/client/views/collections/TreeView.tsx
+++ b/src/client/views/collections/TreeView.tsx
@@ -100,13 +100,14 @@ export class TreeView extends React.Component<TreeViewProps> {
     @observable _dref: DocumentView | undefined | null;
     get displayName() { return "TreeView(" + this.props.document.title + ")"; }  // this makes mobx trace() statements more descriptive
     get defaultExpandedView() {
-        return this.props.treeView.fileSysMode ? (this.doc.isFolder ? this.fieldKey : "aliases") :
-            this.props.treeView.outlineMode || this.childDocs ? this.fieldKey : Doc.UserDoc().noviceMode ? "layout" : StrCast(this.props.treeView.doc.treeViewExpandedView, "fields");
+        return this.doc.viewType === CollectionViewType.Docking ? this.fieldKey :
+            this.props.treeView.fileSysMode ? (this.doc.isFolder ? this.fieldKey : "layout") :
+                this.props.treeView.outlineMode || this.childDocs ? this.fieldKey : Doc.UserDoc().noviceMode ? "layout" : StrCast(this.props.treeView.doc.treeViewExpandedView, "fields");
     }
 
     @computed get doc() { return this.props.document; }
     @computed get treeViewOpen() { return (!this.treeViewOpenIsTransient && Doc.GetT(this.doc, "treeViewOpen", "boolean", true)) || this._transientOpenState; }
-    @computed get treeViewExpandedView() { return StrCast(this.doc.treeViewExpandedView, this.defaultExpandedView); }
+    @computed get treeViewExpandedView() { return this.validExpandViewTypes.includes(StrCast(this.doc.treeViewExpandedView)) ? StrCast(this.doc.treeViewExpandedView) : this.defaultExpandedView; }
     @computed get MAX_EMBED_HEIGHT() { return NumCast(this.props.containerCollection.maxEmbedHeight, 200); }
     @computed get dataDoc() { return this.doc[DataSym]; }
     @computed get layoutDoc() { return Doc.Layout(this.doc); }
@@ -476,17 +477,20 @@ export class TreeView extends React.Component<TreeViewProps> {
         </div>;
     }
 
+    @computed get validExpandViewTypes() {
+        if (this.doc.viewType === CollectionViewType.Docking) return [this.fieldKey];
+        const annos = () => DocListCast(this.doc[this.fieldKey + "-annotations"]).length ? "annotations" : "";
+        const links = () => DocListCast(this.doc.links).length ? "links" : "";
+        const data = () => this.childDocs && !this.props.treeView.dashboardMode ? this.fieldKey : "";
+        const aliases = () => this.props.treeView.dashboardMode ? "" : "aliases";
+        const fields = () => Doc.UserDoc().noviceMode ? "" : "fields";
+        return [data(), "layout", ...(this.props.treeView.fileSysMode ? [aliases(), links(), annos()] : []), fields()].filter(m => m);
+    }
     @action
     expandNextviewType = () => {
         if (this.treeViewOpen && !this.doc.isFolder && !this.props.treeView.outlineMode && !this.doc.treeViewExpandedViewLock) {
-            const next = (modes: any[]) => modes[(modes.indexOf(StrCast(this.doc.treeViewExpandedView)) + 1) % modes.length];
-            const annos = () => DocListCast(this.doc[this.fieldKey + "-annotations"]).length ? "annotations" : "";
-            const links = () => DocListCast(this.doc.links).length ? "links" : "";
-            const data = () => this.childDocs && !this.props.treeView.dashboardMode ? this.fieldKey : "";
-            const aliases = () => this.props.treeView.dashboardMode ? "" : "aliases";
-            const fields = () => Doc.UserDoc().noviceMode ? "" : "fields";
-            const modes = [data(), "layout", ...(this.props.treeView.fileSysMode ? [aliases(), links(), annos()] : []), fields()];
-            this.doc.treeViewExpandedView = next(modes.filter(mode => mode));
+            const next = (modes: any[]) => modes[(modes.indexOf(StrCast(this.treeViewExpandedView)) + 1) % modes.length];
+            this.doc.treeViewExpandedView = next(this.validExpandViewTypes);
         }
         this.treeViewOpen = true;
     }
-- 
cgit v1.2.3-70-g09d2

