All files / app/assets/javascripts/import_entities/import_projects/components provider_repo_table_row.vue

84% Statements 21/25
76.92% Branches 10/13
83.33% Functions 15/18
84% Lines 21/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262                      5x                                                                                           22x                   11x       22x       22x       14x       22x       2x       22x       22x       11x       22x       17x       17x         11x                                   5x 2x 2x 2x     3x   3x                                                                                                                                                                                                                                              
<script>
import {
  GlIcon,
  GlBadge,
  GlFormInput,
  GlButton,
  GlLink,
  GlTooltip,
  GlSprintf,
  GlTooltipDirective,
} from '@gitlab/ui';
// eslint-disable-next-line no-restricted-imports
import { mapState, mapGetters, mapActions } from 'vuex';
import { __ } from '~/locale';
import { helpPagePath } from '~/helpers/help_page_helper';
import ImportTargetDropdown from '../../components/import_target_dropdown.vue';
import ImportStatus from '../../components/import_status.vue';
import { STATUSES } from '../../constants';
import { isProjectImportable, isImporting, isIncompatible, getImportStatus } from '../utils';
 
export default {
  name: 'ProviderRepoTableRow',
  components: {
    ImportStatus,
    ImportTargetDropdown,
    GlFormInput,
    GlButton,
    GlIcon,
    GlBadge,
    GlLink,
    GlTooltip,
    GlSprintf,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  props: {
    repo: {
      type: Object,
      required: true,
    },
    userNamespace: {
      type: String,
      required: true,
    },
    optionalStages: {
      type: Object,
      required: true,
    },
    cancelable: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
 
  data() {
    return {
      isSelectedForReimport: false,
    };
  },
 
  computed: {
    ...mapState(['ciCdOnly']),
    ...mapGetters(['getImportTarget']),
 
    displayFullPath() {
      return this.repo.importedProject?.fullPath.replace(/^\//, '');
    },
 
    isFinished() {
      return this.repo.importedProject?.importStatus === STATUSES.FINISHED;
    },
 
    isImportNotStarted() {
      return isProjectImportable(this.repo);
    },
 
    isIncompatible() {
      return isIncompatible(this.repo);
    },
 
    importStatus() {
      return getImportStatus(this.repo);
    },
 
    isImporting() {
      return isImporting(this.repo);
    },
 
    isCancelable() {
      return this.cancelable && this.isImporting && this.importStatus !== STATUSES.SCHEDULING;
    },
 
    stats() {
      return this.repo.importedProject?.stats;
    },
 
    importTarget() {
      return this.getImportTarget(this.repo.importSource.id);
    },
 
    importedProjectId() {
      return this.repo.importedProject?.id;
    },
 
    importButtonText() {
      Iif (this.ciCdOnly) {
        return __('Connect');
      }
 
      return this.isFinished ? __('Re-import') : __('Import');
    },
 
    newNameInput: {
      get() {
        return this.importTarget.newName;
      },
      set(value) {
        this.updateImportTarget({ newName: value });
      },
    },
  },
 
  methods: {
    ...mapActions(['fetchImport', 'cancelImport', 'setImportTarget']),
    updateImportTarget(changedValues) {
      this.setImportTarget({
        repoId: this.repo.importSource.id,
        importTarget: { ...this.importTarget, ...changedValues },
      });
    },
 
    handleImportRepo() {
      if (this.isFinished && !this.isSelectedForReimport) {
        this.isSelectedForReimport = true;
        this.$nextTick(() => {
          this.$refs.newNameInput.$el.focus();
        });
      } else {
        this.isSelectedForReimport = false;
 
        this.fetchImport({
          repoId: this.repo.importSource.id,
          optionalStages: this.optionalStages,
        });
      }
    },
 
    onSelect(value) {
      this.updateImportTarget({ targetNamespace: value });
    },
  },
 
  helpUrl: helpPagePath('/user/project/import/github.md'),
};
</script>
 
<template>
  <tr
    class="gl-h-11"
    data-testid="project-import-row"
    :data-qa-source-project="repo.importSource.fullName"
  >
    <td>
      <gl-link :href="repo.importSource.providerLink" target="_blank" data-testid="providerLink"
        >{{ repo.importSource.fullName }}
        <gl-icon v-if="repo.importSource.providerLink" name="external-link" />
      </gl-link>
      <div v-if="isFinished" class="gl-font-sm gl-mt-2">
        <gl-sprintf :message="s__('BulkImport|Last imported to %{link}')">
          <template #link>
            <gl-link
              :href="repo.importedProject.fullPath"
              class="gl-font-sm"
              target="_blank"
              data-testid="go-to-project-link"
            >
              {{ displayFullPath }}
            </gl-link>
          </template>
        </gl-sprintf>
      </div>
    </td>
    <td data-testid="fullPath">
      <div class="gl-display-flex gl-sm-flex-wrap">
        <template v-if="repo.importSource.target">{{ repo.importSource.target }}</template>
        <template v-else-if="isImportNotStarted || isSelectedForReimport">
          <div class="gl-display-flex gl-align-items-stretch gl-w-full">
            <import-target-dropdown
              :selected="importTarget.targetNamespace"
              :user-namespace="userNamespace"
              @select="onSelect"
            />
            <div
              class="gl-px-3 gl-display-flex gl-align-items-center gl-border-solid gl-border-0 gl-border-t-1 gl-border-b-1 gl-border-gray-400"
            >
              /
            </div>
            <gl-form-input
              ref="newNameInput"
              v-model="newNameInput"
              class="gl-rounded-top-left-none gl-rounded-bottom-left-none"
              data-testid="project-path-field"
            />
          </div>
        </template>
        <template v-else-if="repo.importedProject">{{ displayFullPath }}</template>
      </div>
    </td>
    <td data-testid="import-status-indicator">
      <import-status :project-id="importedProjectId" :status="importStatus" :stats="stats" />
    </td>
    <td data-testid="actions" class="gl-white-space-nowrap">
      <gl-tooltip :target="() => $refs.cancelButton.$el">
        <div class="gl-text-left">
          <p class="gl-mb-5 gl-font-weight-bold">{{ s__('ImportProjects|Cancel import') }}</p>
          {{
            s__(
              'ImportProjects|Imported files will be kept. You can import this repository again later.',
            )
          }}
          <gl-link :href="$options.helpUrl" target="_blank">{{ __('Learn more.') }}</gl-link>
        </div>
      </gl-tooltip>
      <gl-button
        v-show="isCancelable"
        ref="cancelButton"
        variant="danger"
        category="secondary"
        icon="cancel"
        :aria-label="__('Cancel')"
        @click="cancelImport({ repoId: repo.importSource.id })"
      />
      <gl-button
        v-if="isImportNotStarted || isFinished"
        type="button"
        data-testid="import-button"
        @click="handleImportRepo()"
      >
        {{ importButtonText }}
      </gl-button>
      <gl-icon
        v-if="isFinished"
        v-gl-tooltip
        :size="16"
        name="information-o"
        :title="
          s__(
            'ImportProjects|Re-import creates a new project. It does not sync with the existing project.',
          )
        "
        class="gl-ml-3"
      />
 
      <gl-badge v-else-if="isIncompatible" variant="danger">{{
        __('Incompatible project')
      }}</gl-badge>
    </td>
  </tr>
</template>