2021-06-01 20:09:56 -04:00
|
|
|
<script>
|
|
|
|
import { GlPagination } from '@gitlab/ui';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
GlPagination,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
value: {
|
|
|
|
required: false,
|
|
|
|
type: Object,
|
|
|
|
default: () => ({
|
|
|
|
page: 1,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
pageInfo: {
|
|
|
|
required: false,
|
|
|
|
type: Object,
|
|
|
|
default: () => ({}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
prevPage() {
|
2022-05-16 14:09:11 -04:00
|
|
|
return this.pageInfo?.hasPreviousPage ? this.value.page - 1 : null;
|
2021-06-01 20:09:56 -04:00
|
|
|
},
|
|
|
|
nextPage() {
|
2022-05-16 14:09:11 -04:00
|
|
|
return this.pageInfo?.hasNextPage ? this.value.page + 1 : null;
|
2021-06-01 20:09:56 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
handlePageChange(page) {
|
2022-02-12 07:15:45 -05:00
|
|
|
if (page === 1) {
|
|
|
|
// Small optimization for first page
|
|
|
|
// If we have loaded using "first",
|
|
|
|
// page is already cached.
|
|
|
|
this.$emit('input', {
|
|
|
|
page,
|
|
|
|
});
|
|
|
|
} else if (page > this.value.page) {
|
2021-06-01 20:09:56 -04:00
|
|
|
this.$emit('input', {
|
|
|
|
page,
|
|
|
|
after: this.pageInfo.endCursor,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.$emit('input', {
|
|
|
|
page,
|
|
|
|
before: this.pageInfo.startCursor,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<gl-pagination
|
2022-02-12 07:15:45 -05:00
|
|
|
v-bind="$attrs"
|
2021-06-01 20:09:56 -04:00
|
|
|
:value="value.page"
|
|
|
|
:prev-page="prevPage"
|
|
|
|
:next-page="nextPage"
|
|
|
|
align="center"
|
2022-02-12 07:15:45 -05:00
|
|
|
class="gl-pagination"
|
2021-06-01 20:09:56 -04:00
|
|
|
@input="handlePageChange"
|
|
|
|
/>
|
|
|
|
</template>
|