Skip to content

Commit

Permalink
Merge pull request #2750 from IDEMSInternational/hotfix/action-param-…
Browse files Browse the repository at this point in the history
…self-reference-concat

hotfix: action parameter self-reference concatenation
  • Loading branch information
ChrisMarsh82 authored Jan 31, 2025
2 parents bd6e417 + 3bb2c31 commit 92f3d68
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
Expand All @@ -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(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 92f3d68

Please sign in to comment.