@@ -15,7 +15,6 @@ import type {
1515} from '@mongodb-js/compass-editor' ;
1616import {
1717 CodemirrorInlineEditor as InlineEditor ,
18- createQueryAutocompleter ,
1918 createQueryWithHistoryAutocompleter ,
2019} from '@mongodb-js/compass-editor' ;
2120import { connect } from '../stores/context' ;
@@ -119,9 +118,6 @@ export const OptionEditor: React.FunctionComponent<OptionEditorProps> = ({
119118} ) => {
120119 const editorContainerRef = useRef < HTMLDivElement > ( null ) ;
121120 const editorRef = useRef < EditorRef > ( null ) ;
122- const isQueryHistoryAutocompleteEnabled = usePreference (
123- 'enableQueryHistoryAutocomplete'
124- ) ;
125121
126122 const focusRingProps = useFocusRing ( {
127123 outer : true ,
@@ -158,52 +154,45 @@ export const OptionEditor: React.FunctionComponent<OptionEditorProps> = ({
158154 } , [ optionName , recentQueries , favoriteQueries ] ) ;
159155
160156 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+ } ) ;
200190 } , [
201191 maxTimeMSPreference ,
202192 savedQueries ,
203193 schemaFields ,
204194 serverVersion ,
205195 onApplyQuery ,
206- isQueryHistoryAutocompleteEnabled ,
207196 darkMode ,
208197 optionName ,
209198 ] ) ;
@@ -216,8 +205,7 @@ export const OptionEditor: React.FunctionComponent<OptionEditorProps> = ({
216205 editorRef . current ?. editorContents === '{}'
217206 ) {
218207 editorRef . current ?. applySnippet ( '\\{${}}' ) ;
219- if ( isQueryHistoryAutocompleteEnabled && editorRef . current ?. editor )
220- editorRef . current ?. startCompletion ( ) ;
208+ if ( editorRef . current ?. editor ) editorRef . current ?. startCompletion ( ) ;
221209 }
222210 } ) ;
223211 }
0 commit comments