summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/projects/settings/repository/branch_rules/app.vue
blob: a9eb2a53fbf952d306b1be1f4410cce3dfd2a466 (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
<script>
import { s__ } from '~/locale';
import { createAlert } from '~/flash';
import branchRulesQuery from './graphql/queries/branch_rules.query.graphql';
import BranchRule from './components/branch_rule.vue';

export const i18n = {
  queryError: s__(
    'ProtectedBranch|An error occurred while loading branch rules. Please try again.',
  ),
  emptyState: s__(
    'ProtectedBranch|Protected branches, merge request approvals, and status checks will appear here once configured.',
  ),
};

export default {
  name: 'BranchRules',
  i18n,
  components: {
    BranchRule,
  },
  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: [],
    };
  },
};
</script>

<template>
  <div class="settings-content">
    <branch-rule
      v-for="rule in branchRules"
      :key="rule.name"
      :name="rule.name"
      :is-default="rule.isDefault"
      :branch-protection="rule.branchProtection"
      :status-checks-total="rule.externalStatusChecks.nodes.length"
      :approval-rules-total="rule.approvalRules.nodes.length"
    />

    <span v-if="!branchRules.length" data-testid="empty">{{ $options.i18n.emptyState }}</span>
  </div>
</template>