From 1aaaf0f26ac38c34475c80df4581b4b3a97a27f7 Mon Sep 17 00:00:00 2001 From: Paula Stachova Date: Tue, 18 Mar 2025 18:09:42 +0100 Subject: [PATCH 1/3] feat: validation error details aggregation COMPASS-8868 --- .../pipeline-results-workspace/index.tsx | 65 ++++++++++++++++--- .../src/modules/aggregation.ts | 18 ++++- 2 files changed, 72 insertions(+), 11 deletions(-) diff --git a/packages/compass-aggregations/src/components/pipeline-results-workspace/index.tsx b/packages/compass-aggregations/src/components/pipeline-results-workspace/index.tsx index fa2759de2cc..592da217857 100644 --- a/packages/compass-aggregations/src/components/pipeline-results-workspace/index.tsx +++ b/packages/compass-aggregations/src/components/pipeline-results-workspace/index.tsx @@ -6,13 +6,19 @@ import { cx, spacing, CancelLoader, - ErrorSummary, Subtitle, Button, palette, + Banner, + BannerVariant, + showErrorDetails, } from '@mongodb-js/compass-components'; import type { RootState } from '../../modules'; -import { cancelAggregation, retryAggregation } from '../../modules/aggregation'; +import { + type AggregationError, + cancelAggregation, + retryAggregation, +} from '../../modules/aggregation'; import PipelineResultsList from './pipeline-results-list'; import PipelineEmptyResults from './pipeline-empty-results'; import { @@ -52,6 +58,23 @@ const centered = css({ justifyContent: 'center', }); +const errorBannerStyles = css({ + width: '100%', +}); + +const errorBannerContentStyles = css({ + display: 'flex', + justifyContent: 'space-between', +}); + +const errorBannerTextStyles = css({ + flex: 1, +}); + +const errorDetailsBtnStyles = css({ + marginLeft: spacing[100], +}); + const ResultsContainer: React.FunctionComponent<{ center?: boolean }> = ({ children, center, @@ -102,7 +125,7 @@ type PipelineResultsWorkspaceProps = { documents: HadronDocument[]; isLoading?: boolean; isError?: boolean; - error?: string | null; + error?: AggregationError; isEmpty?: boolean; isMergeOrOutPipeline?: boolean; mergeOrOutDestination?: string | null; @@ -133,12 +156,38 @@ export const PipelineResultsWorkspace: React.FunctionComponent< if (isError && error) { results = ( - + variant={BannerVariant.Danger} + className={errorBannerStyles} + > +
+
{error?.message}
+ + {error?.info && ( + + )} +
+
); } else if (isLoading) { diff --git a/packages/compass-aggregations/src/modules/aggregation.ts b/packages/compass-aggregations/src/modules/aggregation.ts index ed9b9e39930..df3737e8189 100644 --- a/packages/compass-aggregations/src/modules/aggregation.ts +++ b/packages/compass-aggregations/src/modules/aggregation.ts @@ -73,9 +73,14 @@ export type AggregationFinishedAction = { isLast: boolean; }; +export type AggregationError = { + message: string; + info?: Record; +}; + export type AggregationFailedAction = { type: ActionTypes.AggregationFailed; - error: string; + error: AggregationError; page: number; }; @@ -110,7 +115,7 @@ export type State = { isLast: boolean; loading: boolean; abortController?: AbortController; - error?: string; + error?: AggregationError; previousPageData?: PreviousPageData; resultsViewType: 'document' | 'json'; }; @@ -125,6 +130,13 @@ export const INITIAL_STATE: State = { resultsViewType: 'document', }; +function getAggregationError(error: Error): AggregationError { + return { + message: error.message, + info: (error as MongoServerError).errInfo, + }; +} + const reducer: Reducer = (state = INITIAL_STATE, action) => { if ( isAction( @@ -477,7 +489,7 @@ const fetchAggregationData = ( if ((e as MongoServerError).code) { dispatch({ type: ActionTypes.AggregationFailed, - error: (e as Error).message, + error: getAggregationError(e as Error), page, }); if ((e as MongoServerError).codeName === 'MaxTimeMSExpired') { From 8c991935a035840d108410ee8695d0bd812c20ba Mon Sep 17 00:00:00 2001 From: Paula Stachova Date: Thu, 27 Mar 2025 16:32:02 -0400 Subject: [PATCH 2/3] test: add e2e test --- .../pipeline-results-workspace/index.tsx | 2 +- .../helpers/commands/set-validation.ts | 5 +- .../compass-e2e-tests/helpers/selectors.ts | 2 + .../tests/collection-aggregations-tab.test.ts | 78 +++++++++++++++++++ 4 files changed, 85 insertions(+), 2 deletions(-) diff --git a/packages/compass-aggregations/src/components/pipeline-results-workspace/index.tsx b/packages/compass-aggregations/src/components/pipeline-results-workspace/index.tsx index 592da217857..92158002ff4 100644 --- a/packages/compass-aggregations/src/components/pipeline-results-workspace/index.tsx +++ b/packages/compass-aggregations/src/components/pipeline-results-workspace/index.tsx @@ -166,7 +166,7 @@ export const PipelineResultsWorkspace: React.FunctionComponent<