grafana/public/app/features/plugins/admin/components/PluginDetailsHeaderDependencies.tsx
Ashley Harrison 159607fe6f
Navigation: Convert PluginDetails page to use new Page extensions (#58509)
* Added labels

* App page fixes

* Switch to switch

* wip

* Updates

* I am stuck

* Minor tweak

* This props interface could work

* removed change

* use new page extensions in plugin details page

* add link separator, fix action button spacing

* some renaming

* Move PageInfo into it's own folder + add tests

* add support for new props in old page header

* remove PluginDetailsHeader as it's no longer used

* Fix unit tests

* fix some badge alignments

* center align actions

* badge alignment + only show downloads for community/commercial plugins

* better link alignment

* conditionally render description

* move install control warnings to below subtitle + refactor

Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
2022-11-09 14:44:38 +00:00

79 lines
2.0 KiB
TypeScript

import { css } from '@emotion/css';
import React from 'react';
import { GrafanaTheme2 } from '@grafana/data';
import { Stack } from '@grafana/experimental';
import { useStyles2, Icon } from '@grafana/ui';
import { Version, CatalogPlugin, PluginIconName } from '../types';
type Props = {
plugin: CatalogPlugin;
latestCompatibleVersion?: Version;
className?: string;
};
export function PluginDetailsHeaderDependencies({
plugin,
latestCompatibleVersion,
className,
}: Props): React.ReactElement | null {
const styles = useStyles2(getStyles);
const pluginDependencies = plugin.details?.pluginDependencies;
const grafanaDependency = plugin.isInstalled
? plugin.details?.grafanaDependency
: latestCompatibleVersion?.grafanaDependency || plugin.details?.grafanaDependency;
const hasNoDependencyInfo = !grafanaDependency && (!pluginDependencies || !pluginDependencies.length);
if (hasNoDependencyInfo) {
return null;
}
return (
<Stack gap={1}>
{/* Grafana dependency */}
{Boolean(grafanaDependency) && (
<div className={styles.depBadge}>
<Icon name="grafana" className={styles.icon} />
Grafana {grafanaDependency}
</div>
)}
{/* Plugin dependencies */}
{pluginDependencies && pluginDependencies.length > 0 && (
<div>
{pluginDependencies.map((p) => {
return (
<span className={styles.depBadge} key={p.name}>
<Icon name={PluginIconName[p.type]} className={styles.icon} />
{p.name} {p.version}
</span>
);
})}
</div>
)}
</Stack>
);
}
export const getStyles = (theme: GrafanaTheme2) => {
return {
dependencyTitle: css`
margin-right: ${theme.spacing(0.5)};
&::after {
content: '';
padding: 0;
}
`,
depBadge: css({
display: 'flex',
alignItems: 'flex-start',
}),
icon: css`
color: ${theme.colors.text.secondary};
margin-right: ${theme.spacing(0.5)};
`,
};
};