Skip to content

Commit

Permalink
Fix dev tool console autocomplete issue
Browse files Browse the repository at this point in the history
Signed-off-by: Su <[email protected]>
  • Loading branch information
zhongnansu committed Apr 4, 2023
1 parent 2db2c43 commit d5f0812
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const inputId = 'ConAppInputTextarea';

function EditorUI({ initialTextValue }: EditorProps) {
const {
services: { history, notifications, settings: settingsService, opensearchHostService },
services: { history, notifications, settings: settingsService, opensearchHostService, http },
docLinkVersion,
} = useServicesContext();

Expand Down Expand Up @@ -184,7 +184,7 @@ function EditorUI({ initialTextValue }: EditorProps) {
setInputEditor(editor);
setTextArea(editorRef.current!.querySelector('textarea'));

retrieveAutoCompleteInfo(settingsService, settingsService.getAutocomplete());
retrieveAutoCompleteInfo(http, settingsService, settingsService.getAutocomplete());

const unsubscribeResizer = subscribeResizeChecker(editorRef.current!, editor);
setupAutosave();
Expand All @@ -197,7 +197,7 @@ function EditorUI({ initialTextValue }: EditorProps) {
editorInstanceRef.current.getCoreEditor().destroy();
}
};
}, [saveCurrentTextObject, initialTextValue, history, setInputEditor, settingsService]);
}, [saveCurrentTextObject, initialTextValue, history, setInputEditor, settingsService, http]);

useEffect(() => {
const { current: editor } = editorInstanceRef;
Expand Down
20 changes: 13 additions & 7 deletions src/plugins/console/public/application/containers/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import React from 'react';

import { HttpSetup } from 'opensearch-dashboards/public';
import { AutocompleteOptions, DevToolsSettingsModal } from '../components';

// @ts-ignore
Expand All @@ -44,11 +45,16 @@ const getAutocompleteDiff = (newSettings: DevToolsSettings, prevSettings: DevToo
});
};

const refreshAutocompleteSettings = (settings: SettingsService, selectedSettings: any) => {
retrieveAutoCompleteInfo(settings, selectedSettings);
const refreshAutocompleteSettings = (
http: HttpSetup,
settings: SettingsService,
selectedSettings: any
) => {
retrieveAutoCompleteInfo(http, settings, selectedSettings);
};

const fetchAutocompleteSettingsIfNeeded = (
http: HttpSetup,
settings: SettingsService,
newSettings: DevToolsSettings,
prevSettings: DevToolsSettings
Expand All @@ -73,10 +79,10 @@ const fetchAutocompleteSettingsIfNeeded = (
},
{}
);
retrieveAutoCompleteInfo(settings, changedSettings);
retrieveAutoCompleteInfo(http, settings, changedSettings);
} else if (isPollingChanged && newSettings.polling) {
// If the user has turned polling on, then we'll fetch all selected autocomplete settings.
retrieveAutoCompleteInfo(settings, settings.getAutocomplete());
retrieveAutoCompleteInfo(http, settings, settings.getAutocomplete());
}
}
};
Expand All @@ -87,14 +93,14 @@ export interface Props {

export function Settings({ onClose }: Props) {
const {
services: { settings },
services: { settings, http },
} = useServicesContext();

const dispatch = useEditorActionContext();

const onSaveSettings = (newSettings: DevToolsSettings) => {
const prevSettings = settings.toJSON();
fetchAutocompleteSettingsIfNeeded(settings, newSettings, prevSettings);
fetchAutocompleteSettingsIfNeeded(http, settings, newSettings, prevSettings);

// Update the new settings in localStorage
settings.updateSettings(newSettings);
Expand All @@ -112,7 +118,7 @@ export function Settings({ onClose }: Props) {
onClose={onClose}
onSaveSettings={onSaveSettings}
refreshAutocompleteSettings={(selectedSettings: any) =>
refreshAutocompleteSettings(settings, selectedSettings)
refreshAutocompleteSettings(http, settings, selectedSettings)
}
settings={settings.toJSON()}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const useSendCurrentRequestToOpenSearch = () => {
// or templates may have changed, so we'll need to update this data. Assume that if
// the user disables polling they're trying to optimize performance or otherwise
// preserve resources, so they won't want this request sent either.
retrieveAutoCompleteInfo(settings, settings.getAutocomplete());
retrieveAutoCompleteInfo(http, settings, settings.getAutocomplete());
}

dispatch({
Expand Down
Loading

0 comments on commit d5f0812

Please sign in to comment.