Skip to content

Commit 2710616

Browse files
committed
.
1 parent 55fda3c commit 2710616

File tree

6 files changed

+64
-5
lines changed

6 files changed

+64
-5
lines changed

packages/compass-components/src/components/error-warning-summary.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ const actionButtonStyles = css({
2424
marginLeft: 'auto',
2525
});
2626

27+
type DismissProps =
28+
| { dismissible: true; onClose: () => void }
29+
| { dismissible?: false; onClose?: never };
30+
2731
function Summary({ messages }: { messages: string[] }): React.ReactElement {
2832
if (messages.length === 1) {
2933
return <div>{messages[0]}</div>;
@@ -77,11 +81,11 @@ const BannerWithSummary: React.FunctionComponent<
7781
variant: BannerVariant;
7882
['data-testid']?: string;
7983
className?: string;
80-
dismissible?: boolean;
8184
} & (
8285
| { actionText: string; onAction(): void }
8386
| { actionText?: never; onAction?: never }
84-
)
87+
) &
88+
DismissProps
8589
> = ({
8690
['data-testid']: dataTestId,
8791
messages,
@@ -90,6 +94,7 @@ const BannerWithSummary: React.FunctionComponent<
9094
variant,
9195
className,
9296
dismissible,
97+
onClose,
9398
}) => {
9499
const _messages = useMemo(() => {
95100
return !Array.isArray(messages) ? [messages] : messages;
@@ -101,6 +106,7 @@ const BannerWithSummary: React.FunctionComponent<
101106
variant={variant}
102107
className={cx(bannerStyle, className)}
103108
dismissible={dismissible}
109+
onClose={onClose}
104110
>
105111
<div className={summaryStyles}>
106112
<Summary messages={_messages}></Summary>
@@ -127,7 +133,8 @@ export const ErrorSummary: React.FunctionComponent<
127133
} & (
128134
| { actionText: string; onAction(): void }
129135
| { actionText?: never; onAction?: never }
130-
)
136+
) &
137+
DismissProps
131138
> = ({ className, errors, ...props }) => {
132139
return (
133140
<BannerWithSummary
@@ -147,7 +154,8 @@ export const WarningSummary: React.FunctionComponent<
147154
} & (
148155
| { actionText: string; onAction(): void }
149156
| { actionText?: never; onAction?: never }
150-
)
157+
) &
158+
DismissProps
151159
> = ({ className, warnings, ...props }) => {
152160
return (
153161
<BannerWithSummary

packages/compass-schema/src/components/compass-schema.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { useIsLastAppliedQueryOutdated } from '@mongodb-js/compass-query-bar';
3737
import { useTelemetry } from '@mongodb-js/compass-telemetry/provider';
3838
import type { RootState } from '../stores/store';
3939
import {
40+
analysisErrorDismissed,
4041
type SchemaAnalysisError,
4142
startAnalysis,
4243
stopAnalysis,
@@ -383,6 +384,7 @@ const Schema: React.FunctionComponent<{
383384
onExportSchemaClicked: () => void;
384385
onStartAnalysis: () => Promise<void>;
385386
onStopAnalysis: () => void;
387+
onDismissError: () => void;
386388
}> = ({
387389
analysisState,
388390
error,
@@ -391,6 +393,7 @@ const Schema: React.FunctionComponent<{
391393
onExportSchemaClicked,
392394
onStartAnalysis,
393395
onStopAnalysis,
396+
onDismissError,
394397
}) => {
395398
const onApplyClicked = useCallback(() => {
396399
void onStartAnalysis();
@@ -415,6 +418,7 @@ const Schema: React.FunctionComponent<{
415418
onResetClicked={onApplyClicked}
416419
analysisState={analysisState}
417420
error={error}
421+
onDismissError={onDismissError}
418422
isOutdated={!!outdated}
419423
sampleSize={schema ? schema.count : 0}
420424
schemaResultId={resultId || ''}
@@ -452,5 +456,6 @@ export default connect(
452456
onStartAnalysis: startAnalysis,
453457
onStopAnalysis: () => stopAnalysis(),
454458
onExportSchemaClicked: openExportSchema,
459+
onDismissError: analysisErrorDismissed,
455460
}
456461
)(Schema);

packages/compass-schema/src/components/schema-toolbar/schema-toolbar.spec.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ describe('SchemaToolbar', function () {
4747
sampleSize={10}
4848
schemaResultId="123"
4949
onExportSchemaClicked={() => {}}
50+
onDismissError={() => {}}
5051
{...props}
5152
/>
5253
</MockQueryBarPlugin>,
@@ -74,6 +75,22 @@ describe('SchemaToolbar', function () {
7475
expect(screen.getByTestId('schema-toolbar-error-message')).to.be.visible;
7576
});
7677

78+
it('renders timeout error', function () {
79+
renderSchemaToolbar({
80+
analysisState: 'initial',
81+
error: {
82+
errorType: 'TIMEOUT',
83+
errorMessage: 'test error msg',
84+
},
85+
});
86+
87+
expect(screen.getByTestId('schema-toolbar-timeout-message')).to.be
88+
.visible;
89+
expect(
90+
screen.getByTestId('schema-toolbar-timeout-message').textContent
91+
).to.include('Please try increasing the maxTimeMS');
92+
});
93+
7794
it('renders complexity abort error', function () {
7895
renderSchemaToolbar({
7996
analysisState: 'initial',

packages/compass-schema/src/components/schema-toolbar/schema-toolbar.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,15 @@ type SchemaToolbarProps = {
6464
onAnalyzeSchemaClicked: () => void;
6565
onExportSchemaClicked: () => void;
6666
onResetClicked: () => void;
67+
onDismissError: () => void;
6768
sampleSize: number;
6869
schemaResultId: string;
6970
};
7071

7172
const SchemaToolbar: React.FunctionComponent<SchemaToolbarProps> = ({
7273
analysisState,
7374
error,
75+
onDismissError,
7476
isOutdated,
7577
onAnalyzeSchemaClicked,
7678
onExportSchemaClicked,
@@ -134,19 +136,23 @@ const SchemaToolbar: React.FunctionComponent<SchemaToolbarProps> = ({
134136
data-testid="schema-toolbar-error-message"
135137
errors={[`${ERROR_WARNING}: ${error.errorMessage}`]}
136138
dismissible={true}
139+
onClose={onDismissError}
137140
/>
138141
)}
139142
{error?.errorType === 'TIMEOUT' && (
140143
<WarningSummary
144+
data-testid="schema-toolbar-timeout-message"
141145
warnings={[INCREASE_MAX_TIME_MS_HINT_MESSAGE]}
142146
dismissible={true}
147+
onClose={onDismissError}
143148
/>
144149
)}
145150
{error?.errorType === 'HIGH_COMPLEXITY' && (
146151
<Banner
147152
variant={BannerVariant.Danger}
148153
data-testid="schema-toolbar-complexity-abort-message"
149154
dismissible={true}
155+
onClose={onDismissError}
150156
>
151157
The analysis was aborted because the number of fields exceeds 1000.
152158
Consider breaking up your data into more collections with smaller

packages/compass-schema/src/stores/schema-analysis-reducer.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const enum SchemaAnalysisActions {
4242
analysisStarted = 'schema-service/schema-analysis/analysisStarted',
4343
analysisFinished = 'schema-service/schema-analysis/analysisFinished',
4444
analysisFailed = 'schema-service/schema-analysis/analysisFailed',
45+
analysisErrorDismissed = 'schema-service/schema-analysis/analysisErrorDismissed',
4546
}
4647

4748
export type AnalysisStartedAction = {
@@ -59,6 +60,10 @@ export type AnalysisFailedAction = {
5960
error: Error;
6061
};
6162

63+
export type AnalysisErrorDismissedAction = {
64+
type: SchemaAnalysisActions.analysisErrorDismissed;
65+
};
66+
6267
export const schemaAnalysisReducer: Reducer<SchemaAnalysisState, Action> = (
6368
state = getInitialState(),
6469
action
@@ -105,6 +110,18 @@ export const schemaAnalysisReducer: Reducer<SchemaAnalysisState, Action> = (
105110
};
106111
}
107112

113+
if (
114+
isAction<AnalysisErrorDismissedAction>(
115+
action,
116+
SchemaAnalysisActions.analysisErrorDismissed
117+
)
118+
) {
119+
return {
120+
...state,
121+
error: undefined,
122+
};
123+
}
124+
108125
return state;
109126
};
110127

@@ -148,6 +165,12 @@ export const geoLayerAdded = (
148165
};
149166
};
150167

168+
export const analysisErrorDismissed =
169+
(): SchemaThunkAction<AnalysisErrorDismissedAction> => {
170+
return (dispatch) =>
171+
dispatch({ type: SchemaAnalysisActions.analysisErrorDismissed });
172+
};
173+
151174
export const geoLayersEdited = (
152175
field: string,
153176
layers: LayerGroup

packages/compass-schema/src/stores/store.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ describe('Schema Store', function () {
131131
store.dispatch(stopAnalysis());
132132
isCancelErrorStub.returns(true);
133133
await analysisPromise;
134-
expect(store.getState().schemaAnalysis.analysisState).to.equal('error');
134+
expect(store.getState().schemaAnalysis.analysisState).to.equal('initial');
135135
});
136136

137137
describe('schema export', function () {

0 commit comments

Comments
 (0)