Skip to content

Commit cdbc49b

Browse files
committed
adjusting error message and added analytics for error parsing
1 parent f9bf9ea commit cdbc49b

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

packages/compass-indexes/src/components/create-index-form/query-flow-section.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('QueryFlowSection', () => {
6666
type: ActionTypes.SuggestedIndexesFetched,
6767
sampleDocs: [],
6868
indexSuggestions: { a: 1, b: 2 },
69-
fetchingSuggestionsError: null,
69+
error: null,
7070
indexSuggestionsState: 'success',
7171
});
7272
});

packages/compass-indexes/src/modules/create-index.tsx

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,6 @@ export type State = {
306306
// state of the index suggestions
307307
fetchingSuggestionsState: IndexSuggestionState;
308308

309-
// error specific to fetching index suggestions
310-
fetchingSuggestionsError: string | null;
311-
312309
// index suggestions in a format such as {fieldName: 1}
313310
indexSuggestions: Record<string, number> | null;
314311

@@ -324,7 +321,6 @@ export const INITIAL_STATE: State = {
324321
options: INITIAL_OPTIONS_STATE,
325322
currentTab: 'IndexFlow',
326323
fetchingSuggestionsState: 'initial',
327-
fetchingSuggestionsError: null,
328324
indexSuggestions: null,
329325
sampleDocs: null,
330326
};
@@ -367,7 +363,7 @@ export type SuggestedIndexFetchedAction = {
367363
type: ActionTypes.SuggestedIndexesFetched;
368364
sampleDocs: Array<Document>;
369365
indexSuggestions: { [key: string]: number } | null;
370-
fetchingSuggestionsError: string | null;
366+
error: string | null;
371367
indexSuggestionsState: IndexSuggestionState;
372368
};
373369

@@ -389,7 +385,7 @@ export const fetchIndexSuggestions = ({
389385
Promise<void>,
390386
SuggestedIndexFetchedAction | SuggestedIndexesRequestedAction
391387
> => {
392-
return async (dispatch, getState, { dataService }) => {
388+
return async (dispatch, getState, { dataService, track }) => {
393389
dispatch({
394390
type: ActionTypes.SuggestedIndexesRequested,
395391
});
@@ -422,39 +418,28 @@ export const fetchIndexSuggestions = ({
422418
analyzedNamespace
423419
);
424420
const results = await mql.suggestIndex([query]);
425-
const indexSuggestions = results?.index || null;
426-
427-
// TODO in CLOUDP-311787: add info banner and update the current error banner to take in fetchingSuggestionsError as well
428-
if (!indexSuggestions) {
429-
dispatch({
430-
type: ActionTypes.SuggestedIndexesFetched,
431-
sampleDocs: sampleDocuments,
432-
indexSuggestions,
433-
fetchingSuggestionsError:
434-
'No suggested index found. Please choose "Start with an Index" at the top to continue.',
435-
indexSuggestionsState: 'error',
436-
});
437-
return;
438-
}
421+
const indexSuggestions = results?.index;
439422

440423
dispatch({
441424
type: ActionTypes.SuggestedIndexesFetched,
442425
sampleDocs: sampleDocuments,
443426
indexSuggestions,
444-
fetchingSuggestionsError: null,
427+
error: null,
445428
indexSuggestionsState: 'success',
446429
});
447430
} catch (e: unknown) {
448431
dispatch({
449432
type: ActionTypes.SuggestedIndexesFetched,
450433
sampleDocs: sampleDocuments,
451434
indexSuggestions: null,
452-
fetchingSuggestionsError:
435+
error:
453436
e instanceof Error
454437
? 'Error parsing query. Please follow query structure. ' + e.message
455438
: 'Error parsing query. Please follow query structure.',
456439
indexSuggestionsState: 'error',
457440
});
441+
442+
track('Error parsing query', { context: 'Create Index Modal' });
458443
}
459444
};
460445
};
@@ -508,7 +493,6 @@ export const createIndexFormSubmitted = (): IndexesThunkAction<
508493
// Check for field errors.
509494
if (isQueryFlow) {
510495
if (!indexSuggestions) {
511-
// TODO in CLOUDP-311787: add info banner and update the current error banner to take in fetchingSuggestionsError as well
512496
dispatch(
513497
errorEncountered(
514498
'No suggested index found. Please choose "Start with an Index" at the top to continue.'
@@ -780,7 +764,7 @@ const reducer: Reducer<State, Action> = (state = INITIAL_STATE, action) => {
780764
return {
781765
...state,
782766
fetchingSuggestionsState: 'fetching',
783-
fetchingSuggestionsError: null,
767+
error: null,
784768
indexSuggestions: null,
785769
};
786770
}
@@ -794,7 +778,7 @@ const reducer: Reducer<State, Action> = (state = INITIAL_STATE, action) => {
794778
return {
795779
...state,
796780
fetchingSuggestionsState: action.indexSuggestionsState,
797-
fetchingSuggestionsError: action.fetchingSuggestionsError,
781+
error: action.error,
798782
indexSuggestions: action.indexSuggestions,
799783
sampleDocs: action.sampleDocs,
800784
};

packages/compass-telemetry/src/telemetry-events.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2693,6 +2693,20 @@ type CreateIndexButtonClickedEvent = CommonEvent<{
26932693
};
26942694
}>;
26952695

2696+
type CreateIndexErrorParsingQueryEvent = CommonEvent<{
2697+
name: 'Error parsing query';
2698+
payload: {
2699+
context: CreateIndexModalContext;
2700+
};
2701+
}>;
2702+
2703+
type CreateIndexErrorGettingCoveredQueriesEvent = CommonEvent<{
2704+
name: 'Error generating covered queries';
2705+
payload: {
2706+
context: CreateIndexModalContext;
2707+
};
2708+
}>;
2709+
26962710
export type TelemetryEvent =
26972711
| AggregationCanceledEvent
26982712
| AggregationCopiedEvent
@@ -2815,4 +2829,6 @@ export type TelemetryEvent =
28152829
| CumulativeLayoutShiftEvent
28162830
| TimeToFirstByteEvent
28172831
| ExperimentViewedEvent
2818-
| CreateIndexButtonClickedEvent;
2832+
| CreateIndexButtonClickedEvent
2833+
| CreateIndexErrorParsingQueryEvent
2834+
| CreateIndexErrorGettingCoveredQueriesEvent;

0 commit comments

Comments
 (0)