import { ReactNode } from 'react'; import { Trans } from '@grafana/i18n'; import { IconName, Stack, Text, TextLink, Icon, Card, LinkButton } from '@grafana/ui'; import { Repository, ResourceCount } from 'app/api/clients/provisioning/v0alpha1'; import { StatusBadge } from '../Shared/StatusBadge'; import { PROVISIONING_URL } from '../constants'; import { DeleteRepositoryButton } from './DeleteRepositoryButton'; import { SyncRepository } from './SyncRepository'; interface Props { repository: Repository; } export function RepositoryCard({ repository }: Props) { const { metadata, spec, status } = repository; const name = metadata?.name ?? ''; const getRepositoryMeta = (): ReactNode[] => { const meta: ReactNode[] = []; if (spec?.type === 'github') { const { url = '', branch } = spec.github ?? {}; const branchUrl = branch ? `${url}/tree/${branch}` : url; meta.push( {branchUrl} ); if (status?.webhook?.id) { const webhookUrl = `${url}/settings/hooks/${status.webhook.id}`; meta.push( Webhook ); } } else if (spec?.type === 'local') { meta.push( {spec.local?.path ?? ''} ); } return meta; }; const getRepositoryIcon = (): IconName => { return spec?.type === 'github' ? 'github' : 'database'; }; return ( {spec?.title && {spec.title}} {spec?.description && {spec.description}} {status?.stats?.length && ( {status.stats.map((stat, index) => ( {stat.count} {stat.resource} ))} )} {getRepositoryMeta()} View Settings ); } // Helper function function getListURL(repo: Repository, stats: ResourceCount): string { if (stats.resource === 'playlists') { return '/playlists'; } if (repo.spec?.sync.target === 'folder') { return `/dashboards/f/${repo.metadata?.name}`; } return '/dashboards'; }