diff options
author | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2024-06-23 03:36:21 -0400 |
---|---|---|
committer | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2024-06-23 03:36:21 -0400 |
commit | b2691d6119dfa1f192ac6eb19650f44742b253f5 (patch) | |
tree | 5ba18b5eb0181326a2ff2c517852ab8fd2d824c7 | |
parent | 9fab1b3ac096138fba3a99a2515ec44b526a3956 (diff) |
col filling (really external setting of cell fieldval) works properly (reaction); moved 'remove doc' option to bottom of row menu
4 files changed, 21 insertions, 19 deletions
diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx index 9c4eda3b8..2a84efa7c 100644 --- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx +++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx @@ -829,9 +829,9 @@ export class CollectionSchemaView extends CollectionSubView() { this.closeColumnMenu(); }; - setCellValues = (key: string, value: string) => { - if (this._selectedCells.length === 1) this.docs.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 + setColumnValues = (key: string, value: string) => { + if (this._selectedCells.length === 1) this.docs.forEach(doc => !doc._lockedSchemaEditing &&Doc.SetField(doc, key, value)); + else this._selectedCells.forEach(doc => !doc._lockedSchemaEditing && Doc.SetField(doc, key, value)); return true; }; diff --git a/src/client/views/collections/collectionSchema/SchemaCellField.tsx b/src/client/views/collections/collectionSchema/SchemaCellField.tsx index aa6c382ef..e85bf75e6 100644 --- a/src/client/views/collections/collectionSchema/SchemaCellField.tsx +++ b/src/client/views/collections/collectionSchema/SchemaCellField.tsx @@ -36,7 +36,7 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro makeObservable(this); setTimeout(() => { this._unrenderedContent = this._props.GetValue() ?? ''; - this.setContent(this._unrenderedContent, true); + this.setContent(this._unrenderedContent); }, 0); //must be moved to end of batch or else other docs aren't loaded, so render as d-1 in function } @@ -65,6 +65,13 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro }, { fireImmediately: true } ); + this._disposers.fieldUpdate = reaction( + () => this._props.GetValue(), + fieldVal => { + this._unrenderedContent = fieldVal ?? ''; + this.setContent(this._unrenderedContent); + } + ) } componentDidUpdate(prevProps: Readonly<SchemaCellFieldProps>) { @@ -79,7 +86,7 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro componentWillUnmount(): void { this._overlayDisposer?.(); - this._disposers.editing?.(); + Object.values(this._disposers).forEach(disposer => disposer?.()); this.finalizeEdit(false, true, false); } @@ -98,15 +105,12 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro while ((match = pattern.exec(content)) !== null) { const cell = this._props.getCells(match[0]); - //console.log(cell) if (cell.length) { matches.push(match[0]); cells.set(match[0], cell[0]) } } - //console.log(cells) - let matchNum = 0; matches.forEach((match: string) => { const adjMatch = match.replace('this.', `d${this.docIndex}`) @@ -237,6 +241,8 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro case 'Shift': case 'Alt': case 'Meta': case 'Control': case ':': //prettier-ignore break; // eslint-disable-next-line no-fallthrough + case 'P': + break; default: break; } @@ -253,7 +259,6 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro @action finalizeEdit(shiftDown: boolean, lostFocus: boolean, enterKey: boolean) { - this.setContent(this._unrenderedContent); if (this._props.SetValue(this._unrenderedContent, shiftDown, enterKey)) { this._editing = false; } else { diff --git a/src/client/views/collections/collectionSchema/SchemaRowBox.tsx b/src/client/views/collections/collectionSchema/SchemaRowBox.tsx index 45f178815..d2c0d891f 100644 --- a/src/client/views/collections/collectionSchema/SchemaRowBox.tsx +++ b/src/client/views/collections/collectionSchema/SchemaRowBox.tsx @@ -61,11 +61,6 @@ export class SchemaRowBox extends ViewBoxBaseComponent<SchemaRowBoxProps>() { openContextMenu = (x: number, y: number) => { ContextMenu.Instance.clearItems(); ContextMenu.Instance.addItem({ - description: `Close doc`, - event: () => this.schemaView.removeDoc(this.Document), - icon: 'minus', - }); - ContextMenu.Instance.addItem({ description: this.Document._lockedSchemaEditing ? 'Unlock field editing' : 'Lock field editing', event: () => this.Document._lockedSchemaEditing = !this.Document._lockedSchemaEditing, icon: this.Document._lockedSchemaEditing ? 'lock-open' : 'lock', @@ -75,6 +70,11 @@ export class SchemaRowBox extends ViewBoxBaseComponent<SchemaRowBoxProps>() { event: () => this._props.addDocTab(this.Document, OpenWhere.addRight), icon: 'magnifying-glass', }); + ContextMenu.Instance.addItem({ + description: `Close doc`, + event: () => this.schemaView.removeDoc(this.Document), + icon: 'minus', + }); const childDocs = DocListCast(this.Document[Doc.LayoutFieldKey(this.Document)]) if (this.Document.type === 'collection' && childDocs.length) { ContextMenu.Instance.addItem({ @@ -119,7 +119,7 @@ export class SchemaRowBox extends ViewBoxBaseComponent<SchemaRowBoxProps>() { selectCell = (doc: Doc, col: number, shift: boolean, ctrl: boolean) => this.schemaView?.selectCell(doc, col, shift, ctrl); deselectCell = () => this.schemaView?.deselectAllCells(); selectedCells = () => this.schemaView?._selectedDocs; - setColumnValues = (field: any, value: any) => this.schemaView?.setCellValues(field, value) ?? false; + setColumnValues = (field: any, value: any) => this.schemaView?.setColumnValues(field, value) ?? false; columnWidth = computedFn((index: number) => () => this.schemaView?.displayColumnWidths[index] ?? CollectionSchemaView._minColWidth); computeRowIndex = () => this.schemaView?.rowIndex(this.Document); highlightCells = (text: string) => this.schemaView?.highlightCells(text); @@ -130,7 +130,6 @@ export class SchemaRowBox extends ViewBoxBaseComponent<SchemaRowBoxProps>() { const info = this.schemaView.findCellRefs(text); const cells: HTMLDivElement[] = []; info.forEach(info => {cells.push(this.schemaView.getCellElement(info[0], info[1]))}) - console.log('info: ' + info + ' cells: ' + cells); return cells; }; render() { diff --git a/src/client/views/collections/collectionSchema/SchemaTableCell.tsx b/src/client/views/collections/collectionSchema/SchemaTableCell.tsx index 6ccada48c..aa8401502 100644 --- a/src/client/views/collections/collectionSchema/SchemaTableCell.tsx +++ b/src/client/views/collections/collectionSchema/SchemaTableCell.tsx @@ -145,14 +145,12 @@ export class SchemaTableCell extends ObservableReactComponent<SchemaTableCellPro } adjustSelfReference = (field: string) => { - const pattern = /\bthis.\b/g; - const modField = field.replace(pattern, `d${this.docIndex}.`); + const modField = field.replace(/\bthis.\b/g, `d${this.docIndex}.`); return modField; } // parses a field from the "idToDoc(####)" format to DocumentId (d#) format for readability cleanupField = (field: string) => { - if (field === ':=d6.type + d4.type + d3.type') console.log(true) const idPattern = /idToDoc\((.*?)\)/g; let modField = field.slice(); let matches; |