Skip to content

Commit 57e5f51

Browse files
committed
PR suggestions
1 parent 2710616 commit 57e5f51

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('SchemaToolbar', function () {
6666
renderSchemaToolbar({
6767
analysisState: 'initial',
6868
error: {
69-
errorType: 'GENERAL',
69+
errorType: 'general',
7070
errorMessage: 'test error msg',
7171
},
7272
});
@@ -79,7 +79,7 @@ describe('SchemaToolbar', function () {
7979
renderSchemaToolbar({
8080
analysisState: 'initial',
8181
error: {
82-
errorType: 'TIMEOUT',
82+
errorType: 'timeout',
8383
errorMessage: 'test error msg',
8484
},
8585
});
@@ -95,7 +95,7 @@ describe('SchemaToolbar', function () {
9595
renderSchemaToolbar({
9696
analysisState: 'initial',
9797
error: {
98-
errorType: 'HIGH_COMPLEXITY',
98+
errorType: 'highComplexity',
9999
errorMessage: 'test error msg',
100100
},
101101
});

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type { AnalysisState } from '../../constants/analysis-states';
1616
import { ANALYSIS_STATE_COMPLETE } from '../../constants/analysis-states';
1717
import { QueryBar } from '@mongodb-js/compass-query-bar';
1818
import { type SchemaAnalysisError } from '../../stores/schema-analysis-reducer';
19+
import { DISTINCT_FIELDS_ABORT_THRESHOLD } from '../../modules/schema-analysis';
1920

2021
const schemaToolbarStyles = css({
2122
display: 'flex',
@@ -131,33 +132,33 @@ const SchemaToolbar: React.FunctionComponent<SchemaToolbarProps> = ({
131132
</div>
132133
</div>
133134
)}
134-
{error?.errorType === 'GENERAL' && (
135+
{error?.errorType === 'general' && (
135136
<ErrorSummary
136137
data-testid="schema-toolbar-error-message"
137138
errors={[`${ERROR_WARNING}: ${error.errorMessage}`]}
138139
dismissible={true}
139140
onClose={onDismissError}
140141
/>
141142
)}
142-
{error?.errorType === 'TIMEOUT' && (
143+
{error?.errorType === 'timeout' && (
143144
<WarningSummary
144145
data-testid="schema-toolbar-timeout-message"
145146
warnings={[INCREASE_MAX_TIME_MS_HINT_MESSAGE]}
146147
dismissible={true}
147148
onClose={onDismissError}
148149
/>
149150
)}
150-
{error?.errorType === 'HIGH_COMPLEXITY' && (
151+
{error?.errorType === 'highComplexity' && (
151152
<Banner
152153
variant={BannerVariant.Danger}
153154
data-testid="schema-toolbar-complexity-abort-message"
154155
dismissible={true}
155156
onClose={onDismissError}
156157
>
157-
The analysis was aborted because the number of fields exceeds 1000.
158-
Consider breaking up your data into more collections with smaller
159-
documents, and using references to consolidate the data you
160-
need.&nbsp;
158+
The analysis was aborted because the number of fields exceeds{' '}
159+
{DISTINCT_FIELDS_ABORT_THRESHOLD}. Consider breaking up your data into
160+
more collections with smaller documents, and using references to
161+
consolidate the data you need.&nbsp;
161162
<Link href="https://www.mongodb.com/docs/manual/data-modeling/design-antipatterns/bloated-documents/">
162163
Learn more
163164
</Link>

packages/compass-schema/src/modules/schema-analysis.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import type { DataService } from '../stores/store';
1414
import type { Logger } from '@mongodb-js/compass-logging';
1515
import type { PreferencesAccess } from 'compass-preferences-model';
1616

17+
export const DISTINCT_FIELDS_ABORT_THRESHOLD = 1000;
18+
1719
// hack for driver 3.6 not promoting error codes and
1820
// attributes from ejson when promoteValue is false.
1921
function promoteMongoErrorCode(err?: Error & { code?: unknown }) {
@@ -65,7 +67,7 @@ export const analyzeSchema = async (
6567
? {
6668
signal: abortSignal,
6769
storedValuesLengthLimit: 100,
68-
distinctFieldsAbortThreshold: 1000,
70+
distinctFieldsAbortThreshold: DISTINCT_FIELDS_ABORT_THRESHOLD,
6971
}
7072
: {
7173
signal: abortSignal,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const ERROR_CODE_MAX_TIME_MS_EXPIRED = 50;
2727

2828
export type SchemaAnalysisError = {
2929
errorMessage: string;
30-
errorType: 'TIMEOUT' | 'HIGH_COMPLEXITY' | 'GENERAL';
30+
errorType: 'timeout' | 'highComplexity' | 'general';
3131
};
3232

3333
export type SchemaAnalysisState = {
@@ -128,11 +128,11 @@ export const schemaAnalysisReducer: Reducer<SchemaAnalysisState, Action> = (
128128
function getErrorDetails(error: Error): SchemaAnalysisError {
129129
const errorCode = (error as MongoError).code;
130130
const errorMessage = error.message || 'Unknown error';
131-
let errorType: SchemaAnalysisError['errorType'] = 'GENERAL';
131+
let errorType: SchemaAnalysisError['errorType'] = 'general';
132132
if (errorCode === ERROR_CODE_MAX_TIME_MS_EXPIRED) {
133-
errorType = 'TIMEOUT';
133+
errorType = 'timeout';
134134
} else if (error.message.includes('Schema analysis aborted: Fields count')) {
135-
errorType = 'HIGH_COMPLEXITY';
135+
errorType = 'highComplexity';
136136
}
137137

138138
return {

0 commit comments

Comments
 (0)