PromucFlow_constructor/app/client/src/selectors/debuggerSelectors.tsx

131 lines
4.4 KiB
TypeScript
Raw Normal View History

import { matchDatasourcePath } from "constants/routes";
import { Log } from "entities/AppsmithConsole";
import { DataTree, DataTreeWidget } from "entities/DataTree/dataTreeFactory";
import { isEmpty } from "lodash";
import { AppState } from "@appsmith/reducers";
import { CanvasWidgetsReduxState } from "reducers/entityReducers/canvasWidgetsReducer";
import { createSelector } from "reselect";
import { getWidgets } from "sagas/selectors";
feat: List V2 (#15839) ## Description TL;DR This is a complete architectural change of of List widget works to support all widgets we currently have and should automatically support any future widgets. It also introduces nested List widgets i.e a list widget can have a another list widget which in turn can have another list widget. Fixes #18206 Fixes #6775 Fixes #13211 Fixes #16582 Fixes #11739 Fixes #15094 Fixes #6840 Fixes #10841 Fixes #17386 Fixes #18340 Fixes #16898 Fixes #17555 Fixes #6858 Fixes #9568 Fixes #17480 Fixes #18523 Fixes #18206 Fixes #16586 Fixes #18106 Fixes #16576 Fixes #14697 Fixes #9607 Fixes #19648 Fixes #19739 Fixes #19652 Fixes #18730 Fixes #19503 Fixes #19498 Fixes #19437 Fixes #5245 Fixes #19150 Fixes #18638 Fixes #11332 Fixes #17901 Fixes #19043 Fixes #17777 Fixes #8237 Fixes #15487 Fixes #15988 Fixes #18621 Fixes #16788 Fixes #18110 Fixes #18382 Fixes #17427 Fixes #18105 Fixes #18287 Fixes #19808 Fixes #14655 ## Type of change - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Cypress - Jest - Manual ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] 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 --------- Co-authored-by: Tolulope Adetula <31691737+Tooluloope@users.noreply.github.com> Co-authored-by: Favour Ohanekwu <fohanekwu@gmail.com>
2023-02-14 16:07:31 +00:00
import {
shouldSuppressDebuggerError,
isWidget,
} from "@appsmith/workers/Evaluation/evaluationUtils";
import { getDataTree } from "./dataTreeSelectors";
type ErrorObejct = {
[k: string]: Log;
};
2021-04-23 13:50:55 +00:00
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)) {
feat: List V2 (#15839) ## Description TL;DR This is a complete architectural change of of List widget works to support all widgets we currently have and should automatically support any future widgets. It also introduces nested List widgets i.e a list widget can have a another list widget which in turn can have another list widget. Fixes #18206 Fixes #6775 Fixes #13211 Fixes #16582 Fixes #11739 Fixes #15094 Fixes #6840 Fixes #10841 Fixes #17386 Fixes #18340 Fixes #16898 Fixes #17555 Fixes #6858 Fixes #9568 Fixes #17480 Fixes #18523 Fixes #18206 Fixes #16586 Fixes #18106 Fixes #16576 Fixes #14697 Fixes #9607 Fixes #19648 Fixes #19739 Fixes #19652 Fixes #18730 Fixes #19503 Fixes #19498 Fixes #19437 Fixes #5245 Fixes #19150 Fixes #18638 Fixes #11332 Fixes #17901 Fixes #19043 Fixes #17777 Fixes #8237 Fixes #15487 Fixes #15988 Fixes #18621 Fixes #16788 Fixes #18110 Fixes #18382 Fixes #17427 Fixes #18105 Fixes #18287 Fixes #19808 Fixes #14655 ## Type of change - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Cypress - Jest - Manual ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] 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 --------- Co-authored-by: Tolulope Adetula <31691737+Tooluloope@users.noreply.github.com> Co-authored-by: Favour Ohanekwu <fohanekwu@gmail.com>
2023-02-14 16:07:31 +00:00
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: DataTreeWidget,
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 DataTreeWidget;
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: DataTreeWidget) =>
widget.parentId && widget.parentId !== "0";
export const getMessageCount = createSelector(getFilteredErrors, (errors) => {
feat: Error handling phase 1 (#20629) ## Description This PR updates the error logs - Establishing a consistent format for all error messages. - Revising error titles and details for improved understanding. - Compiling internal documentation of all error categories, subcategories, and error descriptions. Updated Error Interface: https://www.notion.so/appsmith/Error-Interface-for-Plugin-Execution-Error-7b3f5323ba4c40bfad281ae717ccf79b PRD: https://www.notion.so/appsmith/PRD-Error-Handling-Framework-4ac9747057fd4105a9d52cb8b42f4452?pvs=4#008e9c79ff3c484abf0250a5416cf052 >TL;DR Fixes # Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video ## Type of change - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Manual - Jest - Cypress ### Test Plan ### Issues raised during DP testing ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] 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 - [x] PR is being merged under a feature flag ### QA activity: - [ ] Test plan has been approved by relevant developers - [ ] 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 --------- Co-authored-by: subrata <subrata@appsmith.com>
2023-02-18 12:55:46 +00:00
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;
feat: Error handling phase 1 (#20629) ## Description This PR updates the error logs - Establishing a consistent format for all error messages. - Revising error titles and details for improved understanding. - Compiling internal documentation of all error categories, subcategories, and error descriptions. Updated Error Interface: https://www.notion.so/appsmith/Error-Interface-for-Plugin-Execution-Error-7b3f5323ba4c40bfad281ae717ccf79b PRD: https://www.notion.so/appsmith/PRD-Error-Handling-Framework-4ac9747057fd4105a9d52cb8b42f4452?pvs=4#008e9c79ff3c484abf0250a5416cf052 >TL;DR Fixes # Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video ## Type of change - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Manual - Jest - Cypress ### Test Plan ### Issues raised during DP testing ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] 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 - [x] PR is being merged under a feature flag ### QA activity: - [ ] Test plan has been approved by relevant developers - [ ] 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 --------- Co-authored-by: subrata <subrata@appsmith.com>
2023-02-18 12:55:46 +00:00
errorsCount = errorsCount - warningsCount;
return { errors: errorsCount, warnings: warningsCount };
});
export const hideDebuggerIconSelector = () =>
matchDatasourcePath(window.location.pathname);