Browse Source

Merge pull request 'improve the plugin connection ux:' (#6) from improve-plugin-connection-ux into master

Reviewed-on: #6
pull/8/head
rozetko 2 years ago
parent
commit
cb9b76397a
  1. 3
      src/components/PluginConfigPage/PluginConfigPage.tsx
  2. 6
      src/components/PluginConfigPage/parts/ConfigurationForm/index.tsx
  3. 18
      src/plugin_state.ts

3
src/components/PluginConfigPage/PluginConfigPage.tsx

@ -16,7 +16,7 @@ const PLUGIN_CONFIGURED_QUERY_PARAM_TRUTHY_VALUE = 'true';
const PLUGIN_CONFIGURED_VERSION_QUERY_PARAM = 'pluginConfiguredVersion'; const PLUGIN_CONFIGURED_VERSION_QUERY_PARAM = 'pluginConfiguredVersion';
const DEFAULT_API_URL = 'http://localhost:8080'; const DEFAULT_API_URL = 'http://localhost:8000';
/** /**
* When everything is successfully configured, reload the page, and pass along a few query parameters * When everything is successfully configured, reload the page, and pass along a few query parameters
@ -84,6 +84,7 @@ export const PluginConfigPage: FC<DataExporterPluginConfigPageProps> = ({
setPluginConnectionCheckError(pluginConnectionResponse); setPluginConnectionCheckError(pluginConnectionResponse);
} else { } else {
setPluginIsConnected(pluginConnectionResponse); setPluginIsConnected(pluginConnectionResponse);
reloadPageWithPluginConfiguredQueryParams(pluginConnectionResponse, true);
} }
setCheckingIfPluginIsConnected(false); setCheckingIfPluginIsConnected(false);

6
src/components/PluginConfigPage/parts/ConfigurationForm/index.tsx

@ -84,7 +84,7 @@ const ConfigurationForm: FC<Props> = ({ onSuccessfulSetup, defaultDataExporterAp
<div className={cx('info-block')}> <div className={cx('info-block')}>
<p>1. Launch the DataExporter backend</p> <p>1. Launch the DataExporter backend</p>
<Text type="secondary"> <Text type="secondary">
Run hobby, dev or production backend. See{' '} Run the backend. See{' '}
<a href="https://code.corpglory.net/corpglory/grafana-data-exporter" target="_blank" rel="noreferrer"> <a href="https://code.corpglory.net/corpglory/grafana-data-exporter" target="_blank" rel="noreferrer">
<Text type="link">here</Text> <Text type="link">here</Text>
</a>{' '} </a>{' '}
@ -97,8 +97,8 @@ const ConfigurationForm: FC<Props> = ({ onSuccessfulSetup, defaultDataExporterAp
<Text type="secondary"> <Text type="secondary">
The DataExporter backend must be reachable from your Grafana installation. Some examples are: The DataExporter backend must be reachable from your Grafana installation. Some examples are:
<br /> <br />
- http://host.docker.internal:8080 - http://host.docker.internal:8000
<br />- http://localhost:8080 <br />- http://localhost:8000
</Text> </Text>
</div> </div>

18
src/plugin_state.ts

@ -90,7 +90,9 @@ class PluginState {
this.grafanaBackend.get<DataExporterAppPluginMeta>(this.GRAFANA_PLUGIN_SETTINGS_URL); this.grafanaBackend.get<DataExporterAppPluginMeta>(this.GRAFANA_PLUGIN_SETTINGS_URL);
static updateGrafanaPluginSettings = async (data: UpdateGrafanaPluginSettingsProps, enabled = true) => static updateGrafanaPluginSettings = async (data: UpdateGrafanaPluginSettingsProps, enabled = true) =>
this.grafanaBackend.post(this.GRAFANA_PLUGIN_SETTINGS_URL, { ...data, enabled, pinned: true }); // @ts-ignore
// for some reason, there is no `options` argument in Grafana's public types for BackendSrv but it exists
this.grafanaBackend.post(this.GRAFANA_PLUGIN_SETTINGS_URL, { ...data, enabled, pinned: true }, { showSuccessAlert: false });
static createGrafanaToken = async () => { static createGrafanaToken = async () => {
const baseUrl = '/api/auth/keys'; const baseUrl = '/api/auth/keys';
@ -98,14 +100,22 @@ class PluginState {
const existingKey = keys.find((key: { id: number; name: string; role: string }) => key.name === 'DataExporter'); const existingKey = keys.find((key: { id: number; name: string; role: string }) => key.name === 'DataExporter');
if (existingKey) { if (existingKey) {
await this.grafanaBackend.delete(`${baseUrl}/${existingKey.id}`); // @ts-ignore
// for some reason, there is no `options` argument in Grafana's public types for BackendSrv but it exists
await this.grafanaBackend.delete(`${baseUrl}/${existingKey.id}`, undefined, { showSuccessAlert: false });
} }
return await this.grafanaBackend.post(baseUrl, { return await this.grafanaBackend.post(
baseUrl,
{
name: 'DataExporter', name: 'DataExporter',
role: 'Admin', role: 'Admin',
secondsToLive: null, secondsToLive: null,
}); },
// @ts-ignore
// for some reason, there is no `options` argument in Grafana's public types for BackendSrv but it exists
{ showSuccessAlert: false }
);
}; };
static timeout = (pollCount: number) => new Promise((resolve) => setTimeout(resolve, 10 * 2 ** pollCount)); static timeout = (pollCount: number) => new Promise((resolve) => setTimeout(resolve, 10 * 2 ** pollCount));

Loading…
Cancel
Save