All files / app/assets/javascripts/packages_and_registries/package_registry/components/list package_list_row.vue

95% Statements 19/20
57.14% Branches 4/7
92.3% Functions 12/13
95% Lines 19/20

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                                                3x                                                             28x     21x     21x     28x     2x     2x     28x     28x 2x 1x   1x     26x 2x     24x     28x     7x         28x           28x                                                                                                                                                                                                                                
<script>
import {
  GlDisclosureDropdown,
  GlDisclosureDropdownItem,
  GlFormCheckbox,
  GlIcon,
  GlSprintf,
  GlTruncate,
  GlLink,
} from '@gitlab/ui';
import { s__, __ } from '~/locale';
import ListItem from '~/vue_shared/components/registry/list_item.vue';
import {
  DELETE_PACKAGE_TEXT,
  ERRORED_PACKAGE_TEXT,
  ERROR_PUBLISHING,
  PACKAGE_ERROR_STATUS,
  PACKAGE_DEFAULT_STATUS,
  WARNING_TEXT,
} from '~/packages_and_registries/package_registry/constants';
import { getPackageTypeLabel } from '~/packages_and_registries/package_registry/utils';
import PackageTags from '~/packages_and_registries/shared/components/package_tags.vue';
import PublishMethod from '~/packages_and_registries/package_registry/components/list/publish_method.vue';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import TimeagoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
 
export default {
  name: 'PackageListRow',
  components: {
    GlDisclosureDropdown,
    GlDisclosureDropdownItem,
    GlFormCheckbox,
    GlIcon,
    GlSprintf,
    GlTruncate,
    GlLink,
    PackageTags,
    PublishMethod,
    ListItem,
    TimeagoTooltip,
  },
  inject: ['isGroupPage', 'canDeletePackages'],
  props: {
    packageEntity: {
      type: Object,
      required: true,
    },
    selected: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  computed: {
    containsWebPathLink() {
      return Boolean(this.packageEntity?._links?.webPath);
    },
    packageType() {
      return getPackageTypeLabel(this.packageEntity.packageType);
    },
    packageId() {
      return getIdFromGraphQLId(this.packageEntity.id);
    },
    pipeline() {
      return this.packageEntity?.pipelines?.nodes[0];
    },
    projectName() {
      return this.packageEntity.project.name;
    },
    projectLink() {
      return this.packageEntity.project.webUrl;
    },
    pipelineUser() {
      return this.pipeline?.user?.name;
    },
    publishedMessage() {
      if (this.isGroupPage) {
        if (this.pipelineUser) {
          return s__(`PackageRegistry|Published to %{projectName} by %{author}, %{date}`);
        }
        return s__(`PackageRegistry|Published to %{projectName}, %{date}`);
      }
 
      if (this.pipelineUser) {
        return s__(`PackageRegistry|Published by %{author}, %{date}`);
      }
 
      return s__(`PackageRegistry|Published %{date}`);
    },
    errorStatusRow() {
      return this.packageEntity.status === PACKAGE_ERROR_STATUS;
    },
    errorStatusMessage() {
      return this.packageEntity.statusMessage
        ? this.packageEntity.statusMessage
        : ERRORED_PACKAGE_TEXT;
    },
    showTags() {
      return Boolean(this.packageEntity.tags?.nodes?.length);
    },
    nonDefaultRow() {
      return this.packageEntity.status && this.packageEntity.status !== PACKAGE_DEFAULT_STATUS;
    },
    errorPackageStyle() {
      return {
        'gl-text-red-500': this.errorStatusRow,
        'gl-font-weight-normal': this.errorStatusRow,
      };
    },
  },
  i18n: {
    createdAt: __('Created %{timestamp}'),
    deletePackage: DELETE_PACKAGE_TEXT,
    errorPublishing: ERROR_PUBLISHING,
    warning: WARNING_TEXT,
    moreActions: __('More actions'),
  },
};
</script>
 
<template>
  <list-item data-testid="package-row" :selected="selected" v-bind="$attrs">
    <template #left-action>
      <gl-form-checkbox
        v-if="canDeletePackages"
        class="gl-m-0"
        :checked="selected"
        @change="$emit('select')"
      />
    </template>
    <template #left-primary>
      <div class="gl-display-flex gl-align-items-center gl-mr-3 gl-min-w-0">
        <router-link
          v-if="containsWebPathLink"
          :class="errorPackageStyle"
          class="gl-text-body gl-min-w-0"
          data-testid="details-link"
          :to="{ name: 'details', params: { id: packageId } }"
        >
          <gl-truncate :text="packageEntity.name" />
        </router-link>
        <gl-truncate v-else :class="errorPackageStyle" :text="packageEntity.name" />
 
        <package-tags
          v-if="showTags"
          class="gl-ml-3"
          :tags="packageEntity.tags.nodes"
          hide-label
          :tag-display-limit="1"
        />
      </div>
    </template>
    <template #left-secondary>
      <div
        v-if="!errorStatusRow"
        class="gl-display-flex gl-align-items-center"
        data-testid="left-secondary-infos"
      >
        <gl-truncate
          class="gl-max-w-15 gl-md-max-w-26"
          :text="packageEntity.version"
          :with-tooltip="true"
        />
        <span class="gl-ml-2" data-testid="package-type">&middot; {{ packageType }}</span>
      </div>
      <div v-else class="gl-text-red-500">
        <gl-icon name="warning" :aria-label="$options.i18n.warning" data-testid="warning-icon" />
        <span data-testid="error-message"
          >{{ $options.i18n.errorPublishing }} &middot; {{ errorStatusMessage }}</span
        >
      </div>
    </template>
 
    <template #right-primary>
      <publish-method :pipeline="pipeline" />
    </template>
 
    <template #right-secondary>
      <span data-testid="right-secondary">
        <gl-sprintf :message="publishedMessage">
          <template v-if="isGroupPage" #projectName>
            <gl-link
              data-testid="root-link"
              class="gl-text-decoration-underline"
              :href="projectLink"
              >{{ projectName }}</gl-link
            >
          </template>
          <template #date>
            <timeago-tooltip :time="packageEntity.createdAt" />
          </template>
          <template v-if="pipelineUser" #author>{{ pipelineUser }}</template>
        </gl-sprintf>
      </span>
    </template>
 
    <template v-if="packageEntity.userPermissions.destroyPackage" #right-action>
      <gl-disclosure-dropdown
        category="tertiary"
        data-testid="delete-dropdown"
        icon="ellipsis_v"
        :toggle-text="$options.i18n.moreActions"
        text-sr-only
        no-caret
      >
        <gl-disclosure-dropdown-item data-testid="action-delete" @action="$emit('delete')">
          <template #list-item>
            <span class="gl-text-red-500">
              {{ $options.i18n.deletePackage }}
            </span>
          </template>
        </gl-disclosure-dropdown-item>
      </gl-disclosure-dropdown>
    </template>
  </list-item>
</template>