| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- import React, { PureComponent } from 'react';
- // @ts-ignore
- import Remarkable from 'remarkable';
- import { getBackendSrv } from '@grafana/runtime';
- interface Props {
- plugin: {
- name: string;
- id: string;
- };
- type: string;
- }
- interface State {
- isError: boolean;
- isLoading: boolean;
- help: string;
- }
- export class PluginHelp extends PureComponent<Props, State> {
- state = {
- isError: false,
- isLoading: false,
- help: '',
- };
- componentDidMount(): void {
- this.loadHelp();
- }
- constructPlaceholderInfo() {
- return 'No plugin help or readme markdown file was found';
- }
- loadHelp = () => {
- const { plugin, type } = this.props;
- this.setState({ isLoading: true });
- getBackendSrv()
- .get(`/api/plugins/${plugin.id}/markdown/${type}`)
- .then((response: string) => {
- const markdown = new Remarkable();
- const helpHtml = markdown.render(response);
- if (response === '' && type === 'help') {
- this.setState({
- isError: false,
- isLoading: false,
- help: this.constructPlaceholderInfo(),
- });
- } else {
- this.setState({
- isError: false,
- isLoading: false,
- help: helpHtml,
- });
- }
- })
- .catch(() => {
- this.setState({
- isError: true,
- isLoading: false,
- });
- });
- };
- render() {
- const { type } = this.props;
- const { isError, isLoading, help } = this.state;
- if (isLoading) {
- return <h2>Loading help...</h2>;
- }
- if (isError) {
- return <h3>'Error occurred when loading help'</h3>;
- }
- if (type === 'panel_help' && help === '') {
- }
- return <div className="markdown-html" dangerouslySetInnerHTML={{ __html: help }} />;
- }
- }
|