All files / app/assets/javascripts/boards/components board_card_inner.vue

84.48% Statements 49/58
86.48% Branches 32/37
89.18% Functions 33/37
88.88% Lines 48/54

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 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441                                          13x                                                                                                               106x                           106x           110x 103x     7x     7x     7x 7x 7x     7x 1x     6x     110x 103x     7x     104x       104x 104x         4x     106x     4x     129x     103x 103x     97x     82x                 4x     4x     4x         2x     104x     47x                 135x 135x     135x     135x     82x 82x     89x                 4x   4x 4x   4x         2x 2x 2x       33x                                                                                                                                                                                                                                                                                                                                                                                                                                      
<script>
import {
  GlLabel,
  GlTooltip,
  GlTooltipDirective,
  GlIcon,
  GlLoadingIcon,
  GlSprintf,
} from '@gitlab/ui';
import { sortBy } from 'lodash';
import boardCardInner from 'ee_else_ce/boards/mixins/board_card_inner';
import { isScopedLabel, convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import { updateHistory, queryToObject } from '~/lib/utils/url_utility';
import { sprintf, __, n__ } from '~/locale';
import isShowingLabelsQuery from '~/graphql_shared/client/is_showing_labels.query.graphql';
import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue';
import WorkItemTypeIcon from '~/work_items/components/work_item_type_icon.vue';
import IssuableBlockedIcon from '~/vue_shared/components/issuable_blocked_icon/issuable_blocked_icon.vue';
import { ListType } from '../constants';
import { setError } from '../graphql/cache_updates';
import IssueDueDate from './issue_due_date.vue';
import IssueTimeEstimate from './issue_time_estimate.vue';
 
export default {
  components: {
    GlTooltip,
    GlLabel,
    GlLoadingIcon,
    GlIcon,
    UserAvatarLink,
    IssueDueDate,
    IssueTimeEstimate,
    IssueCardWeight: () => import('ee_component/boards/components/issue_card_weight.vue'),
    IssuableBlockedIcon,
    GlSprintf,
    WorkItemTypeIcon,
    IssueHealthStatus: () =>
      import('ee_component/related_items_tree/components/issue_health_status.vue'),
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  mixins: [boardCardInner],
  inject: [
    'allowSubEpics',
    'rootPath',
    'scopedLabelsAvailable',
    'isEpicBoard',
    'issuableType',
    'isGroupBoard',
  ],
  props: {
    item: {
      type: Object,
      required: true,
    },
    list: {
      type: Object,
      required: false,
      default: () => ({}),
    },
    updateFilters: {
      type: Boolean,
      required: false,
      default: false,
    },
    index: {
      type: Number,
      required: true,
    },
    showWorkItemTypeIcon: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  data() {
    return {
      limitBeforeCounter: 2,
      maxRender: 3,
      maxCounter: 99,
    };
  },
  apollo: {
    isShowingLabels: {
      query: isShowingLabelsQuery,
      update: (data) => data.isShowingLabels,
    },
  },
  computed: {
    isLoading() {
      return this.item.isLoading || this.item.iid === '-1';
    },
    cappedAssignees() {
      // e.g. maxRender is 4,
      // Render up to all 4 assignees if there are only 4 assigness
      // Otherwise render up to the limitBeforeCounter
      if (this.item.assignees.length <= this.maxRender) {
        return this.item.assignees.slice(0, this.maxRender);
      }
 
      return this.item.assignees.slice(0, this.limitBeforeCounter);
    },
    numberOverLimit() {
      return this.item.assignees.length - this.limitBeforeCounter;
    },
    assigneeCounterTooltip() {
      const { numberOverLimit, maxCounter } = this;
      const count = numberOverLimit > maxCounter ? maxCounter : numberOverLimit;
      return sprintf(__('%{count} more assignees'), { count });
    },
    assigneeCounterLabel() {
      if (this.numberOverLimit > this.maxCounter) {
        return `${this.maxCounter}+`;
      }
 
      return `+${this.numberOverLimit}`;
    },
    shouldRenderCounter() {
      if (this.item.assignees.length <= this.maxRender) {
        return false;
      }
 
      return this.item.assignees.length > this.numberOverLimit;
    },
    itemPrefix() {
      return this.isEpicBoard ? '&' : '#';
    },
 
    itemId() {
      if (this.item.iid) {
        return `${this.itemPrefix}${this.item.iid}`;
      }
      return false;
    },
    hasChildren() {
      return this.totalIssuesCount + this.totalEpicsCount > 0;
    },
    shouldRenderEpicCountables() {
      return this.isEpicBoard && this.hasChildren;
    },
    shouldRenderEpicProgress() {
      return this.totalWeight > 0;
    },
    showLabelFooter() {
      return this.isShowingLabels && this.item.labels.find(this.showLabel);
    },
    itemReferencePath() {
      const { referencePath } = this.item;
      return referencePath.split(this.itemPrefix)[0];
    },
    directNamespaceReference() {
      return this.itemReferencePath.split('/').slice(-1)[0];
    },
    orderedLabels() {
      return sortBy(this.item.labels.filter(this.isNonListLabel), 'title');
    },
    blockedLabel() {
      Iif (this.item.blockedByCount) {
        return n__(`Blocked by %d issue`, `Blocked by %d issues`, this.item.blockedByCount);
      }
      return __('Blocked issue');
    },
    totalEpicsCount() {
      return this.item.descendantCounts.openedEpics + this.item.descendantCounts.closedEpics;
    },
    totalIssuesCount() {
      return this.item.descendantCounts.openedIssues + this.item.descendantCounts.closedIssues;
    },
    totalWeight() {
      return (
        this.item.descendantWeightSum.openedIssues + this.item.descendantWeightSum.closedIssues
      );
    },
    totalProgress() {
      return Math.round((this.item.descendantWeightSum.closedIssues / this.totalWeight) * 100);
    },
    showReferencePath() {
      return this.isGroupBoard && this.itemReferencePath;
    },
    avatarSize() {
      return { default: 16, lg: 24 };
    },
  },
  methods: {
    setError,
    isIndexLessThanlimit(index) {
      return index < this.limitBeforeCounter;
    },
    assigneeUrl(assignee) {
      Iif (!assignee) return '';
      return `${this.rootPath}${assignee.username}`;
    },
    avatarUrlTitle(assignee) {
      return sprintf(__(`Avatar for %{assigneeName}`), { assigneeName: assignee.name });
    },
    avatarUrl(assignee) {
      return assignee.avatarUrl || assignee.avatar || gon.default_avatar_url;
    },
    showLabel(label) {
      Iif (!label.id) return false;
      return true;
    },
    isNonListLabel(label) {
      return (
        label.id &&
        !(
          (this.list.type || this.list.listType) === ListType.label &&
          this.list.title === label.title
        )
      );
    },
    filterByLabel(label) {
      Iif (!this.updateFilters) return;
 
      const filterPath = window.location.search ? `${window.location.search}&` : '?';
      const filter = `label_name[]=${encodeURIComponent(label.title)}`;
 
      if (!filterPath.includes(filter)) {
        updateHistory({
          url: `${filterPath}${filter}`,
        });
 
        const rawFilterParams = queryToObject(window.location.search, { gatherArrays: true });
        const filters = convertObjectPropsToCamelCase(rawFilterParams, {});
        this.$emit('setFilters', filters);
      }
    },
    showScopedLabel(label) {
      return this.scopedLabelsAvailable && isScopedLabel(label);
    },
  },
};
</script>
<template>
  <div>
    <div class="gl-display-flex" dir="auto">
      <h4
        class="board-card-title gl-min-w-0 gl-mb-0 gl-mt-0 gl-mr-3 gl-font-base gl-overflow-break-word"
      >
        <issuable-blocked-icon
          v-if="item.blocked"
          :item="item"
          :unique-id="`${item.id}${list.id}`"
          :issuable-type="issuableType"
          @blocking-issuables-error="setError"
        />
        <gl-icon
          v-if="item.confidential"
          v-gl-tooltip
          name="eye-slash"
          :title="__('Confidential')"
          class="confidential-icon gl-mr-2 gl-text-orange-500 gl-cursor-help"
          :aria-label="__('Confidential')"
        />
        <gl-icon
          v-if="item.hidden"
          v-gl-tooltip
          name="spam"
          :title="__('This issue is hidden because its author has been banned.')"
          class="gl-mr-2 hidden-icon gl-text-orange-500 gl-cursor-help"
          data-testid="hidden-icon"
        />
        <a
          :href="item.path || item.webUrl || ''"
          :title="item.title"
          :class="{ 'gl-text-gray-400!': isLoading }"
          class="js-no-trigger gl-text-body gl-hover-text-gray-900"
          @mousemove.stop
          >{{ item.title }}</a
        >
      </h4>
      <slot></slot>
    </div>
    <div v-if="showLabelFooter" class="board-card-labels gl-mt-2 gl-display-flex gl-flex-wrap">
      <template v-for="label in orderedLabels">
        <gl-label
          :key="label.id"
          class="js-no-trigger gl-mt-2 gl-mr-2"
          :background-color="label.color"
          :title="label.title"
          :description="label.description"
          size="sm"
          :scoped="showScopedLabel(label)"
          target="#"
          @click="filterByLabel(label)"
        />
      </template>
    </div>
    <div
      class="board-card-footer gl-display-flex gl-justify-content-space-between gl-align-items-flex-end"
    >
      <div
        class="gl-display-flex align-items-start gl-flex-wrap-reverse board-card-number-container gl-overflow-hidden"
      >
        <gl-loading-icon v-if="isLoading" size="lg" class="gl-mt-5" />
        <span
          v-if="item.referencePath && !isLoading"
          class="board-card-number gl-overflow-hidden gl-display-flex gl-gap-2 gl-mr-3 gl-mt-3 gl-font-sm gl-text-secondary"
          :class="{ 'gl-font-base': isEpicBoard }"
        >
          <work-item-type-icon
            v-if="showWorkItemTypeIcon"
            :work-item-type="item.type"
            show-tooltip-on-hover
          />
          <span
            v-if="showReferencePath"
            v-gl-tooltip
            :title="itemReferencePath"
            data-placement="bottom"
            class="board-item-path gl-text-truncate gl-font-weight-bold gl-cursor-help"
          >
            {{ directNamespaceReference }}
          </span>
          {{ itemId }}
        </span>
        <span class="board-info-items gl-mt-3 gl-display-inline-block">
          <span v-if="shouldRenderEpicCountables" data-testid="epic-countables">
            <gl-tooltip :target="() => $refs.countBadge">
              <p v-if="allowSubEpics" class="gl-font-weight-bold gl-m-0">
                {{ __('Epics') }} &#8226;
                <span class="gl-font-weight-normal">
                  <gl-sprintf :message="__('%{openedEpics} open, %{closedEpics} closed')">
                    <template #openedEpics>{{ item.descendantCounts.openedEpics }}</template>
                    <template #closedEpics>{{ item.descendantCounts.closedEpics }}</template>
                  </gl-sprintf>
                </span>
              </p>
              <p class="gl-font-weight-bold gl-m-0">
                {{ __('Issues') }} &#8226;
                <span class="gl-font-weight-normal">
                  <gl-sprintf :message="__('%{openedIssues} open, %{closedIssues} closed')">
                    <template #openedIssues>{{ item.descendantCounts.openedIssues }}</template>
                    <template #closedIssues>{{ item.descendantCounts.closedIssues }}</template>
                  </gl-sprintf>
                </span>
              </p>
              <p class="gl-font-weight-bold gl-m-0">
                {{ __('Total weight') }} &#8226;
                <span class="gl-font-weight-normal" data-testid="epic-countables-total-weight">
                  {{ totalWeight }}
                </span>
              </p>
            </gl-tooltip>
 
            <gl-tooltip
              v-if="shouldRenderEpicProgress"
              :target="() => $refs.progressBadge"
              data-testid="epic-progress-tooltip"
            >
              <p class="gl-font-weight-bold gl-m-0">
                {{ __('Progress') }} &#8226;
                <span class="gl-font-weight-normal" data-testid="epic-progress-tooltip-content">
                  <gl-sprintf
                    :message="__('%{completedWeight} of %{totalWeight} weight completed')"
                  >
                    <template #completedWeight>{{
                      item.descendantWeightSum.closedIssues
                    }}</template>
                    <template #totalWeight>{{ totalWeight }}</template>
                  </gl-sprintf>
                </span>
              </p>
            </gl-tooltip>
 
            <span
              ref="countBadge"
              class="board-card-info gl-mr-0 gl-pr-0 gl-pl-3 gl-text-secondary gl-cursor-help"
            >
              <span v-if="allowSubEpics" class="gl-mr-3">
                <gl-icon name="epic" />
                {{ totalEpicsCount }}
              </span>
              <span class="gl-mr-3" data-testid="epic-countables-counts-issues">
                <gl-icon name="issues" />
                {{ totalIssuesCount }}
              </span>
              <span class="gl-mr-3" data-testid="epic-countables-weight-issues">
                <gl-icon name="weight" />
                {{ totalWeight }}
              </span>
            </span>
 
            <span
              v-if="shouldRenderEpicProgress"
              ref="progressBadge"
              class="board-card-info gl-pl-0 gl-text-secondary gl-cursor-help"
            >
              <span class="gl-mr-3" data-testid="epic-progress">
                <gl-icon name="progress" />
                {{ totalProgress }}%
              </span>
            </span>
          </span>
          <span v-if="!isEpicBoard">
            <issue-due-date
              v-if="item.dueDate"
              :date="item.dueDate"
              :closed="Boolean(item.closedAt)"
            />
            <issue-time-estimate v-if="item.timeEstimate" :estimate="item.timeEstimate" />
            <issue-card-weight
              v-if="validIssueWeight(item)"
              :weight="item.weight"
              @click="filterByWeight(item.weight)"
            />
            <issue-health-status v-if="item.healthStatus" :health-status="item.healthStatus" />
          </span>
        </span>
      </div>
      <div class="board-card-assignee gl-display-flex gl-mb-n2">
        <user-avatar-link
          v-for="assignee in cappedAssignees"
          :key="assignee.id"
          :link-href="assigneeUrl(assignee)"
          :img-alt="avatarUrlTitle(assignee)"
          :img-src="avatarUrl(assignee)"
          :img-size="avatarSize"
          class="js-no-trigger user-avatar-link"
          tooltip-placement="bottom"
        >
          <span class="js-assignee-tooltip">
            <span class="gl-font-weight-bold gl-display-block">{{ __('Assignee') }}</span>
            {{ assignee.name }}
            <span class="text-white-50">@{{ assignee.username }}</span>
          </span>
        </user-avatar-link>
        <span
          v-if="shouldRenderCounter"
          v-gl-tooltip
          :title="assigneeCounterTooltip"
          class="avatar-counter gl-bg-gray-100 gl-text-gray-900 gl-cursor-help gl-font-weight-bold gl-border-0 gl-line-height-24 gl-ml-n3"
          data-placement="bottom"
          >{{ assigneeCounterLabel }}</span
        >
      </div>
    </div>
  </div>
</template>