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: action parameter self-reference concatenation #2750

Merged
merged 8 commits into from
Jan 31, 2025
Merged
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
Loading