diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/collections/collectionSchema/CollectionSchemaView.tsx | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx index 2704b5234..19d170c81 100644 --- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx +++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx @@ -287,7 +287,8 @@ export class CollectionSchemaView extends CollectionSubView() { if (!this.documentKeys.includes(key)) { this.addNewKey(key, defaultVal); } - + + this.modifyCellTags(true); const newColWidth = this.tableWidth / (this.storedColumnWidths.length + 1); const currWidths = this.storedColumnWidths.slice(); currWidths.splice(0, 0, newColWidth); @@ -316,37 +317,37 @@ export class CollectionSchemaView extends CollectionSubView() { } } - @action - setupAutoUpdate = (equation: string, doc: Doc) => { - return autorun(() => { - const result = this.parsedEquationResult(equation, doc); - doc[DocData][equation] = result; - }); - } + // @action + // setupAutoUpdate = (equation: string, doc: Doc) => { + // return autorun(() => { + // const result = this.parsedEquationResult(equation, doc); + // doc[DocData][equation] = result; + // }); + // } parseEquation = (eq: string): [string, Map<string, Doc>] => { const variablePattern = /[a-z]+/gi; const tagRefPattern = /{([^}]*)}/g; - const tagRefs = eq.match(tagRefPattern) - const docTagRefPairs = new Map; + const docTagRefPairs = new Map<string, Doc>(); 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); - }) + let match; + + while (match = tagRefPattern.exec(eq)) { + const ref = match[1]; + 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] + + //modifiedEq = modifiedEq.replace(variablePattern, (match) => `doc.${match}`); + + return [modifiedEq, docTagRefPairs]; } - - parsedEquationResult = (eq: string, doc: any): number => { - const func = new Function('doc', 'return ' + eq); - return func(doc); + + parsedEquationResult = (eq: [string, Map<string, Doc>], doc: any): number => { + const func = new Function('doc', 'docTagRefPairs', 'return ' + eq[0]); + return func(doc, eq[1]); } @undoBatch @@ -604,7 +605,7 @@ export class CollectionSchemaView extends CollectionSubView() { const key: string = this.columnKeys[col]; const rowNum = Number(tag.replace(/[^\d]/g, '')); - const doc = this.childDocs[rowNum]; + const doc = this.childDocs[rowNum - 1]; return [doc, key]; } |