diff options
4 files changed, 75 insertions, 28 deletions
diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx index 33ae8aad1..60b3ae4ab 100644 --- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx +++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx @@ -190,13 +190,14 @@ export class CollectionSchemaView extends CollectionSubView() { const lastIndex = this.rowIndex(lastDoc); const curDoc = this.sortedDocs.docs[lastIndex]; if (lastIndex >= 0 && lastIndex < this.childDocs.length - 1) { - !e.shiftKey && this.clearSelection(); const newDoc = this.sortedDocs.docs[lastIndex + 1]; if (this._selectedDocs.includes(newDoc)) { SelectionManager.DeselectView(DocumentManager.Instance.getFirstDocumentView(curDoc)); + this.deselectCell(curDoc); + } else { - this.addDocToSelection(newDoc, e.shiftKey, lastIndex + 1); - this.selectCell(newDoc, this._selectedCells ? this._selectedCells[1] : 0, false); + const shift: boolean = e.shiftKey; + this.selectCell(newDoc, this._selectedCells ? this._selectedCells[1] : 2, shift); this.scrollToDoc(newDoc, {}); } } @@ -210,12 +211,14 @@ export class CollectionSchemaView extends CollectionSubView() { const firstIndex = this.rowIndex(firstDoc); const curDoc = this.sortedDocs.docs[firstIndex]; if (firstIndex > 0 && firstIndex < this.childDocs.length) { - !e.shiftKey && this.clearSelection(); const newDoc = this.sortedDocs.docs[firstIndex - 1]; - if (this._selectedDocs.includes(newDoc)) SelectionManager.DeselectView(DocumentManager.Instance.getFirstDocumentView(curDoc)); - else { - this.addDocToSelection(newDoc, e.shiftKey, firstIndex - 1); - this.selectCell(newDoc, this._selectedCells ? this._selectedCells[1] + 1 : 0, false); + if (this._selectedDocs.includes(newDoc)){ + SelectionManager.DeselectView(DocumentManager.Instance.getFirstDocumentView(curDoc)) + this.deselectCell(curDoc); + } else { + const shift: boolean = e.shiftKey; + + this.selectCell(newDoc, this._selectedCells ? this._selectedCells[1] : 2, shift); this.scrollToDoc(newDoc, {}); } } @@ -231,7 +234,13 @@ export class CollectionSchemaView extends CollectionSubView() { } break; case 'ArrowLeft': - this.changeSelectedCellColumn(); + if (this._selectedCells) { + this._selectedCells = undefined; + //this._selectedCells = [this._selectedCells[0], 2] + //this._selectedCells[1] = Math.max(this._selectedCells[1] - 1, 0); + } else if (this._selectedDocs.length > 0) { + this.selectCell(this._selectedDocs[0], 0, false); + } break; case 'Backspace': { this.removeDocument(this._selectedDocs); @@ -246,11 +255,7 @@ export class CollectionSchemaView extends CollectionSubView() { @action changeSelectedCellColumn = () => { - if (this._selectedCells) { - this._selectedCells[1] = Math.max(this._selectedCells[1] - 1, 0); - } else if (this._selectedDocs.length > 0) { - this.selectCell(this._selectedDocs[0], 0, false); - } + } @undoBatch @@ -422,11 +427,14 @@ export class CollectionSchemaView extends CollectionSubView() { //console.log("doc added"); const rowDocView = DocumentManager.Instance.getDocumentView(doc); if (rowDocView) SelectionManager.SelectView(rowDocView, extendSelection); + //let selectedIndexes: Array<Number> = this._selectedDocs.map(doc => this.rowIndex(doc)); + //console.log(selectedIndexes); }; @action clearSelection = () => { - SelectionManager.DeselectAll() + SelectionManager.DeselectAll(); + this.deselectAllCells(); }; //This method is called in SchemaRowBox.select, which is never called anywhere @@ -435,33 +443,41 @@ export class CollectionSchemaView extends CollectionSubView() { const lastSelectedRow = this.rowIndex(lastSelected); const startRow = Math.min(lastSelectedRow, index); const endRow = Math.max(lastSelectedRow, index); - console.log(lastSelectedRow); - console.log("start: " + startRow + " end: " + endRow); + //console.log(lastSelectedRow); + //console.log("start: " + startRow + " end: " + endRow); for (let i = startRow; i <= endRow; i++) { const currDoc = this.sortedDocs.docs[i]; if (!this._selectedDocs.includes(currDoc)) this.addDocToSelection(currDoc, true, i); + this._selectedCells && this._selectedCells[0].push(currDoc); } }; @action selectCell = (doc: Doc, index: number, shiftKey: boolean) => { - //console.log("cellSelect"); - //console.log(shiftKey); - shiftKey = true; - !this._selectedCells && (this._selectedCells = [[doc], index]); + !shiftKey && this.deselectAllCells(); + !this._selectedCells && (this._selectedCells = [[], index]); this._selectedCells[0].push(doc); this._selectedCells[1] = index; + if (!this) return; const lastSelected = Array.from(this._selectedDocs).lastElement(); if (shiftKey && lastSelected) this.selectRows(doc, lastSelected); else { - this.addDocToSelection(doc, false, 0); + this.addDocToSelection(doc, false, this.rowIndex(doc)); } + + let selectedIndexes: Array<Number> = this._selectedCells[0].map(doc => this.rowIndex(doc)); + console.log("cells: " + selectedIndexes); }; @action deselectCell = (doc: Doc) => { - this._selectedCells && this._selectedCells[0].filter(d => d !== doc); + if (this._selectedCells) + this._selectedCells[0] = this._selectedCells[0].filter(d => d !== doc); + if (this._selectedCells){ + let selectedIndexes: Array<Number> = this._selectedCells[0].map(doc => this.rowIndex(doc)); + console.log("cells: " + selectedIndexes); + } }; @action @@ -590,7 +606,27 @@ export class CollectionSchemaView extends CollectionSubView() { }; setColumnValues = (key: string, value: string) => { - this.childDocs.forEach(doc => KeyValueBox.SetField(doc, key, value)); + this.childDocs.forEach(doc => { + let docIsSelected = this._selectedCells && !(this._selectedCells[0]?.filter(d => d === doc).length === 0); + console.log(docIsSelected); + if (docIsSelected){ + KeyValueBox.SetField(doc, key, value) + } + } + ); + //this.childDocs.forEach(doc => KeyValueBox.SetField(doc, key, value)); + return true; + }; + + setSelectedColumnValues = (key: string, value: string) => { + console.log("called"); + this.childDocs.forEach(doc => { + let docIsSelected = this._selectedCells && !(this._selectedCells[0]?.filter(d => d === doc).length === 0); + if (docIsSelected){ + KeyValueBox.SetField(doc, key, value) + } + } + ); return true; }; diff --git a/src/client/views/collections/collectionSchema/SchemaRowBox.tsx b/src/client/views/collections/collectionSchema/SchemaRowBox.tsx index 0ef78fe07..af502dd03 100644 --- a/src/client/views/collections/collectionSchema/SchemaRowBox.tsx +++ b/src/client/views/collections/collectionSchema/SchemaRowBox.tsx @@ -103,6 +103,7 @@ export class SchemaRowBox extends ViewBoxBaseComponent<SchemaRowBoxProps>() { deselectCell = () => this.schemaView?.deselectAllCells(); selectedCell = () => this.schemaView?._selectedCells; setColumnValues = (field: any, value: any) => this.schemaView?.setColumnValues(field, value) ?? false; + setSelectedColumnValues = (field: any, value: any) => this.schemaView?.setSelectedColumnValues(field, value) ?? false; columnWidth = computedFn((index: number) => () => this.schemaView?.displayColumnWidths[index] ?? CollectionSchemaView._minColWidth); render() { return ( @@ -188,6 +189,7 @@ export class SchemaRowBox extends ViewBoxBaseComponent<SchemaRowBoxProps>() { deselectCell={this.deselectCell} selectedCells={this.selectedCell} setColumnValues={this.setColumnValues} + setSelectedColumnValues={this.setSelectedColumnValues} oneLine={BoolCast(this.schemaDoc?._singleLine)} menuTarget={this.schemaView.MenuTarget} transform={() => { diff --git a/src/client/views/collections/collectionSchema/SchemaTableCell.tsx b/src/client/views/collections/collectionSchema/SchemaTableCell.tsx index 2769b5042..cae16be36 100644 --- a/src/client/views/collections/collectionSchema/SchemaTableCell.tsx +++ b/src/client/views/collections/collectionSchema/SchemaTableCell.tsx @@ -45,6 +45,7 @@ export interface SchemaTableCellProps { isRowActive: () => boolean | undefined; getFinfo: (fieldKey: string) => FInfo | undefined; setColumnValues: (field: string, value: string) => boolean; + setSelectedColumnValues: (field: string, value: string) => boolean; oneLine?: boolean; // whether all input should fit on one line vs allowing textare multiline inputs allowCRs?: boolean; // allow carriage returns in text input (othewrise CR ends the edit) finishEdit?: () => void; // notify container that edit is over (eg. to hide view in DashFieldView) @@ -107,7 +108,7 @@ export class SchemaTableCell extends ObservableReactComponent<SchemaTableCellPro } @computed get selected() { - const selected = this._props.selectedCells(); + const selected: [Doc[], number] | undefined = this._props.selectedCells(); let istrue = this._props.isRowActive() && (selected && selected[0]?.filter(doc => doc === this._props.Document).length !== 0) && selected[1] === this._props.col; //console.log("col: " + this._props.col + "true: " + istrue); return istrue; @@ -135,7 +136,9 @@ export class SchemaTableCell extends ObservableReactComponent<SchemaTableCellPro SetValue={undoable((value: string, shiftDown?: boolean, enterKey?: boolean) => { if (shiftDown && enterKey) { this._props.setColumnValues(this._props.fieldKey.replace(/^_/, ''), value); - } + } /*else { + this._props.setSelectedColumnValues(this._props.fieldKey.replace(/^_/, ''), value); + }*/ const ret = KeyValueBox.SetField(this._props.Document, this._props.fieldKey.replace(/^_/, ''), value); this._props.finishEdit?.(); return ret; @@ -179,7 +182,12 @@ export class SchemaTableCell extends ObservableReactComponent<SchemaTableCellPro return ( <div className="schema-table-cell" - onPointerDown={action(e => !this.selected && this._props.selectCell(this._props.Document, this._props.col, e.shiftKey))} + onPointerDown={action(e => { + console.log(e); + console.log(e.shiftKey); + const shift: boolean = e.shiftKey; + !this.selected && this._props.selectCell(this._props.Document, this._props.col, shift)} + )} style={{ padding: this._props.padding, maxWidth: this._props.maxWidth?.(), width: this._props.columnWidth() || undefined, border: this.selected ? `solid 2px ${Colors.MEDIUM_BLUE}` : undefined }}> {this.content} </div> diff --git a/src/client/views/nodes/formattedText/DashFieldView.tsx b/src/client/views/nodes/formattedText/DashFieldView.tsx index b0c35b161..631de1241 100644 --- a/src/client/views/nodes/formattedText/DashFieldView.tsx +++ b/src/client/views/nodes/formattedText/DashFieldView.tsx @@ -140,13 +140,14 @@ export class DashFieldViewInternal extends ObservableReactComponent<IDashFieldVi selectCell={emptyFunction} maxWidth={this._props.hideKey ? undefined : this.return100} columnWidth={this._props.hideKey ? () => this._props.tbox._props.PanelWidth() - 20 : returnZero} - selectedCells={() => [this._dashDoc!, 0]} + selectedCells={() => [[this._dashDoc!], 0]} fieldKey={this._fieldKey} rowHeight={returnZero} isRowActive={() => this._expanded && this._props.editable} padding={0} getFinfo={emptyFunction} setColumnValues={returnFalse} + setSelectedColumnValues={returnFalse} allowCRs={true} oneLine={!this._expanded} finishEdit={action(() => (this._expanded = false))} |