|
1 | 1 | import React, { Component } from "react"; |
2 | | -import { withStyles } from "@material-ui/core/styles"; |
3 | | -import Link from "@material-ui/core/Link"; |
4 | | -import Table from "@material-ui/core/Table"; |
5 | | -import TableBody from "@material-ui/core/TableBody"; |
| 2 | +import { withStyles, WithStyles, Theme } from "@material-ui/core/styles"; |
6 | 3 | import TableCell from "@material-ui/core/TableCell"; |
7 | | -import TableHead from "@material-ui/core/TableHead"; |
8 | 4 | import TableRow from "@material-ui/core/TableRow"; |
9 | | -import { Typography } from "@material-ui/core"; |
| 5 | +import ReactMarkdown from "react-markdown"; |
| 6 | +import ExpandMoreIcon from "@material-ui/icons/ExpandMore"; |
| 7 | +import { Typography, ExpansionPanelSummary, ExpansionPanelDetails, ExpansionPanel } from "@material-ui/core"; |
10 | 8 | import { types } from "@open-rpc/meta-schema"; |
| 9 | +import ReactJson from "react-json-view"; |
| 10 | +import ExpansionTable from "../ExpansionTable/ExpansionTable"; |
11 | 11 |
|
12 | | -interface IProps { |
| 12 | +const styles = (theme: Theme) => ({ |
| 13 | + heading: { |
| 14 | + flexBasis: "33.33%", |
| 15 | + flexShrink: 0, |
| 16 | + fontSize: theme.typography.pxToRem(15), |
| 17 | + }, |
| 18 | + paramsMargin: { |
| 19 | + marginTop: theme.spacing.unit, |
| 20 | + }, |
| 21 | + secondaryHeading: { |
| 22 | + alignSelf: "end", |
| 23 | + color: theme.palette.text.secondary, |
| 24 | + fontSize: theme.typography.pxToRem(15), |
| 25 | + }, |
| 26 | +}); |
| 27 | + |
| 28 | +interface IProps extends WithStyles<typeof styles> { |
13 | 29 | servers?: types.ServerObject[]; |
| 30 | + uiSchema?: any; |
| 31 | + reactJsonOptions?: any; |
14 | 32 | noTitle?: boolean; |
15 | 33 | } |
16 | 34 |
|
17 | 35 | class Servers extends Component<IProps> { |
18 | 36 | public render() { |
19 | | - const { servers, noTitle } = this.props; |
| 37 | + const { servers, noTitle, reactJsonOptions, uiSchema, classes } = this.props; |
20 | 38 | if (!servers || servers.length === 0) { |
21 | 39 | return null; |
22 | 40 | } |
23 | 41 | return ( |
24 | 42 | <> |
25 | 43 | {noTitle ? null : <Typography variant="h2">Servers</Typography>} |
26 | | - <Table> |
27 | | - <TableHead> |
28 | | - <TableRow> |
29 | | - <TableCell>Name</TableCell> |
30 | | - <TableCell align="right">Url</TableCell> |
31 | | - <TableCell align="right">Description</TableCell> |
32 | | - </TableRow> |
33 | | - </TableHead> |
34 | | - <TableBody> |
35 | | - {servers.map((server) => ( |
36 | | - <TableRow key={server.url}> |
37 | | - <TableCell component="th" scope="row"> |
38 | | - {server.name} |
39 | | - </TableCell> |
40 | | - <TableCell align="right"><Link href={server.url}>{server.url}</Link></TableCell> |
41 | | - <TableCell align="right">{server.description}</TableCell> |
42 | | - </TableRow> |
43 | | - ))} |
44 | | - </TableBody> |
45 | | - </Table> |
| 44 | + <ExpansionTable headers={["Name", "Url", "Summary"]}> |
| 45 | + <TableRow> |
| 46 | + <TableCell colSpan={6}> |
| 47 | + {servers.map((server, i) => ( |
| 48 | + <div style={{ width: "100%" }} key={i}> |
| 49 | + <ExpansionPanel |
| 50 | + style={{ width: "100%" }} |
| 51 | + defaultExpanded={uiSchema && uiSchema.servers["ui:defaultExpanded"]} key={i}> |
| 52 | + <ExpansionPanelSummary |
| 53 | + style={{ justifyContent: "space-between" }} key="servers-header" expandIcon={<ExpandMoreIcon />}> |
| 54 | + <div style={{ display: "flex", justifyContent: "space-between", width: "100%", height: "100%" }}> |
| 55 | + <Typography className={classes.heading}>{server.name}</Typography> |
| 56 | + <Typography className={classes.secondaryHeading}>{server.url}</Typography> |
| 57 | + <Typography className={classes.secondaryHeading}>{server.summary}</Typography> |
| 58 | + </div> |
| 59 | + </ExpansionPanelSummary> |
| 60 | + <ExpansionPanelDetails style={{ display: "block" }} key="servers-body"> |
| 61 | + {server.description && <ReactMarkdown source={server.description} />} |
| 62 | + {server.variables && |
| 63 | + <Typography variant="h6" gutterBottom className={classes.paramsMargin}>Variables</Typography>} |
| 64 | + {server.variables && <ReactJson src={server.variables} {...reactJsonOptions} />} |
| 65 | + </ExpansionPanelDetails> |
| 66 | + </ExpansionPanel> |
| 67 | + </div> |
| 68 | + ))} |
| 69 | + </TableCell> |
| 70 | + </TableRow> |
| 71 | + </ExpansionTable> |
46 | 72 | </> |
47 | 73 | ); |
48 | 74 | } |
49 | 75 | } |
50 | 76 |
|
51 | | -export default Servers; |
| 77 | +export default withStyles(styles)(Servers); |
0 commit comments