All files / app/assets/javascripts/repository/components/table row.vue

75% Statements 33/44
74.07% Branches 20/27
68.18% Functions 15/22
75% Lines 33/44

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  7x                       7x 7x 7x 7x 7x 7x 7x 7x 7x                                                                                                                                                                                                                   17x               17x     17x     34x 34x   34x 8x     26x     17x     17x     17x     17x     17x     4x     17x     18x                                                           1x 1x   1x       1x 1x 1x                           126x                                                                                                                            
<script>
import {
  GlBadge,
  GlLink,
  GlDeprecatedSkeletonLoading as GlSkeletonLoading,
  GlTooltipDirective,
  GlLoadingIcon,
  GlIcon,
  GlHoverLoadDirective,
  GlSafeHtmlDirective,
  GlIntersectionObserver,
} from '@gitlab/ui';
import { escapeRegExp } from 'lodash';
import paginatedTreeQuery from 'shared_queries/repository/paginated_tree.query.graphql';
import { escapeFileUrl } from '~/lib/utils/url_utility';
import { TREE_PAGE_SIZE, ROW_APPEAR_DELAY } from '~/repository/constants';
import FileIcon from '~/vue_shared/components/file_icon.vue';
import TimeagoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import getRefMixin from '../../mixins/get_ref';
import blobInfoQuery from '../../queries/blob_info.query.graphql';
import commitQuery from '../../queries/commit.query.graphql';
 
export default {
  components: {
    GlBadge,
    GlLink,
    GlSkeletonLoading,
    GlLoadingIcon,
    GlIcon,
    TimeagoTooltip,
    FileIcon,
    GlIntersectionObserver,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
    GlHoverLoad: GlHoverLoadDirective,
    SafeHtml: GlSafeHtmlDirective,
  },
  apollo: {
    commit: {
      query: commitQuery,
      variables() {
        return {
          fileName: this.name,
          type: this.type,
          path: this.currentPath,
          projectPath: this.projectPath,
          maxOffset: this.totalEntries,
        };
      },
      skip() {
        return this.glFeatures.lazyLoadCommits;
      },
    },
  },
  mixins: [getRefMixin, glFeatureFlagMixin()],
  props: {
    commitInfo: {
      type: Object,
      required: false,
      default: null,
    },
    rowNumber: {
      type: Number,
      required: false,
      default: null,
    },
    totalEntries: {
      type: Number,
      required: true,
    },
    id: {
      type: String,
      required: true,
    },
    sha: {
      type: String,
      required: true,
    },
    projectPath: {
      type: String,
      required: true,
    },
    currentPath: {
      type: String,
      required: true,
    },
    name: {
      type: String,
      required: true,
    },
    path: {
      type: String,
      required: true,
    },
    mode: {
      type: String,
      required: false,
      default: '',
    },
    type: {
      type: String,
      required: true,
    },
    url: {
      type: String,
      required: false,
      default: null,
    },
    lfsOid: {
      type: String,
      required: false,
      default: null,
    },
    submoduleTreeUrl: {
      type: String,
      required: false,
      default: null,
    },
    loadingPath: {
      type: String,
      required: false,
      default: '',
    },
  },
  data() {
    return {
      commit: null,
      hasRowAppeared: false,
      delayedRowAppear: null,
    };
  },
  computed: {
    commitData() {
      return this.glFeatures.lazyLoadCommits ? this.commitInfo : this.commit;
    },
    refactorBlobViewerEnabled() {
      return this.glFeatures.refactorBlobViewer;
    },
    routerLinkTo() {
      const blobRouteConfig = { path: `/-/blob/${this.escapedRef}/${escapeFileUrl(this.path)}` };
      const treeRouteConfig = { path: `/-/tree/${this.escapedRef}/${escapeFileUrl(this.path)}` };
 
      if (this.refactorBlobViewerEnabled && this.isBlob) {
        return blobRouteConfig;
      }
 
      return this.isFolder ? treeRouteConfig : null;
    },
    isBlob() {
      return this.type === 'blob';
    },
    isFolder() {
      return this.type === 'tree';
    },
    isSubmodule() {
      return this.type === 'commit';
    },
    linkComponent() {
      return this.isFolder || (this.refactorBlobViewerEnabled && this.isBlob) ? 'router-link' : 'a';
    },
    fullPath() {
      return this.path.replace(new RegExp(`^${escapeRegExp(this.currentPath)}/`), '');
    },
    shortSha() {
      return this.sha.slice(0, 8);
    },
    hasLockLabel() {
      return this.commitData && this.commitData.lockLabel;
    },
    showSkeletonLoader() {
      return !this.commitData && this.hasRowAppeared;
    },
  },
  methods: {
    handlePreload() {
      return this.isFolder ? this.loadFolder() : this.loadBlob();
    },
    loadFolder() {
      this.apolloQuery(paginatedTreeQuery, {
        projectPath: this.projectPath,
        ref: this.ref,
        path: this.path,
        nextPageCursor: '',
        pageSize: TREE_PAGE_SIZE,
      });
    },
    loadBlob() {
      if (!this.refactorBlobViewerEnabled) {
        return;
      }
 
      this.apolloQuery(blobInfoQuery, {
        projectPath: this.projectPath,
        filePath: this.path,
        ref: this.ref,
      });
    },
    apolloQuery(query, variables) {
      this.$apollo.query({ query, variables });
    },
    rowAppeared() {
      this.hasRowAppeared = true;
 
I      if (this.commitInfo) {
        return;
      }
 
E      if (this.glFeatures.lazyLoadCommits) {
        this.delayedRowAppear = setTimeout(
          () => this.$emit('row-appear', this.rowNumber),
          ROW_APPEAR_DELAY,
        );
      }
    },
    rowDisappeared() {
      clearTimeout(this.delayedRowAppear);
      this.hasRowAppeared = false;
    },
  },
  safeHtmlConfig: { ADD_TAGS: ['gl-emoji'] },
};
</script>
 
<template>
  <tr class="tree-item">
    <td class="tree-item-file-name cursor-default position-relative">
      <component
        :is="linkComponent"
        ref="link"
        v-gl-hover-load="handlePreload"
        v-gl-tooltip:tooltip-container
        :title="fullPath"
        :to="routerLinkTo"
        :href="url"
        :class="{
          'is-submodule': isSubmodule,
        }"
        class="tree-item-link str-truncated"
        data-qa-selector="file_name_link"
      >
        <file-icon
          :file-name="fullPath"
          :file-mode="mode"
          :folder="isFolder"
          :submodule="isSubmodule"
          :loading="path === loadingPath"
          css-classes="position-relative file-icon"
          class="mr-1 position-relative text-secondary"
        /><span class="position-relative">{{ fullPath }}</span>
      </component>
      <!-- eslint-disable @gitlab/vue-require-i18n-strings -->
      <gl-badge v-if="lfsOid" variant="muted" size="sm" class="ml-1" data-qa-selector="label-lfs"
        >LFS</gl-badge
      >
      <!-- eslint-enable @gitlab/vue-require-i18n-strings -->
      <template v-if="isSubmodule">
        @ <gl-link :href="submoduleTreeUrl" class="commit-sha">{{ shortSha }}</gl-link>
      </template>
      <gl-icon
        v-if="hasLockLabel"
        v-gl-tooltip
        :title="commitData.lockLabel"
        name="lock"
        :size="12"
        class="ml-1"
      />
    </td>
    <td class="d-none d-sm-table-cell tree-commit cursor-default">
      <gl-link
        v-if="commitData"
        v-safe-html:[$options.safeHtmlConfig]="commitData.titleHtml"
        :href="commitData.commitPath"
        :title="commitData.message"
        class="str-truncated-100 tree-commit-link"
      />
      <gl-intersection-observer @appear="rowAppeared" @disappear="rowDisappeared">
        <gl-skeleton-loading v-if="showSkeletonLoader" :lines="1" class="h-auto" />
      </gl-intersection-observer>
    </td>
    <td class="tree-time-ago text-right cursor-default">
      <timeago-tooltip v-if="commitData" :time="commitData.committedDate" />
      <gl-skeleton-loading v-if="showSkeletonLoader" :lines="1" class="ml-auto h-auto w-50" />
    </td>
  </tr>
</template>