Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix: data-items local variables #2780

Merged
merged 4 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ export class DataItemsService {
} as any);
// HACK - still want to be able to use localContext from parent rows so copy to child processor
processor.templateRowMap = JSON.parse(JSON.stringify(templateRowMap));
const templateRowMapValues = Object.fromEntries(
Object.entries(templateRowMap).map(([key, { value }]) => [key, value])
);
processor.templateRowMapValues = templateRowMapValues;

await processor.processContainerTemplateRows();
return processor.renderedRows();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ class MockTemplateRowService implements Partial<TemplateRowService> {
mock_row_1: { value: "", _nested_name: "mock_row_1", name: "mock_row_1", type: "" },
mock_row_2: { value: "", _nested_name: "mock_row_2", name: "mock_row_2", type: "" },
};
templateRowMapValues = {
mock_row_1: "",
mock_row_2: "",
};
processRowUpdates = async () => null;
}

class MockContainer implements Partial<TemplateContainerComponent> {
templateRowService = new MockTemplateRowService() as any as TemplateRowService;

get templateRowMap() {
return this.templateRowService.templateRowMap;
}
Expand Down Expand Up @@ -74,14 +79,16 @@ describe("TemplateActionService", () => {
await service.handleActions([
{ trigger: "click", action_id: "set_local", args: ["mock_row_1", "updated"] },
]);
expect(service.container.templateRowMap.mock_row_1.value).toEqual("updated");
expect(service.container.templateRowService.templateRowMap.mock_row_1.value).toEqual("updated");
expect(service.container.templateRowService.templateRowMapValues.mock_row_1).toEqual("updated");
});

it("set_self action", async () => {
await service.handleActions([
{ trigger: "click", action_id: "set_self", args: ["mock_row_1", "updated"] },
]);
expect(service.container.templateRowMap.mock_row_1.value).toEqual("updated");
expect(service.container.templateRowService.templateRowMap.mock_row_1.value).toEqual("updated");
expect(service.container.templateRowService.templateRowMapValues.mock_row_1).toEqual("updated");
});

it("Uses latest value for `this.value` arg", async () => {
Expand All @@ -97,7 +104,8 @@ describe("TemplateActionService", () => {
],
_triggeredBy
);
expect(service.container.templateRowMap.mock_row_2.value).toEqual("updated");
expect(service.container.templateRowService.templateRowMap.mock_row_2.value).toEqual("updated");
expect(service.container.templateRowService.templateRowMapValues.mock_row_2).toEqual("updated");
// also include test case of concatenated expression
await service.handleActions(
[
Expand All @@ -109,7 +117,9 @@ describe("TemplateActionService", () => {
],
_triggeredBy
);
expect(service.container.templateRowMap.mock_row_2.value).toEqual("prefix_updated");
expect(service.container.templateRowService.templateRowMap.mock_row_2.value).toEqual(
"prefix_updated"
);
});

it("Uses latest value for `this.value` param", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ export class TemplateActionService extends SyncServiceBase {
}
rowEntry.value = value;
this.container.templateRowService.templateRowMap[rowEntry._nested_name] = rowEntry;
this.container.templateRowService.templateRowMapValues[rowEntry._nested_name] =
rowEntry.value;
} else {
// TODO
console.warn("Setting local variable which does not exist", { key, value }, "TODO");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class TemplateProcessService extends SyncServiceBase {
this.container.template = template;
// reset any existing templateRowMap data
this.container.templateRowService.templateRowMap = {};
this.container.templateRowService.templateRowMapValues = {};
// process the template as if it were rendered
// TODO - should filter out template rows to only include those used programatically (e.g. set_variable, set_field etc.)
await this.container.templateRowService.processContainerTemplateRows();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class TemplateRowService extends SyncServiceBase {
public templateRowMap: ITemplateRowMap = {};

/** Modified templateRowMap to only include row values, for use in local evalContext */
private templateRowMapValues: { [row_nested_name: string]: FlowTypes.TemplateRow["value"] } = {};
public templateRowMapValues: { [row_nested_name: string]: FlowTypes.TemplateRow["value"] } = {};

public renderedRows = signal<FlowTypes.TemplateRow[]>([], { equal: isEqual }); // rows processed and filtered by condition

Expand Down
Loading