import { useMemo, useState } from 'react'; import { CellProps, Column, FilterInput, InteractiveTable, Link, LinkButton, Spinner, Stack } from '@grafana/ui'; import { Repository, ResourceListItem, useGetRepositoryResourcesQuery } from 'app/api/clients/provisioning'; import { PROVISIONING_URL } from '../constants'; interface RepoProps { repo: Repository; } type ResourceCell = CellProps< ResourceListItem, ResourceListItem[T] >; export function RepositoryResources({ repo }: RepoProps) { const name = repo.metadata?.name ?? ''; const query = useGetRepositoryResourcesQuery({ name }); const [searchQuery, setSearchQuery] = useState(''); const data = (query.data?.items ?? []).filter((Resource) => Resource.path.toLowerCase().includes(searchQuery.toLowerCase()) ); const columns: Array> = useMemo( () => [ { id: 'title', header: 'Title', sortType: 'string', cell: ({ row: { original } }: ResourceCell<'title'>) => { const { resource, name, title } = original; if (resource === 'dashboards') { return {title}; } if (resource === 'folders') { return {title}; } return {title}; }, }, { id: 'resource', header: 'Type', sortType: 'string', cell: ({ row: { original } }: ResourceCell<'resource'>) => { return {original.resource}; }, }, { id: 'path', header: 'Path', sortType: 'string', cell: ({ row: { original } }: ResourceCell<'path'>) => { const { resource, name, path } = original; if (resource === 'dashboards') { return {path}; } return {path}; }, }, { id: 'hash', header: 'Hash', sortType: 'string', cell: ({ row: { original } }: ResourceCell<'hash'>) => { const { hash } = original; return {hash.substring(0, 7)}; }, }, { id: 'folder', header: 'Folder', sortType: 'string', cell: ({ row: { original } }: ResourceCell<'title'>) => { const { folder } = original; if (folder?.length) { return {folder}; } return ; }, }, { id: 'actions', header: '', cell: ({ row: { original } }: ResourceCell) => { const { resource, name, path } = original; return ( {resource === 'dashboards' && View} {resource === 'folders' && View} History ); }, }, ], [repo.metadata?.name] ); if (query.isLoading) { return ( ); } return ( String(r.path)} /> ); }