@@ -14,6 +14,7 @@ export type ValidationServerAction = 'error' | 'warn';
1414export type ValidationLevel = 'off' | 'moderate' | 'strict' ;
1515
1616const 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
611612export 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