diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-01 12:08:00 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-01 12:08:00 +0000 |
commit | 1a0d6dbdc2ac3047f4953a359ef27ba6e26074ae (patch) | |
tree | ddb78a8a0d1350dc767f049a21e0f7d37edaa82c /app/assets/javascripts/releases/stores/modules/detail/actions.js | |
parent | b11f7057d067885619ee3e513751f180b2e8ad85 (diff) | |
download | gitlab-ce-1a0d6dbdc2ac3047f4953a359ef27ba6e26074ae.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/releases/stores/modules/detail/actions.js')
-rw-r--r-- | app/assets/javascripts/releases/stores/modules/detail/actions.js | 74 |
1 files changed, 64 insertions, 10 deletions
diff --git a/app/assets/javascripts/releases/stores/modules/detail/actions.js b/app/assets/javascripts/releases/stores/modules/detail/actions.js index 1b77f01368e..7b84c18242c 100644 --- a/app/assets/javascripts/releases/stores/modules/detail/actions.js +++ b/app/assets/javascripts/releases/stores/modules/detail/actions.js @@ -41,20 +41,74 @@ export const receiveUpdateReleaseError = ({ commit }, error) => { createFlash(s__('Release|Something went wrong while saving the release details')); }; -export const updateRelease = ({ dispatch, state }) => { +export const updateRelease = ({ dispatch, state, getters }) => { dispatch('requestUpdateRelease'); - return api - .updateRelease(state.projectId, state.tagName, { - name: state.release.name, - description: state.release.description, - }) - .then(() => dispatch('receiveUpdateReleaseSuccess')) - .catch(error => { - dispatch('receiveUpdateReleaseError', error); - }); + const { release } = state; + + return ( + api + .updateRelease(state.projectId, state.tagName, { + name: release.name, + description: release.description, + }) + + /** + * Currently, we delete all existing links and then + * recreate new ones on each edit. This is because the + * REST API doesn't support bulk updating of Release links, + * and updating individual links can lead to validation + * race conditions (in particular, the "URLs must be unique") + * constraint. + * + * This isn't ideal since this is no longer an atomic + * operation - parts of it can fail while others succeed, + * leaving the Release in an inconsistent state. + * + * This logic should be refactored to use GraphQL once + * https://gitlab.com/gitlab-org/gitlab/-/issues/208702 + * is closed. + */ + + .then(() => { + // Delete all links currently associated with this Release + return Promise.all( + getters.releaseLinksToDelete.map(l => + api.deleteReleaseLink(state.projectId, release.tagName, l.id), + ), + ); + }) + .then(() => { + // Create a new link for each link in the form + return Promise.all( + getters.releaseLinksToCreate.map(l => + api.createReleaseLink(state.projectId, release.tagName, l), + ), + ); + }) + .then(() => dispatch('receiveUpdateReleaseSuccess')) + .catch(error => { + dispatch('receiveUpdateReleaseError', error); + }) + ); }; export const navigateToReleasesPage = ({ state }) => { redirectTo(state.releasesPagePath); }; + +export const addEmptyAssetLink = ({ commit }) => { + commit(types.ADD_EMPTY_ASSET_LINK); +}; + +export const updateAssetLinkUrl = ({ commit }, { linkIdToUpdate, newUrl }) => { + commit(types.UPDATE_ASSET_LINK_URL, { linkIdToUpdate, newUrl }); +}; + +export const updateAssetLinkName = ({ commit }, { linkIdToUpdate, newName }) => { + commit(types.UPDATE_ASSET_LINK_NAME, { linkIdToUpdate, newName }); +}; + +export const removeAssetLink = ({ commit }, linkIdToRemove) => { + commit(types.REMOVE_ASSET_LINK, linkIdToRemove); +}; |