Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dev tool console autocomplete not loading issue #3775

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Fixes management app breadcrumb error ([#2344](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2344))
- [BUG] Fix suggestion list cutoff issue ([#2607](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2607))
- [TSVB] Fixes undefined serial diff aggregation documentation link ([#3503](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3503))
- [Console] Fix dev tool console autocomplete not loading issue ([#3775](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3775))

### 🚞 Infrastructure

Expand Down
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