All files / app/assets/javascripts/packages_and_registries/dependency_proxy app.vue

90.47% Statements 19/21
100% Branches 3/3
100% Functions 14/14
90.47% Lines 19/21

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                                              1x                                                                                       31x                   39x           39x     70x     39x 39x     70x     70x                       70x                       70x     70x     70x         4x     3x     1x 1x   1x 1x                                                                                                                                                                                                
<script>
import {
  GlAlert,
  GlButton,
  GlDisclosureDropdown,
  GlDisclosureDropdownItem,
  GlFormGroup,
  GlFormInputGroup,
  GlSkeletonLoader,
  GlModal,
  GlModalDirective,
  GlSprintf,
  GlTooltipDirective,
} from '@gitlab/ui';
import { __, s__, n__, sprintf } from '~/locale';
import Api from '~/api';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
import TitleArea from '~/vue_shared/components/registry/title_area.vue';
import ManifestsList from '~/packages_and_registries/dependency_proxy/components/manifests_list.vue';
import { GRAPHQL_PAGE_SIZE } from '~/packages_and_registries/dependency_proxy/constants';
import { getPageParams } from '~/packages_and_registries/dependency_proxy/utils';
import { extractPageInfo } from '~/packages_and_registries/shared/utils';
 
import getDependencyProxyDetailsQuery from '~/packages_and_registries/dependency_proxy/graphql/queries/get_dependency_proxy_details.query.graphql';
 
export default {
  components: {
    GlAlert,
    GlButton,
    GlDisclosureDropdown,
    GlDisclosureDropdownItem,
    GlSkeletonLoader,
    GlFormGroup,
    GlFormInputGroup,
    GlModal,
    GlSprintf,
    ClipboardButton,
    TitleArea,
    ManifestsList,
  },
  directives: {
    GlModalDirective,
    GlTooltip: GlTooltipDirective,
  },
  inject: ['groupPath', 'groupId', 'canClearCache', 'settingsPath'],
  i18n: {
    proxyImagePrefix: s__('DependencyProxy|Dependency Proxy image prefix'),
    copyImagePrefixText: s__('DependencyProxy|Copy prefix'),
    blobCountAndSize: s__('DependencyProxy|Contains %{count} blobs of images (%{size})'),
    pageTitle: s__('DependencyProxy|Dependency Proxy'),
    deleteCacheAlertMessageSuccess: s__(
      'DependencyProxy|All items in the cache are scheduled for removal.',
    ),
    clearCache: s__('DependencyProxy|Clear cache'),
    settingsText: s__('DependencyProxy|Configure in settings'),
  },
  confirmClearCacheModal: 'confirm-clear-cache-modal',
  modalButtons: {
    primary: {
      text: s__('DependencyProxy|Clear cache'),
      attributes: { variant: 'danger' },
    },
    secondary: {
      text: __('Cancel'),
    },
  },
  data() {
    return {
      group: {},
      showDeleteCacheAlert: false,
      deleteCacheAlertMessage: '',
    };
  },
  apollo: {
    group: {
      query: getDependencyProxyDetailsQuery,
      variables() {
        return this.queryVariables;
      },
    },
  },
  computed: {
    queryVariables() {
      return { fullPath: this.groupPath, first: GRAPHQL_PAGE_SIZE, ...this.pageParams };
    },
    pageInfo() {
      return this.group.dependencyProxyManifests?.pageInfo;
    },
    pageParams() {
      const pageInfo = extractPageInfo(this.$route.query);
      return getPageParams(pageInfo);
    },
    manifests() {
      return this.group.dependencyProxyManifests?.nodes ?? [];
    },
    modalTitleWithCount() {
      return sprintf(
        n__(
          'Clear %{count} image from cache?',
          'Clear %{count} images from cache?',
          this.group.dependencyProxyBlobCount,
        ),
        {
          count: this.group.dependencyProxyBlobCount,
        },
      );
    },
    modalConfirmationMessageWithCount() {
      return sprintf(
        n__(
          'You are about to clear %{count} image from the cache. Once you confirm, the next time a pipeline runs it must pull an image or tag from Docker Hub. Are you sure?',
          'You are about to clear %{count} images from the cache. Once you confirm, the next time a pipeline runs it must pull an image or tag from Docker Hub. Are you sure?',
          this.group.dependencyProxyBlobCount,
        ),
        {
          count: this.group.dependencyProxyBlobCount,
        },
      );
    },
    showDeleteDropdown() {
      return this.manifests?.length > 0 && this.canClearCache;
    },
    dependencyProxyImagePrefix() {
      return this.group.dependencyProxyImagePrefix;
    },
    showDependencyProxyImagePrefix() {
      return this.dependencyProxyImagePrefix?.length > 0;
    },
  },
  methods: {
    fetchNextPage() {
      this.$router.push({ query: { after: this.pageInfo?.endCursor } });
    },
    fetchPreviousPage() {
      this.$router.push({ query: { before: this.pageInfo?.startCursor } });
    },
    async submit() {
      try {
        await Api.deleteDependencyProxyCacheList(this.groupId);
 
        this.deleteCacheAlertMessage = this.$options.i18n.deleteCacheAlertMessageSuccess;
        this.showDeleteCacheAlert = true;
      } catch (err) {
        this.deleteCacheAlertMessage = err;
        this.showDeleteCacheAlert = true;
      }
    },
  },
};
</script>
 
<template>
  <div>
    <gl-alert v-if="showDeleteCacheAlert" @dismiss="showDeleteCacheAlert = false">
      {{ deleteCacheAlertMessage }}
    </gl-alert>
    <title-area :title="$options.i18n.pageTitle">
      <template #right-actions>
        <gl-disclosure-dropdown
          v-if="showDeleteDropdown"
          icon="ellipsis_v"
          :toggle-text="__('More actions')"
          :text-sr-only="true"
          category="tertiary"
          placement="right"
          no-caret
        >
          <gl-disclosure-dropdown-item v-gl-modal-directive="$options.confirmClearCacheModal">
            <template #list-item>
              <span class="gl-text-red-500">
                {{ $options.i18n.clearCache }}
              </span>
            </template>
          </gl-disclosure-dropdown-item>
        </gl-disclosure-dropdown>
        <gl-button
          v-if="canClearCache"
          v-gl-tooltip="$options.i18n.settingsText"
          icon="settings"
          data-testid="settings-link"
          :href="settingsPath"
          :aria-label="$options.i18n.settingsText"
        />
      </template>
    </title-area>
 
    <gl-form-group
      v-if="showDependencyProxyImagePrefix"
      :label="$options.i18n.proxyImagePrefix"
      label-for="proxy-url"
    >
      <gl-form-input-group
        id="proxy-url"
        readonly
        :value="dependencyProxyImagePrefix"
        select-on-click
        class="gl-layout-w-limited"
        data-testid="proxy-url"
      >
        <template #append>
          <clipboard-button
            :text="dependencyProxyImagePrefix"
            :title="$options.i18n.copyImagePrefixText"
          />
        </template>
      </gl-form-input-group>
      <template #description>
        <span data-testid="proxy-count">
          <gl-sprintf :message="$options.i18n.blobCountAndSize">
            <template #count>{{ group.dependencyProxyBlobCount }}</template>
            <template #size>{{ group.dependencyProxyTotalSize }}</template>
          </gl-sprintf>
        </span>
      </template>
    </gl-form-group>
    <gl-skeleton-loader v-else-if="$apollo.queries.group.loading" />
 
    <manifests-list
      :dependency-proxy-image-prefix="dependencyProxyImagePrefix"
      :loading="$apollo.queries.group.loading"
      :manifests="manifests"
      :pagination="pageInfo"
      @prev-page="fetchPreviousPage"
      @next-page="fetchNextPage"
    />
 
    <gl-modal
      :modal-id="$options.confirmClearCacheModal"
      :title="modalTitleWithCount"
      :action-primary="$options.modalButtons.primary"
      :action-secondary="$options.modalButtons.secondary"
      @primary="submit"
    >
      {{ modalConfirmationMessageWithCount }}
    </gl-modal>
  </div>
</template>