All files / ee/app/assets/javascripts/oncall_schedules/components/rotations/components rotation_assignee.vue

20% Statements 3/15
0% Branches 0/1
0% Functions 0/7
23.07% Lines 3/13

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              8x           8x 8x                                                                                                                                                                                                                                        
<script>
import { GlAvatar, GlPopover } from '@gitlab/ui';
import { uniqueId } from 'lodash';
import { formatDate } from '~/lib/utils/datetime_utility';
import { truncate } from '~/lib/utils/text_utility';
import { __, sprintf } from '~/locale';
 
export const SHIFT_WIDTHS = {
  md: 100,
  sm: 75,
  xs: 20,
};
 
const ROTATION_CENTER_CLASS = 'gl-rounded-base gl-display-flex gl-align-items-center';
export const TIME_DATE_FORMAT = 'mmmm d, yyyy, HH:MM ("UTC:" o)';
 
export default {
  ROTATION_CENTER_CLASS,
  components: {
    GlAvatar,
    GlPopover,
  },
  props: {
    assignee: {
      type: Object,
      required: true,
    },
    startsAt: {
      type: String,
      required: true,
    },
    endsAt: {
      type: String,
      required: true,
    },
    containerStyle: {
      type: Object,
      required: true,
    },
    color: {
      type: Object,
      required: true,
    },
  },
  data() {
    const { colorWeight, backgroundStyle, textClass } = this.color;
 
    return {
      colorWeight,
      backgroundStyle,
      textClass,
      shiftWidth: parseInt(this.containerStyle.width, 10),
    };
  },
  computed: {
    assigneeName() {
      Iif (this.shiftWidth <= SHIFT_WIDTHS.md) {
        return truncate(this.assignee.user.username, 3);
      }
 
      return this.assignee.user.username;
    },
    endsAtString() {
      return sprintf(__('Ends: %{endsAt}'), {
        endsAt: `${formatDate(this.endsAt, TIME_DATE_FORMAT)}`,
      });
    },
    rotationAssigneeUniqueID() {
      return uniqueId('rotation-assignee-');
    },
    hasRotationMobileViewAvatar() {
      return this.shiftWidth <= SHIFT_WIDTHS.xs;
    },
    hasRotationMobileViewText() {
      return this.shiftWidth <= SHIFT_WIDTHS.sm;
    },
    startsAtString() {
      return sprintf(__('Starts: %{startsAt}'), {
        startsAt: `${formatDate(this.startsAt, TIME_DATE_FORMAT)}`,
      });
    },
  },
};
</script>
 
<template>
  <div
    class="rotation-asignee-container gl-absolute gl-h-7 gl-mt-3 gl-pr-1"
    :style="containerStyle"
  >
    <div
      :id="rotationAssigneeUniqueID"
      class="gl-h-6"
      :style="backgroundStyle"
      :class="[
        $options.ROTATION_CENTER_CLASS,
        { 'gl-justify-content-center': hasRotationMobileViewText },
      ]"
      data-testid="rotation-assignee"
    >
      <div
        :class="[
          textClass,
          $options.ROTATION_CENTER_CLASS,
          { 'gl-pl-2': !hasRotationMobileViewText },
        ]"
      >
        <gl-avatar v-if="!hasRotationMobileViewAvatar" :src="assignee.user.avatarUrl" :size="16" />
        <span
          v-if="!hasRotationMobileViewText"
          class="gl-ml-2 gl-line-height-24"
          data-testid="rotation-assignee-name"
          >{{ assigneeName }}</span
        >
      </div>
    </div>
    <gl-popover
      :target="rotationAssigneeUniqueID"
      :title="assignee.user.username"
      placement="right"
    >
      <p class="gl-m-0" data-testid="rotation-assignee-starts-at">
        {{ startsAtString }}
      </p>
      <p class="gl-m-0" data-testid="rotation-assignee-ends-at">
        {{ endsAtString }}
      </p>
    </gl-popover>
  </div>
</template>