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

app.vue « branch_rules « repository « settings « projects « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7753b850744c2bfc207e242cb5efb1c1a2d32045 (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
<script>
import { GlButton, GlModal, GlModalDirective, GlCard, GlIcon } from '@gitlab/ui';
import { createAlert } from '~/alert';
import branchRulesQuery from 'ee_else_ce/projects/settings/repository/branch_rules/graphql/queries/branch_rules.query.graphql';
import { expandSection } from '~/settings_panels';
import { scrollToElement } from '~/lib/utils/common_utils';
import BranchRule from './components/branch_rule.vue';
import { I18N, PROTECTED_BRANCHES_ANCHOR, BRANCH_PROTECTION_MODAL_ID } from './constants';

export default {
  name: 'BranchRules',
  i18n: I18N,
  components: {
    BranchRule,
    GlButton,
    GlModal,
    GlCard,
    GlIcon,
  },
  directives: {
    GlModal: GlModalDirective,
  },
  apollo: {
    branchRules: {
      query: branchRulesQuery,
      variables() {
        return {
          projectPath: this.projectPath,
        };
      },
      update(data) {
        return data.project?.branchRules?.nodes || [];
      },
      error() {
        createAlert({ message: this.$options.i18n.queryError });
      },
    },
  },
  inject: {
    projectPath: { default: '' },
  },
  data() {
    return {
      branchRules: [],
    };
  },
  methods: {
    showProtectedBranches() {
      // Protected branches section is on the same page as the branch rules section.
      expandSection(this.$options.protectedBranchesAnchor);
      scrollToElement(this.$options.protectedBranchesAnchor);
    },
  },
  modalId: BRANCH_PROTECTION_MODAL_ID,
  protectedBranchesAnchor: PROTECTED_BRANCHES_ANCHOR,
};
</script>

<template>
  <gl-card
    class="gl-new-card gl-overflow-hidden"
    header-class="gl-new-card-header"
    body-class="gl-new-card-body gl-px-0"
  >
    <template #header>
      <div class="gl-new-card-title-wrapper" data-testid="title">
        <h3 class="gl-new-card-title">
          {{ __('Branch Rules') }}
        </h3>
        <div class="gl-new-card-count">
          <gl-icon name="branch" class="gl-mr-2" />
          {{ branchRules.length }}
        </div>
      </div>
      <gl-button
        v-gl-modal="$options.modalId"
        size="small"
        class="gl-ml-3"
        data-qa-selector="add_branch_rule_button"
        >{{ $options.i18n.addBranchRule }}</gl-button
      >
    </template>
    <ul class="content-list">
      <branch-rule
        v-for="(rule, index) in branchRules"
        :key="`${rule.name}-${index}`"
        :name="rule.name"
        :is-default="rule.isDefault"
        :branch-protection="rule.branchProtection"
        :status-checks-total="
          rule.externalStatusChecks ? rule.externalStatusChecks.nodes.length : 0
        "
        :approval-rules-total="rule.approvalRules ? rule.approvalRules.nodes.length : 0"
        :matching-branches-count="rule.matchingBranchesCount"
        class="gl-px-5! gl-py-4!"
      />
      <div v-if="!branchRules.length" class="gl-new-card-empty gl-px-5 gl-py-4" data-testid="empty">
        {{ $options.i18n.emptyState }}
      </div>
    </ul>
    <gl-modal
      :ref="$options.modalId"
      :modal-id="$options.modalId"
      :title="$options.i18n.addBranchRule"
      :ok-title="$options.i18n.createProtectedBranch"
      @ok="showProtectedBranches"
    >
      <p>{{ $options.i18n.branchRuleModalDescription }}</p>
      <p>{{ $options.i18n.branchRuleModalContent }}</p>
    </gl-modal>
  </gl-card>
</template>