diff --git a/app/client/src/actions/widgetSelectionActions.ts b/app/client/src/actions/widgetSelectionActions.ts index 092400d49b..940a488637 100644 --- a/app/client/src/actions/widgetSelectionActions.ts +++ b/app/client/src/actions/widgetSelectionActions.ts @@ -8,6 +8,7 @@ export interface WidgetSelectionRequestPayload { payload?: string[]; invokedBy?: NavigationMethod; basePageId?: string; + parentId?: string; } export type WidgetSelectionRequest = ( @@ -15,6 +16,7 @@ export type WidgetSelectionRequest = ( payload?: string[], invokedBy?: NavigationMethod, basePageId?: string, + parentId?: string, ) => ReduxAction; // Use to select a widget programmatically via platform action @@ -23,9 +25,10 @@ export const selectWidgetInitAction: WidgetSelectionRequest = ( payload, invokedBy?: NavigationMethod, basePageId?: string, + parentId?: string, ) => ({ type: ReduxActionTypes.SELECT_WIDGET_INIT, - payload: { selectionRequestType, payload, basePageId, invokedBy }, + payload: { selectionRequestType, payload, basePageId, invokedBy, parentId }, }); export interface SetSelectedWidgetsPayload { diff --git a/app/client/src/sagas/WidgetDeletionSagas.ts b/app/client/src/sagas/WidgetDeletionSagas.ts index 518d122bc8..96cd908948 100644 --- a/app/client/src/sagas/WidgetDeletionSagas.ts +++ b/app/client/src/sagas/WidgetDeletionSagas.ts @@ -327,9 +327,23 @@ export function* deleteSaga(deleteAction: ReduxAction) { if (!disallowUndo) { // close property pane after delete yield put(closePropertyPane()); - yield put( - selectWidgetInitAction(SelectionRequestType.Unselect, [widgetId]), - ); + + if (isAnvilLayout) { + yield put( + selectWidgetInitAction( + SelectionRequestType.Unselect, + [widgetId], + undefined, + undefined, + parentId, + ), + ); + } else { + yield put( + selectWidgetInitAction(SelectionRequestType.Unselect, [widgetId]), + ); + } + yield call(postDelete, widgetId, widgetName, otherWidgetsToDelete); } } diff --git a/app/client/src/sagas/WidgetSelectionSagas.ts b/app/client/src/sagas/WidgetSelectionSagas.ts index 0398c4be37..48078f2704 100644 --- a/app/client/src/sagas/WidgetSelectionSagas.ts +++ b/app/client/src/sagas/WidgetSelectionSagas.ts @@ -66,6 +66,7 @@ function* selectWidgetSaga(action: ReduxAction) { const { basePageId, invokedBy, + parentId, payload = [], selectionRequestType, } = action.payload; @@ -93,8 +94,9 @@ function* selectWidgetSaga(action: ReduxAction) { // It is possible that the payload is empty. // These properties can be used for a finding sibling widgets for certain types of selections const widgetId = payload[0]; - const parentId: string | undefined = - widgetId in allWidgets ? allWidgets[widgetId].parentId : undefined; + const finalParentId: string | undefined = + parentId || + (widgetId in allWidgets ? allWidgets[widgetId].parentId : undefined); if ( widgetId && @@ -115,7 +117,7 @@ function* selectWidgetSaga(action: ReduxAction) { } case SelectionRequestType.One: case SelectionRequestType.Create: { - assertParentId(parentId); + assertParentId(finalParentId); newSelection = selectOneWidget(payload); break; } @@ -124,10 +126,10 @@ function* selectWidgetSaga(action: ReduxAction) { break; } case SelectionRequestType.ShiftSelect: { - assertParentId(parentId); + assertParentId(finalParentId); const siblingWidgets: string[] = yield select( getWidgetImmediateChildren, - parentId, + finalParentId, ); newSelection = shiftSelectWidgets( payload, @@ -138,10 +140,10 @@ function* selectWidgetSaga(action: ReduxAction) { break; } case SelectionRequestType.PushPop: { - assertParentId(parentId); + assertParentId(finalParentId); const siblingWidgets: string[] = yield select( getWidgetImmediateChildren, - parentId, + finalParentId, ); newSelection = pushPopWidgetSelection( payload, @@ -151,7 +153,16 @@ function* selectWidgetSaga(action: ReduxAction) { break; } case SelectionRequestType.Unselect: { - newSelection = unselectWidget(payload, selectedWidgets); + const isParentExists = finalParentId + ? finalParentId in allWidgets + : false; + + if (isParentExists) { + assertParentId(finalParentId); + newSelection = [finalParentId]; + } else { + newSelection = unselectWidget(payload, selectedWidgets); + } break; } case SelectionRequestType.All: {