From 95ee93a0d8d3df333ffc64742c7b525a50b640a1 Mon Sep 17 00:00:00 2001 From: Hugo Kiyodi Oshiro Date: Thu, 13 Feb 2025 11:07:24 +0100 Subject: [PATCH] Plugins: Improve plugin details UX for core plugins (#99830) --- public/app/features/plugins/admin/api.ts | 1 + .../components/PluginDetailsPage.test.tsx | 25 +++++++++++++++++++ .../plugins/admin/components/VersionList.tsx | 2 +- .../admin/hooks/usePluginDetailsTabs.tsx | 6 +++-- .../plugins/admin/hooks/usePluginInfo.tsx | 5 +++- public/app/features/plugins/admin/types.ts | 1 + 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/public/app/features/plugins/admin/api.ts b/public/app/features/plugins/admin/api.ts index ef9411bea9e..36d49c2dbd7 100644 --- a/public/app/features/plugins/admin/api.ts +++ b/public/app/features/plugins/admin/api.ts @@ -94,6 +94,7 @@ async function getPluginVersions(id: string, isPublished: boolean): Promise ({ version: v.version, createdAt: v.createdAt, + updatedAt: v.updatedAt, isCompatible: v.isCompatible, grafanaDependency: v.grafanaDependency, angularDetected: v.angularDetected, diff --git a/public/app/features/plugins/admin/components/PluginDetailsPage.test.tsx b/public/app/features/plugins/admin/components/PluginDetailsPage.test.tsx index 4f1bde85393..ad97440a183 100644 --- a/public/app/features/plugins/admin/components/PluginDetailsPage.test.tsx +++ b/public/app/features/plugins/admin/components/PluginDetailsPage.test.tsx @@ -57,6 +57,7 @@ const plugin: CatalogPlugin = { ], grafanaDependency: '>=9.0.0', statusContext: 'stable', + changelog: 'Test changelog', }, angularDetected: false, isFullyInstalled: true, @@ -154,4 +155,28 @@ describe('PluginDetailsPage', () => { render(); expect(screen.getByRole('tab', { name: 'Data source connections' })).toBeVisible(); }); + + it('should not show version and changelog tabs when plugin is core', () => { + mockUseGetSingle.mockReturnValue({ ...plugin, isCore: true }); + render(); + expect(screen.queryByRole('tab', { name: 'Version history' })).not.toBeInTheDocument(); + expect(screen.queryByRole('tab', { name: 'Changelog' })).not.toBeInTheDocument(); + }); + + it('should not show last version in plugin details panel when plugin is core', () => { + config.featureToggles.pluginsDetailsRightPanel = true; + window.matchMedia = jest.fn().mockImplementation((query) => ({ + matches: query !== '(max-width: 600px)', + media: query, + onchange: null, + addEventListener: jest.fn(), + removeEventListener: jest.fn(), + dispatchEvent: jest.fn(), + })); + + mockUseGetSingle.mockReturnValue({ ...plugin, isCore: true, latestVersion: '1.2.0' }); + + render(); + expect(screen.queryByText('Latest Version:')).not.toBeInTheDocument(); + }); }); diff --git a/public/app/features/plugins/admin/components/VersionList.tsx b/public/app/features/plugins/admin/components/VersionList.tsx index aaf98fd183b..2e79b0d43c1 100644 --- a/public/app/features/plugins/admin/components/VersionList.tsx +++ b/public/app/features/plugins/admin/components/VersionList.tsx @@ -96,7 +96,7 @@ export const VersionList = ({ pluginId, versions = [], installedVersion, disable {/* Last updated */} - {dateTimeFormatTimeAgo(version.createdAt)} + {dateTimeFormatTimeAgo(version.updatedAt || version.createdAt)} {/* Dependency */} {version.grafanaDependency || 'N/A'} diff --git a/public/app/features/plugins/admin/hooks/usePluginDetailsTabs.tsx b/public/app/features/plugins/admin/hooks/usePluginDetailsTabs.tsx index e9c50269d15..d9f7c2e1375 100644 --- a/public/app/features/plugins/admin/hooks/usePluginDetailsTabs.tsx +++ b/public/app/features/plugins/admin/hooks/usePluginDetailsTabs.tsx @@ -42,7 +42,8 @@ export const usePluginDetailsTabs = ( const navModelChildren = useMemo(() => { const canConfigurePlugins = plugin && contextSrv.hasPermissionInMetadata(AccessControlAction.PluginsWrite, plugin); const navModelChildren: NavModelItem[] = []; - if (isPublished) { + // currently the versions available of core plugins are not consistent + if (isPublished && !plugin?.isCore) { navModelChildren.push({ text: PluginTabLabels.VERSIONS, id: PluginTabIds.VERSIONS, @@ -51,7 +52,8 @@ export const usePluginDetailsTabs = ( active: PluginTabIds.VERSIONS === currentPageId, }); } - if (isPublished && plugin?.details?.changelog) { + // currently there is not changelog available for core plugins + if (isPublished && plugin?.details?.changelog && !plugin.isCore) { navModelChildren.push({ text: PluginTabLabels.CHANGELOG, id: PluginTabIds.CHANGELOG, diff --git a/public/app/features/plugins/admin/hooks/usePluginInfo.tsx b/public/app/features/plugins/admin/hooks/usePluginInfo.tsx index 1bb1334e1ef..2c9124f1860 100644 --- a/public/app/features/plugins/admin/hooks/usePluginInfo.tsx +++ b/public/app/features/plugins/admin/hooks/usePluginInfo.tsx @@ -53,7 +53,10 @@ export const usePluginInfo = (plugin?: CatalogPlugin): PageInfoItem[] => { latestVersionValue = latestVersion; } - addInfo('latestVersion', latestVersionValue); + // latest versions of core plugins are not consistent + if (!plugin.isCore) { + addInfo('latestVersion', latestVersionValue); + } } if (Boolean(plugin.orgName)) { diff --git a/public/app/features/plugins/admin/types.ts b/public/app/features/plugins/admin/types.ts index 10e2636b2ef..031f6c1543c 100644 --- a/public/app/features/plugins/admin/types.ts +++ b/public/app/features/plugins/admin/types.ts @@ -216,6 +216,7 @@ export interface Build { export interface Version { version: string; createdAt: string; + updatedAt?: string; isCompatible: boolean; grafanaDependency: string | null; angularDetected?: boolean;