|
| 1 | +import { FC } from 'react' |
| 2 | +import { Trans, useTranslation } from 'react-i18next' |
| 3 | +import { styled } from '@mui/material/styles' |
| 4 | +import Box from '@mui/material/Box' |
| 5 | +import Card from '@mui/material/Card' |
| 6 | +import CardHeader from '@mui/material/CardHeader' |
| 7 | +import CardContent from '@mui/material/CardContent' |
| 8 | +import Grid from '@mui/material/Grid' |
| 9 | +import Link from '@mui/material/Link' |
| 10 | +import Typography from '@mui/material/Typography' |
| 11 | +import OpenInNewIcon from '@mui/icons-material/OpenInNew' |
| 12 | +import { RoflAppMetadata } from '../../../oasis-nexus/api' |
| 13 | +import { COLORS } from '../../../styles/theme/colors' |
| 14 | +import { EmptyStateCard } from './EmptyStateCard' |
| 15 | +import { GridRow } from './GridRow' |
| 16 | + |
| 17 | +export const StyledLink = styled(Link)(() => ({ |
| 18 | + display: 'inline-flex', |
| 19 | + alignItems: 'center', |
| 20 | + wordBreak: 'break-all', |
| 21 | + gap: 5, |
| 22 | +})) |
| 23 | + |
| 24 | +type MetaDataCardProps = { |
| 25 | + isFetched: boolean |
| 26 | + metadata: RoflAppMetadata | undefined |
| 27 | +} |
| 28 | + |
| 29 | +// Nexus is not parsing ROFL app metadata, but we can expect props with net.oasis.rofl prefix |
| 30 | +// and object to be similar to this: |
| 31 | +// https://github.com/oasisprotocol/cli/blob/bb1a57c13ce7bed635e5ce4306cba8ec33c9a651/build/rofl/manifest.go#L185 |
| 32 | + |
| 33 | +export const MetaDataCard: FC<MetaDataCardProps> = ({ isFetched, metadata }) => { |
| 34 | + const { t } = useTranslation() |
| 35 | + |
| 36 | + return ( |
| 37 | + <Card sx={{ flex: 1 }}> |
| 38 | + <CardHeader |
| 39 | + titleTypographyProps={{ variant: 'h1' }} |
| 40 | + disableTypography |
| 41 | + component="h3" |
| 42 | + title={ |
| 43 | + <Box sx={{ display: 'flex', alignItems: 'center', gap: 5 }}> |
| 44 | + <Box sx={{ flex: 1, whiteSpace: 'nowrap' }}>{t('rofl.metadata')}</Box> |
| 45 | + <Typography component="span" sx={{ fontSize: '12px', color: COLORS.grayDark }}> |
| 46 | + {t('rofl.metadataInfo')} |
| 47 | + </Typography> |
| 48 | + </Box> |
| 49 | + } |
| 50 | + /> |
| 51 | + <CardContent> |
| 52 | + {isFetched && !metadata && <EmptyStateCard />} |
| 53 | + {metadata && ( |
| 54 | + <> |
| 55 | + <Grid container spacing={4}> |
| 56 | + <GridRow label={t('rofl.roflName')}>{metadata['net.oasis.rofl.name']}</GridRow> |
| 57 | + <GridRow label={t('rofl.description')}>{metadata['net.oasis.rofl.description']}</GridRow> |
| 58 | + <GridRow label={t('rofl.author')}>{metadata['net.oasis.rofl.author']}</GridRow> |
| 59 | + <GridRow label={t('rofl.license')}>{metadata['net.oasis.rofl.license']}</GridRow> |
| 60 | + <GridRow |
| 61 | + label={t('rofl.repositoryUrl')} |
| 62 | + tooltip={ |
| 63 | + <Trans |
| 64 | + i18nKey="rofl.verifyCommand" |
| 65 | + t={t} |
| 66 | + components={{ |
| 67 | + Command: ( |
| 68 | + <Typography variant="mono" component="span"> |
| 69 | + oasis rofl build --verify |
| 70 | + </Typography> |
| 71 | + ), |
| 72 | + }} |
| 73 | + /> |
| 74 | + } |
| 75 | + > |
| 76 | + {metadata['net.oasis.rofl.repository'] ? ( |
| 77 | + <StyledLink |
| 78 | + href={metadata['net.oasis.rofl.repository']} |
| 79 | + rel="noopener noreferrer" |
| 80 | + target="_blank" |
| 81 | + > |
| 82 | + {metadata['net.oasis.rofl.repository']} <OpenInNewIcon sx={{ fontSize: 20 }} /> |
| 83 | + </StyledLink> |
| 84 | + ) : undefined} |
| 85 | + </GridRow> |
| 86 | + </Grid> |
| 87 | + </> |
| 88 | + )} |
| 89 | + </CardContent> |
| 90 | + </Card> |
| 91 | + ) |
| 92 | +} |
0 commit comments