-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: render only the currently open detached widgets. #33040
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
app/client/src/layoutSystems/anvil/integrations/actions/detachedWidgetActions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { AnvilReduxActionTypes } from "./actionTypes"; | ||
|
||
export const showDetachedWidgetAction = (widgetId: string) => { | ||
return { | ||
type: AnvilReduxActionTypes.SHOW_DETACHED_WIDGET, | ||
payload: widgetId, | ||
}; | ||
}; | ||
|
||
export const hideDetachedWidgetAction = (widgetId: string) => { | ||
return { | ||
type: AnvilReduxActionTypes.HIDE_DETACHED_WIDGET, | ||
payload: widgetId, | ||
}; | ||
}; | ||
|
||
export const resetDetachedWidgetsAction = () => { | ||
return { | ||
type: AnvilReduxActionTypes.RESET_DETACHED_WIDGETS, | ||
}; | ||
}; |
15 changes: 2 additions & 13 deletions
15
app/client/src/layoutSystems/anvil/integrations/modalSelectors.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,5 @@ | ||
import type { AppState } from "@appsmith/reducers"; | ||
import { getWidgetIdsByType, getWidgetsMeta } from "sagas/selectors"; | ||
import { WDSModalWidget } from "widgets/wds/WDSModalWidget"; | ||
|
||
export const getCurrentlyOpenAnvilModal = (state: AppState) => { | ||
const allExistingModals = getWidgetIdsByType(state, WDSModalWidget.type); | ||
if (allExistingModals.length === 0) { | ||
return; | ||
} | ||
const metaWidgets = getWidgetsMeta(state); | ||
const currentlyOpenModal = allExistingModals.find((modalId) => { | ||
const modal = metaWidgets[modalId]; | ||
return modal && modal.isVisible; | ||
}); | ||
return currentlyOpenModal; | ||
export const getCurrentlyOpenAnvilDetachedWidgets = (state: AppState) => { | ||
return state.ui.anvilDetachedWidgets.currentlyOpenDetachedWidgets; | ||
}; |
36 changes: 36 additions & 0 deletions
36
app/client/src/layoutSystems/anvil/integrations/reducers/anvilDetachedWidgetsReducer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { createImmerReducer } from "utils/ReducerUtils"; | ||
import { | ||
AnvilReduxActionTypes, | ||
type AnvilReduxAction, | ||
} from "../actions/actionTypes"; | ||
|
||
export interface AnvilDetachedWidgetsReduxState { | ||
currentlyOpenDetachedWidgets: string[]; | ||
} | ||
const initialState: AnvilDetachedWidgetsReduxState = { | ||
currentlyOpenDetachedWidgets: [], | ||
}; | ||
const anvilDetachedWidgetsReducer = createImmerReducer(initialState, { | ||
[AnvilReduxActionTypes.SHOW_DETACHED_WIDGET]: ( | ||
state: AnvilDetachedWidgetsReduxState, | ||
action: AnvilReduxAction<string>, | ||
) => { | ||
state.currentlyOpenDetachedWidgets.push(action.payload); | ||
}, | ||
[AnvilReduxActionTypes.HIDE_DETACHED_WIDGET]: ( | ||
state: AnvilDetachedWidgetsReduxState, | ||
action: AnvilReduxAction<string>, | ||
) => { | ||
state.currentlyOpenDetachedWidgets = | ||
state.currentlyOpenDetachedWidgets.filter( | ||
(widgetId) => widgetId !== action.payload, | ||
); | ||
}, | ||
[AnvilReduxActionTypes.RESET_DETACHED_WIDGETS]: ( | ||
state: AnvilDetachedWidgetsReduxState, | ||
) => { | ||
state.currentlyOpenDetachedWidgets = []; | ||
}, | ||
}); | ||
|
||
export default anvilDetachedWidgetsReducer; |
46 changes: 46 additions & 0 deletions
46
app/client/src/layoutSystems/anvil/integrations/sagas/anvilDetachedWidgetSagas.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type { ReduxAction } from "@appsmith/constants/ReduxActionConstants"; | ||
import { ReduxActionTypes } from "@appsmith/constants/ReduxActionConstants"; | ||
import { all, put, select, takeEvery, takeLatest } from "redux-saga/effects"; | ||
import { callSagaOnlyForAnvil } from "./utils"; | ||
import { | ||
hideDetachedWidgetAction, | ||
resetDetachedWidgetsAction, | ||
showDetachedWidgetAction, | ||
} from "../actions/detachedWidgetActions"; | ||
import { getWidgetByName } from "sagas/selectors"; | ||
import type { FlattenedWidgetProps } from "WidgetProvider/constants"; | ||
|
||
function* closeAnvilModalSaga(action: ReduxAction<{ modalName?: string }>) { | ||
const { modalName } = action.payload; | ||
|
||
if (modalName) { | ||
const widget: FlattenedWidgetProps | undefined = yield select( | ||
getWidgetByName, | ||
modalName, | ||
); | ||
if (widget) { | ||
hideDetachedWidgetAction(widget.widgetId); | ||
} | ||
} else { | ||
yield put(resetDetachedWidgetsAction()); | ||
} | ||
} | ||
|
||
function* showAnvilModalSaga(action: ReduxAction<{ modalId: string }>) { | ||
yield put(showDetachedWidgetAction(action.payload.modalId)); | ||
} | ||
|
||
export default function* anvilDetachedWidgetSagas() { | ||
yield all([ | ||
takeEvery( | ||
ReduxActionTypes.CLOSE_MODAL, | ||
callSagaOnlyForAnvil, | ||
closeAnvilModalSaga, | ||
), | ||
takeLatest( | ||
ReduxActionTypes.SHOW_MODAL, | ||
callSagaOnlyForAnvil, | ||
showAnvilModalSaga, | ||
), | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
app/client/src/layoutSystems/anvil/integrations/sagas/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { ReduxAction } from "@appsmith/constants/ReduxActionConstants"; | ||
import { call, select } from "redux-saga/effects"; | ||
import { getIsAnvilLayout } from "../selectors"; | ||
|
||
export function* callSagaOnlyForAnvil(saga: any, action: ReduxAction<unknown>) { | ||
const isAnvilLayout: boolean = yield select(getIsAnvilLayout); | ||
if (isAnvilLayout) { | ||
yield call(saga, action); | ||
} | ||
} | ||
34 changes: 34 additions & 0 deletions
34
app/client/src/layoutSystems/anvil/viewer/canvas/AnvilDetachedWidgets.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { MAIN_CONTAINER_WIDGET_ID } from "constants/WidgetConstants"; | ||
import { useDetachedChildren } from "layoutSystems/anvil/common/hooks/detachedWidgetHooks"; | ||
import { getAnvilWidgetDOMId } from "layoutSystems/common/utils/LayoutElementPositionsObserver/utils"; | ||
import { renderChildWidget } from "layoutSystems/common/utils/canvasUtils"; | ||
import React from "react"; | ||
import { useSelector } from "react-redux"; | ||
import { getRenderMode } from "selectors/editorSelectors"; | ||
import type { WidgetProps } from "widgets/BaseWidget"; | ||
|
||
export const AnvilDetachedWidgets = () => { | ||
const detachedChildren = useDetachedChildren(); | ||
const renderMode = useSelector(getRenderMode); | ||
return ( | ||
<> | ||
{detachedChildren.map((child) => | ||
renderChildWidget({ | ||
childWidgetData: child as WidgetProps, | ||
defaultWidgetProps: { | ||
className: `${getAnvilWidgetDOMId(child.widgetId)}`, | ||
}, | ||
noPad: false, | ||
// Adding these properties as the type insists on providing this | ||
// while it is not required for detached children | ||
layoutSystemProps: { | ||
layoutId: "", | ||
rowIndex: 0, | ||
}, | ||
renderMode, | ||
widgetId: MAIN_CONTAINER_WIDGET_ID, | ||
}), | ||
)} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a type definition for the
saga
parameter to enhance type safety and maintainability.Committable suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
takeLeading is having type issues if I try this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marks0351, it seems like the type
GeneratorFunction
might not be directly compatible with whattakeLeading
expects for its saga parameter. To resolve the type issues, I recommend checking the type definition oftakeLeading
in your project's version of redux-saga. This will help you identify a compatible type for the saga parameter.If you can provide the specific error message or a snippet of how you're using
takeLeading
withcallSagaOnlyForAnvil
, I can offer more targeted advice. Alternatively, you might consider using a type assertion if you're confident about the types being handled, or adjusting the type to something more specific that matches the expected input fortakeLeading
.