## Description ### Part 3 of selected widget refactor As part of context switching and selected widget refactor, we saw that widgets that are inside modals or tabs and are hidden cannot be switched to without updating some meta properties. The meta properties are actually owned by the end user and the developer user would create some default values for it as well. This becomes a problem soon when the platform also tries to update it. So as part of this refactor, we will use the selected widget ancestry (the chain of widgets from the top to the currently selected widget) to handle if widgets need to be visible or not. It will also indicate the widgets in the path of selection to "make way" for the selected widget to be seen. Media https://user-images.githubusercontent.com/12022471/224916943-b10e8694-0c95-4157-bb93-288d7c0bf60a.mov - This works on any number of levels of hirarchy - The logic is supposed to handled by each widget that can potentially hide other widgets inside it - Improves some platform perf as the handing so widget meta is not done by the platform anymore Affected widgets: - Modal Widget - Tabs Widget > tl;dr: Update the platform's way to show widgets that can be hidden. Makes sure a selected widget is always shown. Fixes #1282 Resolves #18173 ## Type of change - Bug fix (non-breaking change which fixes an issue) ## How Has This Been Tested? - Manual - Cypress ### Test Plan > Test case link:- [#2202](https://github.com/appsmithorg/TestSmith/issues/2202) ### Issues raised during DP testing > Link issues raised during DP testing for better visiblity:- https://github.com/appsmithorg/appsmith/issues/1282#issuecomment-1472204952 ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag ### QA activity: - [x] Test plan has been approved by relevant developers - [x] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test
187 lines
5.5 KiB
TypeScript
187 lines
5.5 KiB
TypeScript
import { createSelector } from "reselect";
|
|
import type { AppState } from "@appsmith/reducers";
|
|
import type {
|
|
CanvasWidgetsReduxState,
|
|
FlattenedWidgetProps,
|
|
} from "reducers/entityReducers/canvasWidgetsReducer";
|
|
import { getExistingWidgetNames } from "sagas/selectors";
|
|
import { getNextEntityName } from "utils/AppsmithUtils";
|
|
|
|
import WidgetFactory from "utils/WidgetFactory";
|
|
import {
|
|
getFocusedWidget,
|
|
getLastSelectedWidget,
|
|
getSelectedWidgets,
|
|
} from "./ui";
|
|
import { MAIN_CONTAINER_WIDGET_ID } from "constants/WidgetConstants";
|
|
import { get } from "lodash";
|
|
import { getAppMode } from "selectors/applicationSelectors";
|
|
import { APP_MODE } from "entities/App";
|
|
import { getIsTableFilterPaneVisible } from "selectors/tableFilterSelectors";
|
|
import { getIsAutoHeightWithLimitsChanging } from "utils/hooks/autoHeightUIHooks";
|
|
|
|
export const getIsDraggingOrResizing = (state: AppState) =>
|
|
state.ui.widgetDragResize.isResizing || state.ui.widgetDragResize.isDragging;
|
|
|
|
export const getIsResizing = (state: AppState) =>
|
|
state.ui.widgetDragResize.isResizing;
|
|
|
|
const getCanvasWidgets = (state: AppState) => state.entities.canvasWidgets;
|
|
export const getModalDropdownList = createSelector(
|
|
getCanvasWidgets,
|
|
(widgets) => {
|
|
const modalWidgets = Object.values(widgets).filter(
|
|
(widget: FlattenedWidgetProps) => widget.type === "MODAL_WIDGET",
|
|
);
|
|
if (modalWidgets.length === 0) return undefined;
|
|
|
|
return modalWidgets.map((widget: FlattenedWidgetProps) => ({
|
|
id: widget.widgetId,
|
|
label: widget.widgetName,
|
|
value: `${widget.widgetName}`,
|
|
}));
|
|
},
|
|
);
|
|
|
|
export const getNextModalName = createSelector(
|
|
getExistingWidgetNames,
|
|
(names) => {
|
|
const prefix =
|
|
WidgetFactory.widgetConfigMap.get("MODAL_WIDGET")?.widgetName || "";
|
|
return getNextEntityName(prefix, names);
|
|
},
|
|
);
|
|
|
|
/**
|
|
* Selector to get the parent widget of a particaular widget with id as a prop
|
|
*/
|
|
export const getParentWidget = createSelector(
|
|
getCanvasWidgets,
|
|
(state: AppState, widgetId: string) => widgetId,
|
|
(canvasWidgets, widgetId: string): FlattenedWidgetProps | undefined => {
|
|
if (canvasWidgets.hasOwnProperty(widgetId)) {
|
|
const widget = canvasWidgets[widgetId];
|
|
if (widget.parentId && canvasWidgets.hasOwnProperty(widget.parentId)) {
|
|
const parent = canvasWidgets[widget.parentId];
|
|
return parent;
|
|
}
|
|
}
|
|
return;
|
|
},
|
|
);
|
|
|
|
export const getFocusedParentToOpen = createSelector(
|
|
getCanvasWidgets,
|
|
(state: AppState) => state.ui.widgetDragResize.focusedWidget,
|
|
(canvasWidgets, focusedWidgetId) => {
|
|
return getParentToOpenIfAny(focusedWidgetId, canvasWidgets);
|
|
},
|
|
);
|
|
|
|
export const getParentToOpenSelector = (widgetId: string) => {
|
|
return createSelector(getCanvasWidgets, (canvasWidgets) => {
|
|
return getParentToOpenIfAny(widgetId, canvasWidgets);
|
|
});
|
|
};
|
|
|
|
// Check if widget is in the list of selected widgets
|
|
export const isWidgetSelected = (widgetId: string) => {
|
|
return createSelector(getSelectedWidgets, (widgets): boolean =>
|
|
widgets.includes(widgetId),
|
|
);
|
|
};
|
|
|
|
export const isCurrentWidgetFocused = (widgetId: string) => {
|
|
return createSelector(
|
|
getFocusedWidget,
|
|
(widget): boolean => widget === widgetId,
|
|
);
|
|
};
|
|
|
|
// Check if current widget is the last selected widget
|
|
export const isCurrentWidgetLastSelected = (widgetId: string) => {
|
|
return createSelector(
|
|
getLastSelectedWidget,
|
|
(widget): boolean => widget === widgetId,
|
|
);
|
|
};
|
|
|
|
// Check if current widget is one of multiple selected widgets
|
|
export const isMultiSelectedWidget = (widgetId: string) => {
|
|
return createSelector(
|
|
getSelectedWidgets,
|
|
(widgets): boolean => widgets.length > 1 && widgets.includes(widgetId),
|
|
);
|
|
};
|
|
|
|
export function getParentToOpenIfAny(
|
|
widgetId: string | undefined,
|
|
widgets: CanvasWidgetsReduxState,
|
|
) {
|
|
if (widgetId) {
|
|
let widget = get(widgets, widgetId, undefined);
|
|
|
|
// While this widget has a openParentPropertyPane equal to true
|
|
while (widget?.openParentPropertyPane) {
|
|
// Get parent widget props
|
|
const parent = get(widgets, `${widget.parentId}`, undefined);
|
|
|
|
// If parent has openParentPropertyPane = false, return the current parent
|
|
if (!parent?.openParentPropertyPane) {
|
|
return parent;
|
|
}
|
|
|
|
if (parent?.parentId && parent.parentId !== MAIN_CONTAINER_WIDGET_ID) {
|
|
widget = get(widgets, `${widget.parentId}`, undefined);
|
|
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
export const shouldWidgetIgnoreClicksSelector = (widgetId: string) => {
|
|
return createSelector(
|
|
getFocusedWidget,
|
|
getIsTableFilterPaneVisible,
|
|
(state: AppState) => state.ui.widgetDragResize.isResizing,
|
|
(state: AppState) => state.ui.widgetDragResize.isDragging,
|
|
(state: AppState) => state.ui.canvasSelection.isDraggingForSelection,
|
|
getAppMode,
|
|
getIsAutoHeightWithLimitsChanging,
|
|
(
|
|
focusedWidgetId,
|
|
isTableFilterPaneVisible,
|
|
isResizing,
|
|
isDragging,
|
|
isDraggingForSelection,
|
|
appMode,
|
|
isAutoHeightWithLimitsChanging,
|
|
) => {
|
|
const isFocused = focusedWidgetId === widgetId;
|
|
|
|
return (
|
|
isDraggingForSelection ||
|
|
isResizing ||
|
|
isDragging ||
|
|
appMode !== APP_MODE.EDIT ||
|
|
!isFocused ||
|
|
isTableFilterPaneVisible ||
|
|
isAutoHeightWithLimitsChanging
|
|
);
|
|
},
|
|
);
|
|
};
|
|
|
|
export const getSelectedWidgetAncestry = (state: AppState) =>
|
|
state.ui.widgetDragResize.selectedWidgetAncestry;
|
|
|
|
export const getEntityExplorerWidgetsToExpand = createSelector(
|
|
getSelectedWidgetAncestry,
|
|
(selectedWidgetAncestry: string[]) => {
|
|
return selectedWidgetAncestry.slice(1);
|
|
},
|
|
);
|