Skip to content

Commit edd6d03

Browse files
authored
fix(compass-schema): complexity and size limits COMPASS-8905 COMPASS-8984 COMPASS-8941 (#6733)
1 parent 25ecd73 commit edd6d03

File tree

16 files changed

+387
-1105
lines changed

16 files changed

+387
-1105
lines changed

package-lock.json

Lines changed: 185 additions & 1025 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-aggregations/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"mongodb-instance-model": "^12.26.2",
9292
"mongodb-ns": "^2.4.2",
9393
"mongodb-query-parser": "^4.3.0",
94-
"mongodb-schema": "^12.3.2",
94+
"mongodb-schema": "^12.4.0",
9595
"prop-types": "^15.7.2",
9696
"re-resizable": "^6.9.0",
9797
"react": "^17.0.2",

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

Lines changed: 14 additions & 3 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>;
@@ -80,14 +84,17 @@ const BannerWithSummary: React.FunctionComponent<
8084
} & (
8185
| { actionText: string; onAction(): void }
8286
| { actionText?: never; onAction?: never }
83-
)
87+
) &
88+
DismissProps
8489
> = ({
8590
['data-testid']: dataTestId,
8691
messages,
8792
onAction,
8893
actionText,
8994
variant,
9095
className,
96+
dismissible,
97+
onClose,
9198
}) => {
9299
const _messages = useMemo(() => {
93100
return !Array.isArray(messages) ? [messages] : messages;
@@ -98,6 +105,8 @@ const BannerWithSummary: React.FunctionComponent<
98105
data-testid={dataTestId}
99106
variant={variant}
100107
className={cx(bannerStyle, className)}
108+
dismissible={dismissible}
109+
onClose={onClose}
101110
>
102111
<div className={summaryStyles}>
103112
<Summary messages={_messages}></Summary>
@@ -124,7 +133,8 @@ export const ErrorSummary: React.FunctionComponent<
124133
} & (
125134
| { actionText: string; onAction(): void }
126135
| { actionText?: never; onAction?: never }
127-
)
136+
) &
137+
DismissProps
128138
> = ({ className, errors, ...props }) => {
129139
return (
130140
<BannerWithSummary
@@ -144,7 +154,8 @@ export const WarningSummary: React.FunctionComponent<
144154
} & (
145155
| { actionText: string; onAction(): void }
146156
| { actionText?: never; onAction?: never }
147-
)
157+
) &
158+
DismissProps
148159
> = ({ className, warnings, ...props }) => {
149160
return (
150161
<BannerWithSummary

packages/compass-field-store/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"@mongodb-js/compass-logging": "^1.6.2",
7474
"hadron-app-registry": "^9.4.2",
7575
"lodash": "^4.17.21",
76-
"mongodb-schema": "^12.3.2",
76+
"mongodb-schema": "^12.4.0",
7777
"react": "^17.0.2",
7878
"react-redux": "^8.1.3",
7979
"redux": "^4.2.1",

packages/compass-generative-ai/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"compass-preferences-model": "^2.33.2",
6363
"hadron-app-registry": "^9.4.2",
6464
"mongodb": "^6.12.0",
65-
"mongodb-schema": "^12.3.2",
65+
"mongodb-schema": "^12.4.0",
6666
"react": "^17.0.2",
6767
"react-redux": "^8.1.3",
6868
"redux": "^4.2.1",

packages/compass-import-export/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"mongodb-data-service": "^22.25.2",
6969
"mongodb-ns": "^2.4.2",
7070
"mongodb-query-parser": "^4.3.0",
71-
"mongodb-schema": "^12.3.2",
71+
"mongodb-schema": "^12.4.0",
7272
"papaparse": "^5.3.2",
7373
"react": "^17.0.2",
7474
"react-redux": "^8.1.3",

packages/compass-query-bar/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"mongodb-ns": "^2.4.2",
8888
"mongodb-query-parser": "^4.3.0",
8989
"mongodb-query-util": "^2.4.2",
90-
"mongodb-schema": "^12.3.2",
90+
"mongodb-schema": "^12.4.0",
9191
"react": "^17.0.2",
9292
"react-redux": "^8.1.3",
9393
"redux": "^4.2.1",

packages/compass-schema/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
"lodash": "^4.17.21",
9393
"mongodb": "^6.12.0",
9494
"mongodb-query-util": "^2.4.2",
95-
"mongodb-schema": "^12.3.2",
95+
"mongodb-schema": "^12.4.0",
9696
"numeral": "^1.5.6",
9797
"prop-types": "^15.7.2",
9898
"react": "^17.0.2",

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ import { getAtlasPerformanceAdvisorLink } from '../utils';
3636
import { useIsLastAppliedQueryOutdated } from '@mongodb-js/compass-query-bar';
3737
import { useTelemetry } from '@mongodb-js/compass-telemetry/provider';
3838
import type { RootState } from '../stores/store';
39-
import { startAnalysis, stopAnalysis } from '../stores/schema-analysis-reducer';
39+
import {
40+
analysisErrorDismissed,
41+
type SchemaAnalysisError,
42+
startAnalysis,
43+
stopAnalysis,
44+
} from '../stores/schema-analysis-reducer';
4045
import { openExportSchema } from '../stores/schema-export-reducer';
4146
import ExportSchemaModal from './export-schema-modal';
4247
import ExportSchemaLegacyBanner from './export-schema-legacy-banner';
@@ -371,22 +376,24 @@ const PerformanceAdvisorBanner = () => {
371376

372377
const Schema: React.FunctionComponent<{
373378
analysisState: AnalysisState;
374-
errorMessage?: string;
379+
error?: SchemaAnalysisError;
375380
maxTimeMS?: number;
376381
schema: MongodbSchema | null;
377382
count?: number;
378383
resultId?: string;
379384
onExportSchemaClicked: () => void;
380385
onStartAnalysis: () => Promise<void>;
381386
onStopAnalysis: () => void;
387+
onDismissError: () => void;
382388
}> = ({
383389
analysisState,
384-
errorMessage,
390+
error,
385391
schema,
386392
resultId,
387393
onExportSchemaClicked,
388394
onStartAnalysis,
389395
onStopAnalysis,
396+
onDismissError,
390397
}) => {
391398
const onApplyClicked = useCallback(() => {
392399
void onStartAnalysis();
@@ -410,7 +417,8 @@ const Schema: React.FunctionComponent<{
410417
onExportSchemaClicked={onExportSchemaClicked}
411418
onResetClicked={onApplyClicked}
412419
analysisState={analysisState}
413-
errorMessage={errorMessage || ''}
420+
error={error}
421+
onDismissError={onDismissError}
414422
isOutdated={!!outdated}
415423
sampleSize={schema ? schema.count : 0}
416424
schemaResultId={resultId || ''}
@@ -440,13 +448,14 @@ const Schema: React.FunctionComponent<{
440448
export default connect(
441449
(state: RootState) => ({
442450
analysisState: state.schemaAnalysis.analysisState,
443-
errorMessage: state.schemaAnalysis.errorMessage,
451+
error: state.schemaAnalysis.error,
444452
schema: state.schemaAnalysis.schema,
445453
resultId: state.schemaAnalysis.resultId,
446454
}),
447455
{
448456
onStartAnalysis: startAnalysis,
449457
onStopAnalysis: () => stopAnalysis(),
450458
onExportSchemaClicked: openExportSchema,
459+
onDismissError: analysisErrorDismissed,
451460
}
452461
)(Schema);

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

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ describe('SchemaToolbar', function () {
4040
<MockQueryBarPlugin {...(queryBarProps as any)}>
4141
<SchemaToolbar
4242
analysisState="complete"
43-
errorMessage={''}
43+
error={undefined}
4444
isOutdated={false}
4545
onAnalyzeSchemaClicked={() => {}}
4646
onResetClicked={() => {}}
4747
sampleSize={10}
4848
schemaResultId="123"
4949
onExportSchemaClicked={() => {}}
50+
onDismissError={() => {}}
5051
{...props}
5152
/>
5253
</MockQueryBarPlugin>,
@@ -60,23 +61,54 @@ describe('SchemaToolbar', function () {
6061
sinon.restore();
6162
});
6263

63-
it("renders errors when they're passed", function () {
64-
renderSchemaToolbar({
65-
analysisState: 'error',
66-
errorMessage: 'test error msg',
64+
describe('errors', function () {
65+
it('renders general error', function () {
66+
renderSchemaToolbar({
67+
analysisState: 'initial',
68+
error: {
69+
errorType: 'general',
70+
errorMessage: 'test error msg',
71+
},
72+
});
73+
74+
expect(screen.getByText(testErrorMessage)).to.be.visible;
75+
expect(screen.getByTestId('schema-toolbar-error-message')).to.be.visible;
6776
});
6877

69-
expect(screen.getByText(testErrorMessage)).to.be.visible;
70-
expect(screen.getByTestId('schema-toolbar-error-message')).to.be.visible;
71-
});
78+
it('renders timeout error', function () {
79+
renderSchemaToolbar({
80+
analysisState: 'initial',
81+
error: {
82+
errorType: 'timeout',
83+
errorMessage: 'test error msg',
84+
},
85+
});
7286

73-
it('does not render errors when the analysis state is not error', function () {
74-
renderSchemaToolbar({
75-
errorMessage: 'test error msg',
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');
7692
});
7793

78-
expect(screen.queryByText(testErrorMessage)).to.not.exist;
79-
expect(screen.queryByTestId('schema-toolbar-error-message')).to.not.exist;
94+
it('renders complexity abort error', function () {
95+
renderSchemaToolbar({
96+
analysisState: 'initial',
97+
error: {
98+
errorType: 'highComplexity',
99+
errorMessage: 'test error msg',
100+
},
101+
});
102+
103+
expect(screen.getByTestId('schema-toolbar-complexity-abort-message')).to
104+
.be.visible;
105+
expect(
106+
screen.getByRole('link', { name: 'Learn more' })
107+
).to.have.attribute(
108+
'href',
109+
'https://www.mongodb.com/docs/manual/data-modeling/design-antipatterns/bloated-documents/'
110+
);
111+
});
80112
});
81113

82114
it('renders the sample size count', function () {

0 commit comments

Comments
 (0)