Bug Fix: Only display latest version if a plugin is not installed (#78178)

This commit is contained in:
Andres Martinez Gotor 2023-11-16 10:47:42 +01:00 committed by GitHub
parent 9452a6fcf7
commit 05cf8c9253
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 15 deletions

View File

@ -4,24 +4,17 @@ import React from 'react';
import { GrafanaTheme2 } from '@grafana/data';
import { useStyles2, Icon, Stack } from '@grafana/ui';
import { Version, CatalogPlugin, PluginIconName } from '../types';
import { CatalogPlugin, PluginIconName } from '../types';
type Props = {
plugin: CatalogPlugin;
latestCompatibleVersion?: Version;
grafanaDependency?: string;
className?: string;
};
export function PluginDetailsHeaderDependencies({
plugin,
latestCompatibleVersion,
className,
}: Props): React.ReactElement | null {
export function PluginDetailsHeaderDependencies({ plugin, grafanaDependency }: 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) {

View File

@ -19,7 +19,11 @@ export const usePluginInfo = (plugin?: CatalogPlugin): PageInfoItem[] => {
// Populate info
const latestCompatibleVersion = getLatestCompatibleVersion(plugin.details?.versions);
const version = plugin.installedVersion || latestCompatibleVersion?.version;
const useLatestCompatibleInfo = !plugin.isInstalled;
let version = plugin.installedVersion;
if (!version && useLatestCompatibleInfo && latestCompatibleVersion?.version) {
version = latestCompatibleVersion?.version;
}
if (Boolean(version)) {
info.push({
@ -47,15 +51,16 @@ export const usePluginInfo = (plugin?: CatalogPlugin): PageInfoItem[] => {
}
const pluginDependencies = plugin.details?.pluginDependencies;
const grafanaDependency = plugin.isInstalled
? plugin.details?.grafanaDependency
: latestCompatibleVersion?.grafanaDependency || plugin.details?.grafanaDependency;
let grafanaDependency = plugin.details?.grafanaDependency;
if (useLatestCompatibleInfo && latestCompatibleVersion?.grafanaDependency) {
grafanaDependency = latestCompatibleVersion?.grafanaDependency;
}
const hasNoDependencyInfo = !grafanaDependency && (!pluginDependencies || !pluginDependencies.length);
if (!hasNoDependencyInfo) {
info.push({
label: 'Dependencies',
value: <PluginDetailsHeaderDependencies plugin={plugin} latestCompatibleVersion={latestCompatibleVersion} />,
value: <PluginDetailsHeaderDependencies plugin={plugin} grafanaDependency={grafanaDependency} />,
});
}