|
|
@ -1,15 +1,14 @@ |
|
|
|
import React, { FC, useCallback, useEffect, useState } from 'react'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { Legend, LoadingPlaceholder } from '@grafana/ui'; |
|
|
|
|
|
|
|
import { useLocation } from 'react-router-dom'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// import logo from '../../img/logo.svg';
|
|
|
|
|
|
|
|
import PluginState, { PluginConnectedStatusResponse } from '../../plugin_state'; |
|
|
|
import PluginState, { PluginConnectedStatusResponse } from '../../plugin_state'; |
|
|
|
|
|
|
|
|
|
|
|
import ConfigurationForm from './parts/ConfigurationForm'; |
|
|
|
import ConfigurationForm from './parts/ConfigurationForm'; |
|
|
|
import RemoveCurrentConfigurationButton from './parts/RemoveCurrentConfigurationButton'; |
|
|
|
import RemoveCurrentConfigurationButton from './parts/RemoveCurrentConfigurationButton'; |
|
|
|
import StatusMessageBlock from './parts/StatusMessageBlock'; |
|
|
|
import StatusMessageBlock from './parts/StatusMessageBlock'; |
|
|
|
import { DataExporterPluginConfigPageProps } from 'types'; |
|
|
|
import { DataExporterPluginConfigPageProps } from '../../types'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { Legend, LoadingPlaceholder } from '@grafana/ui'; |
|
|
|
|
|
|
|
import { useLocation } from 'react-router-dom'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import React, { FC, useCallback, useEffect, useState } from 'react'; |
|
|
|
|
|
|
|
|
|
|
|
const PLUGIN_CONFIGURED_QUERY_PARAM = 'pluginConfigured'; |
|
|
|
const PLUGIN_CONFIGURED_QUERY_PARAM = 'pluginConfigured'; |
|
|
|
const PLUGIN_CONFIGURED_QUERY_PARAM_TRUTHY_VALUE = 'true'; |
|
|
|
const PLUGIN_CONFIGURED_QUERY_PARAM_TRUTHY_VALUE = 'true'; |
|
|
@ -71,24 +70,30 @@ export const PluginConfigPage: FC<DataExporterPluginConfigPageProps> = ({ |
|
|
|
|
|
|
|
|
|
|
|
const resetQueryParams = useCallback(() => removePluginConfiguredQueryParams(pluginIsEnabled), [pluginIsEnabled]); |
|
|
|
const resetQueryParams = useCallback(() => removePluginConfiguredQueryParams(pluginIsEnabled), [pluginIsEnabled]); |
|
|
|
|
|
|
|
|
|
|
|
const checkConnection = useCallback(async () => { |
|
|
|
const checkConnection = useCallback( |
|
|
|
setCheckingIfPluginIsConnected(true); |
|
|
|
async (grafanaDataExporterUrl?: string) => { |
|
|
|
setPluginConnectionCheckError(null); |
|
|
|
setCheckingIfPluginIsConnected(true); |
|
|
|
if (!pluginMetaDataExporterApiUrl) { |
|
|
|
setPluginConnectionCheckError(null); |
|
|
|
setCheckingIfPluginIsConnected(false); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const pluginConnectionResponse = await PluginState.checkIfPluginIsConnected(pluginMetaDataExporterApiUrl); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof pluginConnectionResponse === 'string') { |
|
|
|
const backendUrl = grafanaDataExporterUrl || pluginMetaDataExporterApiUrl; |
|
|
|
setPluginConnectionCheckError(pluginConnectionResponse); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
setPluginIsConnected(pluginConnectionResponse); |
|
|
|
|
|
|
|
reloadPageWithPluginConfiguredQueryParams(pluginConnectionResponse, true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setCheckingIfPluginIsConnected(false); |
|
|
|
if (!backendUrl) { |
|
|
|
}, [pluginMetaDataExporterApiUrl]); |
|
|
|
setCheckingIfPluginIsConnected(false); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const pluginConnectionResponse = await PluginState.checkIfPluginIsConnected(backendUrl); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof pluginConnectionResponse === 'string') { |
|
|
|
|
|
|
|
setPluginConnectionCheckError(pluginConnectionResponse); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
setPluginIsConnected(pluginConnectionResponse); |
|
|
|
|
|
|
|
reloadPageWithPluginConfiguredQueryParams(pluginConnectionResponse, true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setCheckingIfPluginIsConnected(false); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
[pluginMetaDataExporterApiUrl] |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(resetQueryParams, [resetQueryParams]); |
|
|
|
useEffect(resetQueryParams, [resetQueryParams]); |
|
|
|
|
|
|
|
|
|
|
@ -166,10 +171,7 @@ export const PluginConfigPage: FC<DataExporterPluginConfigPageProps> = ({ |
|
|
|
<Legend>Configure DataExporter</Legend> |
|
|
|
<Legend>Configure DataExporter</Legend> |
|
|
|
{pluginIsConnected ? ( |
|
|
|
{pluginIsConnected ? ( |
|
|
|
<> |
|
|
|
<> |
|
|
|
<p> |
|
|
|
<p>Plugin is connected! You can now go to a dashboard and add the DataExporter panel there.</p> |
|
|
|
Plugin is connected! Continue to DataExporter by clicking the{' '} |
|
|
|
|
|
|
|
{/* <img alt="DataExporter Logo" src={logo} width={18} /> icon over there 👈 */} |
|
|
|
|
|
|
|
</p> |
|
|
|
|
|
|
|
<StatusMessageBlock text={`Connected to DataExporter`} /> |
|
|
|
<StatusMessageBlock text={`Connected to DataExporter`} /> |
|
|
|
</> |
|
|
|
</> |
|
|
|
) : ( |
|
|
|
) : ( |
|
|
|