All files / app/assets/javascripts/releases/stores/modules/edit_new mutations.js

100% Statements 43/43
100% Branches 0/0
100% Functions 27/27
100% Lines 41/41

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124        4x 3x         1x                           1x     1x 1x 1x 1x     1x 1x 1x       9x     2x     9x     1x     1x       1x       1x       1x     1x 1x     1x 1x       1x                 1x 1x       1x 1x       1x 1x       5x       7x     1x 1x 1x 1x     7x 7x 7x     1x     1x      
import { uniqueId, cloneDeep } from 'lodash';
import { DEFAULT_ASSET_LINK_TYPE } from '../../../constants';
import * as types from './mutation_types';
 
const findReleaseLink = (release, id) => {
  return release.assets.links.find((l) => l.id === id);
};
 
export default {
  [types.INITIALIZE_EMPTY_RELEASE](state) {
    state.release = {
      tagName: state.tagName,
      name: '',
      description: '',
      milestones: [],
      groupMilestones: [],
      releasedAt: new Date(),
      assets: {
        links: [],
      },
    };
  },
 
  [types.REQUEST_RELEASE](state) {
    state.isFetchingRelease = true;
  },
  [types.RECEIVE_RELEASE_SUCCESS](state, data) {
    state.fetchError = undefined;
    state.isFetchingRelease = false;
    state.release = data;
    state.originalRelease = Object.freeze(cloneDeep(state.release));
  },
  [types.RECEIVE_RELEASE_ERROR](state, error) {
    state.fetchError = error;
    state.isFetchingRelease = false;
    state.release = undefined;
  },
 
  [types.UPDATE_RELEASE_TAG_NAME](state, tagName) {
    state.release.tagName = tagName;
  },
  [types.UPDATE_CREATE_FROM](state, createFrom) {
    state.createFrom = createFrom;
  },
  [types.UPDATE_SHOW_CREATE_FROM](state, showCreateFrom) {
    state.showCreateFrom = showCreateFrom;
  },
  [types.UPDATE_RELEASE_TITLE](state, title) {
    state.release.name = title;
  },
  [types.UPDATE_RELEASE_NOTES](state, notes) {
    state.release.description = notes;
  },
 
  [types.UPDATE_RELEASE_MILESTONES](state, milestones) {
    state.release.milestones = milestones;
  },
 
  [types.UPDATE_RELEASE_GROUP_MILESTONES](state, groupMilestones) {
    state.release.groupMilestones = groupMilestones;
  },
 
  [types.REQUEST_SAVE_RELEASE](state) {
    state.isUpdatingRelease = true;
  },
  [types.RECEIVE_SAVE_RELEASE_SUCCESS](state) {
    state.updateError = undefined;
    state.isUpdatingRelease = false;
  },
  [types.RECEIVE_SAVE_RELEASE_ERROR](state, error) {
    state.updateError = error;
    state.isUpdatingRelease = false;
  },
 
  [types.ADD_EMPTY_ASSET_LINK](state) {
    state.release.assets.links.push({
      id: uniqueId('new-link-'),
      url: '',
      name: '',
      linkType: DEFAULT_ASSET_LINK_TYPE,
    });
  },
 
  [types.UPDATE_ASSET_LINK_URL](state, { linkIdToUpdate, newUrl }) {
    const linkToUpdate = findReleaseLink(state.release, linkIdToUpdate);
    linkToUpdate.url = newUrl;
  },
 
  [types.UPDATE_ASSET_LINK_NAME](state, { linkIdToUpdate, newName }) {
    const linkToUpdate = findReleaseLink(state.release, linkIdToUpdate);
    linkToUpdate.name = newName;
  },
 
  [types.UPDATE_ASSET_LINK_TYPE](state, { linkIdToUpdate, newType }) {
    const linkToUpdate = findReleaseLink(state.release, linkIdToUpdate);
    linkToUpdate.linkType = newType;
  },
 
  [types.REMOVE_ASSET_LINK](state, linkIdToRemove) {
    state.release.assets.links = state.release.assets.links.filter((l) => l.id !== linkIdToRemove);
  },
 
  [types.REQUEST_TAG_NOTES](state) {
    state.isFetchingTagNotes = true;
  },
  [types.RECEIVE_TAG_NOTES_SUCCESS](state, data) {
    state.fetchError = undefined;
    state.isFetchingTagNotes = false;
    state.tagNotes = data.message;
    state.existingRelease = data.release;
  },
  [types.RECEIVE_TAG_NOTES_ERROR](state, error) {
    state.fetchError = error;
    state.isFetchingTagNotes = false;
    state.tagNotes = '';
  },
  [types.UPDATE_INCLUDE_TAG_NOTES](state, includeTagNotes) {
    state.includeTagNotes = includeTagNotes;
  },
  [types.UPDATE_RELEASED_AT](state, releasedAt) {
    state.release.releasedAt = releasedAt;
  },
};