diff --git a/src/app/shared/components/template/components/data-items/data-items.component.spec.ts b/src/app/shared/components/template/components/data-items/data-items.component.spec.ts index e9418ff47..55ed2817c 100644 --- a/src/app/shared/components/template/components/data-items/data-items.component.spec.ts +++ b/src/app/shared/components/template/components/data-items/data-items.component.spec.ts @@ -9,6 +9,7 @@ import { DynamicDataService } from "src/app/shared/services/dynamic-data/dynamic import { _wait } from "packages/shared/src/utils/async-utils"; import { TemplatedData } from "packages/shared/src/models/templatedData/templatedData"; import { MockDynamicDataService } from "src/app/shared/services/dynamic-data/dynamic-data.service.mock.spec"; +import { DataItemsService } from "./data-items.service"; const MOCK_ITEMS_LIST: FlowTypes.Data_listRow[] = [ { id: "id_1", text: "item 1", number: 1, boolean: true }, @@ -89,11 +90,14 @@ describe("DataItemsComponent", () => { provide: DynamicDataService, useValue: new MockDynamicDataService({ data_list: { mock_item_list: MOCK_ITEMS_LIST } }), }, + DataItemsService, ], }).compileComponents(); fixture = TestBed.createComponent(TmplDataItemsComponent); fixture.componentInstance["hackProcessRows"] = mockHackProcessRows; + // HACK - support @local variable processing + fixture.componentInstance.parent = { templateRowService: { templateRowMap: {} } } as any; component = fixture.componentInstance; fixture.detectChanges(); }); @@ -102,7 +106,7 @@ describe("DataItemsComponent", () => { expect(component).toBeTruthy(); }); - it("generates evaluation context for rows", async () => { + fit("generates evaluation context for rows", async () => { const renderedRows = await setTestRow(component, MOCK_DATA_ITEMS_ROW); // all rows should be populated with full item data alongside metadata fields expect(renderedRows[0]._evalContext).toEqual({ diff --git a/src/app/shared/components/template/components/data-items/data-items.component.ts b/src/app/shared/components/template/components/data-items/data-items.component.ts index 1df33ce9c..2942e7773 100644 --- a/src/app/shared/components/template/components/data-items/data-items.component.ts +++ b/src/app/shared/components/template/components/data-items/data-items.component.ts @@ -62,6 +62,7 @@ export class TmplDataItemsComponent extends TemplateBaseComponent implements OnD } private async handleRowUpdate(row: FlowTypes.TemplateRow) { + console.log("handle row update", row); const { templateRowMap } = this.parent.templateRowService; // HACK - row.value = row.value.replace(`@data.`, ""); diff --git a/src/app/shared/components/template/components/data-items/data-items.service.spec.ts b/src/app/shared/components/template/components/data-items/data-items.service.spec.ts new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/shared/components/template/components/data-items/data-items.service.ts b/src/app/shared/components/template/components/data-items/data-items.service.ts index d417e463d..334d5a44d 100644 --- a/src/app/shared/components/template/components/data-items/data-items.service.ts +++ b/src/app/shared/components/template/components/data-items/data-items.service.ts @@ -2,8 +2,7 @@ import { Injectable } from "@angular/core"; import { TemplateVariablesService } from "../../services/template-variables.service"; import { FlowTypes } from "packages/data-models"; import { flattenJson } from "../../utils"; -import { getNestedProperty, setNestedProperty } from "src/app/shared/utils"; -import { addStringDelimiters } from "packages/shared/src/utils/delimiters"; +import { setNestedProperty } from "src/app/shared/utils"; type IDynamicHashmap = Record; export type IDataItemsEvalContext = { @@ -15,6 +14,7 @@ export class DataItemsService { constructor(private templateVariablesService: TemplateVariablesService) {} public async parseRow(row: FlowTypes.TemplateRow, templateRowMap = {}) { + console.log("parse row", row); const parser = new DataItemsParser(); const parsed = parser.parse(row); const evalContext: IDataItemsEvalContext = {}; @@ -62,22 +62,19 @@ class DataItemsParser { if (_dynamicFields) { const flattened = flattenJson(_dynamicFields); - for (const [key, evaluators] of Object.entries(flattened)) { - const expressionVariables: { [prefix in FlowTypes.IDynamicPrefix]?: boolean } = {}; - for (const evaluator of evaluators) { - const { fieldName, type } = evaluator; - // mark fields that are being tracked - expressionVariables[type] = true; - this.variables[`${type}.${fieldName}`] = { type, fieldName }; - } + console.log({ flattened }); - const existing = getNestedProperty(parsed, key) as string; - const delimited = addStringDelimiters(existing, Object.keys(expressionVariables)); - // add delimeters but remove initial curly braces and replace all curly braces for `[]` - // so that can be directly evaluated in JS - const replaced = delimtedToJS(delimited); - setNestedProperty(key, replaced, parsed); - } + // for (const [key, evaluators] of Object.entries(flattened)) { + // const expressionVariables: { [prefix in FlowTypes.IDynamicPrefix]?: boolean } = {}; + // for (const evaluator of evaluators) { + // const { fieldName, type } = evaluator; + // // mark fields that are being tracked + // expressionVariables[type] = true; + // this.variables[`${type}.${fieldName}`] = { type, fieldName }; + // } + + // // setNestedProperty(key, replaced, parsed); + // } delete parsed._dynamicFields; delete parsed._dynamicDependencies; }