mirror of
https://github.com/grafana/grafana.git
synced 2025-09-24 20:04:10 +08:00

* add special handling on the plugin gathering side to check whether secrets manager plugins are enabled or not * show disabled badge in front end if the plugin is not enabled * Only show error in disabled badge hover if one is present (otherwise it shows "undefined") * refactor to make use of fields already available in the DTO * fix typo * if there is no error returned for the plugin, just show 'disabled' * fix typo * Update public/app/features/plugins/admin/components/Badges/PluginDisabledBadge.tsx Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com> * Update frontendsettings.go add clarifying comment * fix unit test * rework task to use new frontend property combined with plugin type to determine if the plugin should be disabled * Update helpers.test.ts revert test change * fix unit test * show custom uninstall message if the plugin is a secrets manager * bogus commit to trigger precommit * undo commit * run precommit manually Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>
125 lines
3.8 KiB
TypeScript
125 lines
3.8 KiB
TypeScript
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 <div className={styles.message}>Renderer plugins cannot be managed by the Plugin Catalog.</div>;
|
|
}
|
|
|
|
if (plugin.type === PluginType.secretsmanager) {
|
|
return <div className={styles.message}>Secrets manager plugins cannot be managed by the Plugin Catalog.</div>;
|
|
}
|
|
|
|
if (plugin.isEnterprise && !featureEnabled('enterprise.plugins')) {
|
|
return (
|
|
<HorizontalGroup height="auto" align="center">
|
|
<span className={styles.message}>No valid Grafana Enterprise license detected.</span>
|
|
<LinkButton
|
|
href={`${getExternalManageLink(plugin.id)}?utm_source=grafana_catalog_learn_more`}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
size="sm"
|
|
fill="text"
|
|
icon="external-link-alt"
|
|
>
|
|
Learn more
|
|
</LinkButton>
|
|
</HorizontalGroup>
|
|
);
|
|
}
|
|
|
|
if (plugin.isDev) {
|
|
return (
|
|
<div className={styles.message}>This is a development build of the plugin and can't be uninstalled.</div>
|
|
);
|
|
}
|
|
|
|
if (!hasPermission && !isExternallyManaged) {
|
|
const message = `You do not have permission to ${pluginStatus} this plugin.`;
|
|
return <div className={styles.message}>{message}</div>;
|
|
}
|
|
|
|
if (!plugin.isPublished) {
|
|
return (
|
|
<div className={styles.message}>
|
|
<Icon name="exclamation-triangle" /> This plugin is not published to{' '}
|
|
<a href="https://www.grafana.com/plugins" target="__blank" rel="noreferrer">
|
|
grafana.com/plugins
|
|
</a>{' '}
|
|
and can't be managed via the catalog.
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (!isCompatible) {
|
|
return (
|
|
<div className={styles.message}>
|
|
<Icon name="exclamation-triangle" />
|
|
This plugin doesn't support your version of Grafana.
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (isExternallyManaged) {
|
|
return <ExternallyManagedButton pluginId={plugin.id} pluginStatus={pluginStatus} />;
|
|
}
|
|
|
|
if (!isRemotePluginsAvailable) {
|
|
return (
|
|
<div className={styles.message}>
|
|
The install controls have been disabled because the Grafana server cannot access grafana.com.
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<InstallControlsButton
|
|
plugin={plugin}
|
|
pluginStatus={pluginStatus}
|
|
latestCompatibleVersion={latestCompatibleVersion}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export const getStyles = (theme: GrafanaTheme2) => {
|
|
return {
|
|
message: css`
|
|
color: ${theme.colors.text.secondary};
|
|
`,
|
|
};
|
|
};
|