All files / app/assets/javascripts/ide/components repo_commit_section.vue

93.75% Statements 15/16
100% Branches 14/14
87.5% Functions 7/8
93.75% Lines 15/16

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  2x 2x 2x 2x                         12x     12x       12x     13x       25x 25x         36x   14x         14x 8x                       60x                            
<script>
import { mapState, mapActions, mapGetters } from 'vuex';
import { stageKeys } from '../constants';
import EmptyState from './commit_sidebar/empty_state.vue';
import CommitFilesList from './commit_sidebar/list.vue';
 
export default {
  components: {
    CommitFilesList,
    EmptyState,
  },
  computed: {
    ...mapState(['changedFiles', 'stagedFiles', 'lastCommitMsg']),
    ...mapState('commit', ['commitMessage', 'submitCommitLoading']),
    ...mapGetters(['lastOpenedFile', 'someUncommittedChanges', 'activeFile']),
    ...mapGetters('commit', ['discardDraftButtonDisabled']),
    showStageUnstageArea() {
      return Boolean(this.someUncommittedChanges || this.lastCommitMsg);
    },
    activeFileKey() {
      return this.activeFile ? this.activeFile.key : null;
    },
  },
  mounted() {
    this.initialize();
  },
  activated() {
    this.initialize();
  },
  methods: {
    ...mapActions(['openPendingTab', 'updateViewer', 'updateActivityBarView']),
    initialize() {
      const file =
        this.lastOpenedFile && this.lastOpenedFile.type !== 'tree'
          ? this.lastOpenedFile
          : this.activeFile;
 
      if (!file) return;
 
      this.openPendingTab({
        file,
        keyPrefix: file.staged ? stageKeys.staged : stageKeys.unstaged,
      })
        .then((changeViewer) => {
          if (changeViewer) {
            this.updateViewer('diff');
          }
        })
        .catch((e) => {
          throw e;
        });
    },
  },
  stageKeys,
};
</script>
 
<template>
  <div class="multi-file-commit-panel-section">
    <template v-if="showStageUnstageArea">
      <commit-files-list
        :key-prefix="$options.stageKeys.staged"
        :file-list="stagedFiles"
        :active-file-key="activeFileKey"
        :empty-state-text="__('There are no changes')"
        class="is-first"
      />
    </template>
    <empty-state v-else />
  </div>
</template>