Skip to content

Commit

Permalink
fix check plugin 2
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Liang <jiallian@amazon.com>
  • Loading branch information
RyanL1997 committed Jul 24, 2024
1 parent 1321b26 commit 3839343
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import {
IntegrationInstancesSearchResult,
} from '../../../../framework/types';
import { INTEGRATIONS_BASE } from '../../../../framework/utils/shared';
import { checkIfPluginIsInstalled } from '../../utils';
import { isPluginInstalled } from '../../utils';

interface DirectQueryDataConnectionDetailProps {
featureFlagStatus: boolean;
Expand Down Expand Up @@ -177,10 +177,8 @@ export const DirectQueryDataConnectionDetail: React.FC<DirectQueryDataConnection
};

useEffect(() => {
checkIfPluginIsInstalled(
'plugin:observabilityDashboards',
setObservabilityDashboardsExists,
notifications
isPluginInstalled('plugin:observabilityDashboards', notifications, http).then(
setObservabilityDashboardsExists
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { DATACONNECTIONS_BASE, observabilityMetricsID } from '../../../constants
import { getRenderCreateAccelerationFlyout } from '../../../plugin';
import { InstallIntegrationFlyout } from '../integrations/installed_integrations_table';
import { redirectToExplorerS3 } from '../associated_object_management/utils/associated_objects_tab_utils';
import { checkIfPluginIsInstalled } from '../../utils';
import { isPluginInstalled } from '../../utils';

interface DataConnection {
connectionType: DirectQueryDatasourceType;
Expand Down Expand Up @@ -143,10 +143,8 @@ export const ManageDirectQueryDataConnectionsTable: React.FC<ManageDirectQueryDa

useEffect(() => {
fetchDataSources();
checkIfPluginIsInstalled(
'plugin:observabilityDashboards',
setObservabilityDashboardsExists,
notifications
isPluginInstalled('plugin:observabilityDashboards', notifications, http).then(
setObservabilityDashboardsExists
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [fetchDataSources]);
Expand Down
48 changes: 16 additions & 32 deletions src/plugins/data_source_management/public/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,37 +408,21 @@ export const formatError = (name: string, message: string, details: string) => {
};
};

export const checkIfPluginIsInstalled = (
export const isPluginInstalled = async (
pluginId: string,
setPluginExists: (exists: boolean) => void,
notifications: NotificationsStart
) => {
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',
})
.then((response) =>
response.json().then((data) => {
const pluginExists = data.status.statuses.some((status: { id: string | string[] }) =>
status.id.includes(pluginId)
);
setPluginExists(pluginExists);
})
)
.catch((error) => {
notifications.toasts.addDanger(`Error checking ${pluginId} Plugin Installation status.`);
// eslint-disable-next-line no-console
console.error(error);
});
notifications: NotificationsStart,
http: HttpStart
): Promise<boolean> => {
try {
const response = await http.get('/api/status');
const pluginExists = response.status.statuses.some((status: { id: string }) =>
status.id.includes(pluginId)
);
return pluginExists;
} catch (error) {
notifications.toasts.addDanger(`Error checking ${pluginId} Plugin Installation status.`);
// eslint-disable-next-line no-console
console.error(error);
return false;
}
};

0 comments on commit 3839343

Please sign in to comment.