Skip to content

Commit 004f107

Browse files
authored
fix: repair schemes servers rendering (via #4913)
* create AuthorizeBtnContainer * remove Servers and AuthorizeBtn from Schemes' concern * add AuthorizeBtnContainer to base * strengthen OAS3 definitionsToAuthorize * drop obsolete tests * linter fixes
1 parent 15d5df0 commit 004f107

File tree

7 files changed

+65
-78
lines changed

7 files changed

+65
-78
lines changed

src/core/components/auth/authorize-btn.jsx

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,21 @@ import PropTypes from "prop-types"
33

44
export default class AuthorizeBtn extends React.Component {
55
static propTypes = {
6-
className: PropTypes.string
7-
}
8-
9-
onClick =() => {
10-
let { authActions, authSelectors } = this.props
11-
let definitions = authSelectors.definitionsToAuthorize()
12-
13-
authActions.showDefinitions(definitions)
6+
onClick: PropTypes.func,
7+
isAuthorized: PropTypes.bool,
8+
showPopup: PropTypes.bool,
9+
getComponent: PropTypes.func.isRequired
1410
}
1511

1612
render() {
17-
let { authSelectors, getComponent } = this.props
13+
let { isAuthorized, showPopup, onClick, getComponent } = this.props
14+
1815
//must be moved out of button component
1916
const AuthorizationPopup = getComponent("authorizationPopup", true)
20-
let showPopup = !!authSelectors.shownDefinitions()
21-
let isAuthorized = !!authSelectors.authorized().size
2217

2318
return (
2419
<div className="auth-wrapper">
25-
<button className={isAuthorized ? "btn authorize locked" : "btn authorize unlocked"} onClick={ this.onClick }>
20+
<button className={isAuthorized ? "btn authorize locked" : "btn authorize unlocked"} onClick={onClick}>
2621
<span>Authorize</span>
2722
<svg width="20" height="20">
2823
<use href={ isAuthorized ? "#locked" : "#unlocked" } xlinkHref={ isAuthorized ? "#locked" : "#unlocked" } />
@@ -32,12 +27,4 @@ export default class AuthorizeBtn extends React.Component {
3227
</div>
3328
)
3429
}
35-
36-
37-
static propTypes = {
38-
getComponent: PropTypes.func.isRequired,
39-
authSelectors: PropTypes.object.isRequired,
40-
errActions: PropTypes.object.isRequired,
41-
authActions: PropTypes.object.isRequired,
42-
}
4330
}

src/core/components/layouts/base.jsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default class BaseLayout extends React.Component {
2626
let Errors = getComponent("errors", true)
2727

2828
const SchemesContainer = getComponent("SchemesContainer", true)
29+
const AuthorizeBtnContainer = getComponent("AuthorizeBtnContainer", true)
2930
const FilterContainer = getComponent("FilterContainer", true)
3031
let isSwagger2 = specSelectors.isSwagger2()
3132
let isOAS3 = specSelectors.isOAS3()
@@ -60,10 +61,15 @@ export default class BaseLayout extends React.Component {
6061
</Col>
6162
</Row>
6263

63-
<SchemesContainer>
64-
<ServersContainer/>
65-
</SchemesContainer>
66-
64+
<div>
65+
<div className="scheme-container">
66+
<Col className="schemes wrapper" mobile={12}>
67+
<ServersContainer />
68+
<SchemesContainer />
69+
<AuthorizeBtnContainer />
70+
</Col>
71+
</div>
72+
</div>
6773

6874
<FilterContainer/>
6975

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from "react"
2+
import PropTypes from "prop-types"
3+
4+
export default class AuthorizeBtnContainer extends React.Component {
5+
6+
static propTypes = {
7+
specActions: PropTypes.object.isRequired,
8+
specSelectors: PropTypes.object.isRequired,
9+
authActions: PropTypes.object.isRequired,
10+
authSelectors: PropTypes.object.isRequired,
11+
getComponent: PropTypes.func.isRequired
12+
}
13+
14+
render () {
15+
const { authActions, authSelectors, specSelectors, getComponent} = this.props
16+
17+
const securityDefinitions = specSelectors.securityDefinitions()
18+
const authorizableDefinitions = authSelectors.definitionsToAuthorize()
19+
20+
const AuthorizeBtn = getComponent("authorizeBtn")
21+
22+
return securityDefinitions ? (
23+
<AuthorizeBtn
24+
onClick={() => authActions.showDefinitions(authorizableDefinitions)}
25+
isAuthorized={!!authSelectors.authorized().size}
26+
showPopup={!!authSelectors.shownDefinitions()}
27+
getComponent={getComponent}
28+
/>
29+
) : null
30+
}
31+
}

src/core/containers/schemes.jsx

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,25 @@ export default class SchemesContainer extends React.Component {
66
static propTypes = {
77
specActions: PropTypes.object.isRequired,
88
specSelectors: PropTypes.object.isRequired,
9-
getComponent: PropTypes.func.isRequired,
10-
children: PropTypes.any
9+
getComponent: PropTypes.func.isRequired
1110
}
1211

1312
render () {
1413
const {specActions, specSelectors, getComponent} = this.props
14+
1515
const currentScheme = specSelectors.operationScheme()
1616
const schemes = specSelectors.schemes()
17-
const securityDefinitions = specSelectors.securityDefinitions()
1817

19-
const Col = getComponent("Col")
20-
const AuthorizeBtn = getComponent("authorizeBtn", true)
2118
const Schemes = getComponent("schemes")
2219

23-
return (
24-
<div>
25-
{schemes && schemes.size || securityDefinitions ? (
26-
<div className="scheme-container">
27-
<Col className="schemes wrapper" mobile={12}>
28-
{this.props.children}
29-
{schemes && schemes.size ? (
30-
<Schemes
31-
currentScheme={currentScheme}
32-
schemes={schemes}
33-
specActions={specActions}
34-
/>
35-
) : null}
36-
{securityDefinitions ? (
37-
<AuthorizeBtn/>
38-
) : null}
39-
</Col>
40-
</div>
41-
) : null}
42-
</div>
43-
)
20+
const schemesArePresent = schemes && schemes.size
21+
22+
return schemesArePresent ? (
23+
<Schemes
24+
currentScheme={currentScheme}
25+
schemes={schemes}
26+
specActions={specActions}
27+
/>
28+
) : null
4429
}
4530
}

src/core/plugins/oas3/auth-extensions/wrap-selectors.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export const definitionsToAuthorize = onlyOAS3(createSelector(
2626
// that look like Swagger2 definitions.
2727
let list = List()
2828

29+
if(!definitions) {
30+
return list
31+
}
32+
2933
definitions.entrySeq().forEach( ([ defName, definition ]) => {
3034
const type = definition.get("type")
3135

src/core/presets/base.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import OperationContainer from "core/containers/OperationContainer"
1818
import App from "core/components/app"
1919
import AuthorizationPopup from "core/components/auth/authorization-popup"
2020
import AuthorizeBtn from "core/components/auth/authorize-btn"
21+
import AuthorizeBtnContainer from "core/containers/authorize-btn"
2122
import AuthorizeOperationBtn from "core/components/auth/authorize-operation-btn"
2223
import Auths from "core/components/auth/auths"
2324
import AuthItem from "core/components/auth/auth-item"
@@ -91,6 +92,7 @@ export default function() {
9192
App,
9293
authorizationPopup: AuthorizationPopup,
9394
authorizeBtn: AuthorizeBtn,
95+
AuthorizeBtnContainer,
9496
authorizeOperationBtn: AuthorizeOperationBtn,
9597
auths: Auths,
9698
AuthItem: AuthItem,

test/components/schemes-wrapper.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -88,32 +88,4 @@ describe("<SchemesContainer/>", function(){
8888
const renderedSchemes = wrapper.find(Schemes)
8989
expect(renderedSchemes.length).toEqual(0)
9090
})
91-
92-
it("renders AuthorizeBtn inside SchemesContainer if security definition is provided", function(){
93-
94-
// Given
95-
let props = {...mockedProps}
96-
props.specSelectors = {...mockedProps.specSelectors}
97-
props.specSelectors.securityDefinitions = function () {return fromJS(twoSecurityDefinitions)}
98-
99-
// When
100-
let wrapper = render(<SchemesContainer {...props}/>)
101-
102-
// Then
103-
const renderedAuthorizeBtn = wrapper.find("span.mocked-button")
104-
expect(renderedAuthorizeBtn.length).toEqual(1)
105-
})
106-
107-
it("does not render AuthorizeBtn if security definition is not provided", function(){
108-
109-
// Given
110-
let props = {...mockedProps}
111-
112-
// When
113-
let wrapper = render(<SchemesContainer {...props}/>)
114-
115-
// Then
116-
const renderedAuthorizeBtn = wrapper.find("span.mocked-button")
117-
expect(renderedAuthorizeBtn.length).toEqual(0)
118-
})
11991
})

0 commit comments

Comments
 (0)