diff options
author | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2024-06-10 14:56:42 -0400 |
---|---|---|
committer | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2024-06-10 14:56:42 -0400 |
commit | 03f9fd4beb2bd3efa8f88c71bdbaf52dbec82e66 (patch) | |
tree | f12c7a7376449f1a79bda11938140eb23401f4dc /src | |
parent | 4b604b5118a1aac89d977c832c81495ec2c9aa19 (diff) |
sub-collection doc adding refactor complete except for small bug
Diffstat (limited to 'src')
3 files changed, 65 insertions, 47 deletions
diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx index 48287c3ec..1952f59f5 100644 --- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx +++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx @@ -65,7 +65,6 @@ export class CollectionSchemaView extends CollectionSubView() { constructor(props: any) { super(props); makeObservable(this); - this.importAddedDocs(); } static _rowHeight: number = 50; @@ -97,7 +96,6 @@ export class CollectionSchemaView extends CollectionSubView() { @observable _colBeingDragged: boolean = false; @observable _colKeysFiltered: boolean = false; @observable _cellTags: ObservableMap = new ObservableMap<Doc, Array<string>>(); - @observable _lentDocs: Doc[] = []; @observable _docs: Doc[] = this.childDocs; // target HTMLelement portal for showing a popup menu to edit cell values. @@ -150,7 +148,7 @@ export class CollectionSchemaView extends CollectionSubView() { } @computed get rowHeights() { - return this.childDocs.concat(this._lentDocs).map(() => this.rowHeightFunc()); + return this.docs.map(() => this.rowHeightFunc()); } @computed get displayColumnWidths() { @@ -198,14 +196,6 @@ 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) => { this.removeDocument(doc); this._docs = this._docs.filter(d => d !== doc) @@ -278,7 +268,6 @@ export class CollectionSchemaView extends CollectionSubView() { break; } case 'P': { - this.importAddedDocs(); break; } default: @@ -651,16 +640,6 @@ export class CollectionSchemaView extends CollectionSubView() { return undefined; }; - addDocsFromOtherCollection = (docs: 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 = this._lentDocs.filter((doc: Doc) => !docs.includes(doc)); - this._docs = this.childDocs.slice().concat(this._lentDocs); - } - @computed get fieldDefaultInput() { switch (this._newFieldType) { case ColumnType.Number: @@ -739,7 +718,7 @@ export class CollectionSchemaView extends CollectionSubView() { }; setCellValues = (key: string, value: string) => { - if (this._selectedCells.length === 1) this.childDocs.forEach(doc => !doc._lockedSchemaEditing && Doc.SetField(doc, key, value)); // if only one cell selected, fill all + if (this._selectedCells.length === 1) this.childDocs.forEach(doc => !doc._lockedSchemaEditing &&Doc.SetField(doc, key, value)); // if only one cell selected, fill all else this._selectedCells.forEach(doc => !doc._lockedSchemaEditing && Doc.SetField(doc, key, value)); // else only fill selected cells return true; }; @@ -1038,16 +1017,36 @@ export class CollectionSchemaView extends CollectionSubView() { } }; + displayedSubCollectionDocs = (doc: Doc) => { + const childDocs = DocListCast(doc[Doc.LayoutFieldKey(doc)]); + const displayedCollections = childDocs.filter(d => d.type === 'collection' && d._childrenSharedWithSchema); + let toReturn: Doc[] = [...childDocs]; + displayedCollections.forEach(d => toReturn = toReturn.concat(this.displayedSubCollectionDocs(d))); + return toReturn; + } + + @computed get docs() { + let docsFromChildren: Doc[] = []; + const displayedCollections = this.childDocs.filter(d => d.type === 'collection' && d._childrenSharedWithSchema); + displayedCollections.forEach(d => { + let docsNotAlreadyDisplayed = this.displayedSubCollectionDocs(d).filter(dc => !this._docs.includes(dc)); + docsFromChildren = docsFromChildren.concat(docsNotAlreadyDisplayed); + }); + let docs = this._docs.concat(docsFromChildren); + return docs; + } + @computed get displayedDocs() { const draggedDocs = this.isContentActive() ? DragManager.docsBeingDragged : []; - const docs = this._docs.filter(d => !draggedDocs.includes(d)); + let docs = [...this.docs]; + docs = docs.filter(d => !draggedDocs.includes(d)); docs.splice(this.rowDropIndex, 0, ...draggedDocs); return { docs }; } @action sortDocs = (docs: Doc[], field: string, desc: boolean) => { - docs = docs.sort((docA, docB) => { + this._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 const aStr = Field.toString(docA[field] as FieldType); const bStr = Field.toString(docB[field] as FieldType); @@ -1115,8 +1114,6 @@ export class CollectionSchemaView extends CollectionSubView() { columnIndex={index} columnKeys={this.columnKeys} columnWidths={this.displayColumnWidths} - sortField={this.sortField} - sortDesc={this.sortDesc} setSort={this.setColumnSort} rowHeight={this.rowHeightFunc} removeColumn={this.removeColumn} diff --git a/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx b/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx index 3719840ff..0da186f81 100644 --- a/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx +++ b/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx @@ -30,8 +30,6 @@ export interface SchemaColumnHeaderProps { columnKeys: string[]; columnWidths: number[]; columnIndex: number; - sortField: string; - sortDesc: boolean; schemaView: CollectionSchemaView; keysDropdown: React.JSX.Element; //cleanupField: (s: string) => string; @@ -158,6 +156,46 @@ export class SchemaColumnHeader extends ObservableReactComponent<SchemaColumnHea return isDefault; } + get headerButton(){ + const toRender = SchemaColumnHeader.isDefaultField(this.fieldKey) ? + (<IconButton + icon={ <FontAwesomeIcon icon="trash" size='sm'/>} + size={Size.XSMALL} + color={'black'} + onPointerDown={e => + setupMoveUpEvents( + this, + e, + returnFalse, + emptyFunction, + undoable(clickEv => { + clickEv.stopPropagation(); + this._props.schemaView.removeColumn(this._props.columnIndex); + }, 'open column menu') + ) + } + />) + : (<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') + ) + } + />) + + return toRender; + } + render() { return ( <div @@ -177,23 +215,7 @@ export class SchemaColumnHeader extends ObservableReactComponent<SchemaColumnHea <div className="schema-header-menu"> <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') - ) - } - /> + {this.headerButton} </div> </div> </div> diff --git a/src/client/views/collections/collectionSchema/SchemaRowBox.tsx b/src/client/views/collections/collectionSchema/SchemaRowBox.tsx index 58964d9fb..a0d3144ce 100644 --- a/src/client/views/collections/collectionSchema/SchemaRowBox.tsx +++ b/src/client/views/collections/collectionSchema/SchemaRowBox.tsx @@ -79,7 +79,6 @@ export class SchemaRowBox extends ViewBoxBaseComponent<SchemaRowBoxProps>() { 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); }, icon: this.Document._childrenSharedWithSchema ? 'minus' : 'plus', }); |