2021-09-10 04:32:21 -05:00
|
|
|
import { css } from '@emotion/css';
|
2022-04-22 08:33:13 -05:00
|
|
|
import React from 'react';
|
|
|
|
|
2021-09-10 04:32:21 -05:00
|
|
|
import { GrafanaTheme2 } from '@grafana/data';
|
|
|
|
import { useStyles2, Icon } from '@grafana/ui';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2021-11-12 04:07:12 -06:00
|
|
|
import { Version, CatalogPlugin, PluginIconName } from '../types';
|
2021-09-10 04:32:21 -05:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
plugin: CatalogPlugin;
|
2021-11-12 04:07:12 -06:00
|
|
|
latestCompatibleVersion?: Version;
|
2021-09-10 04:32:21 -05:00
|
|
|
className?: string;
|
|
|
|
};
|
|
|
|
|
2021-11-12 04:07:12 -06:00
|
|
|
export function PluginDetailsHeaderDependencies({
|
|
|
|
plugin,
|
|
|
|
latestCompatibleVersion,
|
|
|
|
className,
|
|
|
|
}: Props): React.ReactElement | null {
|
2021-09-10 04:32:21 -05:00
|
|
|
const styles = useStyles2(getStyles);
|
|
|
|
const pluginDependencies = plugin.details?.pluginDependencies;
|
2021-11-12 04:07:12 -06:00
|
|
|
const grafanaDependency = plugin.isInstalled
|
|
|
|
? plugin.details?.grafanaDependency
|
|
|
|
: latestCompatibleVersion?.grafanaDependency || plugin.details?.grafanaDependency;
|
2021-09-10 04:32:21 -05:00
|
|
|
const hasNoDependencyInfo = !grafanaDependency && (!pluginDependencies || !pluginDependencies.length);
|
|
|
|
|
|
|
|
if (hasNoDependencyInfo) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={className}>
|
2021-09-10 10:17:57 -05:00
|
|
|
<div className={styles.dependencyTitle}>Dependencies:</div>
|
2021-09-10 04:32:21 -05:00
|
|
|
|
|
|
|
{/* Grafana dependency */}
|
|
|
|
{Boolean(grafanaDependency) && (
|
|
|
|
<div>
|
2021-09-10 10:17:57 -05:00
|
|
|
<Icon name="grafana" className={styles.icon} />
|
2021-09-10 04:32:21 -05:00
|
|
|
Grafana {grafanaDependency}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{/* Plugin dependencies */}
|
|
|
|
{pluginDependencies && pluginDependencies.length > 0 && (
|
|
|
|
<div>
|
|
|
|
{pluginDependencies.map((p) => {
|
|
|
|
return (
|
|
|
|
<span key={p.name}>
|
2021-09-27 11:06:47 -05:00
|
|
|
<Icon name={PluginIconName[p.type]} className={styles.icon} />
|
2021-09-10 04:32:21 -05:00
|
|
|
{p.name} {p.version}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getStyles = (theme: GrafanaTheme2) => {
|
|
|
|
return {
|
2021-09-10 10:17:57 -05:00
|
|
|
dependencyTitle: css`
|
2021-09-10 04:32:21 -05:00
|
|
|
font-weight: ${theme.typography.fontWeightBold};
|
2021-09-10 10:17:57 -05:00
|
|
|
margin-right: ${theme.spacing(0.5)};
|
|
|
|
|
|
|
|
&::after {
|
|
|
|
content: '';
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
icon: css`
|
|
|
|
color: ${theme.colors.text.secondary};
|
|
|
|
margin-right: ${theme.spacing(0.5)};
|
2021-09-10 04:32:21 -05:00
|
|
|
`,
|
|
|
|
};
|
|
|
|
};
|