mirror of https://github.com/grafana/grafana
Plugins Catalog: add support for enable/disable app plugins (#41801)
* refactor(plugins): add empty line between methods * feat(api): add an API function for updating plugin settings * feat(plugins): add a "getting started" guide for enabling / disabling app plugins * test(plugins/admin): add tests for enable/disable functionality * refactor(plugins/admin): update the name of the test cases Now that we have multiple type of post-installation steps it probably makes sense.pull/41876/head
parent
6aeecd48a7
commit
9c2a947605
@ -0,0 +1,62 @@ |
||||
import { PluginMeta } from '@grafana/data'; |
||||
import { Button } from '@grafana/ui'; |
||||
import { usePluginConfig } from '../../hooks/usePluginConfig'; |
||||
import { updatePluginSettings } from '../../api'; |
||||
import React from 'react'; |
||||
import { CatalogPlugin } from '../../types'; |
||||
|
||||
type Props = { |
||||
plugin: CatalogPlugin; |
||||
}; |
||||
|
||||
export function GetStartedWithApp({ plugin }: Props): React.ReactElement | null { |
||||
const { value: pluginConfig } = usePluginConfig(plugin); |
||||
|
||||
if (!pluginConfig) { |
||||
return null; |
||||
} |
||||
|
||||
const { enabled, jsonData } = pluginConfig?.meta; |
||||
|
||||
const enable = () => |
||||
updatePluginSettingsAndReload(plugin.id, { |
||||
enabled: true, |
||||
pinned: true, |
||||
jsonData, |
||||
}); |
||||
|
||||
const disable = () => { |
||||
updatePluginSettingsAndReload(plugin.id, { |
||||
enabled: false, |
||||
pinned: false, |
||||
jsonData, |
||||
}); |
||||
}; |
||||
|
||||
return ( |
||||
<> |
||||
{!enabled && ( |
||||
<Button variant="primary" onClick={enable}> |
||||
Enable |
||||
</Button> |
||||
)} |
||||
|
||||
{enabled && ( |
||||
<Button variant="destructive" onClick={disable}> |
||||
Disable |
||||
</Button> |
||||
)} |
||||
</> |
||||
); |
||||
} |
||||
|
||||
const updatePluginSettingsAndReload = async (id: string, data: Partial<PluginMeta>) => { |
||||
try { |
||||
await updatePluginSettings(id, data); |
||||
|
||||
// Reloading the page as the plugin meta changes made here wouldn't be propagated throughout the app.
|
||||
window.location.reload(); |
||||
} catch (e) { |
||||
console.error('Error while updating the plugin', e); |
||||
} |
||||
}; |
Loading…
Reference in new issue