summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/import_projects/components/provider_repo_table_row.vue
blob: d8cffc6a7d58520bc3a5a65d1c51ac38bc2e0eb7 (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
<script>
import { mapState, mapGetters, mapActions } from 'vuex';
import { GlIcon } from '@gitlab/ui';
import Select2Select from '~/vue_shared/components/select2_select.vue';
import { __ } from '~/locale';
import ImportStatus from './import_status.vue';

export default {
  name: 'ProviderRepoTableRow',
  components: {
    Select2Select,
    ImportStatus,
    GlIcon,
  },
  props: {
    repo: {
      type: Object,
      required: true,
    },
    availableNamespaces: {
      type: Array,
      required: true,
    },
  },

  computed: {
    ...mapState(['ciCdOnly']),
    ...mapGetters(['getImportTarget']),

    importTarget() {
      return this.getImportTarget(this.repo.importSource.id);
    },

    importButtonText() {
      return this.ciCdOnly ? __('Connect') : __('Import');
    },

    select2Options() {
      return {
        data: this.availableNamespaces,
        containerCssClass: 'import-namespace-select qa-project-namespace-select w-auto',
      };
    },

    targetNamespaceSelect: {
      get() {
        return this.importTarget.targetNamespace;
      },
      set(value) {
        this.updateImportTarget({ targetNamespace: value });
      },
    },

    newNameInput: {
      get() {
        return this.importTarget.newName;
      },
      set(value) {
        this.updateImportTarget({ newName: value });
      },
    },
  },

  methods: {
    ...mapActions(['fetchImport', 'setImportTarget']),
    updateImportTarget(changedValues) {
      this.setImportTarget({
        repoId: this.repo.importSource.id,
        importTarget: { ...this.importTarget, ...changedValues },
      });
    },
  },
};
</script>

<template>
  <tr class="qa-project-import-row import-row">
    <td>
      <a
        :href="repo.importSource.providerLink"
        rel="noreferrer noopener"
        target="_blank"
        data-testid="providerLink"
        >{{ repo.importSource.fullName }}
        <gl-icon v-if="repo.importSource.providerLink" name="external-link" />
      </a>
    </td>
    <td class="d-flex flex-wrap flex-lg-nowrap">
      <template v-if="repo.target">{{ repo.target }}</template>
      <template v-else>
        <select2-select v-model="targetNamespaceSelect" :options="select2Options" />
        <span class="px-2 import-slash-divider d-flex justify-content-center align-items-center"
          >/</span
        >
        <input
          v-model="newNameInput"
          type="text"
          class="form-control import-project-name-input qa-project-path-field"
        />
      </template>
    </td>
    <td>
      <import-status :status="repo.importStatus" />
    </td>
    <td>
      <button
        type="button"
        class="qa-import-button btn btn-default"
        @click="fetchImport(repo.importSource.id)"
      >
        {{ importButtonText }}
      </button>
    </td>
  </tr>
</template>