Skip to content

Commit

Permalink
fix check plugin
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 acdb540 commit 1321b26
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
IntegrationInstancesSearchResult,
} from '../../../../framework/types';
import { INTEGRATIONS_BASE } from '../../../../framework/utils/shared';
import { checkIfPluginIsInstalled } from '../../utils';

interface DirectQueryDataConnectionDetailProps {
featureFlagStatus: boolean;
Expand All @@ -70,41 +71,6 @@ export const DirectQueryDataConnectionDetail: React.FC<DirectQueryDataConnection
setBreadcrumbs,
}) => {
const [observabilityDashboardsExists, setObservabilityDashboardsExists] = useState(false);
const checkIfObservabilityDashboardsPluginIsInstalled = () => {
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(function (response) {
return response.json();
})
.then((data) => {
for (let i = 0; i < data.status.statuses.length; ++i) {
if (data.status.statuses[i].id.includes('plugin:observabilityDashboards')) {
setObservabilityDashboardsExists(true);
}
}
})
.catch((error) => {
notifications.toasts.addDanger(
'Error checking Dashboards Observability Plugin Installation status.'
);
// eslint-disable-next-line no-console
console.error(error);
});
};

const { dataSourceName } = useParams<{ dataSourceName: string }>();
const { search } = useLocation();
const queryParams = new URLSearchParams(search);
Expand Down Expand Up @@ -211,7 +177,11 @@ export const DirectQueryDataConnectionDetail: React.FC<DirectQueryDataConnection
};

useEffect(() => {
checkIfObservabilityDashboardsPluginIsInstalled();
checkIfPluginIsInstalled(
'plugin:observabilityDashboards',
setObservabilityDashboardsExists,
notifications
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +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';

interface DataConnection {
connectionType: DirectQueryDatasourceType;
Expand Down Expand Up @@ -75,41 +76,6 @@ export const ManageDirectQueryDataConnectionsTable: React.FC<ManageDirectQueryDa
const [showIntegrationsFlyout, setShowIntegrationsFlyout] = useState(false);
const [integrationsFlyout, setIntegrationsFlyout] = useState<React.JSX.Element | null>(null);

const checkIfObservabilityDashboardsPluginIsInstalled = () => {
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('plugin:observabilityDashboards')
);
if (pluginExists) {
setObservabilityDashboardsExists(true);
}
})
)
.catch((error) => {
notifications.toasts.addDanger(
'Error checking Dashboards Observability Plugin Installation status.'
);
// eslint-disable-next-line no-console
console.error(error);
});
};

const [data, setData] = useState<DataConnection[]>([]);
const [isModalVisible, setIsModalVisible] = useState(false);
const [modalLayout, setModalLayout] = useState(<EuiOverlayMask />);
Expand Down Expand Up @@ -177,7 +143,11 @@ export const ManageDirectQueryDataConnectionsTable: React.FC<ManageDirectQueryDa

useEffect(() => {
fetchDataSources();
checkIfObservabilityDashboardsPluginIsInstalled();
checkIfPluginIsInstalled(
'plugin:observabilityDashboards',
setObservabilityDashboardsExists,
notifications
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [fetchDataSources]);

Expand Down
36 changes: 36 additions & 0 deletions src/plugins/data_source_management/public/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ToastsStart,
ApplicationStart,
CoreStart,
NotificationsStart,
} from 'src/core/public';
import { deepFreeze } from '@osd/std';
import uuid from 'uuid';
Expand Down Expand Up @@ -406,3 +407,38 @@ export const formatError = (name: string, message: string, details: string) => {
},
};
};

export const checkIfPluginIsInstalled = (
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);
});
};

0 comments on commit 1321b26

Please sign in to comment.