Skip to content

Commit c1d15f6

Browse files
committed
fixes
1 parent 13d395b commit c1d15f6

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { ZeroGraphic } from './zero-graphic';
2121
import {
2222
clearRulesGenerationError,
2323
generateValidationRules,
24+
stopRulesGeneration,
2425
} from '../modules/validation';
2526

2627
const validationStatesStyles = css({
@@ -71,6 +72,7 @@ type ValidationStatesProps = {
7172
changeZeroState: (value: boolean) => void;
7273
generateValidationRules: () => void;
7374
clearRulesGenerationError: () => void;
75+
stopRulesGeneration: () => void;
7476
editMode: {
7577
collectionTimeSeries?: boolean;
7678
collectionReadOnly?: boolean;
@@ -150,6 +152,7 @@ export function ValidationStates({
150152
changeZeroState,
151153
generateValidationRules,
152154
clearRulesGenerationError,
155+
stopRulesGeneration,
153156
editMode,
154157
}: ValidationStatesProps) {
155158
const { readOnly, enableExportSchema } = usePreferences([
@@ -173,7 +176,7 @@ export function ValidationStates({
173176
<ErrorSummary
174177
errors={rulesGenerationError}
175178
dismissible={true}
176-
onDismiss={clearRulesGenerationError}
179+
onClose={clearRulesGenerationError}
177180
/>
178181
)}
179182
<ValidationBanners editMode={editMode} />
@@ -183,7 +186,11 @@ export function ValidationStates({
183186
<EmptyContent
184187
icon={ZeroGraphic}
185188
title="Create validation rules"
186-
subTitle="Generate rules via schema analysis from existing sample data or add them manually to enforce document structure during updates and inserts"
189+
subTitle={
190+
enableExportSchema
191+
? 'Generate rules via schema analysis from existing sample data or add them manually to enforce document structure during updates and inserts'
192+
: 'Create rules to enforce data structure of documents on updates and inserts.'
193+
}
187194
callToAction={
188195
<div className={zeroStateButtonsStyles}>
189196
{enableExportSchema && (
@@ -216,7 +223,7 @@ export function ValidationStates({
216223
/>
217224
)}
218225
{isZeroState && isRulesGenerationInProgress && (
219-
<GeneratingScreen onCancelClicked={() => ({})} />
226+
<GeneratingScreen onCancelClicked={stopRulesGeneration} />
220227
)}
221228
{!isZeroState && (
222229
<div className={contentContainerStyles}>
@@ -252,4 +259,5 @@ export default connect(mapStateToProps, {
252259
changeZeroState,
253260
generateValidationRules,
254261
clearRulesGenerationError,
262+
stopRulesGeneration,
255263
})(ValidationStates);

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

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type ValidationServerAction = 'error' | 'warn';
1414
export type ValidationLevel = 'off' | 'moderate' | 'strict';
1515

1616
const SAMPLE_SIZE = 1000;
17+
const ABORT_MESSAGE = 'Operation cancelled';
1718

1819
/**
1920
* The module action prefix.
@@ -609,24 +610,9 @@ export const activateValidation = (): SchemaValidationThunkAction<void> => {
609610
};
610611

611612
export const stopRulesGeneration = (): SchemaValidationThunkAction<void> => {
612-
return (
613-
dispatch,
614-
getState,
615-
{ rulesGenerationAbortControllerRef, connectionInfoRef, track }
616-
) => {
613+
return (dispatch, getState, { rulesGenerationAbortControllerRef }) => {
617614
if (!rulesGenerationAbortControllerRef.current) return;
618-
// const analysisTime =
619-
// Date.now() - (getState().schemaAnalysis.analysisStartTime ?? 0);
620-
// track(
621-
// 'Schema Analysis Cancelled',
622-
// {
623-
// analysis_time_ms: analysisTime,
624-
// with_filter: Object.entries(query.filter ?? {}).length > 0,
625-
// },
626-
// connectionInfoRef.current
627-
// );
628-
629-
rulesGenerationAbortControllerRef.current?.abort('Analysis cancelled');
615+
rulesGenerationAbortControllerRef.current?.abort(ABORT_MESSAGE);
630616
};
631617
};
632618

@@ -643,7 +629,6 @@ export const generateValidationRules = (): SchemaValidationThunkAction<
643629
{ dataService, logger, preferences, rulesGenerationAbortControllerRef }
644630
) => {
645631
dispatch({ type: RULES_GENERATION_STARTED });
646-
console.log('START');
647632

648633
rulesGenerationAbortControllerRef.current = new AbortController();
649634
const abortSignal = rulesGenerationAbortControllerRef.current.signal;
@@ -670,14 +655,14 @@ export const generateValidationRules = (): SchemaValidationThunkAction<
670655
preferences
671656
);
672657
if (abortSignal?.aborted) {
673-
throw new Error(abortSignal?.reason || new Error('Operation aborted'));
658+
throw new Error(ABORT_MESSAGE);
674659
}
675660

676661
const jsonSchema = await schemaAccessor?.getMongoDBJsonSchema({
677662
signal: abortSignal,
678663
});
679664
if (abortSignal?.aborted) {
680-
throw new Error(abortSignal?.reason || new Error('Operation aborted'));
665+
throw new Error(ABORT_MESSAGE);
681666
}
682667
const validator = JSON.stringify(
683668
{ $jsonSchema: jsonSchema },
@@ -690,6 +675,10 @@ export const generateValidationRules = (): SchemaValidationThunkAction<
690675
dispatch({ type: RULES_GENERATION_FINISHED });
691676
dispatch(zeroStateChanged(false));
692677
} catch (error) {
678+
if (abortSignal.aborted) {
679+
dispatch({ type: RULES_GENERATION_FINISHED });
680+
return;
681+
}
693682
dispatch({
694683
type: RULES_GENERATION_FAILED,
695684
message: `Rules generation failed: ${(error as Error).message}`,

0 commit comments

Comments
 (0)