Skip to content

Commit

Permalink
fix: Reverting Anvil currently open modal state implementation (#33067)
Browse files Browse the repository at this point in the history
[![workerB](https://img.shields.io/endpoint?url=https%3A%2F%2Fworkerb.linearb.io%2Fv2%2Fbadge%2Fprivate%2FU2FsdGVkX1p4H4db8lSv1xTwGoYFAZnRwWdBNC5Y%2Fcollaboration.svg%3FcacheSeconds%3D60)](https://workerb.linearb.io/v2/badge/collaboration-page?magicLinkId=MA2NqRe)
## Description
> [!TIP]  
> _Add a TL;DR when the description is longer than 500 words or
extremely technical (helps the content, marketing, and DevRel team)._
>
> _Please also include relevant motivation and context. List any
dependencies that are required for this change. Add links to Notion,
Figma or any other documents that might be relevant to the PR._

In #33040 we added a state exclusively to capture modals that are
opened/closed to avoid computing which modal is open based on meta
state.
However the problem with this approach that I had understood after
testing it with deployed apps is that closing a modal is not done only
via the saga, but is done via actions and the modal itself without
dispatching the common saga.
Obviously the above implementation dunked.

Reverting to the previous implementation of relying on meta state to
select visible detached widgets.


Fixes #`Issue Number`  
_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.Anvil"

### 🔍 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/8895170744>
> Commit: 517ffc6
> Cypress dashboard url: <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=8895170744&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
- [ ] No
  • Loading branch information
marks0351 committed Apr 30, 2024
1 parent 225fa5d commit 3f222e5
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 125 deletions.
2 changes: 0 additions & 2 deletions app/client/src/ce/reducers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ import type { ActiveField } from "reducers/uiReducers/activeFieldEditorReducer";
import type { SelectedWorkspaceReduxState } from "@appsmith/reducers/uiReducers/selectedWorkspaceReducer";
import type { ConsolidatedPageLoadState } from "reducers/uiReducers/consolidatedPageLoadReducer";
import type { BuildingBlocksReduxState } from "reducers/uiReducers/buildingBlockReducer";
import type { AnvilDetachedWidgetsReduxState } from "layoutSystems/anvil/integrations/reducers/anvilDetachedWidgetsReducer";

export const reducerObject = {
entities: entityReducer,
Expand Down Expand Up @@ -147,7 +146,6 @@ export interface AppState {
oneClickBinding: OneClickBindingState;
activeField: ActiveField;
ide: IDEState;
anvilDetachedWidgets: AnvilDetachedWidgetsReduxState;
};
entities: {
canvasWidgetsStructure: CanvasWidgetStructure;
Expand Down
2 changes: 0 additions & 2 deletions app/client/src/ce/reducers/uiReducers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import activeFieldReducer from "reducers/uiReducers/activeFieldEditorReducer";
import selectedWorkspaceReducer from "@appsmith/reducers/uiReducers/selectedWorkspaceReducer";
import ideReducer from "../../../reducers/uiReducers/ideReducer";
import consolidatedPageLoadReducer from "reducers/uiReducers/consolidatedPageLoadReducer";
import anvilDetachedWidgetsReducer from "layoutSystems/anvil/integrations/reducers/anvilDetachedWidgetsReducer";

export const uiReducerObject = {
analytics: analyticsReducer,
Expand Down Expand Up @@ -105,5 +104,4 @@ export const uiReducerObject = {
activeField: activeFieldReducer,
ide: ideReducer,
consolidatedPageLoad: consolidatedPageLoadReducer,
anvilDetachedWidgets: anvilDetachedWidgetsReducer,
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.detachedWidgetsDropOverlay {
z-index: var(--z-index-99);
background-color: var(--modal-overlay-color);
position: fixed;
padding: 40px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,4 @@ export enum AnvilReduxActionTypes {
ANVIL_SPACE_DISTRIBUTION_STOP = "ANVIL_SPACE_DISTRIBUTION_STOP",
ANVIL_SET_HIGHLIGHT_SHOWN = "ANVIL_SET_HIGHLIGHT_SHOWN",
ANVIL_WIDGET_SELECTION_CLICK = "ANVIL_WIDGET_SELECTION_CLICK",
SHOW_DETACHED_WIDGET = "SHOW_DETACHED_WIDGET",
HIDE_DETACHED_WIDGET = "HIDE_DETACHED_WIDGET",
RESET_DETACHED_WIDGETS = "RESET_DETACHED_WIDGETS",
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import type { AppState } from "@appsmith/reducers";
import { getAllDetachedWidgetIds, getWidgetsMeta } from "sagas/selectors";

export const getCurrentlyOpenAnvilDetachedWidgets = (state: AppState) => {
return state.ui.anvilDetachedWidgets.currentlyOpenDetachedWidgets;
const allExistingDetachedWidgets = getAllDetachedWidgetIds(state);
if (allExistingDetachedWidgets.length === 0) {
return [];
}
const metaWidgets = getWidgetsMeta(state);
const currentlyOpenWidgets = allExistingDetachedWidgets.filter((modalId) => {
const modal = metaWidgets[modalId];
return modal && modal.isVisible;
});
return currentlyOpenWidgets;
};

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import anvilSectionSagas from "./sectionSagas";
import anvilSpaceDistributionSagas from "./anvilSpaceDistributionSagas";
import anvilWidgetSelectionSaga from "./anvilWidgetSelectionSaga";
import pasteSagas from "./pasteSagas";
import anvilDetachedWidgetSagas from "./anvilDetachedWidgetSagas";

export default function* anvilSagas() {
yield fork(LayoutElementPositionsSaga);
Expand All @@ -14,5 +13,4 @@ export default function* anvilSagas() {
yield fork(anvilSpaceDistributionSagas);
yield fork(anvilWidgetSelectionSaga);
yield fork(pasteSagas);
yield fork(anvilDetachedWidgetSagas);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { updateAndSaveAnvilLayout } from "../../utils/anvilChecksUtils";
import { builderURL } from "@appsmith/RouteBuilder";
import { getCurrentPageId } from "selectors/editorSelectors";
import {
type ReduxAction,
ReduxActionErrorTypes,
ReduxActionTypes,
} from "@appsmith/constants/ReduxActionConstants";
Expand All @@ -23,7 +24,7 @@ import { getDestinedParent } from "layoutSystems/anvil/utils/paste/destinationUt
import { pasteWidgetsIntoMainCanvas } from "layoutSystems/anvil/utils/paste/mainCanvasPasteUtils";
import { MAIN_CONTAINER_WIDGET_ID } from "constants/WidgetConstants";
import WidgetFactory from "WidgetProvider/factory";
import { callSagaOnlyForAnvil } from "./utils";
import { getIsAnvilLayout } from "../selectors";

function* pasteWidgetSagas() {
try {
Expand Down Expand Up @@ -121,11 +122,18 @@ function* pasteWidgetSagas() {
}
}

function* shouldCallSaga(saga: any, action: ReduxAction<unknown>) {
const isAnvilLayout: boolean = yield select(getIsAnvilLayout);
if (isAnvilLayout) {
yield call(saga, action);
}
}

export default function* pasteSagas() {
yield all([
takeLeading(
ReduxActionTypes.PASTE_COPIED_WIDGET_INIT,
callSagaOnlyForAnvil,
shouldCallSaga,
pasteWidgetSagas,
),
]);
Expand Down
10 changes: 0 additions & 10 deletions app/client/src/layoutSystems/anvil/integrations/sagas/utils.ts

This file was deleted.

6 changes: 6 additions & 0 deletions app/client/src/sagas/selectors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ export const getWidgetIdsByType = (state: AppState, type: WidgetType) => {
.map((widget: FlattenedWidgetProps) => widget.widgetId);
};

export const getAllDetachedWidgetIds = (state: AppState) => {
return Object.values(state.entities.canvasWidgets)
.filter((widget: FlattenedWidgetProps) => !!widget.detachFromLayout)
.map((widget: FlattenedWidgetProps) => widget.widgetId);
};

export const getWidgetOptionsTree = memoize((state: AppState) =>
Object.values(state.entities.canvasWidgets)
.filter((w) => w.type !== "CANVAS_WIDGET" && w.type !== "BUTTON_WIDGET")
Expand Down

0 comments on commit 3f222e5

Please sign in to comment.