Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Fix dev tool console autocomplete not loading issue (opensearch-proje…
Browse files Browse the repository at this point in the history
…ct#3775)

* Fix dev tool console autocomplete issue
* add changelog

Signed-off-by: Su <[email protected]>

---------

Signed-off-by: Su <[email protected]>
Signed-off-by: David Sinclair <[email protected]>
  • Loading branch information
zhongnansu authored and sikhote committed Apr 24, 2023
1 parent 892ed44 commit 9ecc3dd
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 88 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,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

0 comments on commit 9ecc3dd

Please sign in to comment.