Skip to content

Commit 9146c66

Browse files
committed
address PR comments
1 parent c61a63b commit 9146c66

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ const Schema: React.FunctionComponent<{
399399
toolbar={
400400
<SchemaToolbar
401401
onAnalyzeSchemaClicked={onApplyClicked}
402-
onResetClicked={onStartAnalysis}
402+
onResetClicked={onApplyClicked}
403403
analysisState={analysisState}
404404
errorMessage={errorMessage || ''}
405405
isOutdated={!!outdated}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export const enum SchemaActions {
4343
analysisStarted = 'schema-service/schema/analysisStarted',
4444
analysisFinished = 'schema-service/schema/analysisFinished',
4545
analysisFailed = 'schema-service/schema/analysisFailed',
46-
analysisCancelled = 'schema-service/schema/analysisCancelled',
4746
}
4847

4948
export type AnalysisStartedAction = {
@@ -119,8 +118,10 @@ function resultId(): string {
119118
export const handleSchemaShare = (): SchemaThunkAction<void> => {
120119
return (dispatch, getState, { namespace }) => {
121120
const { schema } = getState();
122-
void navigator.clipboard.writeText(JSON.stringify(schema, null, ' '));
123121
const hasSchema = schema !== null;
122+
if (hasSchema) {
123+
void navigator.clipboard.writeText(JSON.stringify(schema, null, ' '));
124+
}
124125
dispatch(_trackSchemaShared(hasSchema));
125126
openToast(
126127
'share-schema',
@@ -209,6 +210,7 @@ export const geoLayersDeleted = (
209210

210211
export const stopAnalysis = (): SchemaThunkAction<void> => {
211212
return (dispatch, getState, { abortControllerRef }) => {
213+
if (!abortControllerRef) return;
212214
abortControllerRef.current?.abort();
213215
};
214216
};
@@ -234,6 +236,11 @@ export const startAnalysis = (): SchemaThunkAction<
234236
track,
235237
}
236238
) => {
239+
const { analysisState } = getState();
240+
if (analysisState === ANALYSIS_STATE_ANALYZING) {
241+
debug('analysis already in progress. ignoring subsequent start');
242+
return;
243+
}
237244
const query = queryBar.getLastAppliedQuery('schema');
238245

239246
const sampleSize = query.limit

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type { PreferencesAccess } from 'compass-preferences-model/provider';
1212
import type { FieldStoreService } from '@mongodb-js/compass-field-store';
1313
import type { QueryBarService } from '@mongodb-js/compass-query-bar';
1414
import type { TrackFunction } from '@mongodb-js/compass-telemetry';
15-
import reducer, { handleSchemaShare } from './reducer';
15+
import reducer, { handleSchemaShare, stopAnalysis } from './reducer';
1616
import type { InternalLayer } from '../modules/geo';
1717

1818
export type DataService = Pick<OriginalDataService, 'sample' | 'isCancelError'>;
@@ -53,7 +53,7 @@ export type SchemaThunkDispatch<A extends AnyAction = AnyAction> =
5353
export function activateSchemaPlugin(
5454
{ namespace }: Pick<CollectionTabPluginMetadata, 'namespace'>,
5555
services: SchemaPluginServices,
56-
{ on, cleanup }: ActivateHelpers
56+
{ on, cleanup, addCleanup }: ActivateHelpers
5757
) {
5858
const store = configureStore(services, namespace);
5959
/**
@@ -66,6 +66,8 @@ export function activateSchemaPlugin(
6666
() => store.dispatch(handleSchemaShare()) // TODO: get the action
6767
);
6868

69+
addCleanup(() => store.dispatch(stopAnalysis()));
70+
6971
return {
7072
store,
7173
deactivate() {

0 commit comments

Comments
 (0)