diff options
-rw-r--r-- | src/client/views/collections/collectionSchema/CollectionSchemaView.tsx | 73 |
1 files changed, 56 insertions, 17 deletions
diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx index f7a553da3..2704b5234 100644 --- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx +++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx @@ -324,9 +324,24 @@ export class CollectionSchemaView extends CollectionSubView() { }); } - parseEquation = (eq: string): string => { + parseEquation = (eq: string): [string, Map<string, Doc>] => { const variablePattern = /[a-z]+/gi; - return eq.replace(variablePattern, (match) => `doc.${match}`); + const tagRefPattern = /{([^}]*)}/g; + const tagRefs = eq.match(tagRefPattern) + const docTagRefPairs = new Map; + let modifiedEq = eq; + + if (tagRefs){ + tagRefs.forEach(ref => { + const [doc, key] = this.getCellInfoFromTag(ref); + docTagRefPairs.set(ref, doc); + const replacement = `docTagRefPairs.get('${ref}').${key}`; + modifiedEq = modifiedEq.replace(new RegExp(ref, 'g'), replacement); + }) + } + modifiedEq = modifiedEq.replace(variablePattern, (match) => `doc.${match}`); + + return [eq, docTagRefPairs] } parsedEquationResult = (eq: string, doc: any): number => { @@ -529,6 +544,9 @@ export class CollectionSchemaView extends CollectionSubView() { @action selectCell = (doc: Doc, col: number, shiftKey: boolean, ctrlKey: boolean) => { + this.populateCellTags(); + console.log(this.getCellTag(doc, col)); + console.log(this.getCellInfoFromTag("C1")); if (!shiftKey && !ctrlKey) this.clearSelection(); !this._selectedCells && (this._selectedCells = []); !shiftKey && this._selectedCells && this._selectedCells.push(doc); @@ -551,10 +569,46 @@ export class CollectionSchemaView extends CollectionSubView() { // let selectedIndexes: Array<Number> = this._selectedCells.map(doc => this.rowIndex(doc)); }; + @action + deselectCell = (doc: Doc) => { + this._selectedCells && (this._selectedCells = this._selectedCells.filter(d => d !== doc)); + if (this.rowIndex(doc) === this._lowestSelectedIndex) this._lowestSelectedIndex = Math.min(...this._selectedDocs.map(d => this.rowIndex(d))); + }; + + @action + deselectAllCells = () => { + this._selectedCells = []; + this._lowestSelectedIndex = -1; + }; + + sortedSelectedDocs = () => this.sortedDocs.docs.filter(doc => this._selectedDocs.includes(doc)); + + getCellTag = (doc: Doc, col: number) => { return this._cellTags.get(doc)[col]; } + getCellInfoFromTag = (tag: string): [Doc, string] => { + const lettersToNumber = (letters: string) => { + let number = 0; + let length = letters.length; + for (let i = 0; i < length; i++) { + number *= 26; + number += (letters.charCodeAt(i) - 'A'.charCodeAt(0) + 1); + } + return number; + } + + const colTag = tag.replace(/[^A-Z]/g, ''); + const col = lettersToNumber(colTag); + const key: string = this.columnKeys[col]; + + const rowNum = Number(tag.replace(/[^\d]/g, '')); + const doc = this.childDocs[rowNum]; + + return [doc, key]; + } + populateCellTags = () => { this.childDocs.forEach(doc => this.addTags(doc)); } @@ -594,20 +648,6 @@ export class CollectionSchemaView extends CollectionSubView() { return result; } - @action - deselectCell = (doc: Doc) => { - this._selectedCells && (this._selectedCells = this._selectedCells.filter(d => d !== doc)); - if (this.rowIndex(doc) === this._lowestSelectedIndex) this._lowestSelectedIndex = Math.min(...this._selectedDocs.map(d => this.rowIndex(d))); - }; - - @action - deselectAllCells = () => { - this._selectedCells = []; - this._lowestSelectedIndex = -1; - }; - - sortedSelectedDocs = () => this.sortedDocs.docs.filter(doc => this._selectedDocs.includes(doc)); - @computed get rowDropIndex() { const mouseY = this.ScreenToLocalBoxXf().transformPoint(this._mouseCoordinates.x, this._mouseCoordinates.y)[1]; @@ -774,7 +814,6 @@ export class CollectionSchemaView extends CollectionSubView() { @action setKey = (key: string, defaultVal?: any) => { - console.log("called") if (this._makeNewColumn) { this.addColumn(key, defaultVal); } else { |