All files / ee/app/assets/javascripts/geo_replicable/components geo_replicable_item.vue

100% Statements 2/2
100% Branches 2/2
100% Functions 1/1
100% Lines 2/2

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    3x                                                                                                       16x                                                                                                                                  
<script>
import { GlButton } from '@gitlab/ui';
// eslint-disable-next-line no-restricted-imports
import { mapActions, mapState } from 'vuex';
import { capitalizeFirstCharacter } from '~/lib/utils/text_utility';
import { __, s__ } from '~/locale';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { ACTION_TYPES } from '../constants';
import GeoReplicableStatus from './geo_replicable_status.vue';
import GeoReplicableTimeAgo from './geo_replicable_time_ago.vue';
 
export default {
  name: 'GeoReplicableItem',
  i18n: {
    unknown: __('Unknown'),
    nA: __('Not applicable.'),
    resync: s__('Geo|Resync'),
    reverify: s__('Geo|Reverify'),
    lastVerified: s__('Geo|Last time verified'),
  },
  components: {
    GlButton,
    GeoReplicableTimeAgo,
    GeoReplicableStatus,
  },
  mixins: [glFeatureFlagMixin()],
  props: {
    name: {
      type: String,
      required: true,
    },
    registryId: {
      type: [String, Number],
      required: true,
    },
    syncStatus: {
      type: String,
      required: false,
      default: '',
    },
    lastSynced: {
      type: String,
      required: false,
      default: '',
    },
    lastVerified: {
      type: String,
      required: false,
      default: '',
    },
  },
  computed: {
    ...mapState(['verificationEnabled']),
    timeAgoArray() {
      return [
        {
          label: capitalizeFirstCharacter(this.syncStatus),
          dateString: this.lastSynced,
          defaultText: this.$options.i18n.unknown,
        },
        {
          label: this.$options.i18n.lastVerified,
          dateString: this.lastVerified,
          defaultText: this.verificationEnabled
            ? this.$options.i18n.unknown
            : this.$options.i18n.nA,
        },
      ];
    },
  },
  methods: {
    ...mapActions(['initiateReplicableAction']),
  },
  actionTypes: ACTION_TYPES,
};
</script>
 
<template>
  <div class="gl-border-b gl-p-5">
    <div
      class="geo-replicable-item-grid gl-display-grid gl-align-items-center gl-pb-4"
      data-testid="replicable-item-header"
    >
      <geo-replicable-status :status="syncStatus" />
      <span class="gl-font-weight-bold">{{ name }}</span>
      <div>
        <gl-button
          data-testid="geo-resync-item"
          size="small"
          @click="
            initiateReplicableAction({ registryId, name, action: $options.actionTypes.RESYNC })
          "
        >
          {{ $options.i18n.resync }}
        </gl-button>
        <gl-button
          v-if="verificationEnabled"
          data-testid="geo-reverify-item"
          size="small"
          @click="
            initiateReplicableAction({ registryId, name, action: $options.actionTypes.REVERIFY })
          "
        >
          {{ $options.i18n.reverify }}
        </gl-button>
      </div>
    </div>
    <div class="gl-display-flex gl-align-items-center gl-flex-wrap">
      <geo-replicable-time-ago
        v-for="(timeAgo, index) in timeAgoArray"
        :key="index"
        :label="timeAgo.label"
        :date-string="timeAgo.dateString"
        :default-text="timeAgo.defaultText"
        :show-divider="index !== timeAgoArray.length - 1"
      />
    </div>
  </div>
</template>