import { css } from '@emotion/css'; import { useMemo } from 'react'; import { Trans, t } from '@grafana/i18n'; import { Box, Card, CellProps, Grid, InteractiveTable, LinkButton, Stack, Text, useStyles2 } from '@grafana/ui'; import { Repository, ResourceCount } from 'app/api/clients/provisioning/v0alpha1'; import { RecentJobs } from '../Job/RecentJobs'; import { formatTimestamp } from '../utils/time'; import { CheckRepository } from './CheckRepository'; import { RepositoryHealth } from './RepositoryHealth'; import { SyncRepository } from './SyncRepository'; type StatCell = CellProps; function getColumnCount(hasWebhook: boolean): 3 | 4 { return hasWebhook ? 4 : 3; } export function RepositoryOverview({ repo }: { repo: Repository }) { const styles = useStyles2(getStyles); const status = repo.status; const webhookURL = getWebhookURL(repo); const columns = getColumnCount(Boolean(repo.status?.webhook)); const resourceColumns = useMemo( () => [ { id: 'Resource', header: 'Resource Type', cell: ({ row: { original } }: StatCell<'resource'>) => { return {original.resource}; }, size: 'auto', }, { id: 'count', header: 'Count', cell: ({ row: { original } }: StatCell<'count'>) => { return {original.count}; }, size: 100, }, ], [] ); return (
Resources {repo.status?.stats ? ( `${r.group}-${r.resource}`} /> ) : null} View Folder
{repo.status?.health && (
Health
Status:
{status?.health?.healthy ? t('provisioning.repository-overview.healthy', 'Healthy') : t('provisioning.repository-overview.unhealthy', 'Unhealthy')}
Checked:
{formatTimestamp(status?.health?.checked)}
{!!status?.health?.message?.length && ( <>
Messages:
{status.health.message.map((msg, idx) => ( {msg} ))}
)}
)}
Pull status
Status:
{status?.sync.state ?? 'N/A'}
Job ID:
{status?.sync.job ?? 'N/A'}
Last Ref:
{status?.sync.lastRef ? status.sync.lastRef.substring(0, 7) : t('provisioning.repository-overview.not-available', 'N/A')}
Started:
{formatTimestamp(status?.sync.started)}
Finished:
{formatTimestamp(status?.sync.finished)}
{!!status?.sync?.message?.length && ( <>
Messages:
{status.sync.message.map((msg, idx) => ( {msg} ))}
)}
{repo.status?.webhook && (
Webhook
ID:
{status?.webhook?.id ?? 'N/A'}
Events:
{status?.webhook?.subscribedEvents?.join(', ') ?? 'N/A'}
Last Event:
{formatTimestamp(status?.webhook?.lastEvent)}
{webhookURL && ( View Webhook )}
)}
); } function getFolderURL(repo: Repository) { if (repo.spec?.sync.target === 'folder') { return `/dashboards/f/${repo.metadata?.name}`; } return '/dashboards'; } const getStyles = () => { return { cardContainer: css({ height: '100%', }), card: css({ height: '100%', display: 'flex', flexDirection: 'column', }), actions: css({ marginTop: 'auto', }), labelColumn: css({ gridColumn: 'span 3', }), valueColumn: css({ gridColumn: 'span 9', }), }; }; function getWebhookURL(repo: Repository) { const { status, spec } = repo; if (spec?.type === 'github' && status?.webhook?.url && spec.github?.url) { return `${spec.github.url}/settings/hooks/${status.webhook?.id}`; } return undefined; }