import { css } from '@emotion/css'; import React from 'react'; import { GrafanaTheme2, PluginType } from '@grafana/data'; import { config, featureEnabled } from '@grafana/runtime'; import { HorizontalGroup, Icon, LinkButton, useStyles2 } from '@grafana/ui'; import { getExternalManageLink, isInstallControlsEnabled } from '../../helpers'; import { isGrafanaAdmin } from '../../permissions'; import { useIsRemotePluginsAvailable } from '../../state/hooks'; import { CatalogPlugin, PluginStatus, Version } from '../../types'; import { ExternallyManagedButton } from './ExternallyManagedButton'; import { InstallControlsButton } from './InstallControlsButton'; interface Props { plugin: CatalogPlugin; latestCompatibleVersion?: Version; } export const InstallControls = ({ plugin, latestCompatibleVersion }: Props) => { const styles = useStyles2(getStyles); const isExternallyManaged = config.pluginAdminExternalManageEnabled; const hasPermission = isGrafanaAdmin(); const isRemotePluginsAvailable = useIsRemotePluginsAvailable(); const isCompatible = Boolean(latestCompatibleVersion); const isInstallControlsDisabled = plugin.isCore || plugin.isDisabled || !isInstallControlsEnabled(); const pluginStatus = plugin.isInstalled ? plugin.hasUpdate ? PluginStatus.UPDATE : PluginStatus.UNINSTALL : PluginStatus.INSTALL; if (isInstallControlsDisabled) { return null; } if (plugin.type === PluginType.renderer) { return
Renderer plugins cannot be managed by the Plugin Catalog.
; } if (plugin.isEnterprise && !featureEnabled('enterprise.plugins')) { return ( No valid Grafana Enterprise license detected. Learn more ); } if (plugin.isDev) { return (
This is a development build of the plugin and can't be uninstalled.
); } if (!hasPermission && !isExternallyManaged) { const message = `You do not have permission to ${pluginStatus} this plugin.`; return
{message}
; } if (!plugin.isPublished) { return (
This plugin is not published to{' '} grafana.com/plugins {' '} and can't be managed via the catalog.
); } if (!isCompatible) { return (
 This plugin doesn't support your version of Grafana.
); } if (isExternallyManaged) { return ; } if (!isRemotePluginsAvailable) { return (
The install controls have been disabled because the Grafana server cannot access grafana.com.
); } return ( ); }; export const getStyles = (theme: GrafanaTheme2) => { return { message: css` color: ${theme.colors.text.secondary}; `, }; };