All files / ee/app/assets/javascripts/compliance_dashboard/components/shared pagination.vue

100% Statements 8/8
80% Branches 8/10
100% Functions 6/6
100% Lines 8/8

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  3x 3x                           5x           5x     4x     4x         8x           24x                      
<script>
import { GlPagination } from '@gitlab/ui';
import { getParameterValues, setUrlParams } from '~/lib/utils/url_utility';
 
export default {
  components: {
    GlPagination,
  },
  props: {
    isLastPage: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  data() {
    return {
      page: parseInt(getParameterValues('page')[0], 10) || 1,
    };
  },
  computed: {
    isOnlyPage() {
      return this.isLastPage && this.page === 1;
    },
    prevPage() {
      return this.page > 1 ? this.page - 1 : null;
    },
    nextPage() {
      return !this.isLastPage ? this.page + 1 : null;
    },
  },
  methods: {
    generateLink(page) {
      return setUrlParams({ page });
    },
  },
};
</script>
 
<template>
  <gl-pagination
    v-if="!isOnlyPage"
    v-model="page"
    :prev-page="prevPage"
    :next-page="nextPage"
    :link-gen="generateLink"
    align="center"
    class="w-100"
  />
</template>