diff --git a/src/app/shared/components/template/services/instance/template-action.service.spec.ts b/src/app/shared/components/template/services/instance/template-action.service.spec.ts index 9398bf0d4..42f948cbb 100644 --- a/src/app/shared/components/template/services/instance/template-action.service.spec.ts +++ b/src/app/shared/components/template/services/instance/template-action.service.spec.ts @@ -84,7 +84,7 @@ describe("TemplateActionService", () => { expect(service.container.templateRowMap.mock_row_1.value).toEqual("updated"); }); - it("Uses updated args when successive actions change same variable", async () => { + it("Uses latest value for `this.value` arg", async () => { const _triggeredBy = { _nested_name: "mock_row_1", name: "mock_row_1", type: "" }; await service.handleActions( [ @@ -98,9 +98,21 @@ describe("TemplateActionService", () => { _triggeredBy ); expect(service.container.templateRowMap.mock_row_2.value).toEqual("updated"); + // also include test case of concatenated expression + await service.handleActions( + [ + { + trigger: "click", + action_id: "set_local", + args: ["mock_row_2", "prefix_{this.value}"], + }, + ], + _triggeredBy + ); + expect(service.container.templateRowMap.mock_row_2.value).toEqual("prefix_updated"); }); - it("Uses updated params when successive actions change same variable", async () => { + it("Uses latest value for `this.value` param", async () => { const _triggeredBy = { _nested_name: "mock_row_1", name: "mock_row_1", type: "" }; await service.handleActions( [ diff --git a/src/app/shared/components/template/services/instance/template-action.service.ts b/src/app/shared/components/template/services/instance/template-action.service.ts index 8c31cd84f..d9b28f3e2 100644 --- a/src/app/shared/components/template/services/instance/template-action.service.ts +++ b/src/app/shared/components/template/services/instance/template-action.service.ts @@ -337,19 +337,25 @@ export class TemplateActionService extends SyncServiceBase { ): FlowTypes.TemplateRowAction { // Update action.args and action.params const currentValue = this.container?.templateRowMap?.[action._triggeredBy?._nested_name]?.value; - if (action.args) { - action.args = action.args.map((arg) => { - if (arg === "this.value") { + // define a replacer that preserves type if `this.value` specified, replacing as string for + // other expressions `@local.some_field_{this.value}` + function replaceReference(v: any) { + if (typeof v === "string") { + if (v === "this.value") { return currentValue; } - return arg; - }); + if (v.includes("{this.value}")) { + return v.replace("{this.value}", currentValue); + } + } + return v; + } + if (action.args) { + action.args = action.args.map((arg) => replaceReference(arg)); } if (action.params) { for (const [key, value] of Object.entries(action.params)) { - if (value === "this.value") { - action.params[key] = currentValue; - } + action.params[key] = replaceReference(value); } } return action;