diff options
| author | bobzel <zzzman@gmail.com> | 2021-03-17 18:32:51 -0400 |
|---|---|---|
| committer | bobzel <zzzman@gmail.com> | 2021-03-17 18:32:51 -0400 |
| commit | 6f4f0ffb9f4ab816cf6055c62afc6f79b8e4961f (patch) | |
| tree | b1f238076751b2b2e969373403e9be8da29ccd05 /src/client/views/collections/CollectionDockingView.tsx | |
| parent | 73dc79ddc41b56e2f36a5b2e442fe9c71648b118 (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/client/views/collections/CollectionDockingView.tsx')
| -rw-r--r-- | src/client/views/collections/CollectionDockingView.tsx | 34 |
1 files changed, 18 insertions, 16 deletions
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 |
