Skip to content

Commit 2b05eb9

Browse files
author
Bogdans Afonins
committed
console: Fix gateway api keys error handling
check for error only after the _REQUEST action
1 parent e99478c commit 2b05eb9

File tree

2 files changed

+20
-36
lines changed

2 files changed

+20
-36
lines changed

pkg/webui/console/views/gateway-api-key-add/index.js

Lines changed: 12 additions & 18 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 { replace } 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 { ApiKeyCreateForm } from '../../components/api-key-form'
27+
import withRequest from '../../../lib/components/with-request'
2828

2929
import { getGatewaysRightsList } from '../../store/actions/gateways'
3030
import {
@@ -43,7 +43,15 @@ import api from '../../api'
4343
error: selectGatewayRightsError(state),
4444
rights: selectGatewayRights(state),
4545
universalRights: selectGatewayUniversalRights(state),
46+
}),
47+
dispatch => ({
48+
getGatewaysRightsList: gtwId => dispatch(getGatewaysRightsList(gtwId)),
49+
navigateToList: gtwId => dispatch(replace(`/console/gateways/${gtwId}/api-keys`)),
4650
}))
51+
@withRequest(
52+
({ gtwId, getGatewaysRightsList }) => getGatewaysRightsList(gtwId),
53+
({ fetching, rights }) => fetching || !Boolean(rights.length)
54+
)
4755
@withBreadcrumb('gtws.single.api-keys.add', function (props) {
4856
const gtwId = props.gtwId
4957

@@ -64,28 +72,14 @@ export default class GatewayApiKeyAdd extends React.Component {
6472
this.createGatewayKey = key => api.gateway.apiKeys.create(props.gtwId, key)
6573
}
6674

67-
componentDidMount () {
68-
const { dispatch, gtwId } = this.props
69-
70-
dispatch(getGatewaysRightsList(gtwId))
71-
}
72-
7375
handleApprove () {
74-
const { dispatch, gtwId } = this.props
76+
const { navigateToList, gtwId } = this.props
7577

76-
dispatch(replace(`/console/gateways/${gtwId}/api-keys`))
78+
navigateToList(gtwId)
7779
}
7880

7981
render () {
80-
const { rights, fetching, error, universalRights } = this.props
81-
82-
if (error) {
83-
throw error
84-
}
85-
86-
if (fetching || !rights.length) {
87-
return <Spinner center />
88-
}
82+
const { rights, universalRights } = this.props
8983

9084
return (
9185
<Container>

pkg/webui/console/views/gateway-api-key-edit/index.js

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import { replace } from 'connected-react-router'
2121
import { withBreadcrumb } from '../../../components/breadcrumbs/context'
2222
import Breadcrumb from '../../../components/breadcrumbs/breadcrumb'
2323
import sharedMessages from '../../../lib/shared-messages'
24-
import Spinner from '../../../components/spinner'
2524
import Message from '../../../lib/components/message'
2625
import IntlHelmet from '../../../lib/components/intl-helmet'
2726
import { ApiKeyEditForm } from '../../components/api-key-form'
27+
import withRequest from '../../../lib/components/with-request'
2828

2929
import {
3030
getGatewayApiKey,
@@ -61,12 +61,16 @@ import api from '../../api'
6161
}
6262
},
6363
dispatch => ({
64-
async loadPageData (gtwId, apiKeyId) {
65-
await dispatch(getGatewaysRightsList(gtwId))
64+
loadData (gtwId, apiKeyId) {
65+
dispatch(getGatewaysRightsList(gtwId))
6666
dispatch(getGatewayApiKey(gtwId, apiKeyId))
6767
},
6868
deleteSuccess: gtwId => dispatch(replace(`/console/gateways/${gtwId}/api-keys`)),
6969
}))
70+
@withRequest(
71+
({ gtwId, keyId, loadData }) => loadData(gtwId, keyId),
72+
({ fetching, apiKey }) => fetching || !Boolean(apiKey)
73+
)
7074
@withBreadcrumb('gtws.single.api-keys.edit', function (props) {
7175
const { gtwId, keyId } = props
7276

@@ -92,28 +96,14 @@ export default class GatewayApiKeyEdit extends React.Component {
9296
)
9397
}
9498

95-
componentDidMount () {
96-
const { loadPageData, gtwId, keyId } = this.props
97-
98-
loadPageData(gtwId, keyId)
99-
}
100-
10199
onDeleteSuccess () {
102100
const { gtwId, deleteSuccess } = this.props
103101

104102
deleteSuccess(gtwId)
105103
}
106104

107105
render () {
108-
const { apiKey, rights, fetching, error, universalRights } = this.props
109-
110-
if (error) {
111-
throw error
112-
}
113-
114-
if (fetching || !apiKey) {
115-
return <Spinner center />
116-
}
106+
const { apiKey, rights, universalRights } = this.props
117107

118108
return (
119109
<Container>

0 commit comments

Comments
 (0)