Skip to content

Commit 97cb6f1

Browse files
authored
Merge pull request #306 from open-rpc/feat/json-schema-to-react-tree
feat: add json schema to react tree to better visualize json schema
2 parents ada511d + 699472e commit 97cb6f1

File tree

9 files changed

+881
-156
lines changed

9 files changed

+881
-156
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
build
33
coverage
4+
*.tgz

jest.config.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@ module.exports = {
66
"rootDir": "./src",
77
"testEnvironment": "jsdom",
88
"testPathIgnorePatterns": ["./build"],
9-
"preset": "ts-jest"
10-
}
9+
"preset": "ts-jest",
10+
"moduleNameMapper": {
11+
"\\.(css|less|sass|scss)$": "jest-transform-css"
12+
}
13+
}

package-lock.json

+842-135
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55
"main": "build/index.js",
66
"scripts": {
77
"lint": "tslint --fix -p .",
8-
"build": "tsc",
8+
"build": "tsc && cp src/ContentDescriptor/ContentDescriptor.css build/ContentDescriptor/",
99
"test": "npm run lint && jest --coverage"
1010
},
1111
"author": "",
1212
"license": "Apache-2.0",
1313
"dependencies": {
14-
"@material-ui/core": "^4.7.1",
15-
"@material-ui/icons": "^4.5.1",
14+
"@material-ui/core": "^4.9.8",
15+
"@material-ui/icons": "^4.9.1",
16+
"@material-ui/lab": "^4.0.0-alpha.47",
1617
"@material-ui/styles": "^4.7.1",
1718
"@open-rpc/examples": "^1.3.3",
19+
"@xops.net/json-schema-to-react-tree": "^1.0.2",
1820
"hash-color-material": "^1.1.3",
21+
"jest-transform-css": "^2.0.0",
1922
"json-schema": "^0.2.3",
2023
"lodash": "^4.17.15",
2124
"react": "^16.12.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.MuiExpansionPanelSummary-expandIcon.Mui-expanded {
2+
transform: rotate(0deg) !important;
3+
}
4+
.MuiExpansionPanelSummary-expandIcon {
5+
order: -1;
6+
transform: rotate(-90deg) !important;
7+
margin-right: 0px !important;
8+
}
9+
10+
.MuiExpansionPanelSummary-content {
11+
align-items: center;
12+
}
13+
14+
.MuiExpansionPanelSummary-root {
15+
padding: 0 24px 0 0px !important;
16+
}

src/ContentDescriptor/ContentDescriptor.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import ExpansionPanelDetails from "@material-ui/core/ExpansionPanelDetails";
66
import JSONSchema from "../JSONSchema/JSONSchema";
77
import ExpandMoreIcon from "@material-ui/icons/ExpandMore";
88
import ReactMarkdown from "react-markdown";
9+
import JSONSchemaTree from "@xops.net/json-schema-to-react-tree";
910
import { ContentDescriptorObject } from "@open-rpc/meta-schema";
11+
import "./ContentDescriptor.css";
1012

1113
const styles = (theme: Theme) => ({
1214
description: {
@@ -47,7 +49,7 @@ class ContentDescriptor extends Component<IProps> {
4749
<ExpansionPanelSummary
4850
expandIcon={(!contentDescriptor.name || hideIcon) ? null : <ExpandMoreIcon />}
4951
style={{ justifyContent: "space-between" }}>
50-
<div style={{ display: "flex", justifyContent: "space-between", width: "100%", height: "100%" }}>
52+
<div style={{ display: "flex", justifyContent: "space-between", width: "100%", height: "100%", alignItems: "center" }}>
5153
<Typography className={classes.heading}>{contentDescriptor.name}</Typography>
5254
<Typography className={classes.secondaryHeading}>{contentDescriptor.summary}</Typography>
5355
{hideRequired ? null : <Typography className={classes.secondaryHeading}>
@@ -63,7 +65,7 @@ class ContentDescriptor extends Component<IProps> {
6365
{contentDescriptor.schema &&
6466
<>
6567
<Typography variant="body1" color="primary">schema</Typography>
66-
<JSONSchema schema={contentDescriptor.schema} />
68+
<JSONSchemaTree schema={contentDescriptor.schema} />
6769
</>
6870
}
6971
</>

src/Methods/Methods.test.tsx

+2-7
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,7 @@ it("renders schema methods result", () => {
201201
],
202202
};
203203
ReactDOM.render(<Methods schema={schema as any} disableTransitionProps={true} />, div);
204-
expect(div.innerHTML.includes("name")).toBe(true);
205-
expect(div.innerHTML.includes("tag")).toBe(true);
206-
expect(div.innerHTML.includes("id")).toBe(true);
204+
expect(div.innerHTML.includes("Object")).toBe(true);
207205
ReactDOM.unmountComponentAtNode(div);
208206
});
209207

@@ -273,9 +271,6 @@ it("renders schema methods tags", () => {
273271
],
274272
};
275273
ReactDOM.render(<Methods schema={schema as any} disableTransitionProps={true} />, div);
276-
expect(div.innerHTML.includes("tag3")).toBe(true);
277-
expect(div.innerHTML.includes("tag4")).toBe(true);
278-
expect(div.innerHTML.includes("salad")).toBe(true);
279-
expect(div.innerHTML.includes("mytag")).toBe(true);
274+
expect(div.innerHTML.includes("Object")).toBe(true);
280275
ReactDOM.unmountComponentAtNode(div);
281276
});

src/Params/Params.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const styles = (theme: Theme) => ({
1616
padding: theme.spacing(2),
1717
},
1818
tableEnd: {
19-
paddingRight: `${theme.spacing(20)}px !important`,
19+
paddingLeft: theme.spacing(3),
2020
},
2121
tableStart: {
2222
paddingLeft: theme.spacing(3),

src/Servers/Servers.tsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import TableCell from "@material-ui/core/TableCell";
44
import TableRow from "@material-ui/core/TableRow";
55
import ReactMarkdown from "react-markdown";
66
import ExpandMoreIcon from "@material-ui/icons/ExpandMore";
7-
import { Typography, ExpansionPanelSummary, ExpansionPanelDetails, ExpansionPanel } from "@material-ui/core";
7+
import { Typography, ExpansionPanelSummary, ExpansionPanelDetails, ExpansionPanel, Grid } from "@material-ui/core";
88
import { ServerObject } from "@open-rpc/meta-schema";
99
import ReactJson from "react-json-view";
1010
import ExpansionTable from "../ExpansionTable/ExpansionTable";
@@ -54,11 +54,9 @@ class Servers extends Component<IProps> {
5454
defaultExpanded={uiSchema && uiSchema.servers["ui:defaultExpanded"]} key={i}>
5555
<ExpansionPanelSummary
5656
style={{ justifyContent: "space-between" }} key="servers-header" expandIcon={<ExpandMoreIcon />}>
57-
<div style={{ display: "flex", justifyContent: "space-between", width: "100%", height: "100%" }}>
58-
<Typography className={classes.heading}>{server.name}</Typography>
59-
<Typography className={classes.secondaryHeading}>{server.url}</Typography>
60-
<Typography className={classes.secondaryHeading}>{server.summary}</Typography>
61-
</div>
57+
<Typography className={classes.heading}>{server.name}</Typography>
58+
<Typography className={classes.secondaryHeading}>{server.url}</Typography>
59+
<Typography className={classes.secondaryHeading}>{server.summary}</Typography>
6260
</ExpansionPanelSummary>
6361
<ExpansionPanelDetails style={{ display: "block" }} key="servers-body">
6462
{server.description &&

0 commit comments

Comments
 (0)