Skip to content

Commit

Permalink
fix: Handles button binding during buildingblock pasting (#33674)
Browse files Browse the repository at this point in the history
## Description
This pull request adds the handleButtonDynamicTriggerPathList function
to the BuildingBlockAdditionSagas.ts file. This function is responsible
for handling the dynamic trigger path list for button widgets. It
iterates over the widgetNameMap and updates the dynamicTriggerPathList
of each button widget with the newWidgetName.

Additionally, unit tests have been added to ensure the correct
functionality of the handleButtonDynamicTriggerPathList function. This
change improves the functionality of button widgets when pasting
building block widgets.


Fixes #33658 
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/ok-to-test tags="@tag.Widget"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/9268894716>
> Commit: a675a5c
> Cypress dashboard url: <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9268894716&attempt=1"
target="_blank">Click here!</a>

<!-- end of auto-generated comment: Cypress test results  -->




## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No

---------

Co-authored-by: Ashok Kumar M <[email protected]>
  • Loading branch information
rahulbarwal and marks0351 authored May 29, 2024
1 parent 3fd1d52 commit bb39e4f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { updateWidgetPositions } from "layoutSystems/autolayout/utils/positionUt
import type { FlexLayer } from "layoutSystems/autolayout/utils/types";
import {
getNewPositions,
handleButtonDynamicTriggerPathList,
handleImageWidgetWhenPasting,
handleJSONFormPropertiesListedInDynamicBindingPath,
handleJSONFormWidgetWhenPasting,
Expand Down Expand Up @@ -835,6 +836,9 @@ function handleOtherWidgetReferencesWhilePastingBuildingBlockWidget(
case "IMAGE_WIDGET":
handleImageWidgetWhenPasting(widgetNameMap, widget);
break;
case "BUTTON_WIDGET":
handleButtonDynamicTriggerPathList(widgetNameMap, widget);
break;
default:
widgets = handleSpecificCasesWhilePasting(
widget,
Expand Down
26 changes: 26 additions & 0 deletions app/client/src/sagas/PasteWidgetUtils/PasteWidgetUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
handleJSONFormWidgetWhenPasting,
handleTextWidgetWhenPasting,
handleJSONFormPropertiesListedInDynamicBindingPath,
handleButtonDynamicTriggerPathList,
} from ".";
import {
widget,
Expand All @@ -17,6 +18,7 @@ import {
const widgetNameMap = {
table1: "table1Copy",
};
import { klona } from "klona";

function testIndividualWidgetPasting(
widgetNameMap: Record<string, string>,
Expand Down Expand Up @@ -229,3 +231,27 @@ describe("handleJSONFormPropertiesListedInDynamicBindingPath", () => {
]);
});
});

describe("handleButtonDynamicTriggerPathList", () => {
const widget = {
dynamicTriggerPathList: [{ key: "onClick" }],
onClick: "{{oldName.val}}",
} as any as FlattenedWidgetProps;
it("1. should replace old widget names with new widget names in dynamic trigger paths", () => {
const widgetNameMap = {
oldName: "newName",
};
const button = klona(widget);
handleButtonDynamicTriggerPathList(widgetNameMap, button);
expect(button.onClick).toEqual("{{newName.val}}");
});

it("2. should do nothing if the widgetNameMap does not contain names in dynamic trigger paths", () => {
const widgetNameMap = {
oldWidget1: "newWidget1",
};
const button = klona(widget);
handleButtonDynamicTriggerPathList(widgetNameMap, button);
expect(button.onClick).toEqual("{{oldName.val}}");
});
});
11 changes: 11 additions & 0 deletions app/client/src/sagas/PasteWidgetUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,14 @@ export function accessNestedObjectValue(
),
);
}

export function handleButtonDynamicTriggerPathList(
widgetNameMap: Record<string, string>,
widget: FlattenedWidgetProps,
) {
Object.entries(widgetNameMap).forEach(([oldWidgetName, newWidgetName]) => {
widget.dynamicTriggerPathList?.forEach((path: { key: string }) => {
accessNestedObjectValue(widget, path.key, oldWidgetName, newWidgetName);
});
});
}

0 comments on commit bb39e4f

Please sign in to comment.