@@ -15,7 +15,6 @@ import type {
15
15
} from '@mongodb-js/compass-editor' ;
16
16
import {
17
17
CodemirrorInlineEditor as InlineEditor ,
18
- createQueryAutocompleter ,
19
18
createQueryWithHistoryAutocompleter ,
20
19
} from '@mongodb-js/compass-editor' ;
21
20
import { connect } from '../stores/context' ;
@@ -119,9 +118,6 @@ export const OptionEditor: React.FunctionComponent<OptionEditorProps> = ({
119
118
} ) => {
120
119
const editorContainerRef = useRef < HTMLDivElement > ( null ) ;
121
120
const editorRef = useRef < EditorRef > ( null ) ;
122
- const isQueryHistoryAutocompleteEnabled = usePreference (
123
- 'enableQueryHistoryAutocomplete'
124
- ) ;
125
121
126
122
const focusRingProps = useFocusRing ( {
127
123
outer : true ,
@@ -158,52 +154,45 @@ export const OptionEditor: React.FunctionComponent<OptionEditorProps> = ({
158
154
} , [ optionName , recentQueries , favoriteQueries ] ) ;
159
155
160
156
const completer = useMemo ( ( ) => {
161
- return isQueryHistoryAutocompleteEnabled
162
- ? createQueryWithHistoryAutocompleter ( {
163
- queryProperty : optionName ,
164
- savedQueries,
165
- options : {
166
- fields : schemaFields ,
167
- serverVersion,
168
- } ,
169
- onApply : ( query : SavedQuery [ 'queryProperties' ] ) => {
170
- // When we are applying a query from `filter` field, we want to apply the whole query,
171
- // otherwise we want to preserve the other fields that are already in the current query.
172
- const fieldsToPreserve =
173
- optionName === 'filter'
174
- ? [ ]
175
- : QUERY_PROPERTIES . filter ( ( x ) => x !== optionName ) ;
176
- onApplyQuery ( query , fieldsToPreserve ) ;
177
- if ( ! query [ optionName ] ) {
178
- return ;
179
- }
180
- const formFields = mapQueryToFormFields (
181
- { maxTimeMS : maxTimeMSPreference } ,
182
- {
183
- ...DEFAULT_FIELD_VALUES ,
184
- ...query ,
185
- }
186
- ) ;
187
- const optionFormField =
188
- formFields [ optionName as keyof QueryFormFields ] ;
189
- if ( optionFormField ?. string ) {
190
- // When we did apply something we want to move the cursor to the end of the input.
191
- editorRef . current ?. cursorDocEnd ( ) ;
192
- }
193
- } ,
194
- theme : darkMode ? 'dark' : 'light' ,
195
- } )
196
- : createQueryAutocompleter ( {
197
- fields : schemaFields ,
198
- serverVersion,
199
- } ) ;
157
+ return createQueryWithHistoryAutocompleter ( {
158
+ queryProperty : optionName ,
159
+ savedQueries,
160
+ options : {
161
+ fields : schemaFields ,
162
+ serverVersion,
163
+ } ,
164
+ onApply : ( query : SavedQuery [ 'queryProperties' ] ) => {
165
+ // When we are applying a query from `filter` field, we want to apply the whole query,
166
+ // otherwise we want to preserve the other fields that are already in the current query.
167
+ const fieldsToPreserve =
168
+ optionName === 'filter'
169
+ ? [ ]
170
+ : QUERY_PROPERTIES . filter ( ( x ) => x !== optionName ) ;
171
+ onApplyQuery ( query , fieldsToPreserve ) ;
172
+ if ( ! query [ optionName ] ) {
173
+ return ;
174
+ }
175
+ const formFields = mapQueryToFormFields (
176
+ { maxTimeMS : maxTimeMSPreference } ,
177
+ {
178
+ ...DEFAULT_FIELD_VALUES ,
179
+ ...query ,
180
+ }
181
+ ) ;
182
+ const optionFormField = formFields [ optionName as keyof QueryFormFields ] ;
183
+ if ( optionFormField ?. string ) {
184
+ // When we did apply something we want to move the cursor to the end of the input.
185
+ editorRef . current ?. cursorDocEnd ( ) ;
186
+ }
187
+ } ,
188
+ theme : darkMode ? 'dark' : 'light' ,
189
+ } ) ;
200
190
} , [
201
191
maxTimeMSPreference ,
202
192
savedQueries ,
203
193
schemaFields ,
204
194
serverVersion ,
205
195
onApplyQuery ,
206
- isQueryHistoryAutocompleteEnabled ,
207
196
darkMode ,
208
197
optionName ,
209
198
] ) ;
@@ -216,8 +205,7 @@ export const OptionEditor: React.FunctionComponent<OptionEditorProps> = ({
216
205
editorRef . current ?. editorContents === '{}'
217
206
) {
218
207
editorRef . current ?. applySnippet ( '\\{${}}' ) ;
219
- if ( isQueryHistoryAutocompleteEnabled && editorRef . current ?. editor )
220
- editorRef . current ?. startCompletion ( ) ;
208
+ if ( editorRef . current ?. editor ) editorRef . current ?. startCompletion ( ) ;
221
209
}
222
210
} ) ;
223
211
}
0 commit comments