summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ide/components/repo_commit_section.vue
blob: 6f1a941fbc4940d612228193c1fc1634b70ae5fe (plain)
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
<script>
import { mapState, mapActions, mapGetters } from 'vuex';
import tooltip from '~/vue_shared/directives/tooltip';
import Icon from '~/vue_shared/components/icon.vue';
import DeprecatedModal from '~/vue_shared/components/deprecated_modal.vue';
import CommitFilesList from './commit_sidebar/list.vue';
import EmptyState from './commit_sidebar/empty_state.vue';
import * as consts from '../stores/modules/commit/constants';
import { activityBarViews, stageKeys } from '../constants';

export default {
  components: {
    DeprecatedModal,
    Icon,
    CommitFilesList,
    EmptyState,
  },
  directives: {
    tooltip,
  },
  computed: {
    ...mapState([
      'changedFiles',
      'stagedFiles',
      'rightPanelCollapsed',
      'lastCommitMsg',
      'unusedSeal',
    ]),
    ...mapState('commit', ['commitMessage', 'submitCommitLoading']),
    ...mapGetters(['lastOpenedFile', 'hasChanges', 'someUncommitedChanges', 'activeFile']),
    ...mapGetters('commit', ['discardDraftButtonDisabled']),
    showStageUnstageArea() {
      return !!(this.someUncommitedChanges || this.lastCommitMsg || !this.unusedSeal);
    },
    activeFileKey() {
      return this.activeFile ? this.activeFile.key : null;
    },
  },
  watch: {
    hasChanges() {
      if (!this.hasChanges) {
        this.updateActivityBarView(activityBarViews.edit);
      }
    },
  },
  mounted() {
    if (this.lastOpenedFile && this.lastOpenedFile.type !== 'tree') {
      this.openPendingTab({
        file: this.lastOpenedFile,
        keyPrefix: this.lastOpenedFile.changed ? stageKeys.unstaged : stageKeys.staged,
      })
        .then(changeViewer => {
          if (changeViewer) {
            this.updateViewer('diff');
          }
        })
        .catch(e => {
          throw e;
        });
    }
  },
  methods: {
    ...mapActions(['openPendingTab', 'updateViewer', 'updateActivityBarView']),
    ...mapActions('commit', ['commitChanges', 'updateCommitAction']),
    forceCreateNewBranch() {
      return this.updateCommitAction(consts.COMMIT_TO_NEW_BRANCH).then(() => this.commitChanges());
    },
  },
  stageKeys,
};
</script>

<template>
  <div
    class="multi-file-commit-panel-section"
  >
    <deprecated-modal
      id="ide-create-branch-modal"
      :primary-button-label="__('Create new branch')"
      :title="__('Branch has changed')"
      kind="success"
      @submit="forceCreateNewBranch"
    >
      <template slot="body">
        {{ __(`This branch has changed since you started editing.
          Would you like to create a new branch?`) }}
      </template>
    </deprecated-modal>
    <template
      v-if="showStageUnstageArea"
    >
      <commit-files-list
        :title="__('Unstaged')"
        :key-prefix="$options.stageKeys.unstaged"
        :file-list="changedFiles"
        :action-btn-text="__('Stage all changes')"
        :active-file-key="activeFileKey"
        action="stageAllChanges"
        action-btn-icon="mobile-issue-close"
        item-action-component="stage-button"
        class="is-first"
        icon-name="unstaged"
      />
      <commit-files-list
        :title="__('Staged')"
        :key-prefix="$options.stageKeys.staged"
        :file-list="stagedFiles"
        :action-btn-text="__('Unstage all changes')"
        :staged-list="true"
        :active-file-key="activeFileKey"
        action="unstageAllChanges"
        action-btn-icon="history"
        item-action-component="unstage-button"
        icon-name="staged"
      />
    </template>
    <empty-state
      v-if="unusedSeal"
    />
  </div>
</template>