From e1671eda049d7d830bdcad30fddb45d9cee096c2 Mon Sep 17 00:00:00 2001 From: Jialiang Liang Date: Tue, 10 Dec 2024 16:03:26 -0800 Subject: [PATCH] Use HTTP service instead of fetch Signed-off-by: Jialiang Liang --- .../create/create_acceleration.tsx | 1 + .../selectors/preview_sql_defintion.tsx | 23 +++++-------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/plugins/data_source_management/public/components/direct_query_data_sources_components/acceleration_creation/create/create_acceleration.tsx b/src/plugins/data_source_management/public/components/direct_query_data_sources_components/acceleration_creation/create/create_acceleration.tsx index 556e6a1a690c..d13956cd25cf 100644 --- a/src/plugins/data_source_management/public/components/direct_query_data_sources_components/acceleration_creation/create/create_acceleration.tsx +++ b/src/plugins/data_source_management/public/components/direct_query_data_sources_components/acceleration_creation/create/create_acceleration.tsx @@ -277,6 +277,7 @@ export const CreateAcceleration = ({ resetFlyout={resetFlyout} notifications={notifications} application={application} + http={http} /> diff --git a/src/plugins/data_source_management/public/components/direct_query_data_sources_components/acceleration_creation/selectors/preview_sql_defintion.tsx b/src/plugins/data_source_management/public/components/direct_query_data_sources_components/acceleration_creation/selectors/preview_sql_defintion.tsx index 382d47a61a96..4486aa3e01ae 100644 --- a/src/plugins/data_source_management/public/components/direct_query_data_sources_components/acceleration_creation/selectors/preview_sql_defintion.tsx +++ b/src/plugins/data_source_management/public/components/direct_query_data_sources_components/acceleration_creation/selectors/preview_sql_defintion.tsx @@ -13,7 +13,7 @@ import { EuiText, } from '@elastic/eui'; import React, { useEffect, useState } from 'react'; -import { ApplicationStart, NotificationsStart } from 'opensearch-dashboards/public'; +import { ApplicationStart, NotificationsStart, HttpStart } from 'opensearch-dashboards/public'; import { queryWorkbenchPluginCheck, queryWorkbenchPluginID, @@ -28,6 +28,7 @@ interface PreviewSQLDefinitionProps { resetFlyout: () => void; notifications: NotificationsStart; application: ApplicationStart; + http: HttpStart; } export const PreviewSQLDefinition = ({ @@ -36,6 +37,7 @@ export const PreviewSQLDefinition = ({ resetFlyout, notifications, application, + http, }: PreviewSQLDefinitionProps) => { const [isPreviewStale, setIsPreviewStale] = useState(false); const [isPreviewTriggered, setIsPreviewTriggered] = useState(false); @@ -60,23 +62,10 @@ export const PreviewSQLDefinition = ({ }; const checkIfSQLWorkbenchPluginIsInstalled = () => { - fetch('/api/status', { - headers: { - 'Content-Type': 'application/json', - 'osd-xsrf': 'true', - 'accept-language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,zh-TW;q=0.6', - pragma: 'no-cache', - 'sec-fetch-dest': 'empty', - 'sec-fetch-mode': 'cors', - 'sec-fetch-site': 'same-origin', - }, - method: 'GET', - referrerPolicy: 'strict-origin-when-cross-origin', - mode: 'cors', - credentials: 'include', - }) + http + .get('/api/status') .then(function (response) { - return response.json(); + return response; }) .then((data) => { for (let i = 0; i < data.status.statuses.length; ++i) {