@stoplight/elements-dev-portal 3.0.11 → 3.0.12-beta-0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/.storybook/main.js +6 -0
  2. package/.storybook/manager.js +1 -0
  3. package/.storybook/preview.jsx +46 -0
  4. package/dist/LICENSE +190 -0
  5. package/dist/README.md +22 -0
  6. package/{index.esm.js → dist/index.esm.js} +8 -2
  7. package/{index.js → dist/index.js} +8 -2
  8. package/{index.mjs → dist/index.mjs} +8 -2
  9. package/dist/package.json +51 -0
  10. package/dist/version.d.ts +1 -0
  11. package/{web-components.min.js → dist/web-components.min.js} +1 -1
  12. package/jest.config.js +10 -0
  13. package/package.json +71 -17
  14. package/src/__fixtures__/branches.json +28 -0
  15. package/src/__fixtures__/node-content.json +257 -0
  16. package/src/__fixtures__/table-of-contents.json +144 -0
  17. package/src/components/BranchSelector/BranchSelector.spec.tsx +61 -0
  18. package/src/components/BranchSelector/BranchSelector.stories.tsx +41 -0
  19. package/src/components/BranchSelector/BranchSelector.tsx +50 -0
  20. package/src/components/BranchSelector/index.tsx +1 -0
  21. package/src/components/DevPortalProvider/index.tsx +25 -0
  22. package/src/components/Forbidden.tsx +11 -0
  23. package/src/components/Loading.tsx +9 -0
  24. package/src/components/NodeContent/NodeContent.spec.tsx +128 -0
  25. package/src/components/NodeContent/NodeContent.stories.tsx +60 -0
  26. package/src/components/NodeContent/NodeContent.tsx +235 -0
  27. package/src/components/NodeContent/index.tsx +1 -0
  28. package/src/components/NotFound.tsx +11 -0
  29. package/src/components/Search/Search.stories.tsx +151 -0
  30. package/src/components/Search/Search.tsx +161 -0
  31. package/src/components/Search/SearchOverlay.tsx +88 -0
  32. package/src/components/Search/index.tsx +1 -0
  33. package/src/components/TableOfContents/TableOfContents.stories.tsx +68 -0
  34. package/src/components/TableOfContents/TableOfContents.tsx +54 -0
  35. package/src/components/TableOfContents/index.tsx +1 -0
  36. package/src/components/UpgradeToStarter.tsx +22 -0
  37. package/src/consts.ts +32 -0
  38. package/src/containers/StoplightProject.spec.tsx +78 -0
  39. package/src/containers/StoplightProject.stories.tsx +28 -0
  40. package/src/containers/StoplightProject.tsx +269 -0
  41. package/src/handlers/__tests__/getBranches.test.ts +30 -0
  42. package/src/handlers/__tests__/getNodeContent.test.ts +35 -0
  43. package/src/handlers/__tests__/getNodes.test.ts +38 -0
  44. package/src/handlers/__tests__/getTableOfContents.test.ts +34 -0
  45. package/src/handlers/__tests__/getWorkspace.test.ts +30 -0
  46. package/src/handlers/getBranches.ts +27 -0
  47. package/src/handlers/getNodeContent.ts +53 -0
  48. package/src/handlers/getNodes.ts +69 -0
  49. package/src/handlers/getTableOfContents.ts +30 -0
  50. package/src/handlers/getWorkspace.ts +27 -0
  51. package/src/hooks/__tests__/dataFetching.spec.tsx +42 -0
  52. package/src/hooks/useGetBranches.ts +17 -0
  53. package/src/hooks/useGetNodeContent.ts +24 -0
  54. package/src/hooks/useGetNodes.ts +34 -0
  55. package/src/hooks/useGetTableOfContents.ts +17 -0
  56. package/src/hooks/useGetWorkspace.tsx +13 -0
  57. package/src/index.ts +25 -0
  58. package/src/styles.css +1 -0
  59. package/src/types.ts +85 -0
  60. package/src/version.ts +2 -0
  61. package/src/web-components/__stories__/StoplightProject.stories.tsx +33 -0
  62. package/src/web-components/components.ts +19 -0
  63. package/src/web-components/index.ts +3 -0
  64. package/tsconfig.build.json +18 -0
  65. package/tsconfig.json +7 -0
  66. package/web-components.config.js +1 -0
  67. package/version.d.ts +0 -1
  68. /package/{components → dist/components}/BranchSelector/BranchSelector.d.ts +0 -0
  69. /package/{components → dist/components}/BranchSelector/BranchSelector.spec.d.ts +0 -0
  70. /package/{components → dist/components}/BranchSelector/BranchSelector.stories.d.ts +0 -0
  71. /package/{components → dist/components}/BranchSelector/index.d.ts +0 -0
  72. /package/{components → dist/components}/DevPortalProvider/index.d.ts +0 -0
  73. /package/{components → dist/components}/Forbidden.d.ts +0 -0
  74. /package/{components → dist/components}/Loading.d.ts +0 -0
  75. /package/{components → dist/components}/NodeContent/NodeContent.d.ts +0 -0
  76. /package/{components → dist/components}/NodeContent/NodeContent.spec.d.ts +0 -0
  77. /package/{components → dist/components}/NodeContent/NodeContent.stories.d.ts +0 -0
  78. /package/{components → dist/components}/NodeContent/index.d.ts +0 -0
  79. /package/{components → dist/components}/NotFound.d.ts +0 -0
  80. /package/{components → dist/components}/Search/Search.d.ts +0 -0
  81. /package/{components → dist/components}/Search/Search.stories.d.ts +0 -0
  82. /package/{components → dist/components}/Search/SearchOverlay.d.ts +0 -0
  83. /package/{components → dist/components}/Search/index.d.ts +0 -0
  84. /package/{components → dist/components}/TableOfContents/TableOfContents.d.ts +0 -0
  85. /package/{components → dist/components}/TableOfContents/TableOfContents.stories.d.ts +0 -0
  86. /package/{components → dist/components}/TableOfContents/index.d.ts +0 -0
  87. /package/{components → dist/components}/UpgradeToStarter.d.ts +0 -0
  88. /package/{consts.d.ts → dist/consts.d.ts} +0 -0
  89. /package/{containers → dist/containers}/StoplightProject.d.ts +0 -0
  90. /package/{containers → dist/containers}/StoplightProject.spec.d.ts +0 -0
  91. /package/{containers → dist/containers}/StoplightProject.stories.d.ts +0 -0
  92. /package/{handlers → dist/handlers}/getBranches.d.ts +0 -0
  93. /package/{handlers → dist/handlers}/getNodeContent.d.ts +0 -0
  94. /package/{handlers → dist/handlers}/getNodes.d.ts +0 -0
  95. /package/{handlers → dist/handlers}/getTableOfContents.d.ts +0 -0
  96. /package/{handlers → dist/handlers}/getWorkspace.d.ts +0 -0
  97. /package/{hooks → dist/hooks}/useGetBranches.d.ts +0 -0
  98. /package/{hooks → dist/hooks}/useGetNodeContent.d.ts +0 -0
  99. /package/{hooks → dist/hooks}/useGetNodes.d.ts +0 -0
  100. /package/{hooks → dist/hooks}/useGetTableOfContents.d.ts +0 -0
  101. /package/{hooks → dist/hooks}/useGetWorkspace.d.ts +0 -0
  102. /package/{index.d.ts → dist/index.d.ts} +0 -0
  103. /package/{styles.min.css → dist/styles.min.css} +0 -0
  104. /package/{types.d.ts → dist/types.d.ts} +0 -0
  105. /package/{web-components → dist/web-components}/components.d.ts +0 -0
  106. /package/{web-components → dist/web-components}/index.d.ts +0 -0
  107. /package/{web-components.min.js.LICENSE.txt → dist/web-components.min.js.LICENSE.txt} +0 -0
package/jest.config.js ADDED
@@ -0,0 +1,10 @@
1
+ module.exports = {
2
+ ...require('../../jest.config'),
3
+ reporters: [
4
+ 'default',
5
+ [
6
+ 'jest-junit',
7
+ { suiteName: 'elements-dev-portal', outputFile: '<rootDir>/../../test-results/elements-dev-portal/results.xml' },
8
+ ],
9
+ ],
10
+ };
package/package.json CHANGED
@@ -1,34 +1,72 @@
1
1
  {
2
2
  "name": "@stoplight/elements-dev-portal",
3
- "version": "3.0.11",
3
+ "version": "3.0.12-beta-0.2",
4
4
  "description": "UI components for composing beautiful developer documentation.",
5
5
  "keywords": [],
6
- "main": "./index.js",
7
6
  "sideEffects": [
8
7
  "web-components.min.js",
9
8
  "src/web-components/**",
10
9
  "**/*.css"
11
10
  ],
12
- "files": [
13
- "**/*"
14
- ],
11
+ "homepage": "https://github.com/stoplightio/elements",
12
+ "bugs": "https://github.com/stoplightio/elements/issues",
15
13
  "author": "Stoplight <support@stoplight.io>",
16
14
  "repository": {
17
15
  "type": "git",
18
16
  "url": "https://github.com/stoplightio/elements"
19
17
  },
20
18
  "license": "Apache-2.0",
19
+ "type": "commonjs",
20
+ "main": "./dist/index.js",
21
+ "module": "./dist/index.esm.js",
22
+ "exports": {
23
+ "./styles.min.css": "./styles.min.css",
24
+ "./web-components.min.js": "./web-components.min.js",
25
+ ".": {
26
+ "require": "./dist/index.js",
27
+ "import": "./dist/index.mjs"
28
+ }
29
+ },
30
+ "files": [
31
+ "**/*"
32
+ ],
21
33
  "engines": {
22
34
  "node": ">=16"
23
35
  },
36
+ "scripts": {
37
+ "build": "yarn version.set && yarn build.react && yarn build.webcomponents",
38
+ "postbuild": "yarn build.styles",
39
+ "build.react": "sl-scripts bundle",
40
+ "build.webcomponents": "node --max-old-space-size=4096 ./../../node_modules/webpack/bin/webpack.js -c ./web-components.config.js",
41
+ "build.docs": "storybook build -c .storybook -o dist-storybook",
42
+ "build.styles": "postcss src/styles.css -o dist/styles.min.css",
43
+ "version.set": "replace \"appVersion = '.*'\" \"appVersion = '$npm_package_version'\" src/version.ts --silent",
44
+ "commit": "git-cz",
45
+ "release": "sl-scripts release",
46
+ "release.docs": "sl-scripts release:docs",
47
+ "release.dryRun": "sl-scripts release --dry-run --debug",
48
+ "storybook": "yarn version.set && storybook dev -p 9001",
49
+ "test": "jest",
50
+ "test.prod": "yarn test --coverage --maxWorkers=2",
51
+ "test.update": "yarn test --updateSnapshot",
52
+ "test.watch": "yarn test --watch",
53
+ "test.packaging": "node --input-type=commonjs -e \"require('./dist/index.js')\" && node --input-type=module -e \"import './dist/index.mjs'\"",
54
+ "type-check": "tsc --noEmit"
55
+ },
24
56
  "peerDependencies": {
25
57
  "react": ">=16.8",
26
58
  "react-dom": ">=16.8"
27
59
  },
60
+ "rollup": {
61
+ "bundleDeps": [
62
+ "@fortawesome/free-solid-svg-icons",
63
+ "use-debounce"
64
+ ]
65
+ },
28
66
  "dependencies": {
29
- "@stoplight/elements-core": "~9.0.11",
30
67
  "@stoplight/markdown-viewer": "^5.7.1",
31
68
  "@stoplight/mosaic": "^1.53.5",
69
+ "@stoplight/elements-core": "9.0.12-beta-0.2",
32
70
  "@stoplight/path": "^1.3.2",
33
71
  "@stoplight/types": "^14.0.0",
34
72
  "classnames": "^2.2.6",
@@ -37,15 +75,31 @@
37
75
  "react-router-dom": "^6.28.0",
38
76
  "use-debounce": "^6.0.1"
39
77
  },
40
- "type": "commonjs",
41
- "exports": {
42
- "./styles.min.css": "./styles.min.css",
43
- "./web-components.min.js": "./web-components.min.js",
44
- ".": {
45
- "require": "./index.js",
46
- "import": "./index.mjs"
47
- }
78
+ "devDependencies": {
79
+ "@fortawesome/free-solid-svg-icons": "^6.1.1",
80
+ "@stoplight/scripts": "10.0.0",
81
+ "@testing-library/dom": "^7.26.5",
82
+ "@testing-library/jest-dom": "^5.16.4",
83
+ "@testing-library/react": "^11.1.1",
84
+ "@testing-library/react-hooks": "^8.0.1",
85
+ "@testing-library/user-event": "^12.2.0",
86
+ "@types/lodash": "4.17.7",
87
+ "@types/react": "16.9.56",
88
+ "@types/react-dom": "16.9.12",
89
+ "@types/react-router-dom": "^5.3.3",
90
+ "react": "16.14.0",
91
+ "react-dom": "16.14.0",
92
+ "react-test-renderer": "^16.8.0",
93
+ "replace": "^1.2.2",
94
+ "resolve-url-loader": "^5.0.0",
95
+ "storybook": "next",
96
+ "style-loader": "^3.3.3",
97
+ "ts-loader": "^9.2.8"
98
+ },
99
+ "publishConfig": {
100
+ "directory": "dist"
48
101
  },
49
- "typings": "index.d.ts",
50
- "module": "./index.esm.js"
51
- }
102
+ "release": {
103
+ "extends": "@stoplight/scripts/release"
104
+ }
105
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "items": [
3
+ {
4
+ "id": "YnI6NDc4MDUy",
5
+ "name": null,
6
+ "slug": "master",
7
+ "is_default": true,
8
+ "is_published": true,
9
+ "project_id": "cHJqOjM1ODEw"
10
+ },
11
+ {
12
+ "id": "YnI6OTYwNDM4",
13
+ "name": null,
14
+ "slug": "v2",
15
+ "is_default": false,
16
+ "is_published": true,
17
+ "project_id": "cHJqOjM1ODEw"
18
+ },
19
+ {
20
+ "id": "YnI6OTYwNDM5",
21
+ "name": null,
22
+ "slug": "feat/toc-file",
23
+ "is_default": false,
24
+ "is_published": true,
25
+ "project_id": "cHJqOjM1ODEw"
26
+ }
27
+ ]
28
+ }
@@ -0,0 +1,257 @@
1
+ {
2
+ "id": "b3A6Mzg5NDM2",
3
+ "branch_node_id": 21,
4
+ "type": "http_operation",
5
+ "uri": "/reference/todos/todo.v1.yaml/paths/~1todos/post",
6
+ "slug": "b3A6Mzg5NDM2-create-todo",
7
+ "title": "Create Todo",
8
+ "branch": "master",
9
+ "summary": "This creates a Todo object\n\n*Markdown is supported in descriptions. Add information here for users to get accustomed to endpoints*",
10
+ "project_id": "cHJqOjExOTY",
11
+ "branch_id": "YnI6MTAyODA",
12
+ "data": {
13
+ "id": "?http-operation-id?",
14
+ "iid": "post-todos",
15
+ "description": "This creates a Todo object\n\n*Markdown is supported in descriptions. Add information here for users to get accustomed to endpoints*",
16
+ "method": "post",
17
+ "path": "/todos",
18
+ "summary": "Create Todo",
19
+ "responses": [
20
+ {
21
+ "code": "201",
22
+ "description": "New Todo Created",
23
+ "headers": [],
24
+ "contents": [
25
+ {
26
+ "mediaType": "multipart/form-data",
27
+ "schema": {
28
+ "description": "I'm a model's description.",
29
+ "type": "object",
30
+ "x-examples": {},
31
+ "title": "Todo",
32
+ "properties": {
33
+ "id": {
34
+ "type": "number",
35
+ "minimum": 0,
36
+ "maximum": 9999,
37
+ "description": "ID of the task",
38
+ "readOnly": true
39
+ },
40
+ "name": { "type": "string", "minLength": 1, "maxLength": 100, "description": "Name of the task" },
41
+ "completed": {
42
+ "type": "boolean",
43
+ "default": false,
44
+ "description": "Boolean indicating if the task has been completed or not"
45
+ },
46
+ "completed_at": {
47
+ "type": "string",
48
+ "format": "date-time",
49
+ "description": "Time when the task was completed",
50
+ "readOnly": true
51
+ },
52
+ "created_at": {
53
+ "type": "string",
54
+ "format": "date-time",
55
+ "description": "Time when the task was created",
56
+ "readOnly": true
57
+ },
58
+ "updated_at": {
59
+ "type": "string",
60
+ "format": "date-time",
61
+ "description": "Time when the task was updated",
62
+ "readOnly": true
63
+ }
64
+ },
65
+ "required": ["id", "name", "completed_at", "created_at", "updated_at"],
66
+ "$schema": "http://json-schema.org/draft-07/schema#"
67
+ },
68
+ "examples": [
69
+ {
70
+ "key": "Example Todo",
71
+ "value": {
72
+ "id": 0,
73
+ "name": "string",
74
+ "completed": true,
75
+ "completed_at": "2019-08-24T14:15:22Z",
76
+ "created_at": "2019-08-24T14:15:22Z",
77
+ "updated_at": "2019-08-24T14:15:22Z"
78
+ }
79
+ }
80
+ ],
81
+ "encodings": []
82
+ }
83
+ ]
84
+ },
85
+ {
86
+ "code": "403",
87
+ "description": "Action not allowed",
88
+ "headers": [],
89
+ "contents": [
90
+ {
91
+ "mediaType": "application/json",
92
+ "schema": {
93
+ "type": "object",
94
+ "properties": { "message": { "type": "string" } },
95
+ "required": ["message"],
96
+ "$schema": "http://json-schema.org/draft-07/schema#"
97
+ },
98
+ "examples": [],
99
+ "encodings": []
100
+ }
101
+ ]
102
+ },
103
+ {
104
+ "code": "404",
105
+ "description": "Resource not found",
106
+ "headers": [],
107
+ "contents": [
108
+ {
109
+ "mediaType": "application/json",
110
+ "schema": {
111
+ "title": "Error",
112
+ "type": "object",
113
+ "description": "A standard error object.",
114
+ "x-tags": ["Common"],
115
+ "properties": { "status": { "type": "string", "description": "A code." }, "error": { "type": "string" } },
116
+ "required": ["status", "error"],
117
+ "$schema": "http://json-schema.org/draft-07/schema#"
118
+ },
119
+ "examples": [],
120
+ "encodings": []
121
+ }
122
+ ]
123
+ }
124
+ ],
125
+ "servers": [
126
+ { "description": "Production", "url": "https://todos.stoplight.io" },
127
+ { "description": "Sandbox", "url": "https://todos-sandbox.stoplight.io" }
128
+ ],
129
+ "request": {
130
+ "body": {
131
+ "description": "Name of the Todo",
132
+ "contents": [
133
+ {
134
+ "mediaType": "application/json",
135
+ "schema": {
136
+ "description": "I'm a model's description.",
137
+ "type": "object",
138
+ "x-examples": {},
139
+ "title": "Todo",
140
+ "properties": {
141
+ "id": {
142
+ "type": "number",
143
+ "minimum": 0,
144
+ "maximum": 9999,
145
+ "description": "ID of the task",
146
+ "readOnly": true
147
+ },
148
+ "name": { "type": "string", "minLength": 1, "maxLength": 100, "description": "Name of the task" },
149
+ "completed": {
150
+ "type": "boolean",
151
+ "default": false,
152
+ "description": "Boolean indicating if the task has been completed or not"
153
+ },
154
+ "completed_at": {
155
+ "type": "string",
156
+ "format": "date-time",
157
+ "description": "Time when the task was completed",
158
+ "readOnly": true
159
+ },
160
+ "created_at": {
161
+ "type": "string",
162
+ "format": "date-time",
163
+ "description": "Time when the task was created",
164
+ "readOnly": true
165
+ },
166
+ "updated_at": {
167
+ "type": "string",
168
+ "format": "date-time",
169
+ "description": "Time when the task was updated",
170
+ "readOnly": true
171
+ }
172
+ },
173
+ "required": ["id", "name", "completed_at", "created_at", "updated_at"],
174
+ "$schema": "http://json-schema.org/draft-07/schema#"
175
+ },
176
+ "examples": [],
177
+ "encodings": []
178
+ }
179
+ ]
180
+ },
181
+ "headers": [
182
+ {
183
+ "name": "Content-Type",
184
+ "required": true,
185
+ "description": "application/json",
186
+ "schema": {
187
+ "type": "string",
188
+ "default": "application/json",
189
+ "$schema": "http://json-schema.org/draft-07/schema#"
190
+ },
191
+ "examples": []
192
+ }
193
+ ],
194
+ "query": [],
195
+ "cookie": [],
196
+ "path": []
197
+ },
198
+ "tags": [],
199
+ "security": [
200
+ [
201
+ {
202
+ "key": "API Key",
203
+ "description": "Just use `123`. It's super secure ;)",
204
+ "type": "apiKey",
205
+ "name": "apikey",
206
+ "in": "query"
207
+ }
208
+ ]
209
+ ]
210
+ },
211
+ "links": { "mock_url": "https://stoplight.io/mocks/demo/studio-demo/389434/todos" },
212
+ "outbound_edges": [
213
+ {
214
+ "id": "c2NoOjkxNDY1MDA",
215
+ "type": "model",
216
+ "slug": "c2NoOjkxNDY1MDA-todo",
217
+ "title": "Todo",
218
+ "uri": "/reference/todos/todo.v1.yaml/components/schemas/Todos"
219
+ },
220
+ {
221
+ "id": "YXBpOjM4OTQzNA",
222
+ "type": "http_service",
223
+ "slug": "YXBpOjM4OTQzNA-to-dos",
224
+ "title": "To-dos",
225
+ "uri": "/reference/todos/todo.v1.yaml"
226
+ },
227
+ {
228
+ "id": "YXBpOjM4OTQzNA",
229
+ "type": "http_service",
230
+ "slug": "YXBpOjM4OTQzNA-to-dos",
231
+ "title": "To-dos",
232
+ "uri": "/reference/todos/todo.v1.yaml"
233
+ },
234
+ {
235
+ "id": "YXBpOjM4OTQzNA",
236
+ "type": "http_service",
237
+ "slug": "YXBpOjM4OTQzNA-to-dos",
238
+ "title": "To-dos",
239
+ "uri": "/reference/todos/todo.v1.yaml"
240
+ },
241
+ {
242
+ "id": "c2NoOjkxNDY1MDA",
243
+ "type": "model",
244
+ "slug": "c2NoOjkxNDY1MDA-todo",
245
+ "title": "Todo",
246
+ "uri": "/reference/todos/todo.v1.yaml/components/schemas/Todos"
247
+ },
248
+ {
249
+ "id": "YXBpOjM4OTQzNA",
250
+ "type": "http_service",
251
+ "slug": "YXBpOjM4OTQzNA-to-dos",
252
+ "title": "To-dos",
253
+ "uri": "/reference/todos/todo.v1.yaml"
254
+ }
255
+ ],
256
+ "inbound_edges": []
257
+ }
@@ -0,0 +1,144 @@
1
+ {
2
+ "showPoweredBy": true,
3
+ "items": [
4
+ { "id": "ZG9jOjE", "title": "Introduction", "type": "article", "slug": "ZG9jOjE-introduction", "meta": "" },
5
+ { "id": "ZG9jOjI", "title": "UI Overview", "type": "article", "slug": "ZG9jOjI-ui-overview", "meta": "" },
6
+ { "title": "markdown" },
7
+ { "id": "ZG9jOjM", "title": "Markdown Basics", "type": "article", "slug": "ZG9jOjM-markdown-basics", "meta": "" },
8
+ {
9
+ "id": "ZG9jOjQ",
10
+ "title": "Stoplight Flavored Markdown (SMD)",
11
+ "type": "article",
12
+ "slug": "ZG9jOjQ-stoplight-flavored-markdown-smd",
13
+ "meta": ""
14
+ },
15
+ { "title": "APIS" },
16
+ {
17
+ "id": "YXBpOjEy",
18
+ "title": "Swagger Petstore",
19
+ "type": "http_service",
20
+ "slug": "YXBpOjEy-swagger-petstore",
21
+ "meta": "",
22
+ "items": [
23
+ {
24
+ "title": "pets",
25
+ "items": [
26
+ {
27
+ "id": "b3A6MTU",
28
+ "title": "Create a pet",
29
+ "type": "http_operation",
30
+ "slug": "b3A6MTU-create-a-pet",
31
+ "meta": "post"
32
+ },
33
+ {
34
+ "id": "b3A6MTY",
35
+ "title": "Info for a specific pet",
36
+ "type": "http_operation",
37
+ "slug": "b3A6MTY-info-for-a-specific-pet",
38
+ "meta": "get"
39
+ },
40
+ {
41
+ "id": "b3A6MTQ",
42
+ "title": "List all pets",
43
+ "type": "http_operation",
44
+ "slug": "b3A6MTQ-list-all-pets",
45
+ "meta": "get"
46
+ }
47
+ ]
48
+ },
49
+ {
50
+ "title": "Schemas",
51
+ "items": [{ "id": "c2NoOjg", "title": "Pets", "type": "model", "slug": "c2NoOjg-pets", "meta": "" }]
52
+ }
53
+ ]
54
+ },
55
+ {
56
+ "id": "YXBpOjM4OTQzNA",
57
+ "title": "To-dos",
58
+ "type": "http_service",
59
+ "slug": "YXBpOjM4OTQzNA-to-dos",
60
+ "meta": "",
61
+ "items": [
62
+ {
63
+ "id": "b3A6Mzg5NDM1",
64
+ "title": "List Todos",
65
+ "type": "http_operation",
66
+ "slug": "b3A6Mzg5NDM1-list-todos",
67
+ "meta": "get"
68
+ },
69
+ {
70
+ "id": "b3A6Mzg5NDM2",
71
+ "title": "Create Todo",
72
+ "type": "http_operation",
73
+ "slug": "b3A6Mzg5NDM2-create-todo",
74
+ "meta": "post"
75
+ },
76
+ {
77
+ "id": "b3A6Mzg5NDM4",
78
+ "title": "Get Todo",
79
+ "type": "http_operation",
80
+ "slug": "b3A6Mzg5NDM4-get-todo",
81
+ "meta": "get"
82
+ },
83
+ {
84
+ "id": "b3A6OTE0NjUxMA",
85
+ "title": "Replace Todo",
86
+ "type": "http_operation",
87
+ "slug": "b3A6OTE0NjUxMA-replace-todo",
88
+ "meta": "put"
89
+ },
90
+ {
91
+ "id": "b3A6Mzg5NDM5",
92
+ "title": "Delete Todo",
93
+ "type": "http_operation",
94
+ "slug": "b3A6Mzg5NDM5-delete-todo",
95
+ "meta": "delete"
96
+ },
97
+ {
98
+ "id": "b3A6Mzg5NDQw",
99
+ "title": "Update Todo",
100
+ "type": "http_operation",
101
+ "slug": "b3A6Mzg5NDQw-update-todo",
102
+ "meta": "patch"
103
+ },
104
+ {
105
+ "title": "Users",
106
+ "items": [
107
+ {
108
+ "id": "b3A6OTE0NjUxMw",
109
+ "title": "Get User",
110
+ "type": "http_operation",
111
+ "slug": "b3A6OTE0NjUxMw-get-user",
112
+ "meta": "get"
113
+ },
114
+ {
115
+ "id": "b3A6OTE0NjUxNA",
116
+ "title": "Delete User",
117
+ "type": "http_operation",
118
+ "slug": "b3A6OTE0NjUxNA-delete-user",
119
+ "meta": "delete"
120
+ },
121
+ {
122
+ "id": "b3A6OTE0NjUxNQ",
123
+ "title": "Create User",
124
+ "type": "http_operation",
125
+ "slug": "b3A6OTE0NjUxNQ-create-user",
126
+ "meta": "post"
127
+ }
128
+ ]
129
+ },
130
+ {
131
+ "title": "Schemas",
132
+ "items": [
133
+ { "id": "c2NoOjkxNDY1MDA", "title": "Todo", "type": "model", "slug": "c2NoOjkxNDY1MDA-todo", "meta": "" },
134
+ { "id": "c2NoOjkxNDY1MDE", "title": "User", "type": "model", "slug": "c2NoOjkxNDY1MDE-user", "meta": "" }
135
+ ]
136
+ }
137
+ ]
138
+ },
139
+ { "title": "Schemas" },
140
+ { "id": "c2NoOjU", "title": "Error", "type": "model", "slug": "c2NoOjU-error", "meta": "" },
141
+ { "id": "c2NoOjY", "title": "Category", "type": "model", "slug": "c2NoOjY-category", "meta": "" },
142
+ { "id": "c2NoOjc", "title": "Pet", "type": "model", "slug": "c2NoOjc-pet", "meta": "" }
143
+ ]
144
+ }
@@ -0,0 +1,61 @@
1
+ import { Provider as MosaicProvider } from '@stoplight/mosaic';
2
+ import { screen } from '@testing-library/dom';
3
+ import { render } from '@testing-library/react';
4
+ import userEvent from '@testing-library/user-event';
5
+ import * as React from 'react';
6
+
7
+ import { Branch } from '../../types';
8
+ import { BranchSelector } from './BranchSelector';
9
+
10
+ export const branches: Branch[] = [
11
+ {
12
+ id: 0,
13
+ slug: 'main',
14
+ is_default: true,
15
+ is_published: false,
16
+ name: 'main-name',
17
+ },
18
+ {
19
+ id: 1,
20
+ slug: 'beta',
21
+ is_default: false,
22
+ is_published: false,
23
+ },
24
+ {
25
+ id: 2,
26
+ slug: 'feature-branch',
27
+ is_default: false,
28
+ is_published: false,
29
+ },
30
+ ];
31
+
32
+ const BranchSelectorWrapper: React.FC = () => {
33
+ const [branchSlug, setBranchSlug] = React.useState('main');
34
+
35
+ return (
36
+ <MosaicProvider>
37
+ <BranchSelector branchSlug={branchSlug} branches={branches} onChange={branch => setBranchSlug(branch.slug)} />
38
+ </MosaicProvider>
39
+ );
40
+ };
41
+
42
+ function getBranchSelector() {
43
+ return screen.getByRole('button');
44
+ }
45
+
46
+ describe('Branch selector', () => {
47
+ it('shows the default branch by default', () => {
48
+ render(<BranchSelectorWrapper />);
49
+
50
+ expect(getBranchSelector()).toHaveTextContent('main-name');
51
+ });
52
+
53
+ it('selects a branch', () => {
54
+ render(<BranchSelectorWrapper />);
55
+
56
+ userEvent.click(getBranchSelector());
57
+ userEvent.click(screen.getByRole('menuitemradio', { name: 'beta' }));
58
+
59
+ expect(getBranchSelector()).toHaveTextContent('beta');
60
+ });
61
+ });
@@ -0,0 +1,41 @@
1
+ import { Box } from '@stoplight/mosaic';
2
+ import { Story } from '@storybook/react';
3
+ import * as React from 'react';
4
+
5
+ import { useGetBranches } from '../../hooks/useGetBranches';
6
+ import { BranchSelector } from './';
7
+
8
+ // Wrapper to show how to use the node content hook
9
+ const BranchSelectorWrapper = ({ projectId }: { projectId: string }) => {
10
+ const [branchSlug, setBranchSlug] = React.useState('master');
11
+ const { data } = useGetBranches({ projectId });
12
+
13
+ if (data) {
14
+ return (
15
+ <Box mt={10} w={40}>
16
+ <BranchSelector branchSlug={branchSlug} branches={data.items} onChange={branch => setBranchSlug(branch.slug)} />
17
+ </Box>
18
+ );
19
+ }
20
+
21
+ return <Box>Loading</Box>;
22
+ };
23
+
24
+ export default {
25
+ title: 'Public/BranchSelector',
26
+ component: BranchSelectorWrapper,
27
+ argTypes: {
28
+ projectId: { table: { category: 'Input' } },
29
+ platformUrl: { table: { category: 'Input' } },
30
+ },
31
+ args: {
32
+ projectId: 'cHJqOjYwNjYx',
33
+ platformUrl: 'https://stoplight.io',
34
+ },
35
+ };
36
+
37
+ export const Playground: Story<{ nodeSlug: string; projectId: string; branchSlug?: string }> = args => (
38
+ <BranchSelectorWrapper {...args} />
39
+ );
40
+
41
+ Playground.storyName = 'Studio Demo';