diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-04 18:08:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-04 18:08:09 +0300 |
commit | d3fc3be040a4fed2328e23ef28696dd8bd8238b4 (patch) | |
tree | f1874ea5e6e3c50c6a3c2ca2900af4ae73a53119 /app/assets/javascripts/vue_shared/components/sidebar/labels_select_vue/store/mutations.js | |
parent | c6c7437861bff9572747674095c4dfbdfbea4988 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/vue_shared/components/sidebar/labels_select_vue/store/mutations.js')
-rw-r--r-- | app/assets/javascripts/vue_shared/components/sidebar/labels_select_vue/store/mutations.js | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/app/assets/javascripts/vue_shared/components/sidebar/labels_select_vue/store/mutations.js b/app/assets/javascripts/vue_shared/components/sidebar/labels_select_vue/store/mutations.js new file mode 100644 index 00000000000..32a78507e88 --- /dev/null +++ b/app/assets/javascripts/vue_shared/components/sidebar/labels_select_vue/store/mutations.js @@ -0,0 +1,76 @@ +import * as types from './mutation_types'; + +export default { + [types.SET_INITIAL_STATE](state, props) { + Object.assign(state, { ...props }); + }, + + [types.TOGGLE_DROPDOWN_BUTTON](state) { + state.showDropdownButton = !state.showDropdownButton; + }, + + [types.TOGGLE_DROPDOWN_CONTENTS](state) { + if (!state.dropdownOnly) { + state.showDropdownButton = !state.showDropdownButton; + } + state.showDropdownContents = !state.showDropdownContents; + // Ensure that Create View is hidden by default + // when dropdown contents are revealed. + if (state.showDropdownContents) { + state.showDropdownContentsCreateView = false; + } + }, + + [types.TOGGLE_DROPDOWN_CONTENTS_CREATE_VIEW](state) { + state.showDropdownContentsCreateView = !state.showDropdownContentsCreateView; + }, + + [types.REQUEST_LABELS](state) { + state.labelsFetchInProgress = true; + }, + [types.RECEIVE_SET_LABELS_SUCCESS](state, labels) { + // Iterate over every label and add a `set` prop + // to determine whether it is already a part of + // selectedLabels array. + const selectedLabelIds = state.selectedLabels.map(label => label.id); + state.labelsFetchInProgress = false; + state.labels = labels.reduce((allLabels, label) => { + allLabels.push({ + ...label, + set: selectedLabelIds.includes(label.id), + }); + return allLabels; + }, []); + }, + [types.RECEIVE_SET_LABELS_FAILURE](state) { + state.labelsFetchInProgress = false; + }, + + [types.REQUEST_CREATE_LABEL](state) { + state.labelCreateInProgress = true; + }, + [types.RECEIVE_CREATE_LABEL_SUCCESS](state) { + state.labelCreateInProgress = false; + }, + [types.RECEIVE_CREATE_LABEL_FAILURE](state) { + state.labelCreateInProgress = false; + }, + + [types.UPDATE_SELECTED_LABELS](state, { labels }) { + // Iterate over all the labels and update + // `set` prop value to represent their current state. + const labelIds = labels.map(label => label.id); + state.labels = state.labels.reduce((allLabels, label) => { + if (labelIds.includes(label.id)) { + allLabels.push({ + ...label, + touched: true, + set: !label.set, + }); + } else { + allLabels.push(label); + } + return allLabels; + }, []); + }, +}; |