diff options
author | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2024-05-09 23:33:17 -0400 |
---|---|---|
committer | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2024-05-09 23:33:17 -0400 |
commit | 2d7037dd5664700cda04b1fb0c6c77fe6f49d66c (patch) | |
tree | 63a5493139d91b7fd18cff0f1909a8a5e375939c | |
parent | 8fe221d77d8c5e0ffce67a1dd0483b41368820ee (diff) |
goodbye old parser ;( hello new parser :)
5 files changed, 48 insertions, 41 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 1c18c0d84..f0974f5dd 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -43,7 +43,7 @@ export class FInfo { readOnly: boolean = false; fieldType?: FInfoFieldType; values?: FieldType[]; - + onLayout?: boolean; filterable?: boolean = true; // can be used as a Filter in FilterPanel // format?: string; // format to display values (e.g, decimal places, $, etc) // parse?: ScriptField; // parse a value from a string diff --git a/src/client/views/FieldsDropdown.tsx b/src/client/views/FieldsDropdown.tsx index 0ea0ebd83..011cd51b3 100644 --- a/src/client/views/FieldsDropdown.tsx +++ b/src/client/views/FieldsDropdown.tsx @@ -34,7 +34,7 @@ export class FieldsDropdown extends ObservableReactComponent<fieldsDropdownProps makeObservable(this); } - @computed get allDescendantDocs() { + @computed get allDescendantDocs() { //!!! const allDocs = new Set<Doc>(); SearchUtil.foreachRecursiveDoc([this._props.Document], (depth, doc) => allDocs.add(doc)); return Array.from(allDocs); @@ -57,7 +57,7 @@ export class FieldsDropdown extends ObservableReactComponent<fieldsDropdownProps const filteredOptions = ['author', ...(this._newField ? [this._newField] : []), ...(this._props.addedFields ?? []), ...this.fieldsOfDocuments.filter(facet => facet[0] === facet.charAt(0).toUpperCase())]; Object.entries(DocOptions) - .filter(opts => opts[1].filterable) + .filter(opts => opts[1].filterable) //!!! .forEach((pair: [string, FInfo]) => filteredOptions.push(pair[0])); const options = filteredOptions.sort().map(facet => ({ value: facet, label: facet })); diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx index 19d170c81..e493b2e5d 100644 --- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx +++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx @@ -6,7 +6,7 @@ import { observer } from 'mobx-react'; import * as React from 'react'; import { returnEmptyDoclist, returnEmptyString, returnFalse, returnIgnore, returnNever, returnTrue, setupMoveUpEvents, smoothScroll } from '../../../../ClientUtils'; import { emptyFunction } from '../../../../Utils'; -import { Doc, DocListCast, Field, FieldType, NumListCast, Opt, StrListCast } from '../../../../fields/Doc'; +import { Doc, DocListCast, Field, FieldType, IdToDoc, NumListCast, Opt, StrListCast } from '../../../../fields/Doc'; import { DocData } from '../../../../fields/DocSymbols'; import { Id } from '../../../../fields/FieldSymbols'; import { List } from '../../../../fields/List'; @@ -288,7 +288,6 @@ export class CollectionSchemaView extends CollectionSubView() { 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); @@ -302,19 +301,24 @@ export class CollectionSchemaView extends CollectionSubView() { @action addNewKey = (key: string, defaultVal: any) => { - if (this._newFieldType == ColumnType.Equation) { - this.childDocs.forEach(doc => { - const parsedEquation = this.parseEquation(defaultVal); - const val = computed(() => { return this.parsedEquationResult(parsedEquation, doc);}) - doc[DocData][key] = val.get(); - // doc[DocData][key] = this.parsedEquationResult(eq, doc); - // this.setupAutoUpdate(eq, doc); - }); - } else { - this.childDocs.forEach(doc => { - doc[DocData][key] = defaultVal; - }); + this.childDocs.forEach(doc => { + doc[DocData][key] = defaultVal; + }); + } + + cleanupComputedField = (field: string) => { + const idPattern = /idToDoc\((.*?)\)/g; + let modField = field.slice(); + let matches; + let results = new Map<string, string>(); + while ((matches = idPattern.exec(field)) !== null) { + results.set(matches[0], matches[1].replace(/"/g, '')); } + console.log(results); + results.forEach((id, funcId) => { + modField = modField.replace(funcId, 'd' + (this.rowIndex(IdToDoc(id)) + 1).toString()); + }) + return modField; } // @action @@ -325,30 +329,30 @@ export class CollectionSchemaView extends CollectionSubView() { // }); // } - parseEquation = (eq: string): [string, Map<string, Doc>] => { - const variablePattern = /[a-z]+/gi; - const tagRefPattern = /{([^}]*)}/g; - const docTagRefPairs = new Map<string, Doc>(); - let modifiedEq = eq; - let match; + // parseEquation = (eq: string): [string, Map<string, Doc>] => { + // const variablePattern = /[a-z]+/gi; + // const tagRefPattern = /{([^}]*)}/g; + // const docTagRefPairs = new Map<string, Doc>(); + // let modifiedEq = eq; + // 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); - } + // 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}`); + // modifiedEq = modifiedEq.replace(variablePattern, (match) => `doc.${match}`); - return [modifiedEq, docTagRefPairs]; - } + // return [modifiedEq, docTagRefPairs]; + // } - parsedEquationResult = (eq: [string, Map<string, Doc>], doc: any): number => { - const func = new Function('doc', 'docTagRefPairs', 'return ' + eq[0]); - return func(doc, eq[1]); - } + // parsedEquationResult = (eq: [string, Map<string, Doc>], doc: any): number => { + // const func = new Function('doc', 'docTagRefPairs', 'return ' + eq[0]); + // return func(doc, eq[1]); + // } @undoBatch removeColumn = (index: number) => { @@ -547,7 +551,6 @@ export class CollectionSchemaView extends CollectionSubView() { 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); @@ -602,7 +605,7 @@ export class CollectionSchemaView extends CollectionSubView() { const colTag = tag.replace(/[^A-Z]/g, ''); const col = lettersToNumber(colTag); - const key: string = this.columnKeys[col]; + const key: string = this.columnKeys[col - 1]; const rowNum = Number(tag.replace(/[^\d]/g, '')); const doc = this.childDocs[rowNum - 1]; diff --git a/src/client/views/collections/collectionSchema/SchemaRowBox.tsx b/src/client/views/collections/collectionSchema/SchemaRowBox.tsx index 760089ffb..3295c9ab1 100644 --- a/src/client/views/collections/collectionSchema/SchemaRowBox.tsx +++ b/src/client/views/collections/collectionSchema/SchemaRowBox.tsx @@ -52,6 +52,7 @@ export class SchemaRowBox extends ViewBoxBaseComponent<SchemaRowBoxProps>() { this._props.setContentViewBox?.(this); } + cleanupField = (field: string) => this.schemaView.cleanupComputedField(field) setCursorIndex = (mouseY: number) => this.schemaView?.setRelCursorIndex(mouseY); selectedCol = () => this.schemaView._selectedCol; getFinfo = computedFn((fieldKey: string) => this.schemaView?.fieldInfos.get(fieldKey)); @@ -149,6 +150,7 @@ export class SchemaRowBox extends ViewBoxBaseComponent<SchemaRowBoxProps>() { setSelectedColumnValues={this.setSelectedColumnValues} oneLine={BoolCast(this.schemaDoc?._singleLine)} menuTarget={this.schemaView.MenuTarget} + cleanupField={this.cleanupField} transform={() => { const ind = index === this.schemaView.columnKeys.length - 1 ? this.schemaView.columnKeys.length - 3 : index; const x = this.schemaView?.displayColumnWidths.reduce((p, c, i) => (i <= ind ? p + c : p), 0); diff --git a/src/client/views/collections/collectionSchema/SchemaTableCell.tsx b/src/client/views/collections/collectionSchema/SchemaTableCell.tsx index 67991b8a2..d11af6b3c 100644 --- a/src/client/views/collections/collectionSchema/SchemaTableCell.tsx +++ b/src/client/views/collections/collectionSchema/SchemaTableCell.tsx @@ -57,6 +57,7 @@ export interface SchemaTableCellProps { transform: () => Transform; autoFocus?: boolean; // whether to set focus on creation, othwerise wait for a click rootSelected?: () => boolean; + cleanupField: (field: string) => string; } function selectedCell(props: SchemaTableCellProps) { @@ -141,14 +142,15 @@ export class SchemaTableCell extends ObservableReactComponent<SchemaTableCellPro contents={undefined} fieldContents={fieldProps} editing={selectedCell(this._props) ? undefined : false} - GetValue={() => Field.toKeyValueString(fieldProps.Document, this._props.fieldKey, SnappingManager.MetaKey)} + GetValue={() => this._props.cleanupField(Field.toKeyValueString(fieldProps.Document, this._props.fieldKey, SnappingManager.MetaKey))} //TODO: feed this into parser that handles idToDoc SetValue={undoable((value: string, shiftDown?: boolean, enterKey?: boolean) => { if (shiftDown && enterKey) { this._props.setColumnValues(this._props.fieldKey.replace(/^_/, ''), value); this._props.finishEdit?.(); return true; } - const ret = Doc.SetField(fieldProps.Document, this._props.fieldKey.replace(/^_/, ''), value, Doc.IsDataProto(fieldProps.Document) ? true : undefined); + const hasNoLayout = Doc.IsDataProto(fieldProps.Document) ? true : undefined; // the "delegate" is a a data document so never write to it's proto + const ret = Doc.SetField(fieldProps.Document, this._props.fieldKey.replace(/^_/, ''), value, hasNoLayout); this._props.finishEdit?.(); return ret; }, 'edit schema cell')} |