2023-01-03 07:20:27 -06:00
|
|
|
import React from 'react';
|
|
|
|
import { useAsync } from 'react-use';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2019-06-26 06:15:45 -05:00
|
|
|
import { renderMarkdown } from '@grafana/data';
|
2019-06-03 10:55:59 -05:00
|
|
|
import { getBackendSrv } from '@grafana/runtime';
|
2023-01-03 07:20:27 -06:00
|
|
|
import { LoadingPlaceholder } from '@grafana/ui';
|
2018-12-17 09:42:02 -06:00
|
|
|
|
|
|
|
interface Props {
|
2023-01-03 07:20:27 -06:00
|
|
|
pluginId: string;
|
2018-12-17 09:42:02 -06:00
|
|
|
}
|
|
|
|
|
2023-01-03 07:20:27 -06:00
|
|
|
export function PluginHelp({ pluginId }: Props) {
|
|
|
|
const { value, loading, error } = useAsync(async () => {
|
|
|
|
return getBackendSrv().get(`/api/plugins/${pluginId}/markdown/query_help`);
|
|
|
|
}, []);
|
2018-12-17 09:42:02 -06:00
|
|
|
|
2023-01-03 07:20:27 -06:00
|
|
|
const renderedMarkdown = renderMarkdown(value);
|
2018-12-18 07:40:54 -06:00
|
|
|
|
2023-01-03 07:20:27 -06:00
|
|
|
if (loading) {
|
|
|
|
return <LoadingPlaceholder text="Loading help..." />;
|
2018-12-17 09:42:02 -06:00
|
|
|
}
|
|
|
|
|
2023-01-03 07:20:27 -06:00
|
|
|
if (error) {
|
|
|
|
return <h3>An error occurred when loading help.</h3>;
|
2018-12-19 03:53:14 -06:00
|
|
|
}
|
2018-12-18 07:40:54 -06:00
|
|
|
|
2023-01-03 07:20:27 -06:00
|
|
|
if (value === '') {
|
|
|
|
return <h3>No query help could be found.</h3>;
|
2018-12-17 09:42:02 -06:00
|
|
|
}
|
2023-01-03 07:20:27 -06:00
|
|
|
|
|
|
|
return <div className="markdown-html" dangerouslySetInnerHTML={{ __html: renderedMarkdown }} />;
|
2018-12-17 09:42:02 -06:00
|
|
|
}
|