diff options
Diffstat (limited to 'src')
4 files changed, 53 insertions, 15 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 365af66b7..4908d2952 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -227,7 +227,7 @@ export class DocumentOptions { _header_pointerEvents?: PEVt = new PEInfo('types of events the header of a custom text document can consume'); _lockedPosition?: BOOLt = new BoolInfo("lock the x,y coordinates of the document so that it can't be dragged"); _lockedTransform?: BOOLt = new BoolInfo('lock the freeform_panx,freeform_pany and scale parameters of the document so that it be panned/zoomed'); - _childrenSharedWithSchema?: BOOLt = new BoolInfo("whether this document's children are displayed in its parent schema view"); + _childrenSharedWithSchema?: BOOLt = new BoolInfo("whether this document's children are displayed in its parent schema view", false); dataViz_title?: string; dataViz_line?: string; 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 diff --git a/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx b/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx index dd4a13776..dbbf76ea7 100644 --- a/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx +++ b/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx @@ -22,6 +22,7 @@ import { SnappingManager } from '../../../util/SnappingManager'; import { undoable } from '../../../util/UndoManager'; import { FInfo } from '../../../documents/Documents'; import { ColumnType } from '../../../../fields/SchemaHeaderField'; +import { IconButton, Size } from 'browndash-components'; export interface SchemaColumnHeaderProps { Document: Doc; @@ -174,10 +175,26 @@ export class SchemaColumnHeader extends ObservableReactComponent<SchemaColumnHea <div>{this.editableView}</div> <div className="schema-header-menu"> - <div className="schema-header-button" onPointerDown={e => this._props.openContextMenu(e.clientX, e.clientY, this._props.columnIndex)}> - <FontAwesomeIcon icon="ellipsis-h" /> + <div className="schema-header-button"> + <IconButton + icon={ <FontAwesomeIcon icon="caret-down" size='lg'/>} + size={Size.XSMALL} + color={'black'} + onPointerDown={e => + setupMoveUpEvents( + this, + e, + returnFalse, + emptyFunction, + undoable(clickEv => { + clickEv.stopPropagation(); + this._props.openContextMenu(e.clientX, e.clientY, this._props.columnIndex) + }, 'open column menu') + ) + } + /> </div> - </div> + </div> </div> ); } diff --git a/src/client/views/collections/collectionSchema/SchemaRowBox.tsx b/src/client/views/collections/collectionSchema/SchemaRowBox.tsx index 665704de1..cdd47f644 100644 --- a/src/client/views/collections/collectionSchema/SchemaRowBox.tsx +++ b/src/client/views/collections/collectionSchema/SchemaRowBox.tsx @@ -60,7 +60,7 @@ export class SchemaRowBox extends ViewBoxBaseComponent<SchemaRowBoxProps>() { ContextMenu.Instance.clearItems(); ContextMenu.Instance.addItem({ description: `Close doc`, - event: () => this._props.removeDocument?.(this.Document), + event: () => this.schemaView.removeDoc(this.Document), icon: 'minus', }); ContextMenu.Instance.addItem({ @@ -74,13 +74,12 @@ export class SchemaRowBox extends ViewBoxBaseComponent<SchemaRowBoxProps>() { icon: 'magnifying-glass', }); const childDocs = DocListCast(this.Document[Doc.LayoutFieldKey(this.Document)]) - if (this.Document['type'] === 'collection' && childDocs.length) { + if (this.Document.type === 'collection' && childDocs.length) { ContextMenu.Instance.addItem({ description: this.Document._childrenSharedWithSchema ? 'Remove children from schema' : 'Add children to schema', event: () => { this.Document._childrenSharedWithSchema = !this.Document._childrenSharedWithSchema; - this.Document._childrenSharedWithSchema ? - this.schemaView.addDocsFromOtherCollection(childDocs) : this.schemaView.removeDocsFromOtherCollection(childDocs); + this.Document._childrenSharedWithSchema ? this.schemaView.addDocsFromOtherCollection(childDocs) : this.schemaView.removeDocsFromOtherCollection(childDocs); }, icon: this.Document._childrenSharedWithSchema ? 'minus' : 'plus', }); @@ -115,7 +114,7 @@ export class SchemaRowBox extends ViewBoxBaseComponent<SchemaRowBoxProps>() { }}> <IconButton tooltip="Open actions menu" - icon={ <FontAwesomeIcon icon="list" size='lg'/>} + icon={ <FontAwesomeIcon icon="caret-right" size='lg'/>} size={Size.XSMALL} color={'black'} onPointerDown={e => |