## Description few type errors which are being thrown in ee because of the split is fixed in this PR #### Type of change - Chore (housekeeping or task changes that don't impact user perception) > > > ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [ ] Manual - [ ] JUnit - [ ] Jest - [ ] 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 - [ ] My code follows the style guidelines of this project - [ ] 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 - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] 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 - [ ] 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 - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
152 lines
5.1 KiB
TypeScript
152 lines
5.1 KiB
TypeScript
import type { Log } from "entities/AppsmithConsole";
|
|
import type { WidgetEntity } from "@appsmith/entities/DataTree/types";
|
|
import type { DataTree } from "entities/DataTree/dataTreeTypes";
|
|
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";
|
|
|
|
interface 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)) {
|
|
const widgetEntity = entity as WidgetEntity;
|
|
if (shouldSuppressDebuggerError(widgetEntity)) {
|
|
return false;
|
|
}
|
|
if (!hasParentWidget(widgetEntity)) {
|
|
return widgetEntity.isVisible
|
|
? true
|
|
: alwaysShowEntities[widgetEntity.widgetId];
|
|
} else {
|
|
const isParentWidgetVisible = isParentVisible(
|
|
widgetEntity,
|
|
canvasWidgets,
|
|
dataTree,
|
|
);
|
|
return widgetEntity.isVisible
|
|
? isParentWidgetVisible
|
|
: isParentWidgetVisible &&
|
|
alwaysShowEntities[widgetEntity.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;
|