From 794ef1bbd68f5cc6f7ccf08ec68d0f17a209a31a Mon Sep 17 00:00:00 2001 From: akash-codemonk <67054171+akash-codemonk@users.noreply.github.com> Date: Thu, 15 Jul 2021 12:44:42 +0530 Subject: [PATCH] Fix: Fix bugs related to debugger errors (#5824) --- .../src/entities/AppsmithConsole/index.ts | 2 + app/client/src/sagas/ActionSagas.ts | 8 +++- app/client/src/sagas/DebuggerSagas.ts | 36 +++++++++++++++- app/client/src/sagas/EvaluationsSaga.ts | 7 +++ app/client/src/sagas/WidgetOperationSagas.tsx | 43 +++++++++++-------- app/client/src/selectors/entitiesSelector.ts | 5 ++- 6 files changed, 79 insertions(+), 22 deletions(-) diff --git a/app/client/src/entities/AppsmithConsole/index.ts b/app/client/src/entities/AppsmithConsole/index.ts index caa66bcb44..0ae20d2dee 100644 --- a/app/client/src/entities/AppsmithConsole/index.ts +++ b/app/client/src/entities/AppsmithConsole/index.ts @@ -63,6 +63,8 @@ export interface LogActionPayload { source?: SourceEntity; // Snapshot KV pair of scope variables or state associated with this event. state?: Record; + // Any other data required for analytics + analytics?: Record; } export interface Message extends LogActionPayload { diff --git a/app/client/src/sagas/ActionSagas.ts b/app/client/src/sagas/ActionSagas.ts index badbc47aef..1695f2a788 100644 --- a/app/client/src/sagas/ActionSagas.ts +++ b/app/client/src/sagas/ActionSagas.ts @@ -345,7 +345,9 @@ export function* deleteActionSaga( try { const id = actionPayload.payload.id; const name = actionPayload.payload.name; - const action = yield select(getAction, id); + const action: Action | undefined = yield select(getAction, id); + + if (!action) return; const isApi = action.pluginType === PluginType.API; const isQuery = action.pluginType === PluginType.DB; @@ -401,7 +403,11 @@ export function* deleteActionSaga( name: response.data.name, id: response.data.id, }, + analytics: { + pluginId: action.pluginId, + }, }); + yield put(deleteActionSuccess({ id })); } } catch (error) { diff --git a/app/client/src/sagas/DebuggerSagas.ts b/app/client/src/sagas/DebuggerSagas.ts index 3c4c490bb5..6c77b78c12 100644 --- a/app/client/src/sagas/DebuggerSagas.ts +++ b/app/client/src/sagas/DebuggerSagas.ts @@ -22,7 +22,11 @@ import { } from "redux-saga/effects"; import { get, set } from "lodash"; import { getDebuggerErrors } from "selectors/debuggerSelectors"; -import { getAction, getPlugin } from "selectors/entitiesSelector"; +import { + getAction, + getPlugin, + getPluginNameFromId, +} from "selectors/entitiesSelector"; import { Action, PluginType } from "entities/Action"; import LOG_TYPE from "entities/AppsmithConsole/logtype"; import { DataTree } from "entities/DataTree/dataTreeFactory"; @@ -81,8 +85,13 @@ function* onEntityDeleteSaga(payload: Message) { yield put(debuggerLog(payload)); return; } + const currentPageId = yield select(getCurrentPageId); + let pluginName: string = yield select( + getPluginNameFromId, + payload?.analytics?.pluginId, + ); - const errors = yield select(getDebuggerErrors); + const errors: Record = yield select(getDebuggerErrors); const errorIds = Object.keys(errors); const updatedErrors: any = {}; @@ -91,6 +100,29 @@ function* onEntityDeleteSaga(payload: Message) { if (!includes) { updatedErrors[e] = errors[e]; + } else { + // If the error is being removed here + // need to send an analytics event for the same + const error = errors[e]; + pluginName = pluginName.replace(/ /g, ""); + + if (source.type === ENTITY_TYPE.ACTION) { + AnalyticsUtil.logEvent("DEBUGGER_RESOLVED_ERROR", { + entityType: pluginName, + propertyPath: `${pluginName}.${error.source?.propertyPath ?? ""}`, + errorMessages: error.messages, + pageId: currentPageId, + }); + } else if (source.type === ENTITY_TYPE.WIDGET) { + const widgetType = error?.analytics?.widgetType; + + AnalyticsUtil.logEvent("DEBUGGER_RESOLVED_ERROR", { + entityType: widgetType, + propertyPath: `${widgetType}.${error.source?.propertyPath ?? ""}`, + errorMessages: error.messages, + pageId: currentPageId, + }); + } } }); diff --git a/app/client/src/sagas/EvaluationsSaga.ts b/app/client/src/sagas/EvaluationsSaga.ts index ab34c60334..9b79555d45 100644 --- a/app/client/src/sagas/EvaluationsSaga.ts +++ b/app/client/src/sagas/EvaluationsSaga.ts @@ -129,6 +129,12 @@ function getLatestEvalPropertyErrors( ); } + const analyticsData = isWidget(entity) + ? { + widgetType: entity.type, + } + : {}; + // Add or update updatedDebuggerErrors[debuggerKey] = { logType: LOG_TYPE.EVAL_ERROR, @@ -147,6 +153,7 @@ function getLatestEvalPropertyErrors( state: { [propertyPath]: evaluatedValue, }, + analytics: analyticsData, }; } else if (debuggerKey in updatedDebuggerErrors) { store.dispatch( diff --git a/app/client/src/sagas/WidgetOperationSagas.tsx b/app/client/src/sagas/WidgetOperationSagas.tsx index ce8da595f2..0577df0b6e 100644 --- a/app/client/src/sagas/WidgetOperationSagas.tsx +++ b/app/client/src/sagas/WidgetOperationSagas.tsx @@ -528,14 +528,16 @@ export function* deleteAllSelectedWidgetsSaga( setTimeout(() => { if (bulkDeleteKey) { flushDeletedWidgets(bulkDeleteKey); - AppsmithConsole.info({ - logType: LOG_TYPE.ENTITY_DELETED, - text: `${selectedWidgets.length} were deleted`, - source: { - name: "Group Delete", - type: ENTITY_TYPE.WIDGET, - id: bulkDeleteKey, - }, + falttendedWidgets.map((widget: any) => { + AppsmithConsole.info({ + logType: LOG_TYPE.ENTITY_DELETED, + text: "Widget was deleted", + source: { + name: widget.widgetName, + type: ENTITY_TYPE.WIDGET, + id: widget.widgetId, + }, + }); }); } }, WIDGET_DELETE_UNDO_TIMEOUT); @@ -575,7 +577,9 @@ export function* deleteSaga(deleteAction: ReduxAction) { const { disallowUndo, isShortcut } = deleteAction.payload; if (!widgetId) { - const selectedWidget = yield select(getSelectedWidget); + const selectedWidget: FlattenedWidgetProps | undefined = yield select( + getSelectedWidget, + ); if (!selectedWidget) return; // if widget is not deletable, don't don anything @@ -588,7 +592,7 @@ export function* deleteSaga(deleteAction: ReduxAction) { if (widgetId && parentId) { const stateWidgets = yield select(getWidgets); const widgets = { ...stateWidgets }; - const stateWidget = yield select(getWidget, widgetId); + const stateWidget: WidgetProps = yield select(getWidget, widgetId); const widget = { ...stateWidget }; const stateParent: FlattenedWidgetProps = yield select( @@ -641,17 +645,20 @@ export function* deleteSaga(deleteAction: ReduxAction) { }, }, }); + setTimeout(() => { if (widgetId) { flushDeletedWidgets(widgetId); - AppsmithConsole.info({ - logType: LOG_TYPE.ENTITY_DELETED, - text: "Widget was deleted", - source: { - name: widgetName, - type: ENTITY_TYPE.WIDGET, - id: widgetId, - }, + otherWidgetsToDelete.map((widget) => { + AppsmithConsole.info({ + logType: LOG_TYPE.ENTITY_DELETED, + text: "Widget was deleted", + source: { + name: widget.widgetName, + type: ENTITY_TYPE.WIDGET, + id: widget.widgetId, + }, + }); }); } }, WIDGET_DELETE_UNDO_TIMEOUT); diff --git a/app/client/src/selectors/entitiesSelector.ts b/app/client/src/selectors/entitiesSelector.ts index 5ad7ba33d6..ad8900f47a 100644 --- a/app/client/src/selectors/entitiesSelector.ts +++ b/app/client/src/selectors/entitiesSelector.ts @@ -80,7 +80,10 @@ export const getPluginPackageFromDatasourceId = ( return plugin.packageName; }; -export const getPluginNameFromId = (state: AppState, pluginId: string) => { +export const getPluginNameFromId = ( + state: AppState, + pluginId: string, +): string => { const plugin = state.entities.plugins.list.find( (plugin) => plugin.id === pluginId, );