Skip to content

Commit 5d3acb6

Browse files
Marcell Tothmpodlasin
andauthored
feat: special treatment for top level rows (#135)
* feat: flatten top level objects * feat: perfect caret alignment Caret is now exactly in line with the left side of the component / the row above. * feat: increase nesting offset To match Figma design more closely * feat: special handling for top level arrays * fix: indentation * fix: indentation * fix: perfect caret alignment * feat: top level schema picker * fix: type error * test: update snapshots * fix: font sizes * chore: update snapshots * chore: remove unused TypeSelector.tsx Co-authored-by: Mateusz Podlasin <[email protected]>
1 parent a22e20f commit 5d3acb6

File tree

13 files changed

+1481
-1193
lines changed

13 files changed

+1481
-1193
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
"type": [
3+
"array"
4+
],
5+
"items":{
6+
"title": "User",
7+
"type": "object",
8+
"properties": {
9+
"name": {
10+
"type": "string",
11+
"const": "Constant name",
12+
"examples": ["Example name", "Different name"],
13+
"description": "The user's full name. This description can be long and should truncate once it reaches the end of the row. If it's not truncating then theres and issue that needs to be fixed. Help!"
14+
},
15+
"age": {
16+
"type": "number",
17+
"minimum": 10,
18+
"maximum": 40,
19+
"multipleOf": 10,
20+
"default": 20,
21+
"enum": [10, 20, 30, 40],
22+
"readOnly": true
23+
},
24+
"completed_at": {
25+
"type": "string",
26+
"format": "date-time",
27+
"writeOnly": true,
28+
"pattern": "^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$"
29+
},
30+
"items": {
31+
"type": ["null", "array"],
32+
"items": {
33+
"type": ["string", "number"]
34+
},
35+
"minItems": 1,
36+
"maxItems": 4,
37+
"description": "This description can be long and should truncate once it reaches the end of the row. If it's not truncating then theres and issue that needs to be fixed. Help!"
38+
},
39+
"email": {
40+
"type": "string",
41+
"format": "email",
42+
43+
"deprecated": true,
44+
"default": "[email protected]",
45+
"minLength": 2
46+
},
47+
"plan": {
48+
"anyOf": [
49+
{
50+
"type": "object",
51+
"properties": {
52+
"foo": {
53+
"type": "string"
54+
},
55+
"bar": {
56+
"type": "string"
57+
}
58+
},
59+
"deprecated": false,
60+
"example": "hi",
61+
"required": ["foo", "bar"]
62+
},
63+
{
64+
"type": "array",
65+
"items": {
66+
"type": "integer"
67+
}
68+
}
69+
]
70+
},
71+
"permissions": {
72+
"type": ["string", "object"],
73+
"properties": {
74+
"ids": {
75+
"type": "array",
76+
"items": {
77+
"type": "integer"
78+
}
79+
}
80+
}
81+
},
82+
"ref": {
83+
"$ref": "#/properties/permissions"
84+
}
85+
},
86+
"patternProperties": {
87+
"^id_": { "type": "number" },
88+
"foo": { "type": "integer" },
89+
"_name$": { "type": "string" }
90+
},
91+
"required": ["name", "age", "completed_at"]
92+
}
93+
94+
}

src/__stories__/JsonSchemaViewer.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const nullRefSchema = require('../__fixtures__/references/nullish.json');
1616
const brokenRefArraySchema = require('../__fixtures__/arrays/of-refs.json');
1717
const oneOfWithArraySchema = require('../__fixtures__/combiners/oneof-with-array-type.json');
1818
const oneOfWithArraySchema2 = require('../__fixtures__/combiners/oneof-within-array-item.json');
19+
const arrayOfComplexObjects = require('../__fixtures__/arrays/of-complex-objects.json');
1920

2021
subscribeTheme({ mode: 'light' });
2122

@@ -64,6 +65,13 @@ storiesOf('JsonSchemaViewer', module)
6465
/>
6566
);
6667
})
68+
.add('array of objects', () => (
69+
<JsonSchemaViewer
70+
schema={arrayOfComplexObjects as JSONSchema4}
71+
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
72+
onGoToRef={action('onGoToRef')}
73+
/>
74+
))
6775
.add('stress-test schema', () => (
6876
<JsonSchemaViewer
6977
schema={stressSchema as JSONSchema4}

src/__stories__/_styles.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@
33

44
.JsonSchemaViewer {
55
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', system-ui, sans-serif,
6-
'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';}
6+
'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
7+
border: 1px dotted #bbb; // to visualize component boundaries
8+
}
9+
10+
#root > div > div > div {
11+
background-color: #f8f8fb; // to visualize component boundaries
12+
}

0 commit comments

Comments
 (0)