mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
* refactor(pluginhelp): rewrite as functional component with useAsync * mimic old behaviour * feat(pluginhelp): display message if backend returned an empty string Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
33 lines
844 B
TypeScript
33 lines
844 B
TypeScript
import React from 'react';
|
|
import { useAsync } from 'react-use';
|
|
|
|
import { renderMarkdown } from '@grafana/data';
|
|
import { getBackendSrv } from '@grafana/runtime';
|
|
import { LoadingPlaceholder } from '@grafana/ui';
|
|
|
|
interface Props {
|
|
pluginId: string;
|
|
}
|
|
|
|
export function PluginHelp({ pluginId }: Props) {
|
|
const { value, loading, error } = useAsync(async () => {
|
|
return getBackendSrv().get(`/api/plugins/${pluginId}/markdown/query_help`);
|
|
}, []);
|
|
|
|
const renderedMarkdown = renderMarkdown(value);
|
|
|
|
if (loading) {
|
|
return <LoadingPlaceholder text="Loading help..." />;
|
|
}
|
|
|
|
if (error) {
|
|
return <h3>An error occurred when loading help.</h3>;
|
|
}
|
|
|
|
if (value === '') {
|
|
return <h3>No query help could be found.</h3>;
|
|
}
|
|
|
|
return <div className="markdown-html" dangerouslySetInnerHTML={{ __html: renderedMarkdown }} />;
|
|
}
|