PromucFlow_constructor/app/client/src/selectors/debuggerSelectors.tsx
Druthi Polisetty 50cd13e362
fix: Retain last selected tab on debugger and user selected filter condition (#25538)
## Description
Retains last selected tab on debugger and user selected filter condition

#### PR fixes following issue(s)
Fixes #23108

#### Type of change
- Bug fix (non-breaking change which fixes an issue)

>
>
## Testing
>
#### How Has This Been Tested?
- [x] Manual
- [x] Cypress
>
>
#### Test Plan
> Add Testsmith test cases links that relate to this PR
>
>
#### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
>
>
>
## 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:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [x] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [x] Manually tested functionality on DP
- [x] We had an implementation alignment call with stakeholders post QA
Round 2
- [x] Cypress test cases have been added and approved by SDET/manual QA
- [x] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed

---------

Co-authored-by: Rishabh Rathod <rishabh.rathod@appsmith.com>
Co-authored-by: arunvjn <arun@appsmith.com>
2023-08-09 15:19:32 +05:30

149 lines
5.0 KiB
TypeScript

import type { Log } from "entities/AppsmithConsole";
import type { DataTree, WidgetEntity } from "entities/DataTree/dataTreeFactory";
import { isEmpty } from "lodash";
import type { AppState } from "@appsmith/reducers";
import type { CanvasWidgetsReduxState } from "reducers/entityReducers/canvasWidgetsReducer";
import { createSelector } from "reselect";
import { getWidgets } from "sagas/selectors";
import {
shouldSuppressDebuggerError,
isWidget,
} from "@appsmith/workers/Evaluation/evaluationUtils";
import { getDataTree } from "./dataTreeSelectors";
type ErrorObejct = {
[k: string]: Log;
};
export const getDebuggerErrors = (state: AppState) => state.ui.debugger.errors;
export const hideErrors = (state: AppState) => state.ui.debugger.hideErrors;
const emptyErrorObejct: ErrorObejct = {};
export const getFilteredErrors = createSelector(
getDebuggerErrors,
hideErrors,
getWidgets,
getDataTree,
(errors, hideErrors, canvasWidgets, dataTree: DataTree) => {
if (hideErrors) return emptyErrorObejct;
if (isEmpty(errors)) return emptyErrorObejct;
const alwaysShowEntities: Record<string, boolean> = {};
Object.entries(errors).forEach(([, error]) => {
const entity = error?.source?.name && dataTree[error.source.name];
if (
entity &&
isWidget(entity) &&
error.source?.propertyPath === "isVisible"
) {
alwaysShowEntities[error.source.id] = true;
}
});
const filteredErrors = Object.fromEntries(
Object.entries(errors).filter(([, error]) => {
const entity = error?.source?.name && dataTree[error.source.name];
// filter error - when widget or parent widget is hidden
// parent widgets e.g. modal, tab, container
if (entity && isWidget(entity)) {
if (shouldSuppressDebuggerError(entity)) {
return false;
}
if (!hasParentWidget(entity)) {
return entity.isVisible
? true
: alwaysShowEntities[entity.widgetId];
} else {
const isParentWidgetVisible = isParentVisible(
entity,
canvasWidgets,
dataTree,
);
return entity.isVisible
? isParentWidgetVisible
: isParentWidgetVisible && alwaysShowEntities[entity.widgetId];
}
}
return true;
}),
);
return filteredErrors;
},
);
export const isParentVisible = (
currentWidgetData: WidgetEntity,
canvasWidgets: CanvasWidgetsReduxState,
dataTree: DataTree,
): boolean => {
const isWidgetVisible = !!currentWidgetData.isVisible;
if (!hasParentWidget(currentWidgetData)) {
return isWidgetVisible;
}
const parentWidget = canvasWidgets[currentWidgetData.parentId as string];
if (!parentWidget) return isWidgetVisible;
const parentWidgetData = dataTree[parentWidget.widgetName] as WidgetEntity;
if (!parentWidgetData) return isWidgetVisible;
switch (parentWidgetData.type) {
// check for widget types instead of harcoded string
case "TABS_WIDGET":
// need type for selectedTab and tabName
const isTabContentVisible =
!!parentWidgetData.isVisible &&
parentWidgetData.selectedTab === currentWidgetData.tabName;
return isTabContentVisible
? isParentVisible(parentWidgetData, canvasWidgets, dataTree)
: false;
case "MODAL_WIDGET":
return !!parentWidgetData.isVisible;
default:
return parentWidgetData.isVisible
? isParentVisible(parentWidgetData, canvasWidgets, dataTree)
: false;
}
};
export const hasParentWidget = (widget: WidgetEntity) =>
widget.parentId && widget.parentId !== "0";
export const getMessageCount = createSelector(getFilteredErrors, (errors) => {
let errorsCount = 0;
// count number of messages in each error.
// This logic is required because each messages in error is rendered separately.
Object.values(errors).forEach((error) => {
if (error.messages) {
errorsCount += error.messages.length;
}
});
// count number of warnings.
const warningsCount = Object.keys(errors).filter((key: string) =>
key.includes("warning"),
).length;
errorsCount = errorsCount - warningsCount;
return { errors: errorsCount, warnings: warningsCount };
});
// get selected tab in debugger.
export const getDebuggerSelectedTab = (state: AppState) =>
state.ui.debugger.context.selectedDebuggerTab;
export const getDebuggerSelectedFilter = (state: AppState) =>
state.ui.debugger.context.selectedDebuggerFilter;
export const getResponsePaneHeight = (state: AppState) =>
state.ui.debugger.context.responseTabHeight;
export const getErrorCount = (state: AppState) =>
state.ui.debugger.context.errorCount;
export const getScrollPosition = (state: AppState) =>
state.ui.debugger.context.scrollPosition;
export const getDebuggerContext = (state: AppState) =>
state.ui.debugger.context;
export const showDebuggerFlag = (state: AppState) =>
state.ui.debugger.isOpen && !state.ui.editor.isPreviewMode;