mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
* 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>
86 lines
2.4 KiB
TypeScript
86 lines
2.4 KiB
TypeScript
import { css } from '@emotion/css';
|
|
import React from 'react';
|
|
|
|
import { GrafanaTheme2, PluginSignatureType } from '@grafana/data';
|
|
|
|
import { PageInfoItem } from '../../../../core/components/Page/types';
|
|
import { PluginDisabledBadge } from '../components/Badges';
|
|
import { PluginDetailsHeaderDependencies } from '../components/PluginDetailsHeaderDependencies';
|
|
import { PluginDetailsHeaderSignature } from '../components/PluginDetailsHeaderSignature';
|
|
import { getLatestCompatibleVersion } from '../helpers';
|
|
import { CatalogPlugin } from '../types';
|
|
|
|
export const usePluginInfo = (plugin?: CatalogPlugin): PageInfoItem[] => {
|
|
const info: PageInfoItem[] = [];
|
|
|
|
if (!plugin) {
|
|
return info;
|
|
}
|
|
|
|
// Populate info
|
|
const latestCompatibleVersion = getLatestCompatibleVersion(plugin.details?.versions);
|
|
const version = plugin.installedVersion || latestCompatibleVersion?.version;
|
|
|
|
if (Boolean(version)) {
|
|
info.push({
|
|
label: 'Version',
|
|
value: version,
|
|
});
|
|
}
|
|
|
|
if (Boolean(plugin.orgName)) {
|
|
info.push({
|
|
label: 'From',
|
|
value: plugin.orgName,
|
|
});
|
|
}
|
|
|
|
const showDownloads =
|
|
!plugin.signatureType ||
|
|
plugin.signatureType === PluginSignatureType.community ||
|
|
plugin.signatureType === PluginSignatureType.commercial;
|
|
if (showDownloads && Boolean(plugin.downloads > 0)) {
|
|
info.push({
|
|
label: 'Downloads',
|
|
value: new Intl.NumberFormat().format(plugin.downloads),
|
|
});
|
|
}
|
|
|
|
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) {
|
|
info.push({
|
|
label: 'Dependencies',
|
|
value: <PluginDetailsHeaderDependencies plugin={plugin} latestCompatibleVersion={latestCompatibleVersion} />,
|
|
});
|
|
}
|
|
|
|
if (plugin.isDisabled) {
|
|
info.push({
|
|
label: 'Status',
|
|
value: <PluginDisabledBadge error={plugin.error!} />,
|
|
});
|
|
}
|
|
|
|
info.push({
|
|
label: 'Signature',
|
|
value: <PluginDetailsHeaderSignature plugin={plugin} />,
|
|
});
|
|
|
|
return info;
|
|
};
|
|
|
|
export const getStyles = (theme: GrafanaTheme2) => {
|
|
return {
|
|
subtitle: css`
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: ${theme.spacing(1)};
|
|
`,
|
|
};
|
|
};
|