import React from 'react'; import { Button, Legend, useStyles2 } from '@grafana/ui'; import { PluginConfigPageProps, AppPluginMeta, PluginMeta, GrafanaTheme2 } from '@grafana/data'; import { getBackendSrv } from '@grafana/runtime'; import { css } from '@emotion/css'; import { lastValueFrom } from 'rxjs'; export type AppPluginSettings = {}; export interface AppConfigProps extends PluginConfigPageProps> {} export const AppConfig = ({ plugin }: AppConfigProps) => { const s = useStyles2(getStyles); const { enabled, jsonData } = plugin.meta; return (
{/* Enable the plugin */} Enable / Disable {!enabled && ( <>
The plugin is currently not enabled.
)} {/* Disable the plugin */} {enabled && ( <>
The plugin is currently enabled.
)}
); }; const getStyles = (theme: GrafanaTheme2) => ({ colorWeak: css` color: ${theme.colors.text.secondary}; `, marginTop: css` margin-top: ${theme.spacing(3)}; `, }); const updatePluginAndReload = async (pluginId: string, data: Partial) => { try { await updatePlugin(pluginId, data); // Reloading the page as the changes made here wouldn't be propagated to the actual plugin otherwise. // This is not ideal, however unfortunately currently there is no supported way for updating the plugin state. window.location.reload(); } catch (e) { console.error('Error while updating the plugin', e); } }; export const updatePlugin = async (pluginId: string, data: Partial) => { const response = getBackendSrv().fetch({ url: `/api/plugins/${pluginId}/settings`, method: 'POST', data, }); return lastValueFrom(response); };