Skip to content

Commit

Permalink
Merge pull request #1031 from TheThingsNetwork/fix/1021-persistent-er…
Browse files Browse the repository at this point in the history
…rors

Fix component throw persistent error
  • Loading branch information
Bogdans authored Jul 26, 2019
2 parents ce0c448 + 1e9f65d commit 2f46879
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 168 deletions.
30 changes: 12 additions & 18 deletions pkg/webui/console/views/application-api-key-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 { replace } 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 { ApiKeyCreateForm } from '../../components/api-key-form'
import withRequest from '../../../lib/components/with-request'

import { getApplicationsRightsList } from '../../store/actions/applications'
import {
Expand All @@ -43,7 +43,15 @@ import api from '../../api'
error: selectApplicationRightsError(state),
rights: selectApplicationRights(state),
universalRights: selectApplicationUniversalRights(state),
}),
dispatch => ({
getApplicationsRightsList: appId => dispatch(getApplicationsRightsList(appId)),
navigateToList: appId => dispatch(replace(`/console/applications/${appId}/api-keys`)),
}))
@withRequest(
({ appId, getApplicationsRightsList }) => getApplicationsRightsList(appId),
({ fetching, rights }) => fetching || !Boolean(rights.length)
)
@withBreadcrumb('apps.single.api-keys.add', function (props) {
const appId = props.appId
return (
Expand All @@ -63,28 +71,14 @@ export default class ApplicationApiKeyAdd extends React.Component {
this.createApplicationKey = key => api.application.apiKeys.create(props.appId, key)
}

componentDidMount () {
const { dispatch, appId } = this.props

dispatch(getApplicationsRightsList(appId))
}

handleApprove () {
const { dispatch, appId } = this.props
const { navigateToList, appId } = this.props

dispatch(replace(`/console/applications/${appId}/api-keys`))
navigateToList(appId)
}

render () {
const { rights, fetching, error, universalRights } = this.props

if (error) {
throw error
}

if (fetching || !rights.length) {
return <Spinner center />
}
const { rights, universalRights } = this.props

return (
<Container>
Expand Down
26 changes: 8 additions & 18 deletions pkg/webui/console/views/application-api-key-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import { replace } from 'connected-react-router'
import { withBreadcrumb } from '../../../components/breadcrumbs/context'
import Breadcrumb from '../../../components/breadcrumbs/breadcrumb'
import sharedMessages from '../../../lib/shared-messages'
import Spinner from '../../../components/spinner'
import Message from '../../../lib/components/message'
import IntlHelmet from '../../../lib/components/intl-helmet'
import { ApiKeyEditForm } from '../../components/api-key-form'
import withRequest from '../../../lib/components/with-request'

import {
getApplicationApiKey,
Expand Down Expand Up @@ -62,12 +62,16 @@ import api from '../../api'
}
},
dispatch => ({
async loadPageData (appId, apiKeyId) {
await dispatch(getApplicationsRightsList(appId))
loadData (appId, apiKeyId) {
dispatch(getApplicationsRightsList(appId))
dispatch(getApplicationApiKey(appId, apiKeyId))
},
deleteSuccess: appId => dispatch(replace(`/console/applications/${appId}/api-keys`)),
}))
@withRequest(
({ loadData, appId, keyId }) => loadData(appId, keyId),
({ fetching, apiKey }) => fetching || !Boolean(apiKey)
)
@withBreadcrumb('apps.single.api-keys.edit', function (props) {
const { appId, keyId } = props

Expand All @@ -93,28 +97,14 @@ export default class ApplicationApiKeyEdit extends React.Component {
)
}

componentDidMount () {
const { loadPageData, appId, keyId } = this.props

loadPageData(appId, keyId)
}

onDeleteSuccess () {
const { appId, deleteSuccess } = this.props

deleteSuccess(appId)
}

render () {
const { apiKey, rights, fetching, error, universalRights } = this.props

if (error) {
throw error
}

if (fetching || !apiKey) {
return <Spinner center />
}
const { apiKey, rights, universalRights } = this.props

return (
<Container>
Expand Down
26 changes: 5 additions & 21 deletions pkg/webui/console/views/application-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 CollaboratorForm from '../../components/collaborator-form'
import Message from '../../../lib/components/message'
import IntlHelmet from '../../../lib/components/intl-helmet'
import withRequest from '../../../lib/components/with-request'

import { getApplicationsRightsList } from '../../store/actions/applications'
import {
Expand Down Expand Up @@ -54,6 +54,10 @@ import api from '../../api'
redirectToList: () => dispatchProps.redirectToList(stateProps.appId),
getApplicationsRightsList: () => dispatchProps.getApplicationsRightsList(stateProps.appId),
}))
@withRequest(
({ getApplicationsRightsList }) => getApplicationsRightsList(),
({ fetching, rights }) => fetching || !Boolean(rights.length)
)
@withBreadcrumb('apps.single.collaborators.add', function (props) {
const appId = props.appId
return (
Expand All @@ -71,39 +75,19 @@ export default class ApplicationCollaboratorAdd extends React.Component {
error: '',
}

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

getApplicationsRightsList()
}

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

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

async handleSubmit (collaborator) {
const { appId } = this.props

await api.application.collaborators.add(appId, collaborator)

}

render () {
const {
rights,
fetching,
universalRights,
redirectToList,
} = this.props

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

return (
<Container>
<Row>
Expand Down
25 changes: 5 additions & 20 deletions pkg/webui/console/views/application-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 {
getApplicationCollaborator,
Expand Down Expand Up @@ -84,6 +84,10 @@ import api from '../../api'
redirectToList: () => dispatchProps.redirectToList(stateProps.appId),
})
)
@withRequest(
({ loadData }) => loadData(),
({ fetching, collaborator }) => fetching || !Boolean(collaborator)
)
@withBreadcrumb('apps.single.collaborators.edit', function (props) {
const { appId, collaboratorId, collaboratorType } = props

Expand All @@ -102,20 +106,6 @@ export default class ApplicationCollaboratorEdit extends React.Component {
error: '',
}

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

loadData()
}

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

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

async handleSubmit (updatedCollaborator) {
const { appId } = this.props

Expand Down Expand Up @@ -158,15 +148,10 @@ export default class ApplicationCollaboratorEdit extends React.Component {
const {
collaborator,
rights,
fetching,
universalRights,
redirectToList,
} = this.props

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

return (
<Container>
<Row>
Expand Down
21 changes: 6 additions & 15 deletions pkg/webui/console/views/application-integration-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import IntlHelmet from '../../../lib/components/intl-helmet'
import Message from '../../../lib/components/message'
import WebhookForm from '../../components/webhook-form'
import toast from '../../../components/toast'
import Spinner from '../../../components/spinner'
import diff from '../../../lib/diff'
import sharedMessages from '../../../lib/shared-messages'
import withRequest from '../../../lib/components/with-request'

import {
selectSelectedWebhook,
Expand Down Expand Up @@ -70,6 +70,10 @@ const webhookEntitySelector = [
navigateToList: () => dispatch(replace(`/console/applications/${appId}/integrations`)),
}
})
@withRequest(
({ getWebhook }) => getWebhook(),
({ fetching, webhook }) => fetching || !Boolean(webhook)
)
@withBreadcrumb('apps.single.integrations.edit', function (props) {
const { appId, match: { params: { webhookId }}} = props
return (
Expand All @@ -82,11 +86,6 @@ const webhookEntitySelector = [
})
@bind
export default class ApplicationIntegrationEdit extends Component {
componentDidMount () {
const { getWebhook } = this.props

getWebhook()
}

async handleSubmit (webhook) {
const { appId, match: { params: { webhookId }}, webhook: originalWebhook } = this.props
Expand Down Expand Up @@ -120,15 +119,7 @@ export default class ApplicationIntegrationEdit extends Component {
}

render () {
const { webhook, fetching, error } = this.props

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

if (error) {
throw error
}
const { webhook } = this.props

return (
<Container>
Expand Down
30 changes: 12 additions & 18 deletions pkg/webui/console/views/gateway-api-key-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 { replace } 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 { ApiKeyCreateForm } from '../../components/api-key-form'
import withRequest from '../../../lib/components/with-request'

import { getGatewaysRightsList } from '../../store/actions/gateways'
import {
Expand All @@ -43,7 +43,15 @@ import api from '../../api'
error: selectGatewayRightsError(state),
rights: selectGatewayRights(state),
universalRights: selectGatewayUniversalRights(state),
}),
dispatch => ({
getGatewaysRightsList: gtwId => dispatch(getGatewaysRightsList(gtwId)),
navigateToList: gtwId => dispatch(replace(`/console/gateways/${gtwId}/api-keys`)),
}))
@withRequest(
({ gtwId, getGatewaysRightsList }) => getGatewaysRightsList(gtwId),
({ fetching, rights }) => fetching || !Boolean(rights.length)
)
@withBreadcrumb('gtws.single.api-keys.add', function (props) {
const gtwId = props.gtwId

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

componentDidMount () {
const { dispatch, gtwId } = this.props

dispatch(getGatewaysRightsList(gtwId))
}

handleApprove () {
const { dispatch, gtwId } = this.props
const { navigateToList, gtwId } = this.props

dispatch(replace(`/console/gateways/${gtwId}/api-keys`))
navigateToList(gtwId)
}

render () {
const { rights, fetching, error, universalRights } = this.props

if (error) {
throw error
}

if (fetching || !rights.length) {
return <Spinner center />
}
const { rights, universalRights } = this.props

return (
<Container>
Expand Down
Loading

0 comments on commit 2f46879

Please sign in to comment.