Skip to content

Commit eaa1f4a

Browse files
authored
bug: enum Select crashes when selecting the empty value (via #5463)
* add failing tests * fix property access * @babel/plugin-proposal-optional-chaining
1 parent 7479253 commit eaa1f4a

File tree

6 files changed

+76
-2
lines changed

6 files changed

+76
-2
lines changed

.babelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"corejs": "2"
2424
}],
2525
"@babel/plugin-proposal-class-properties",
26+
"@babel/plugin-proposal-optional-chaining",
2627
["transform-react-remove-prop-types", {
2728
"additionalLibraries": ["react-immutable-proptypes"]
2829
}],

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"@babel/core": "^7.0.0",
8585
"@babel/plugin-proposal-class-properties": "^7.5.0",
8686
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
87-
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
87+
"@babel/plugin-proposal-optional-chaining": "^7.2.0",
8888
"@babel/plugin-transform-runtime": "^7.0.0",
8989
"@babel/preset-env": "^7.0.0",
9090
"@babel/preset-react": "^7.0.0",

src/core/components/layout-utils.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export class Select extends React.Component {
186186

187187
render(){
188188
let { allowedValues, multiple, allowEmptyValue, disabled } = this.props
189-
let value = this.state.value.toJS ? this.state.value.toJS() : this.state.value
189+
let value = this.state.value?.toJS?.() || this.state.value
190190

191191
return (
192192
<select className={this.props.className} multiple={ multiple } value={value} onChange={ this.onChange } disabled={disabled} >
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
openapi: "3.0.0"
2+
info:
3+
title: Testcase API
4+
version: 2.0.0
5+
paths:
6+
'/endpoint':
7+
get:
8+
parameters:
9+
- name: type
10+
in: query
11+
example: fruit
12+
schema:
13+
type: string
14+
enum:
15+
- fruit
16+
- vegetable
17+
- drink
18+
responses:
19+
'200':
20+
description: 200 response
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
swagger: "2.0"
2+
info:
3+
title: Testcase API
4+
version: 2.0.0
5+
paths:
6+
'/endpoint':
7+
get:
8+
parameters:
9+
- name: type
10+
in: query
11+
x-example: fruit
12+
type: string
13+
enum:
14+
- fruit
15+
- vegetable
16+
- drink
17+
responses:
18+
'200':
19+
description: 200 response
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @prettier
3+
*/
4+
5+
describe("#5452: <Select /> crashing in Parameters", function() {
6+
describe("in OpenAPI 3", () => {
7+
it("should not result in a render error", function() {
8+
cy.visit("http://localhost:3230/?url=/documents/bugs/5452/openapi.yaml")
9+
.get("#operations-default-get_endpoint")
10+
.click()
11+
.get(".parameters > tbody > tr > .col > select")
12+
.select("")
13+
.get(".parameters > tbody > tr > .col > select")
14+
.should("exist")
15+
.select("fruit")
16+
.get(".parameters > tbody > tr > .col > select")
17+
.should("exist")
18+
})
19+
})
20+
describe("in Swagger 2", () => {
21+
it("should not result in a render error", function() {
22+
cy.visit("http://localhost:3230/?url=/documents/bugs/5452/swagger.yaml")
23+
.get("#operations-default-get_endpoint")
24+
.click()
25+
.get(".parameters > tbody > tr > .col > select")
26+
.select("")
27+
.get(".parameters > tbody > tr > .col > select")
28+
.should("exist")
29+
.select("fruit")
30+
.get(".parameters > tbody > tr > .col > select")
31+
.should("exist")
32+
})
33+
})
34+
})

0 commit comments

Comments
 (0)