Repository: appsmithorg/appsmith
File: app/client/src/layoutSystems/anvil/integrations/sagas/anvilWidgetAdditionSagas/index.ts (TypeScript)

Code before:
      yield put(
        selectWidgetInitAction(SelectionRequestType.One, [
          newWidgetParams.newWidgetId,
        ]),
      );
    }
  } catch (e) {
    log.debug("Error adding suggested widget to Anvil Canvas: ", e);
  }
}

// function to add a new child widget to the DSL
export function* getUpdatedListOfWidgetsAfterAddingNewWidget(
  highlight: AnvilHighlightInfo, // Highlight information for the drop zone
  newWidget: {
    newWidgetId: string;
    type: string;
    detachFromLayout: boolean;
  },
  isMainCanvas: boolean, // Indicates if the drop zone is the main canvas
  isSection: boolean, // Indicates if the drop zone is a section
) {
  const { alignment, canvasId } = highlight;
  const allWidgets: CanvasWidgetsReduxState = yield select(getWidgets);

  const parentWidgetWithLayout = allWidgets[canvasId];

  // Creating a shallow copy of the widgets from redux state
  // as these will be mutated in the course of the operation
  let updatedWidgets: CanvasWidgetsReduxState = { ...allWidgets };

  const draggedWidgets: WidgetLayoutProps[] = [
    {
      alignment,
      widgetId: newWidget.newWidgetId,
      widgetType: newWidget.type,
    },
  ];

  // Follow the operations necessary for detached widgets like Modal Widget
  if (newWidget.detachFromLayout) {
    updatedWidgets = yield call(addDetachedWidgetToMainCanvas, updatedWidgets, {
      widgetId: newWidget.newWidgetId,
      type: newWidget.type,
    });
  } else {
    // Handle different scenarios based on the drop zone type (main canvas, section, or generic layout)
    // If the widget is dropped in the main canvas or into a detached widget like the Modal Widget
    if (isMainCanvas || parentWidgetWithLayout.detachFromLayout) {
      updatedWidgets = yield call(
        addWidgetsToMainCanvasLayout,

Review comment (suggestion):
@riodeuno Is this safe? The use case is aichatwidget wants to modify the parent zone's elevatedBackground to false. ( that code is written in aichatbot blueprint operation ).
So the problem I was facing is if there is an existing zone that is empty and I drop aichatwidget into it, I was not able to modify the zone elevated background, as the redux state was coming from immer reducer and it was immutable, due to which the property was readonly.

Code after:
      // Select the added widget
      yield put(
        selectWidgetInitAction(SelectionRequestType.One, [
          newWidgetParams.newWidgetId,
        ]),
      );
    }
  } catch (e) {
    log.debug("Error adding suggested widget to Anvil Canvas: ", e);
  }
}

// function to add a new child widget to the DSL
export function* getUpdatedListOfWidgetsAfterAddingNewWidget(
  highlight: AnvilHighlightInfo, // Highlight information for the drop zone
  newWidget: {
    newWidgetId: string;
    type: string;
    detachFromLayout: boolean;
  },
  isMainCanvas: boolean, // Indicates if the drop zone is the main canvas
  isSection: boolean, // Indicates if the drop zone is a section
) {
  const { alignment, canvasId } = highlight;
  const allWidgetsFromRedux: CanvasWidgetsReduxState = yield select(getWidgets);
  const allWidgets = klona(allWidgetsFromRedux) as CanvasWidgetsReduxState;

  const parentWidgetWithLayout = allWidgets[canvasId];

  // Creating a shallow copy of the widgets from redux state
  // as these will be mutated in the course of the operation
  let updatedWidgets: CanvasWidgetsReduxState = { ...allWidgets };

  const draggedWidgets: WidgetLayoutProps[] = [
    {
      alignment,
      widgetId: newWidget.newWidgetId,
      widgetType: newWidget.type,
    },
  ];

  // Follow the operations necessary for detached widgets like Modal Widget
  if (newWidget.detachFromLayout) {
    updatedWidgets = yield call(addDetachedWidgetToMainCanvas, updatedWidgets, {
      widgetId: newWidget.newWidgetId,
      type: newWidget.type,
    });
  } else {
    // Handle different scenarios based on the drop zone type (main canvas, section, or generic layout)
    // If the widget is dropped in the main canvas or into a detached widget like the Modal Widget
    if (isMainCanvas || parentWidgetWithLayout.detachFromLayout) {