Skip to content

Commit

Permalink
fix: Environment creating state (#4060)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-ssg authored Jun 5, 2024
1 parent 1600ed7 commit 652af8f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 35 deletions.
1 change: 1 addition & 0 deletions frontend/common/providers/ProjectProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const ProjectProvider = class extends React.Component {
this.setState(
Object.assign(
{
error: ProjectStore.error,
isLoading: ProjectStore.isLoading,
isSaving: ProjectStore.isSaving,
},
Expand Down
69 changes: 37 additions & 32 deletions frontend/common/stores/project-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const data = require('../data/base/_data')
const controller = {
createEnv: (name, projectId, cloneId, description) => {
API.trackEvent(Constants.events.CREATE_ENVIRONMENT)
store.saving()
const req = cloneId
? data.post(`${Project.api}environments/${cloneId}/clone/`, {
description,
Expand All @@ -26,39 +27,43 @@ const controller = {
project: projectId,
})

req.then((res) =>
data
.put(`${Project.api}environments/${res.api_key}/`, {
description,
name,
project: projectId,
})
.then((res) =>
data
.post(
`${Project.api}environments/${
res.api_key
}/${Utils.getIdentitiesEndpoint()}/`,
{
environment: res.api_key,
identifier: `${name.toLowerCase()}_user_123456`,
},
)
.then(() => {
store.savedEnv = res
if (store.model && store.model.environments) {
store.model.environments = store.model.environments.concat([
res,
])
}
store.saved()
getStore().dispatch(
environmentService.util.invalidateTags(['Environment']),
req
.then((res) =>
data
.put(`${Project.api}environments/${res.api_key}/`, {
description,
name,
project: projectId,
})
.then((res) =>
data
.post(
`${Project.api}environments/${
res.api_key
}/${Utils.getIdentitiesEndpoint()}/`,
{
environment: res.api_key,
identifier: `${name.toLowerCase()}_user_123456`,
},
)
AppActions.refreshOrganisation()
}),
),
)
.then(() => {
store.savedEnv = res
if (store.model && store.model.environments) {
store.model.environments = store.model.environments.concat([
res,
])
}
store.saved()
getStore().dispatch(
environmentService.util.invalidateTags(['Environment']),
)
AppActions.refreshOrganisation()
}),
),
)
.catch((e) => {
API.ajaxHandler(store, e)
})
},

deleteEnv: (env) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/web/components/ErrorMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class ErrorMessage extends PureComponent {
const errorMessageClassName = `alert alert-danger ${
this.props.errorMessageClass || 'flex-1 align-items-center'
}`
const error = this.props.error?.data || this.props.error
const error = this.props.error?.data || this.props.error?.message || this.props.error
return this.props.error ? (
<div
className={errorMessageClassName}
Expand Down
6 changes: 5 additions & 1 deletion frontend/web/components/pages/CreateEnvironmentPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,13 @@ const CreateEnvironmentPage = class extends Component {
/>
)}
</CondensedRow>
{error && (
<CondensedRow>
<ErrorMessage error={error} />
</CondensedRow>
)}
</div>

{error && <ErrorMessage error={error} />}
<CondensedRow>
<div className='text-right'>
{permission ? (
Expand Down
8 changes: 7 additions & 1 deletion frontend/web/project/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ global.API = {

// Catch coding errors that end up here
if (res instanceof Error) {
console.log(res)
console.error(res)
store.error = res
store.goneABitWest()
return
} else if (res.data) {
store.error = res.data
store.goneABitWest()
return
}

Expand Down

0 comments on commit 652af8f

Please sign in to comment.