11import type { Document } from 'mongodb' ;
2+ import type { Document as BsonDocument } from 'bson' ;
23import { EJSON , ObjectId } from 'bson' ;
34import type { CreateIndexesOptions , IndexDirection } from 'mongodb' ;
45import { isCollationValid } from 'mongodb-query-parser' ;
56import React from 'react' ;
6- import type { Action , Reducer , Dispatch } from 'redux' ;
7+ import type { Action , Dispatch , Reducer } from 'redux' ;
78import { Badge , Link } from '@mongodb-js/compass-components' ;
89import { isAction } from '../utils/is-action' ;
9- import type { IndexesThunkAction } from '.' ;
10- import type { RootState } from '.' ;
10+ import type { IndexesThunkAction , RootState } from '.' ;
1111import { createRegularIndex } from './regular-indexes' ;
1212import * as mql from 'mongodb-mql-engines' ;
1313import _parseShellBSON , { ParseMode } from '@mongodb-js/shell-bson-parser' ;
@@ -77,6 +77,7 @@ type ErrorClearedAction = {
7777
7878export type CreateIndexOpenedAction = {
7979 type : ActionTypes . CreateIndexOpened ;
80+ query ?: BsonDocument ;
8081} ;
8182
8283type CreateIndexClosedAction = {
@@ -314,6 +315,9 @@ export type State = {
314315
315316 // sample documents used for getting index suggestions
316317 sampleDocs : Array < Document > | null ;
318+
319+ // base query to be used for query flow index creation
320+ query : BsonDocument | null ;
317321} ;
318322
319323export const INITIAL_STATE : State = {
@@ -327,6 +331,7 @@ export const INITIAL_STATE: State = {
327331 fetchingSuggestionsError : null ,
328332 indexSuggestions : null ,
329333 sampleDocs : null ,
334+ query : null ,
330335} ;
331336
332337function getInitialState ( ) : State {
@@ -338,8 +343,9 @@ function getInitialState(): State {
338343
339344//-------
340345
341- export const createIndexOpened = ( ) => ( {
346+ export const createIndexOpened = ( query ?: BsonDocument ) => ( {
342347 type : ActionTypes . CreateIndexOpened ,
348+ query,
343349} ) ;
344350
345351export const createIndexClosed = ( ) => ( {
@@ -706,6 +712,8 @@ const reducer: Reducer<State, Action> = (state = INITIAL_STATE, action) => {
706712 return {
707713 ...getInitialState ( ) ,
708714 isVisible : true ,
715+ query : action . query ?? null ,
716+ currentTab : action . query ? 'QueryFlow' : 'IndexFlow' ,
709717 } ;
710718 }
711719
0 commit comments