Rewire AuthorizeOperationBtn; create new selector for filtering definitions
This commit is contained in:
@@ -1,25 +1,23 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import PropTypes from "prop-types"
|
import PropTypes from "prop-types"
|
||||||
import ImPropTypes from "react-immutable-proptypes"
|
|
||||||
|
|
||||||
export default class AuthorizeOperationBtn extends React.Component {
|
export default class AuthorizeOperationBtn extends React.Component {
|
||||||
|
static propTypes = {
|
||||||
|
isAuthorized: PropTypes.bool.isRequired,
|
||||||
|
onClick: PropTypes.func
|
||||||
|
}
|
||||||
|
|
||||||
onClick =(e) => {
|
onClick =(e) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
|
let { onClick } = this.props
|
||||||
|
|
||||||
let { security, authActions, authSelectors } = this.props
|
if(onClick) {
|
||||||
let definitions = authSelectors.getDefinitionsByNames(security)
|
onClick()
|
||||||
|
}
|
||||||
authActions.showDefinitions(definitions)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let { security, authSelectors } = this.props
|
let { isAuthorized } = this.props
|
||||||
|
|
||||||
let isAuthorized = authSelectors.isAuthorized(security)
|
|
||||||
|
|
||||||
if(isAuthorized === null) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button className={isAuthorized ? "authorization__btn locked" : "authorization__btn unlocked"} onClick={ this.onClick }>
|
<button className={isAuthorized ? "authorization__btn locked" : "authorization__btn unlocked"} onClick={ this.onClick }>
|
||||||
@@ -30,10 +28,4 @@ export default class AuthorizeOperationBtn extends React.Component {
|
|||||||
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
static propTypes = {
|
|
||||||
authSelectors: PropTypes.object.isRequired,
|
|
||||||
authActions: PropTypes.object.isRequired,
|
|
||||||
security: ImPropTypes.iterable.isRequired
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import React, { PureComponent } from "react"
|
import React, { PureComponent } from "react"
|
||||||
|
import { List } from "immutable"
|
||||||
import PropTypes from "prop-types"
|
import PropTypes from "prop-types"
|
||||||
import { getList } from "core/utils"
|
import { getList } from "core/utils"
|
||||||
import * as CustomPropTypes from "core/proptypes"
|
import * as CustomPropTypes from "core/proptypes"
|
||||||
@@ -183,9 +184,13 @@ export default class Operation extends PureComponent {
|
|||||||
|
|
||||||
{
|
{
|
||||||
(!security || !security.count()) ? null :
|
(!security || !security.count()) ? null :
|
||||||
<AuthorizeOperationBtn authActions={ authActions }
|
<AuthorizeOperationBtn
|
||||||
security={ security }
|
isAuthorized={ authSelectors.isAuthorized(security) }
|
||||||
authSelectors={ authSelectors }/>
|
onClick={() => {
|
||||||
|
const applicableDefinitions = authSelectors.definitionsForRequirements(security)
|
||||||
|
authActions.showDefinitions(applicableDefinitions)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -58,6 +58,13 @@ export const getDefinitionsByNames = ( state, securities ) => ( { specSelectors
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const definitionsForRequirements = (state, securities) => ({ authSelectors }) => {
|
||||||
|
const allDefinitions = authSelectors.definitionsToAuthorize()
|
||||||
|
return allDefinitions.filter((def, name) => {
|
||||||
|
return securities.has(name)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export const authorized = createSelector(
|
export const authorized = createSelector(
|
||||||
state,
|
state,
|
||||||
auth => auth.get("authorized") || Map()
|
auth => auth.get("authorized") || Map()
|
||||||
|
|||||||
Reference in New Issue
Block a user