Welcome to mirror list, hosted at ThFree Co, Russian Federation.

compare_app.vue « components « merge_requests « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8e02048f4948e5eccb67b34b840dc9f64eee8553 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
<script>
import { GlLoadingIcon, GlIcon } from '@gitlab/ui';
import SafeHtml from '~/vue_shared/directives/safe_html';
import axios from '~/lib/utils/axios_utils';
import CompareDropdown from '~/merge_requests/components/compare_dropdown.vue';

export default {
  components: {
    GlIcon,
    GlLoadingIcon,
    CompareDropdown,
  },
  directives: {
    SafeHtml,
  },
  inject: {
    projectsPath: {
      default: '',
    },
    branchCommitPath: {
      default: '',
    },
    currentProject: {
      default: () => ({}),
    },
    currentBranch: {
      default: () => ({}),
    },
    inputs: {
      default: () => ({}),
    },
    i18n: {
      default: () => ({}),
    },
    toggleClass: {
      default: () => ({}),
    },
    branchQaSelector: {
      default: '',
    },
  },
  data() {
    return {
      selectedProject: this.currentProject,
      selectedBranch: this.currentBranch,
      loading: false,
      commitHtml: null,
    };
  },
  computed: {
    staticProjectData() {
      if (this.projectsPath) return undefined;

      return [this.currentProject];
    },
    showCommitBox() {
      return this.commitHtml || this.loading || !this.selectedBranch.value;
    },
  },
  mounted() {
    this.fetchCommit();
  },
  methods: {
    selectProject(p) {
      this.selectedProject = p;
    },
    selectBranch(branch) {
      this.selectedBranch = branch;
      this.fetchCommit();
    },
    async fetchCommit() {
      if (!this.selectedBranch.value) return;

      this.loading = true;

      const { data } = await axios.get(this.branchCommitPath, {
        params: { target_project_id: this.selectedProject.value, ref: this.selectedBranch.value },
      });

      this.loading = false;
      this.commitHtml = data;
    },
  },
};
</script>

<template>
  <div>
    <div class="clearfix">
      <div class="merge-request-select gl-pl-0">
        <compare-dropdown
          :static-data="staticProjectData"
          :endpoint="projectsPath"
          :default="currentProject"
          :dropdown-header="i18n.projectHeaderText"
          :input-id="inputs.project.id"
          :input-name="inputs.project.name"
          :toggle-class="toggleClass.project"
          is-project
          @selected="selectProject"
        />
      </div>
      <div class="merge-request-select merge-request-branch-select gl-pr-0">
        <compare-dropdown
          :endpoint="selectedProject.refsUrl"
          :dropdown-header="i18n.branchHeaderText"
          :input-id="inputs.branch.id"
          :input-name="inputs.branch.name"
          :default="currentBranch"
          :toggle-class="toggleClass.branch"
          :qa-selector="branchQaSelector"
          @selected="selectBranch"
        />
      </div>
    </div>
    <div
      v-if="showCommitBox"
      class="gl-bg-gray-50 gl-rounded-base gl-my-4"
      data-testid="commit-box"
    >
      <gl-loading-icon v-if="loading" class="gl-py-3" />
      <template v-else>
        <div
          v-if="!selectedBranch.value"
          class="compare-commit-empty gl-display-flex gl-align-items-center gl-p-5"
        >
          <gl-icon name="branch" class="gl-mr-3" />
          {{ __('Select a branch to compare') }}
        </div>
        <ul v-safe-html="commitHtml" class="list-unstyled mr_source_commit"></ul>
      </template>
    </div>
  </div>
</template>