aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
diff options
context:
space:
mode:
authorNathan-SR <144961007+Nathan-SR@users.noreply.github.com>2024-06-10 04:01:01 -0400
committerNathan-SR <144961007+Nathan-SR@users.noreply.github.com>2024-06-10 04:01:01 -0400
commit99b0ce24e4d56100746016995c20f9bb9c109072 (patch)
tree733ee6074eb67ebaf4a5a17fed471ec092dfbf40 /src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
parent97977e7156eb852c20422fa995bbf96529dfb4e5 (diff)
adding/removing children from collection works (probably buggy); backspace delete broken
Diffstat (limited to 'src/client/views/collections/collectionSchema/CollectionSchemaView.tsx')
-rw-r--r--src/client/views/collections/collectionSchema/CollectionSchemaView.tsx34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
index a2f88eb80..f501993b5 100644
--- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
+++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
@@ -1,7 +1,7 @@
/* eslint-disable no-restricted-syntax */
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { IconButton, Popup, PopupTrigger, Size, Type } from 'browndash-components';
-import { ObservableMap, action, autorun, computed, makeObservable, observable, observe, runInAction } from 'mobx';
+import { ObservableMap, action, autorun, computed, makeObservable, observable, observe, override, runInAction } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
import { returnEmptyDoclist, returnEmptyString, returnFalse, returnIgnore, returnNever, returnTrue, setupMoveUpEvents, smoothScroll } from '../../../../ClientUtils';
@@ -65,6 +65,7 @@ export class CollectionSchemaView extends CollectionSubView() {
constructor(props: any) {
super(props);
makeObservable(this);
+ this.importAddedDocs();
}
static _rowHeight: number = 50;
@@ -106,7 +107,7 @@ export class CollectionSchemaView extends CollectionSubView() {
@computed get _selectedDocs() {
// get all selected documents then filter out any whose parent is not this schema document
- const selected = DocumentView.SelectedDocs().filter(doc => this.childDocs.includes(doc));
+ const selected = DocumentView.SelectedDocs().filter(doc => this._docs.includes(doc));
if (!selected.length) {
// if no schema doc is directly selected, test if a child of a schema doc is selected (such as in the preview window)
const childOfSchemaDoc = DocumentView.SelectedDocs().find(sel => DocumentView.getContextPath(sel, true).includes(this.Document));
@@ -197,6 +198,22 @@ export class CollectionSchemaView extends CollectionSubView() {
// ViewBoxInterface overrides
override isUnstyledView = returnTrue; // used by style provider : turns off opacity, animation effects, scaling
+ importAddedDocs = () => {
+ const collections = this.childDocs.filter((doc: Doc) => doc.type === 'collection');
+ collections.forEach((doc: Doc) => {
+ const childDocs = DocListCast(doc[Doc.LayoutFieldKey(doc)]);
+ doc._childrenSharedWithSchema && this.addDocsFromOtherCollection(childDocs);
+ });
+ }
+
+ removeDoc = (doc: Doc) => {
+ console.log('called')
+ this.removeDocument(doc);
+ if (doc instanceof Doc) {
+ console.log('doc is doc')
+ this._docs = this._docs.filter(d => d !== doc)};
+ }
+
rowIndex = (doc: Doc) => this.displayedDocs.docs.indexOf(doc);
@action
@@ -256,13 +273,17 @@ export class CollectionSchemaView extends CollectionSubView() {
}
break;
case 'Backspace': {
- undoable(() => this.removeDocument(this._selectedDocs), 'delete schema row');
+ undoable(() => {this._selectedDocs.forEach(d => this._docs.includes(d) && this.removeDoc(d));}, 'delete schema row');
break;
}
case 'Escape': {
this.deselectAllCells();
break;
}
+ case 'P': {
+ this.importAddedDocs();
+ break;
+ }
default:
}
}
@@ -635,11 +656,12 @@ export class CollectionSchemaView extends CollectionSubView() {
};
addDocsFromOtherCollection = (docs: Doc[]) => {
- docs.forEach((doc: Doc) => {!this.displayedDocsFunc().includes(doc) && this._lentDocs.push(doc)});
+ docs.forEach((doc: Doc) => !this.displayedDocsFunc().includes(doc) && this._lentDocs.push(doc));
this._docs = this.childDocs.slice().concat(this._lentDocs);
}
+
removeDocsFromOtherCollection = (docs: Doc[]) => {
- this._lentDocs.filter((doc: Doc) => !docs.includes(doc));
+ this._lentDocs = this._lentDocs.filter((doc: Doc) => !docs.includes(doc));
this._docs = this.childDocs.slice().concat(this._lentDocs);
}
@@ -1032,7 +1054,7 @@ export class CollectionSchemaView extends CollectionSubView() {
return { docs };
}
- @action
+ @action
sortDocs = (docs: Doc[], field: string, desc: boolean) => {
docs = docs.sort((docA, docB) => {
// this sorts the documents based on the selected field. returning -1 for a before b, 0 for a = b, 1 for a > b