aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2021-03-17 18:32:51 -0400
committerbobzel <zzzman@gmail.com>2021-03-17 18:32:51 -0400
commit6f4f0ffb9f4ab816cf6055c62afc6f79b8e4961f (patch)
treeb1f238076751b2b2e969373403e9be8da29ccd05 /src
parent73dc79ddc41b56e2f36a5b2e442fe9c71648b118 (diff)
fix Doc.MakeClone to deal wth links correctly again. fixed dashboard snapshot to either alias top-level documents, or clone everything.
Diffstat (limited to 'src')
-rw-r--r--src/client/documents/Documents.ts2
-rw-r--r--src/client/util/CurrentUserUtils.ts4
-rw-r--r--src/client/views/collections/CollectionDockingView.tsx34
-rw-r--r--src/fields/Doc.ts4
-rw-r--r--src/fields/util.ts13
5 files changed, 26 insertions, 31 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 0a3865a13..8aa478cc1 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -780,8 +780,6 @@ export namespace Docs {
LinkManager.Instance.addLink(doc);
- source.doc.links === undefined && (Doc.GetProto(source.doc).links = ComputedField.MakeFunction("links(self)"));
- target.doc.links === undefined && (Doc.GetProto(target.doc).links = ComputedField.MakeFunction("links(self)"));
return doc;
}
diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts
index 2a84171cb..e601d33f7 100644
--- a/src/client/util/CurrentUserUtils.ts
+++ b/src/client/util/CurrentUserUtils.ts
@@ -1156,8 +1156,8 @@ export class CurrentUserUtils {
input.click();
}
- public static snapshotDashboard = (userDoc: Doc) => {
- const copy = CollectionDockingView.Copy(CurrentUserUtils.ActiveDashboard);
+ public static async snapshotDashboard(userDoc: Doc) {
+ const copy = await CollectionDockingView.Copy(CurrentUserUtils.ActiveDashboard);
Doc.AddDocToList(Cast(userDoc.myDashboards, Doc, null), "data", copy);
CurrentUserUtils.openDashboard(userDoc, copy);
}
diff --git a/src/client/views/collections/CollectionDockingView.tsx b/src/client/views/collections/CollectionDockingView.tsx
index b9757dde3..57f4555a1 100644
--- a/src/client/views/collections/CollectionDockingView.tsx
+++ b/src/client/views/collections/CollectionDockingView.tsx
@@ -342,25 +342,27 @@ export class CollectionDockingView extends CollectionSubView(doc => doc) {
}
}
- public static Copy(doc: Doc) {
+ public static async Copy(doc: Doc, clone = false) {
+ clone = !Doc.UserDoc().noviceMode;
let json = StrCast(doc.dockingConfig);
+ if (clone) {
+ const cloned = (await Doc.MakeClone(doc));
+ Array.from(cloned.map.entries()).map(entry => json = json.replace(entry[0], entry[1][Id]));
+ Doc.SetInPlace(cloned.clone, "dockingConfig", json, true);
+ return cloned.clone;
+ }
const matches = json.match(/\"documentId\":\"[a-z0-9-]+\"/g);
- const docids = matches?.map(m => m.replace("\"documentId\":\"", "").replace("\"", "")) || [];
- const docs = docids.map(id => DocServer.GetCachedRefField(id)).filter(f => f).map(f => f as Doc);
- const newtabs = docs.map(doc => {
- const copy = Doc.MakeAlias(doc);
- json = json.replace(doc[Id], copy[Id]);
- return copy;
+ const origtabids = matches?.map(m => m.replace("\"documentId\":\"", "").replace("\"", "")) || [];
+ const origtabs = origtabids.map(id => DocServer.GetCachedRefField(id)).filter(f => f).map(f => f as Doc);
+ const newtabs = origtabs.map(origtab => {
+ const origtabdocs = DocListCast(origtab.data);
+ const newtab = origtabdocs.length ? Doc.MakeCopy(origtab, true) : Doc.MakeAlias(origtab);
+ const newtabdocs = origtabdocs.map(origtabdoc => Doc.MakeAlias(origtabdoc));
+ newtabdocs.length && Doc.SetInPlace(newtab, "data", new List<Doc>(newtabdocs), true);
+ json = json.replace(origtab[Id], newtab[Id]);
+ return newtab;
});
- const copy = Docs.Create.DockDocument(newtabs, json, { title: "Snapshot: " + doc.title });
- const docsublists = DocListCast(doc.data);
- const copysublists = DocListCast(copy.data);
- const docother = Cast(docsublists[1], Doc, null);
- const copyother = Cast(copysublists[1], Doc, null);
- const newother = DocListCast(docother.data).map(doc => Doc.MakeAlias(doc));
- Doc.GetProto(copyother).data = new List<Doc>(newother);
-
- return copy;
+ return Docs.Create.DockDocument(newtabs, json, { title: "Snapshot: " + doc.title });
}
@action
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts
index 5a8b1097a..4f9377aa0 100644
--- a/src/fields/Doc.ts
+++ b/src/fields/Doc.ts
@@ -510,11 +510,11 @@ export namespace Doc {
cloneMap.set(doc[Id], copy);
if (LinkManager.Instance.getAllLinks().includes(doc) && LinkManager.Instance.getAllLinks().indexOf(copy) === -1) LinkManager.Instance.addLink(copy);
const filter = [...exclusions, ...Cast(doc.cloneFieldFilter, listSpec("string"), [])];
- await Promise.all(Object.keys(doc).map(async key => {
+ await Promise.all([...Object.keys(doc), "links"].map(async key => {
if (filter.includes(key)) return;
const assignKey = (val: any) => !dontCreate && (copy[key] = val);
const cfield = ComputedField.WithoutComputed(() => FieldValue(doc[key]));
- const field = ProxyField.WithoutProxy(() => doc[key]);
+ const field = key === "links" && Doc.IsPrototype(doc) ? doc[key] : ProxyField.WithoutProxy(() => doc[key]);
const copyObjectField = async (field: ObjectField) => {
const list = Cast(doc[key], listSpec(Doc));
const docs = list && (await DocListCastAsync(list))?.filter(d => d instanceof Doc);
diff --git a/src/fields/util.ts b/src/fields/util.ts
index 5d98971da..6038a0534 100644
--- a/src/fields/util.ts
+++ b/src/fields/util.ts
@@ -302,20 +302,15 @@ export function setter(target: any, in_prop: string | symbol | number, value: an
}
export function getter(target: any, in_prop: string | symbol | number, receiver: any): any {
- const prop = in_prop;
+ let prop = in_prop;
if (in_prop === AclSym) return target[AclSym];
if (in_prop === "toString" || (in_prop !== HeightSym && in_prop !== WidthSym && in_prop !== LayoutSym && typeof prop === "symbol")) return target.__fields[prop] || target[prop];
if (GetEffectiveAcl(target) === AclPrivate) return prop === HeightSym || prop === WidthSym ? returnZero : undefined;
if (prop === LayoutSym) return target.__LAYOUT__;
- let search = false;
if (typeof prop === "string" && prop !== "__id" && prop !== "__fields" && prop.startsWith("_")) {
- // if (!prop.startsWith("_")) {
- // console.log(prop + " is deprecated - switch to _" + prop);
- // prop = "_" + prop;
- // }
- if (!prop.startsWith("__")) search = true;
- if (target.__LAYOUT__) return target.__LAYOUT__[prop] ?? (search ? target.__LAYOUT__[prop.substring(1)] : undefined);
+ if (!prop.startsWith("__")) prop = prop.substring(1);
+ if (target.__LAYOUT__) return target.__LAYOUT__[prop];
}
if (prop === "then") {//If we're being awaited
return undefined;
@@ -326,7 +321,7 @@ export function getter(target: any, in_prop: string | symbol | number, receiver:
if (SerializationHelper.IsSerializing()) {
return target[prop];
}
- return (search ? getFieldImpl(target, (prop as any as string).substring(1), receiver) : undefined) ?? getFieldImpl(target, prop, receiver);
+ return getFieldImpl(target, prop, receiver);
}
function getFieldImpl(target: any, prop: string | number, receiver: any, ignoreProto: boolean = false): any {