|
| 1 | +import React from "react"; |
| 2 | +import { useParams, Link } from "react-router-dom"; |
| 3 | +import { TestVariation } from "../types"; |
| 4 | +import { testVariationService, staticService } from "../services"; |
| 5 | +import { |
| 6 | + Container, |
| 7 | + Box, |
| 8 | + Grid, |
| 9 | + Typography, |
| 10 | + Card, |
| 11 | + CardMedia, |
| 12 | + makeStyles, |
| 13 | + CardActions, |
| 14 | + Button, |
| 15 | +} from "@material-ui/core"; |
| 16 | +import { buildTestRunUrl } from "../_helpers/route.helpers"; |
| 17 | + |
| 18 | +const useStyles = makeStyles({ |
| 19 | + media: { |
| 20 | + height: 600, |
| 21 | + backgroundSize: "contain", |
| 22 | + }, |
| 23 | +}); |
| 24 | + |
| 25 | +const TestVariationDetailsPage: React.FunctionComponent = () => { |
| 26 | + const classes = useStyles(); |
| 27 | + const { testVariationId } = useParams(); |
| 28 | + const [testVariation, setTestVariation] = React.useState<TestVariation>(); |
| 29 | + |
| 30 | + React.useEffect(() => { |
| 31 | + if (testVariationId) { |
| 32 | + testVariationService.getDetails(testVariationId).then((item) => { |
| 33 | + setTestVariation(item); |
| 34 | + }); |
| 35 | + } |
| 36 | + }, [testVariationId]); |
| 37 | + |
| 38 | + return ( |
| 39 | + <React.Fragment> |
| 40 | + <Container> |
| 41 | + <Box mt={2}> |
| 42 | + {testVariation && ( |
| 43 | + <Grid container direction="column" spacing={2}> |
| 44 | + <Typography>{testVariation.name}</Typography> |
| 45 | + |
| 46 | + <Grid container spacing={2}> |
| 47 | + <Grid item> |
| 48 | + <Typography>OS: {testVariation.os}</Typography> |
| 49 | + </Grid> |
| 50 | + <Grid item> |
| 51 | + <Typography>Browser: {testVariation.browser}</Typography> |
| 52 | + </Grid> |
| 53 | + <Grid item> |
| 54 | + <Typography>Viewport: {testVariation.viewport}</Typography> |
| 55 | + </Grid> |
| 56 | + </Grid> |
| 57 | + {testVariation.baselines.map((baseline) => ( |
| 58 | + <Grid item key={baseline.id}> |
| 59 | + <Card> |
| 60 | + <CardActions> |
| 61 | + <Button |
| 62 | + color="primary" |
| 63 | + component={Link} |
| 64 | + to={buildTestRunUrl(testVariation, baseline.testRun)} |
| 65 | + > |
| 66 | + {baseline.createdAt} |
| 67 | + </Button> |
| 68 | + </CardActions> |
| 69 | + <CardMedia |
| 70 | + className={classes.media} |
| 71 | + image={staticService.getImage(baseline.baselineName)} |
| 72 | + /> |
| 73 | + </Card> |
| 74 | + </Grid> |
| 75 | + ))} |
| 76 | + </Grid> |
| 77 | + )} |
| 78 | + </Box> |
| 79 | + </Container> |
| 80 | + </React.Fragment> |
| 81 | + ); |
| 82 | +}; |
| 83 | + |
| 84 | +export default TestVariationDetailsPage; |
0 commit comments