Skip to content

Commit

Permalink
chore: code tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismclarke committed Oct 8, 2024
1 parent fff347e commit 289941b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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();
});
Expand All @@ -102,7 +106,7 @@ describe("DataItemsComponent", () => {
expect(component).toBeTruthy();
});

it("generates evaluation context for rows", async () => {
fit("generates evaluation context for rows", async () => {

Check failure on line 109 in src/app/shared/components/template/components/data-items/data-items.component.spec.ts

View workflow job for this annotation

GitHub Actions / test / build

Unexpected fit
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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.`, "");
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, { type: FlowTypes.IDynamicPrefix; fieldName: string }>;
export type IDataItemsEvalContext = {
Expand All @@ -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 = {};
Expand Down Expand Up @@ -62,22 +62,19 @@ class DataItemsParser {

if (_dynamicFields) {
const flattened = flattenJson<FlowTypes.TemplateRowDynamicEvaluator[]>(_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;
}
Expand Down

0 comments on commit 289941b

Please sign in to comment.