All files / ee/app/assets/javascripts/boards/components epic_lane.vue

88.88% Statements 24/27
69.23% Branches 9/13
95.65% Functions 22/23
88.88% Lines 24/27

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                                      3x                                                                                                             16x   16x   16x                     16x                 15x                       16x     18x     18x     31x     14x     16x                 16x     32x     32x     32x     14x         15x         2x   2x 2x                         60x     15x         1x                                                                                                                                                                                      
<script>
import {
  GlButton,
  GlIcon,
  GlIntersectionObserver,
  GlLink,
  GlLoadingIcon,
  GlPopover,
  GlTooltipDirective,
} from '@gitlab/ui';
import { STATUS_OPEN } from '~/issues/constants';
import { formatDate } from '~/lib/utils/datetime_utility';
import { __, n__, sprintf, s__ } from '~/locale';
import timeagoMixin from '~/vue_shared/mixins/timeago';
import { formatListIssuesForLanes } from 'ee/boards/boards_util';
import listsIssuesQuery from '~/boards/graphql/lists_issues.query.graphql';
import { setError } from '~/boards/graphql/cache_updates';
import { BoardType } from 'ee_else_ce/boards/constants';
import updateBoardEpicUserPreferencesMutation from '../graphql/update_board_epic_user_preferences.mutation.graphql';
import IssuesLaneList from './issues_lane_list.vue';
 
export default {
  components: {
    GlButton,
    GlIcon,
    GlIntersectionObserver,
    GlLink,
    GlLoadingIcon,
    GlPopover,
    IssuesLaneList,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  mixins: [timeagoMixin],
  inject: ['fullPath', 'boardType'],
  props: {
    epic: {
      type: Object,
      required: true,
    },
    lists: {
      type: Array,
      required: true,
    },
    canAdminList: {
      type: Boolean,
      required: false,
      default: false,
    },
    canAdminEpic: {
      type: Boolean,
      required: false,
      default: false,
    },
    boardId: {
      type: String,
      required: true,
    },
    filterParams: {
      type: Object,
      required: true,
    },
    highlightedLists: {
      type: Array,
      required: false,
      default: () => [],
    },
    totalIssuesCountByListId: {
      type: Object,
      required: true,
    },
  },
  data() {
    const { userPreferences } = this.epic;
 
    const { collapsed = false } = userPreferences || {};
 
    return {
      isCollapsed: collapsed,
      listsWithIssues: [],
      showShadow: false,
      laneScrollOffset: 0,
    };
  },
  apollo: {
    listsWithIssues: {
      query: listsIssuesQuery,
      variables() {
        return {
          fullPath: this.fullPath,
          boardId: this.boardId,
          filters: { ...this.filterParams, epicId: this.epic.id },
          isGroup: this.boardType === BoardType.group,
          isProject: this.boardType === BoardType.project,
        };
      },
      update(data) {
        return data[this.boardType]?.board.lists.nodes;
      },
      error(error) {
        setError({
          error,
          message: s__('Boards|An error occurred while fetching issues. Please try again.'),
        });
      },
    },
  },
  computed: {
    isOpen() {
      return this.epic.state === STATUS_OPEN;
    },
    chevronTooltip() {
      return this.isCollapsed ? __('Expand') : __('Collapse');
    },
    chevronIcon() {
      return this.isCollapsed ? 'chevron-right' : 'chevron-down';
    },
    issuesCount() {
      return this.listsWithIssues.reduce((total, list) => total + list.issues.nodes.length, 0);
    },
    issuesCountTooltipText() {
      return n__(`%d issue in this group`, `%d issues in this group`, this.issuesCount);
    },
    epicTimeAgoString() {
      return this.isOpen
        ? sprintf(__(`Created %{epicTimeagoDate}`), {
            epicTimeagoDate: this.timeFormatted(this.epic.createdAt),
          })
        : sprintf(__(`Closed %{epicTimeagoDate}`), {
            epicTimeagoDate: this.timeFormatted(this.epic.closedAt),
          });
    },
    epicDateString() {
      return formatDate(this.epic.createdAt);
    },
    isLoading() {
      return this.$apollo.queries.listsWithIssues.loading;
    },
    shouldDisplay() {
      return this.issuesCount > 0 || this.isLoading;
    },
    showIssuesLane() {
      return !this.isCollapsed && this.issuesCount > 0;
    },
    issuesByList() {
      return formatListIssuesForLanes(this.listsWithIssues);
    },
  },
  watch: {
    listsWithIssues() {
      this.setLaneScrollOffset();
    },
  },
  methods: {
    async toggleCollapsed() {
      this.isCollapsed = !this.isCollapsed;
 
      try {
        await this.$apollo.mutate({
          mutation: updateBoardEpicUserPreferencesMutation,
          variables: {
            boardId: this.boardId,
            epicId: this.epic.id,
            collapsed: this.isCollapsed,
          },
        });
      } catch (error) {
        setError({ error, message: __('Unable to save your preference') });
      }
    },
    getIssuesByList(listId) {
      return this.issuesByList[listId];
    },
    setLaneScrollOffset() {
      this.laneScrollOffset =
        document.querySelector('[data-testid="board-swimlanes-headers"]')?.getBoundingClientRect()
          .height || 0 + this.$refs.header.getBoundingClientRect().height;
    },
    setShowShadow() {
      this.showShadow = true;
    },
    setHideShadow() {
      this.showShadow = false;
    },
  },
};
</script>
 
<template>
  <div v-if="shouldDisplay" class="board-epic-lane-container">
    <div
      ref="header"
      class="board-epic-lane gl-w-full gl-max-w-full gl-sticky gl-left-0 gl-display-inline-block"
      :class="{
        'board-epic-lane-shadow': !isCollapsed,
        show: showShadow,
      }"
      data-testid="board-epic-lane"
    >
      <div class="gl-py-3 gl-px-3 gl-display-flex gl-align-items-center">
        <div class="gl-display-flex gl-align-items-center gl-sticky gl-left-0">
          <gl-button
            v-gl-tooltip.hover.right
            :aria-label="chevronTooltip"
            :title="chevronTooltip"
            :icon="chevronIcon"
            class="gl-mr-2 gl-cursor-pointer"
            category="tertiary"
            size="small"
            @click="toggleCollapsed"
          />
          <h4
            ref="epicTitle"
            class="gl-my-0 gl-mr-3 gl-font-weight-bold gl-font-base gl-white-space-nowrap gl-text-overflow-ellipsis gl-overflow-hidden"
          >
            {{ epic.title }}
          </h4>
          <gl-popover :target="() => $refs.epicTitle" placement="top">
            <template #title>{{ epic.title }} &middot; {{ epic.reference }}</template>
            <div>{{ epicTimeAgoString }}</div>
            <div class="gl-mb-2">{{ epicDateString }}</div>
            <gl-link :href="epic.webUrl" class="gl-font-sm">{{ __('Go to epic') }}</gl-link>
          </gl-popover>
          <span
            v-if="!isLoading"
            v-gl-tooltip.hover
            :title="issuesCountTooltipText"
            class="gl-display-flex gl-align-items-center gl-text-gray-500"
            tabindex="0"
            :aria-label="issuesCountTooltipText"
            data-testid="epic-lane-issue-count"
          >
            <gl-icon class="gl-mr-2 gl-flex-shrink-0" name="issues" />
            <span aria-hidden="true">{{ issuesCount }}</span>
          </span>
          <gl-loading-icon v-else class="gl-p-2" />
        </div>
      </div>
    </div>
    <div class="gl-relative">
      <div :style="`top: -${laneScrollOffset}px`" class="gl-absolute gl-w-full">
        <gl-intersection-observer @appear="setHideShadow" @disappear="setShowShadow">
          <div></div>
        </gl-intersection-observer>
      </div>
    </div>
    <div
      v-if="showIssuesLane"
      class="gl-display-flex gl-pt-3 gl-pb-5 board-epic-lane-issues"
      data-testid="board-epic-lane-issues"
    >
      <issues-lane-list
        v-for="list in lists"
        :key="`${list.id}-issues`"
        :list="list"
        :issues="getIssuesByList(list.id)"
        :epic-id="epic.id"
        :epic-is-confidential="epic.confidential"
        :can-admin-list="canAdminList"
        :board-id="boardId"
        :filter-params="filterParams"
        :highlighted-lists="highlightedLists"
        :can-admin-epic="canAdminEpic"
        :lists="lists"
        :total-issues-count="totalIssuesCountByListId[list.id]"
        @setFilters="$emit('setFilters', $event)"
      />
    </div>
  </div>
</template>