|
| 1 | +import { type FC } from 'react' |
| 2 | +import { Link } from 'react-router-dom' |
| 3 | +import { useGetRuntimeRoflmarketInstances, type RoflApp } from '../../nexus/api' |
| 4 | +import { Button } from '@oasisprotocol/ui-library/src/components/ui/button' |
| 5 | +import { useAccount } from 'wagmi' |
| 6 | +import { hasViewLogsPermission } from '../../utils/hasViewLogsPermission' |
| 7 | +import { isMachineRemoved } from '../MachineStatusIcon/isMachineRemoved' |
| 8 | + |
| 9 | +type ViewWithOnlyLogsPermissionProps = { |
| 10 | + app: RoflApp |
| 11 | + network: 'mainnet' | 'testnet' |
| 12 | +} |
| 13 | + |
| 14 | +export const ViewWithOnlyLogsPermission: FC<ViewWithOnlyLogsPermissionProps> = ({ app, network }) => { |
| 15 | + const { address } = useAccount() |
| 16 | + const machinesQuery = useGetRuntimeRoflmarketInstances(network, 'sapphire', { |
| 17 | + limit: 100, |
| 18 | + offset: 0, |
| 19 | + deployed_app_id: app.id, |
| 20 | + }) |
| 21 | + const machinesWithOnlyLogsPermission = |
| 22 | + address && machinesQuery.data?.data.instances |
| 23 | + ? machinesQuery.data.data.instances |
| 24 | + .filter(machine => !isMachineRemoved(machine)) |
| 25 | + .filter(machine => hasViewLogsPermission(machine, address)) |
| 26 | + : [] |
| 27 | + |
| 28 | + if (machinesWithOnlyLogsPermission.length <= 0) return |
| 29 | + return ( |
| 30 | + <div className="flex flex-col gap-2"> |
| 31 | + {machinesWithOnlyLogsPermission.map(machine => ( |
| 32 | + <Button key={machine.id} variant="default" asChild> |
| 33 | + {/* TODO: Link to logs subpage. But shadcn does not support routed tabs nicely. */} |
| 34 | + <Link to={`/dashboard/machines/${machine.provider}/instances/${machine.id}`}>View logs</Link> |
| 35 | + </Button> |
| 36 | + ))} |
| 37 | + </div> |
| 38 | + ) |
| 39 | +} |
0 commit comments