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

confirm_fork_modal.vue « web_ide « components « vue_shared « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b4afb27c497a816872576edc5b8a95e9ae74a9fa (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
<script>
import { GlModal, GlLoadingIcon, GlLink } from '@gitlab/ui';
import { __ } from '~/locale';
import getWritableForksQuery from './get_writable_forks.query.graphql';

export const i18n = {
  btnText: __('Create a new fork'),
  title: __('Fork project?'),
  message: __('You can’t edit files directly in this project.'),
  existingForksMessage: __(
    'To submit your changes in a merge request, switch to one of these forks or create a new fork.',
  ),
  newForkMessage: __('To submit your changes in a merge request, create a new fork.'),
};

export default {
  name: 'ConfirmForkModal',
  components: {
    GlModal,
    GlLoadingIcon,
    GlLink,
  },
  inject: {
    projectPath: {
      default: '',
    },
  },
  model: {
    prop: 'visible',
    event: 'change',
  },
  props: {
    visible: {
      type: Boolean,
      required: false,
      default: false,
    },
    modalId: {
      type: String,
      required: true,
    },
    forkPath: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      forks: [],
    };
  },
  apollo: {
    forks: {
      query: getWritableForksQuery,
      variables() {
        return {
          projectPath: this.projectPath,
        };
      },
      update({ project } = {}) {
        return project?.visibleForks?.nodes.map((node) => {
          return {
            text: node.fullPath,
            href: node.webUrl,
          };
        });
      },
    },
  },
  computed: {
    isLoading() {
      return this.$apollo.queries.forks.loading;
    },
    hasWritableForks() {
      return this.forks.length;
    },
    btnActions() {
      return {
        cancel: { text: __('Cancel') },
        primary: {
          text: this.$options.i18n.btnText,
          attributes: {
            href: this.forkPath,
            variant: 'confirm',
            'data-qa-selector': 'fork_project_button',
          },
        },
      };
    },
  },
  i18n,
};
</script>
<template>
  <gl-modal
    :visible="visible"
    data-qa-selector="confirm_fork_modal"
    :modal-id="modalId"
    :title="$options.i18n.title"
    :action-primary="btnActions.primary"
    :action-cancel="btnActions.cancel"
    @change="$emit('change', $event)"
  >
    <p>{{ $options.i18n.message }}</p>
    <gl-loading-icon v-if="isLoading" />
    <template v-else-if="hasWritableForks">
      <p>{{ $options.i18n.existingForksMessage }}</p>
      <div v-for="fork in forks" :key="fork.text">
        <gl-link :href="fork.href">{{ fork.text }}</gl-link>
      </div>
    </template>
    <p v-else>{{ $options.i18n.newForkMessage }}</p>
  </gl-modal>
</template>