Skip to content

Commit

Permalink
console: Fix gateway collaborators error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdans Afonins committed Jul 25, 2019
1 parent f063418 commit 1e9f65d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 40 deletions.
25 changes: 5 additions & 20 deletions pkg/webui/console/views/gateway-collaborator-add/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import bind from 'autobind-decorator'
import { connect } from 'react-redux'
import { push } from 'connected-react-router'

import Spinner from '../../../components/spinner'
import Breadcrumb from '../../../components/breadcrumbs/breadcrumb'
import { withBreadcrumb } from '../../../components/breadcrumbs/context'
import sharedMessages from '../../../lib/shared-messages'
import Message from '../../../lib/components/message'
import IntlHelmet from '../../../lib/components/intl-helmet'
import CollaboratorForm from '../../components/collaborator-form'
import withRequest from '../../../lib/components/with-request'

import {
selectSelectedGatewayId,
Expand Down Expand Up @@ -56,6 +56,10 @@ import api from '../../api'
getGatewaysRightsList: () => dispatchProps.getGatewaysRightsList(stateProps.gtwId),
redirectToList: () => dispatchProps.redirectToList(stateProps.gtwId),
}))
@withRequest(
({ getGatewaysRightsList }) => getGatewaysRightsList(),
({ fetching, rights }) => fetching || !Boolean(rights.length)
)
@withBreadcrumb('gtws.single.collaborators.add', function (props) {
const gtwId = props.gtwId
return (
Expand All @@ -73,20 +77,6 @@ export default class GatewayCollaboratorAdd extends React.Component {
error: '',
}

componentDidMount () {
const { getGatewaysRightsList } = this.props

getGatewaysRightsList()
}

componentDidUpdate (prevProps) {
const { error } = this.props

if (Boolean(error) && prevProps.error !== error) {
throw error
}
}

handleSubmit (collaborator) {
const { gtwId } = this.props

Expand All @@ -96,15 +86,10 @@ export default class GatewayCollaboratorAdd extends React.Component {
render () {
const {
rights,
fetching,
redirectToList,
universalRights,
} = this.props

if (fetching && !rights.length) {
return <Spinner center />
}

return (
<Container>
<Row>
Expand Down
25 changes: 5 additions & 20 deletions pkg/webui/console/views/gateway-collaborator-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import { withBreadcrumb } from '../../../components/breadcrumbs/context'
import Breadcrumb from '../../../components/breadcrumbs/breadcrumb'
import sharedMessages from '../../../lib/shared-messages'
import CollaboratorForm from '../../components/collaborator-form'
import Spinner from '../../../components/spinner'
import Message from '../../../lib/components/message'
import IntlHelmet from '../../../lib/components/intl-helmet'
import toast from '../../../components/toast'
import withRequest from '../../../lib/components/with-request'

import {
getGatewayCollaborator,
Expand Down Expand Up @@ -85,6 +85,10 @@ import api from '../../api'
),
redirectToList: () => dispatchProps.redirectToList(stateProps.gtwId),
}))
@withRequest(
({ loadData }) => loadData(),
({ fetching, collaborator }) => fetching || !Boolean(collaborator)
)
@withBreadcrumb('gtws.single.collaborators.edit', function (props) {
const { gtwId, collaboratorId } = props

Expand All @@ -103,20 +107,6 @@ export default class GatewayCollaboratorEdit extends React.Component {
error: '',
}

componentDidMount () {
const { loadData } = this.props

loadData()
}

componentDidUpdate (prevProps) {
const { error } = this.props

if (Boolean(error) && prevProps.error !== error) {
throw error
}
}

handleSubmit (updatedCollaborator) {
const { gtwId } = this.props

Expand All @@ -140,15 +130,10 @@ export default class GatewayCollaboratorEdit extends React.Component {
const {
collaborator,
rights,
fetching,
redirectToList,
universalRights,
} = this.props

if (fetching || !collaborator) {
return <Spinner center />
}

return (
<Container>
<Row>
Expand Down

0 comments on commit 1e9f65d

Please sign in to comment.