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

fix: Anvil Modal rendering issues when added via property pane. #33161

Merged
merged 10 commits into from
May 7, 2024
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from "react";
import type { BaseWidgetProps } from "widgets/BaseWidgetHOC/withBaseWidgetHOC";
import { AnvilWidgetComponent } from "../common/widgetComponent/AnvilWidgetComponent";
import { useObserveDetachedWidget } from "layoutSystems/common/utils/LayoutElementPositionsObserver/usePositionObserver";
import {
useAddBordersToDetachedWidgets,
useHandleDetachedWidgetSelect,
} from "layoutSystems/anvil/common/hooks/detachedWidgetHooks";
import { AnvilErrorBoundary } from "../common/widgetComponent/AnvilErrorBoundary";
import { SKELETON_WIDGET_TYPE } from "constants/WidgetConstants";

/**
* AnvilEditorDetachedWidgetOnion
Expand All @@ -18,14 +19,12 @@ import {
*
* @returns Enhanced Widget
*/
export const AnvilEditorDetachedWidgetOnion = (
props: BaseWidgetProps,
): JSX.Element => {
export const AnvilEditorDetachedWidgetOnion = (props: BaseWidgetProps) => {
useObserveDetachedWidget(props.widgetId);
useHandleDetachedWidgetSelect(props.widgetId);
useAddBordersToDetachedWidgets(props.widgetId, props.type);

return (
<AnvilWidgetComponent {...props}>{props.children}</AnvilWidgetComponent>
);
return props.type !== SKELETON_WIDGET_TYPE ? (
<AnvilErrorBoundary {...props}>{props.children}</AnvilErrorBoundary>
) : null;
};
22 changes: 17 additions & 5 deletions app/client/src/layoutSystems/anvil/integrations/modalSelectors.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import type { AppState } from "@appsmith/reducers";
import memoize from "micro-memoize";
import { getAllDetachedWidgetIds, getWidgetsMeta } from "sagas/selectors";

const getCurrentlyOpenWidgets = memoize(
(allExistingDetachedWidgets: string[], metaWidgets: Record<string, any>) => {
return allExistingDetachedWidgets.filter((modalId) => {
const modal = metaWidgets[modalId];
return modal && modal.isVisible;
});
},
);

export const getCurrentlyOpenAnvilDetachedWidgets = (state: AppState) => {
const allExistingDetachedWidgets = getAllDetachedWidgetIds(state);
const allExistingDetachedWidgets = getAllDetachedWidgetIds(
state.entities.canvasWidgets,
);
if (allExistingDetachedWidgets.length === 0) {
return [];
}
const metaWidgets = getWidgetsMeta(state);
const currentlyOpenWidgets = allExistingDetachedWidgets.filter((modalId) => {
const modal = metaWidgets[modalId];
return modal && modal.isVisible;
});
const currentlyOpenWidgets = getCurrentlyOpenWidgets(
allExistingDetachedWidgets,
metaWidgets,
);
return currentlyOpenWidgets;
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from "react";

import type { BaseWidgetProps } from "widgets/BaseWidgetHOC/withBaseWidgetHOC";
import { AnvilWidgetComponent } from "../common/widgetComponent/AnvilWidgetComponent";
import { AnvilErrorBoundary } from "../common/widgetComponent/AnvilErrorBoundary";
import { SKELETON_WIDGET_TYPE } from "constants/WidgetConstants";

/**
* AnvilViewerDetachedWidgetOnion
Expand All @@ -15,7 +16,7 @@ import { AnvilWidgetComponent } from "../common/widgetComponent/AnvilWidgetCompo
* @returns Enhanced Widget
*/
export const AnvilViewerDetachedWidgetOnion = (props: BaseWidgetProps) => {
return (
<AnvilWidgetComponent {...props}>{props.children}</AnvilWidgetComponent>
);
return props.type !== SKELETON_WIDGET_TYPE ? (
<AnvilErrorBoundary {...props}>{props.children}</AnvilErrorBoundary>
) : null;
};
12 changes: 7 additions & 5 deletions app/client/src/sagas/selectors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ 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 getAllDetachedWidgetIds = memoize(
(canvasWidgets: CanvasWidgetsReduxState) => {
return Object.values(canvasWidgets)
.filter((widget: FlattenedWidgetProps) => !!widget.detachFromLayout)
.map((widget: FlattenedWidgetProps) => widget.widgetId);
},
);

export const getWidgetOptionsTree = memoize((state: AppState) =>
Object.values(state.entities.canvasWidgets)
Expand Down
Loading