All files / app/assets/javascripts/import_entities/components import_status.vue

4.76% Statements 1/21
0% Branches 0/14
16.66% Functions 2/12
4.76% Lines 1/21

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                14x                                                                                                                                                                                                                                                                    
<script>
import { GlAccordion, GlAccordionItem, GlBadge, GlIcon, GlLink } from '@gitlab/ui';
import { s__ } from '~/locale';
 
import { STATISTIC_ITEMS } from '~/import/constants';
import { STATUSES, STATUS_ICON_MAP } from '../constants';
 
function isIncompleteImport(stats) {
  return Object.keys(stats?.fetched ?? []).some(
    (key) => stats.fetched[key] !== stats.imported[key],
  );
}
 
export default {
  name: 'ImportStatus',
  components: {
    GlAccordion,
    GlAccordionItem,
    GlBadge,
    GlIcon,
    GlLink,
  },
  inject: {
    detailsPath: {
      default: undefined,
    },
  },
  props: {
    projectId: {
      type: Number,
      required: false,
      default: null,
    },
    status: {
      type: String,
      required: true,
    },
    stats: {
      type: Object,
      required: false,
      default: () => ({ fetched: {}, imported: {} }),
    },
  },
 
  computed: {
    knownStats() {
      const knownStatisticKeys = Object.keys(STATISTIC_ITEMS);
      return Object.keys(this.stats?.fetched ?? []).filter((key) =>
        knownStatisticKeys.includes(key),
      );
    },
 
    hasStats() {
      return this.stats && this.knownStats.length > 0;
    },
 
    isIncomplete() {
      return this.status === STATUSES.FINISHED && this.stats && isIncompleteImport(this.stats);
    },
 
    mappedStatus() {
      Iif (this.isIncomplete) {
        return STATUS_ICON_MAP[STATUSES.PARTIAL];
      }
 
      return STATUS_ICON_MAP[this.status];
    },
 
    showDetails() {
      return Boolean(this.detailsPathForProject) && this.isIncomplete;
    },
 
    detailsPathForProject() {
      Iif (!this.projectId || !this.detailsPath) {
        return null;
      }
 
      return `${this.detailsPath}?project_id=${this.projectId}`;
    },
  },
 
  methods: {
    getStatisticIconProps(key) {
      const fetched = this.stats.fetched[key];
      const imported = this.stats.imported[key];
 
      Iif (fetched === imported) {
        return { name: 'status-success', class: 'gl-text-green-400' };
      }
      Iif (imported === 0) {
        return { name: 'status-scheduled', class: 'gl-text-gray-400' };
      }
      Iif (this.status === STATUSES.FINISHED) {
        return { name: 'status-alert', class: 'gl-text-orange-400' };
      }
 
      return { name: 'status-running', class: 'gl-text-blue-400' };
    },
  },
 
  STATISTIC_ITEMS,
  i18n: {
    detailsLink: s__('Import|See failures'),
  },
};
</script>
 
<template>
  <div>
    <div class="gl-display-inline-block">
      <gl-badge :icon="mappedStatus.icon" :variant="mappedStatus.variant" size="md" icon-size="sm">
        {{ mappedStatus.text }}
      </gl-badge>
    </div>
    <gl-accordion v-if="hasStats" :header-level="3">
      <gl-accordion-item :title="__('Details')">
        <ul class="gl-p-0 gl-mb-3 gl-list-style-none gl-font-sm">
          <li v-for="key in knownStats" :key="key">
            <div class="gl-display-flex gl-w-20 gl-align-items-center">
              <gl-icon
                :size="12"
                class="gl-mr-3 gl-flex-shrink-0"
                v-bind="getStatisticIconProps(key)"
              />
              <span class="">{{ $options.STATISTIC_ITEMS[key] }}</span>
              <span class="gl-ml-auto">
                {{ stats.imported[key] || 0 }}/{{ stats.fetched[key] }}
              </span>
            </div>
          </li>
        </ul>
        <gl-link v-if="showDetails" :href="detailsPathForProject">{{
          $options.i18n.detailsLink
        }}</gl-link>
      </gl-accordion-item>
    </gl-accordion>
  </div>
</template>