From c9620b220231cd0ff994fa8ef06127c2e8618cff Mon Sep 17 00:00:00 2001 From: Jack Westbrook Date: Fri, 10 Sep 2021 17:17:57 +0200 Subject: [PATCH] Catalog: Add update text to PluginListCard (#39087) * feat(catalog): add update info to PluginListCard * refactor(catalog): use IconName enum and minor styling changes to PluginHeaderDependencies * fix(catalog): add a semver range to grafanaVersion for dependency checks in InstallControls --- public/app/features/plugins/admin/api.ts | 9 ++++- .../PluginDetailsHeaderDependencies.tsx | 29 +++++++-------- .../admin/components/PluginListCard.tsx | 36 ++++++++++--------- public/app/features/plugins/admin/types.ts | 7 ++++ 4 files changed, 50 insertions(+), 31 deletions(-) diff --git a/public/app/features/plugins/admin/api.ts b/public/app/features/plugins/admin/api.ts index 6af527707e1..7740d4a5969 100644 --- a/public/app/features/plugins/admin/api.ts +++ b/public/app/features/plugins/admin/api.ts @@ -21,9 +21,16 @@ export async function getPluginDetails(id: string): Promise=${dependencies?.grafanaVersion}` + : ''; return { - grafanaDependency: dependencies?.grafanaDependency || dependencies?.grafanaVersion || '', + grafanaDependency, pluginDependencies: dependencies?.plugins || [], links: remote?.json?.info.links || local?.info.links || [], readme: remote?.readme, diff --git a/public/app/features/plugins/admin/components/PluginDetailsHeaderDependencies.tsx b/public/app/features/plugins/admin/components/PluginDetailsHeaderDependencies.tsx index 84431c14305..045979a72ac 100644 --- a/public/app/features/plugins/admin/components/PluginDetailsHeaderDependencies.tsx +++ b/public/app/features/plugins/admin/components/PluginDetailsHeaderDependencies.tsx @@ -2,22 +2,13 @@ import React from 'react'; import { css } from '@emotion/css'; import { GrafanaTheme2 } from '@grafana/data'; import { useStyles2, Icon } from '@grafana/ui'; -import { CatalogPlugin } from '../types'; +import { CatalogPlugin, IconName } from '../types'; type Props = { plugin: CatalogPlugin; className?: string; }; -const PluginIconClassName: Record = { - datasource: 'gicon gicon-datasources', - panel: 'icon-gf icon-gf-panel', - app: 'icon-gf icon-gf-apps', - page: 'icon-gf icon-gf-endpoint-tiny', - dashboard: 'gicon gicon-dashboard', - default: 'icon-gf icon-gf-apps', -}; - export function PluginDetailsHeaderDependencies({ plugin, className }: Props): React.ReactElement | null { const styles = useStyles2(getStyles); const pluginDependencies = plugin.details?.pluginDependencies; @@ -30,12 +21,12 @@ export function PluginDetailsHeaderDependencies({ plugin, className }: Props): R return (
-
Dependencies:
+
Dependencies:
{/* Grafana dependency */} {Boolean(grafanaDependency) && (
- + Grafana {grafanaDependency}
)} @@ -46,7 +37,7 @@ export function PluginDetailsHeaderDependencies({ plugin, className }: Props): R {pluginDependencies.map((p) => { return ( - + {p.name} {p.version} ); @@ -59,8 +50,18 @@ export function PluginDetailsHeaderDependencies({ plugin, className }: Props): R export const getStyles = (theme: GrafanaTheme2) => { return { - textBold: css` + dependencyTitle: css` font-weight: ${theme.typography.fontWeightBold}; + margin-right: ${theme.spacing(0.5)}; + + &::after { + content: ''; + padding: 0; + } + `, + icon: css` + color: ${theme.colors.text.secondary}; + margin-right: ${theme.spacing(0.5)}; `, }; }; diff --git a/public/app/features/plugins/admin/components/PluginListCard.tsx b/public/app/features/plugins/admin/components/PluginListCard.tsx index 0ef2c218f8d..5f3ce47c441 100644 --- a/public/app/features/plugins/admin/components/PluginListCard.tsx +++ b/public/app/features/plugins/admin/components/PluginListCard.tsx @@ -1,31 +1,23 @@ import React from 'react'; import { css } from '@emotion/css'; -import { Icon, useStyles2, CardContainer, VerticalGroup } from '@grafana/ui'; +import { Icon, useStyles2, CardContainer, HorizontalGroup, VerticalGroup, Tooltip } from '@grafana/ui'; import { GrafanaTheme2 } from '@grafana/data'; -import { CatalogPlugin } from '../types'; +import { CatalogPlugin, IconName } from '../types'; import { PluginLogo } from './PluginLogo'; import { PluginListBadges } from './PluginListBadges'; const LOGO_SIZE = '48px'; -enum IconName { - app = 'apps', - datasource = 'database', - panel = 'credit-card', - renderer = 'pen', -} - type PluginListCardProps = { plugin: CatalogPlugin; pathName: string; }; export function PluginListCard({ plugin, pathName }: PluginListCardProps) { - const { name, id, orgName, type } = plugin; const styles = useStyles2(getStyles); return ( - +
-

{name}

- {type && ( +

{plugin.name}

+ {plugin.type && (
- +
)}
-

By {orgName}

- +

By {plugin.orgName}

+ + + {plugin.hasUpdate && !plugin.isCore ? ( + +

Update available!

+
+ ) : null} +
); @@ -78,4 +77,9 @@ const getStyles = (theme: GrafanaTheme2) => ({ color: ${theme.colors.text.secondary}; margin-bottom: 0; `, + hasUpdate: css` + color: ${theme.colors.text.secondary}; + font-size: ${theme.typography.bodySmall.fontSize}; + margin-bottom: 0; + `, }); diff --git a/public/app/features/plugins/admin/types.ts b/public/app/features/plugins/admin/types.ts index c2bbebfb568..08e0aed2b4e 100644 --- a/public/app/features/plugins/admin/types.ts +++ b/public/app/features/plugins/admin/types.ts @@ -13,6 +13,13 @@ export enum PluginAdminRoutes { DetailsAdmin = 'plugins-details-admin', } +export enum IconName { + app = 'apps', + datasource = 'database', + panel = 'credit-card', + renderer = 'pen', +} + export interface CatalogPlugin { description: string; downloads: number;