Skip to content

Commit 1e9f65d

Browse files
author
Bogdans Afonins
committed
console: Fix gateway collaborators error handling
1 parent f063418 commit 1e9f65d

File tree

2 files changed

+10
-40
lines changed
  • pkg/webui/console/views

2 files changed

+10
-40
lines changed

pkg/webui/console/views/gateway-collaborator-add/index.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import bind from 'autobind-decorator'
1818
import { connect } from 'react-redux'
1919
import { push } from 'connected-react-router'
2020

21-
import Spinner from '../../../components/spinner'
2221
import Breadcrumb from '../../../components/breadcrumbs/breadcrumb'
2322
import { withBreadcrumb } from '../../../components/breadcrumbs/context'
2423
import sharedMessages from '../../../lib/shared-messages'
2524
import Message from '../../../lib/components/message'
2625
import IntlHelmet from '../../../lib/components/intl-helmet'
2726
import CollaboratorForm from '../../components/collaborator-form'
27+
import withRequest from '../../../lib/components/with-request'
2828

2929
import {
3030
selectSelectedGatewayId,
@@ -56,6 +56,10 @@ import api from '../../api'
5656
getGatewaysRightsList: () => dispatchProps.getGatewaysRightsList(stateProps.gtwId),
5757
redirectToList: () => dispatchProps.redirectToList(stateProps.gtwId),
5858
}))
59+
@withRequest(
60+
({ getGatewaysRightsList }) => getGatewaysRightsList(),
61+
({ fetching, rights }) => fetching || !Boolean(rights.length)
62+
)
5963
@withBreadcrumb('gtws.single.collaborators.add', function (props) {
6064
const gtwId = props.gtwId
6165
return (
@@ -73,20 +77,6 @@ export default class GatewayCollaboratorAdd extends React.Component {
7377
error: '',
7478
}
7579

76-
componentDidMount () {
77-
const { getGatewaysRightsList } = this.props
78-
79-
getGatewaysRightsList()
80-
}
81-
82-
componentDidUpdate (prevProps) {
83-
const { error } = this.props
84-
85-
if (Boolean(error) && prevProps.error !== error) {
86-
throw error
87-
}
88-
}
89-
9080
handleSubmit (collaborator) {
9181
const { gtwId } = this.props
9282

@@ -96,15 +86,10 @@ export default class GatewayCollaboratorAdd extends React.Component {
9686
render () {
9787
const {
9888
rights,
99-
fetching,
10089
redirectToList,
10190
universalRights,
10291
} = this.props
10392

104-
if (fetching && !rights.length) {
105-
return <Spinner center />
106-
}
107-
10893
return (
10994
<Container>
11095
<Row>

pkg/webui/console/views/gateway-collaborator-edit/index.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import { withBreadcrumb } from '../../../components/breadcrumbs/context'
2222
import Breadcrumb from '../../../components/breadcrumbs/breadcrumb'
2323
import sharedMessages from '../../../lib/shared-messages'
2424
import CollaboratorForm from '../../components/collaborator-form'
25-
import Spinner from '../../../components/spinner'
2625
import Message from '../../../lib/components/message'
2726
import IntlHelmet from '../../../lib/components/intl-helmet'
2827
import toast from '../../../components/toast'
28+
import withRequest from '../../../lib/components/with-request'
2929

3030
import {
3131
getGatewayCollaborator,
@@ -85,6 +85,10 @@ import api from '../../api'
8585
),
8686
redirectToList: () => dispatchProps.redirectToList(stateProps.gtwId),
8787
}))
88+
@withRequest(
89+
({ loadData }) => loadData(),
90+
({ fetching, collaborator }) => fetching || !Boolean(collaborator)
91+
)
8892
@withBreadcrumb('gtws.single.collaborators.edit', function (props) {
8993
const { gtwId, collaboratorId } = props
9094

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

106-
componentDidMount () {
107-
const { loadData } = this.props
108-
109-
loadData()
110-
}
111-
112-
componentDidUpdate (prevProps) {
113-
const { error } = this.props
114-
115-
if (Boolean(error) && prevProps.error !== error) {
116-
throw error
117-
}
118-
}
119-
120110
handleSubmit (updatedCollaborator) {
121111
const { gtwId } = this.props
122112

@@ -140,15 +130,10 @@ export default class GatewayCollaboratorEdit extends React.Component {
140130
const {
141131
collaborator,
142132
rights,
143-
fetching,
144133
redirectToList,
145134
universalRights,
146135
} = this.props
147136

148-
if (fetching || !collaborator) {
149-
return <Spinner center />
150-
}
151-
152137
return (
153138
<Container>
154139
<Row>

0 commit comments

Comments
 (0)