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
This commit is contained in:
@@ -3,26 +3,21 @@ import PropTypes from "prop-types"
|
|||||||
|
|
||||||
export default class AuthorizeBtn extends React.Component {
|
export default class AuthorizeBtn extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
className: PropTypes.string
|
onClick: PropTypes.func,
|
||||||
}
|
isAuthorized: PropTypes.bool,
|
||||||
|
showPopup: PropTypes.bool,
|
||||||
onClick =() => {
|
getComponent: PropTypes.func.isRequired
|
||||||
let { authActions, authSelectors } = this.props
|
|
||||||
let definitions = authSelectors.definitionsToAuthorize()
|
|
||||||
|
|
||||||
authActions.showDefinitions(definitions)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let { authSelectors, getComponent } = this.props
|
let { isAuthorized, showPopup, onClick, getComponent } = this.props
|
||||||
|
|
||||||
//must be moved out of button component
|
//must be moved out of button component
|
||||||
const AuthorizationPopup = getComponent("authorizationPopup", true)
|
const AuthorizationPopup = getComponent("authorizationPopup", true)
|
||||||
let showPopup = !!authSelectors.shownDefinitions()
|
|
||||||
let isAuthorized = !!authSelectors.authorized().size
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="auth-wrapper">
|
<div className="auth-wrapper">
|
||||||
<button className={isAuthorized ? "btn authorize locked" : "btn authorize unlocked"} onClick={ this.onClick }>
|
<button className={isAuthorized ? "btn authorize locked" : "btn authorize unlocked"} onClick={onClick}>
|
||||||
<span>Authorize</span>
|
<span>Authorize</span>
|
||||||
<svg width="20" height="20">
|
<svg width="20" height="20">
|
||||||
<use href={ isAuthorized ? "#locked" : "#unlocked" } xlinkHref={ isAuthorized ? "#locked" : "#unlocked" } />
|
<use href={ isAuthorized ? "#locked" : "#unlocked" } xlinkHref={ isAuthorized ? "#locked" : "#unlocked" } />
|
||||||
@@ -32,12 +27,4 @@ export default class AuthorizeBtn extends React.Component {
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static propTypes = {
|
|
||||||
getComponent: PropTypes.func.isRequired,
|
|
||||||
authSelectors: PropTypes.object.isRequired,
|
|
||||||
errActions: PropTypes.object.isRequired,
|
|
||||||
authActions: PropTypes.object.isRequired,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ export default class BaseLayout extends React.Component {
|
|||||||
let Errors = getComponent("errors", true)
|
let Errors = getComponent("errors", true)
|
||||||
|
|
||||||
const SchemesContainer = getComponent("SchemesContainer", true)
|
const SchemesContainer = getComponent("SchemesContainer", true)
|
||||||
|
const AuthorizeBtnContainer = getComponent("AuthorizeBtnContainer", true)
|
||||||
const FilterContainer = getComponent("FilterContainer", true)
|
const FilterContainer = getComponent("FilterContainer", true)
|
||||||
let isSwagger2 = specSelectors.isSwagger2()
|
let isSwagger2 = specSelectors.isSwagger2()
|
||||||
let isOAS3 = specSelectors.isOAS3()
|
let isOAS3 = specSelectors.isOAS3()
|
||||||
@@ -60,10 +61,15 @@ export default class BaseLayout extends React.Component {
|
|||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
<SchemesContainer>
|
<div>
|
||||||
|
<div className="scheme-container">
|
||||||
|
<Col className="schemes wrapper" mobile={12}>
|
||||||
<ServersContainer />
|
<ServersContainer />
|
||||||
</SchemesContainer>
|
<SchemesContainer />
|
||||||
|
<AuthorizeBtnContainer />
|
||||||
|
</Col>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<FilterContainer/>
|
<FilterContainer/>
|
||||||
|
|
||||||
|
|||||||
31
src/core/containers/authorize-btn.jsx
Normal file
31
src/core/containers/authorize-btn.jsx
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import React from "react"
|
||||||
|
import PropTypes from "prop-types"
|
||||||
|
|
||||||
|
export default class AuthorizeBtnContainer extends React.Component {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
specActions: PropTypes.object.isRequired,
|
||||||
|
specSelectors: PropTypes.object.isRequired,
|
||||||
|
authActions: PropTypes.object.isRequired,
|
||||||
|
authSelectors: PropTypes.object.isRequired,
|
||||||
|
getComponent: PropTypes.func.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
|
render () {
|
||||||
|
const { authActions, authSelectors, specSelectors, getComponent} = this.props
|
||||||
|
|
||||||
|
const securityDefinitions = specSelectors.securityDefinitions()
|
||||||
|
const authorizableDefinitions = authSelectors.definitionsToAuthorize()
|
||||||
|
|
||||||
|
const AuthorizeBtn = getComponent("authorizeBtn")
|
||||||
|
|
||||||
|
return securityDefinitions ? (
|
||||||
|
<AuthorizeBtn
|
||||||
|
onClick={() => authActions.showDefinitions(authorizableDefinitions)}
|
||||||
|
isAuthorized={!!authSelectors.authorized().size}
|
||||||
|
showPopup={!!authSelectors.shownDefinitions()}
|
||||||
|
getComponent={getComponent}
|
||||||
|
/>
|
||||||
|
) : null
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,40 +6,25 @@ export default class SchemesContainer extends React.Component {
|
|||||||
static propTypes = {
|
static propTypes = {
|
||||||
specActions: PropTypes.object.isRequired,
|
specActions: PropTypes.object.isRequired,
|
||||||
specSelectors: PropTypes.object.isRequired,
|
specSelectors: PropTypes.object.isRequired,
|
||||||
getComponent: PropTypes.func.isRequired,
|
getComponent: PropTypes.func.isRequired
|
||||||
children: PropTypes.any
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const {specActions, specSelectors, getComponent} = this.props
|
const {specActions, specSelectors, getComponent} = this.props
|
||||||
|
|
||||||
const currentScheme = specSelectors.operationScheme()
|
const currentScheme = specSelectors.operationScheme()
|
||||||
const schemes = specSelectors.schemes()
|
const schemes = specSelectors.schemes()
|
||||||
const securityDefinitions = specSelectors.securityDefinitions()
|
|
||||||
|
|
||||||
const Col = getComponent("Col")
|
|
||||||
const AuthorizeBtn = getComponent("authorizeBtn", true)
|
|
||||||
const Schemes = getComponent("schemes")
|
const Schemes = getComponent("schemes")
|
||||||
|
|
||||||
return (
|
const schemesArePresent = schemes && schemes.size
|
||||||
<div>
|
|
||||||
{schemes && schemes.size || securityDefinitions ? (
|
return schemesArePresent ? (
|
||||||
<div className="scheme-container">
|
|
||||||
<Col className="schemes wrapper" mobile={12}>
|
|
||||||
{this.props.children}
|
|
||||||
{schemes && schemes.size ? (
|
|
||||||
<Schemes
|
<Schemes
|
||||||
currentScheme={currentScheme}
|
currentScheme={currentScheme}
|
||||||
schemes={schemes}
|
schemes={schemes}
|
||||||
specActions={specActions}
|
specActions={specActions}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null
|
||||||
{securityDefinitions ? (
|
|
||||||
<AuthorizeBtn/>
|
|
||||||
) : null}
|
|
||||||
</Col>
|
|
||||||
</div>
|
|
||||||
) : null}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ export const definitionsToAuthorize = onlyOAS3(createSelector(
|
|||||||
// that look like Swagger2 definitions.
|
// that look like Swagger2 definitions.
|
||||||
let list = List()
|
let list = List()
|
||||||
|
|
||||||
|
if(!definitions) {
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
definitions.entrySeq().forEach( ([ defName, definition ]) => {
|
definitions.entrySeq().forEach( ([ defName, definition ]) => {
|
||||||
const type = definition.get("type")
|
const type = definition.get("type")
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import OperationContainer from "core/containers/OperationContainer"
|
|||||||
import App from "core/components/app"
|
import App from "core/components/app"
|
||||||
import AuthorizationPopup from "core/components/auth/authorization-popup"
|
import AuthorizationPopup from "core/components/auth/authorization-popup"
|
||||||
import AuthorizeBtn from "core/components/auth/authorize-btn"
|
import AuthorizeBtn from "core/components/auth/authorize-btn"
|
||||||
|
import AuthorizeBtnContainer from "core/containers/authorize-btn"
|
||||||
import AuthorizeOperationBtn from "core/components/auth/authorize-operation-btn"
|
import AuthorizeOperationBtn from "core/components/auth/authorize-operation-btn"
|
||||||
import Auths from "core/components/auth/auths"
|
import Auths from "core/components/auth/auths"
|
||||||
import AuthItem from "core/components/auth/auth-item"
|
import AuthItem from "core/components/auth/auth-item"
|
||||||
@@ -91,6 +92,7 @@ export default function() {
|
|||||||
App,
|
App,
|
||||||
authorizationPopup: AuthorizationPopup,
|
authorizationPopup: AuthorizationPopup,
|
||||||
authorizeBtn: AuthorizeBtn,
|
authorizeBtn: AuthorizeBtn,
|
||||||
|
AuthorizeBtnContainer,
|
||||||
authorizeOperationBtn: AuthorizeOperationBtn,
|
authorizeOperationBtn: AuthorizeOperationBtn,
|
||||||
auths: Auths,
|
auths: Auths,
|
||||||
AuthItem: AuthItem,
|
AuthItem: AuthItem,
|
||||||
|
|||||||
@@ -88,32 +88,4 @@ describe("<SchemesContainer/>", function(){
|
|||||||
const renderedSchemes = wrapper.find(Schemes)
|
const renderedSchemes = wrapper.find(Schemes)
|
||||||
expect(renderedSchemes.length).toEqual(0)
|
expect(renderedSchemes.length).toEqual(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("renders AuthorizeBtn inside SchemesContainer if security definition is provided", function(){
|
|
||||||
|
|
||||||
// Given
|
|
||||||
let props = {...mockedProps}
|
|
||||||
props.specSelectors = {...mockedProps.specSelectors}
|
|
||||||
props.specSelectors.securityDefinitions = function () {return fromJS(twoSecurityDefinitions)}
|
|
||||||
|
|
||||||
// When
|
|
||||||
let wrapper = render(<SchemesContainer {...props}/>)
|
|
||||||
|
|
||||||
// Then
|
|
||||||
const renderedAuthorizeBtn = wrapper.find("span.mocked-button")
|
|
||||||
expect(renderedAuthorizeBtn.length).toEqual(1)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("does not render AuthorizeBtn if security definition is not provided", function(){
|
|
||||||
|
|
||||||
// Given
|
|
||||||
let props = {...mockedProps}
|
|
||||||
|
|
||||||
// When
|
|
||||||
let wrapper = render(<SchemesContainer {...props}/>)
|
|
||||||
|
|
||||||
// Then
|
|
||||||
const renderedAuthorizeBtn = wrapper.find("span.mocked-button")
|
|
||||||
expect(renderedAuthorizeBtn.length).toEqual(0)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user