Commit b2820d25 authored by Olena Horal-Koretska's avatar Olena Horal-Koretska

Merge branch...

Merge branch '341868-refactor-import_entities-import_groups-app-to-use-new-pagination_bar' into 'master'

Refactor import_entities/import_groups app to use new pagination_bar

See merge request gitlab-org/gitlab!76423
parents 04a576e2 50c52424
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
import { import {
GlButton, GlButton,
GlEmptyState, GlEmptyState,
GlDropdown,
GlDropdownItem,
GlIcon, GlIcon,
GlLink, GlLink,
GlLoadingIcon, GlLoadingIcon,
...@@ -15,7 +13,7 @@ import { ...@@ -15,7 +13,7 @@ import {
import { debounce } from 'lodash'; import { debounce } from 'lodash';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { s__, __, n__ } from '~/locale'; import { s__, __, n__ } from '~/locale';
import PaginationLinks from '~/vue_shared/components/pagination_links.vue'; import PaginationBar from '~/vue_shared/components/pagination_bar/pagination_bar.vue';
import { getGroupPathAvailability } from '~/rest_api'; import { getGroupPathAvailability } from '~/rest_api';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { DEFAULT_DEBOUNCE_AND_THROTTLE_MS } from '~/lib/utils/constants'; import { DEFAULT_DEBOUNCE_AND_THROTTLE_MS } from '~/lib/utils/constants';
...@@ -44,8 +42,6 @@ export default { ...@@ -44,8 +42,6 @@ export default {
components: { components: {
GlButton, GlButton,
GlEmptyState, GlEmptyState,
GlDropdown,
GlDropdownItem,
GlIcon, GlIcon,
GlLink, GlLink,
GlLoadingIcon, GlLoadingIcon,
...@@ -57,7 +53,7 @@ export default { ...@@ -57,7 +53,7 @@ export default {
ImportTargetCell, ImportTargetCell,
ImportStatusCell, ImportStatusCell,
ImportActionsCell, ImportActionsCell,
PaginationLinks, PaginationBar,
}, },
props: { props: {
...@@ -600,49 +596,13 @@ export default { ...@@ -600,49 +596,13 @@ export default {
/> />
</template> </template>
</gl-table> </gl-table>
<div v-if="hasGroups" class="gl-display-flex gl-mt-3 gl-align-items-center"> <pagination-bar
<pagination-links v-if="hasGroups"
:change="setPage" :page-info="bulkImportSourceGroups.pageInfo"
:page-info="bulkImportSourceGroups.pageInfo" class="gl-mt-3"
class="gl-m-0" @set-page="setPage"
/> @set-page-size="setPageSize"
<gl-dropdown category="tertiary" :aria-label="__('Page size')" class="gl-ml-auto"> />
<template #button-content>
<span class="font-weight-bold">
<gl-sprintf :message="__('%{count} items per page')">
<template #count>
{{ perPage }}
</template>
</gl-sprintf>
</span>
<gl-icon class="gl-button-icon dropdown-chevron" name="chevron-down" />
</template>
<gl-dropdown-item
v-for="size in $options.PAGE_SIZES"
:key="size"
@click="setPageSize(size)"
>
<gl-sprintf :message="__('%{count} items per page')">
<template #count>
{{ size }}
</template>
</gl-sprintf>
</gl-dropdown-item>
</gl-dropdown>
<div class="gl-ml-2">
<gl-sprintf :message="s__('BulkImport|Showing %{start}-%{end} of %{total}')">
<template #start>
{{ paginationInfo.start }}
</template>
<template #end>
{{ paginationInfo.end }}
</template>
<template #total>
{{ humanizedTotal }}
</template>
</gl-sprintf>
</div>
</div>
</template> </template>
</template> </template>
</div> </div>
......
...@@ -7,7 +7,7 @@ import { parseIntPagination, normalizeHeaders } from '~/lib/utils/common_utils'; ...@@ -7,7 +7,7 @@ import { parseIntPagination, normalizeHeaders } from '~/lib/utils/common_utils';
import { joinPaths } from '~/lib/utils/url_utility'; import { joinPaths } from '~/lib/utils/url_utility';
import { getBulkImportsHistory } from '~/rest_api'; import { getBulkImportsHistory } from '~/rest_api';
import ImportStatus from '~/import_entities/components/import_status.vue'; import ImportStatus from '~/import_entities/components/import_status.vue';
import PaginationBar from '~/import_entities/components/pagination_bar.vue'; import PaginationBar from '~/vue_shared/components/pagination_bar/pagination_bar.vue';
import TimeAgo from '~/vue_shared/components/time_ago_tooltip.vue'; import TimeAgo from '~/vue_shared/components/time_ago_tooltip.vue';
import { DEFAULT_ERROR } from '../utils/error_messages'; import { DEFAULT_ERROR } from '../utils/error_messages';
...@@ -166,7 +166,6 @@ export default { ...@@ -166,7 +166,6 @@ export default {
</gl-table> </gl-table>
<pagination-bar <pagination-bar
:page-info="pageInfo" :page-info="pageInfo"
:items-count="historyItems.length"
class="gl-m-0 gl-mt-3" class="gl-m-0 gl-mt-3"
@set-page="paginationConfig.page = $event" @set-page="paginationConfig.page = $event"
@set-page-size="paginationConfig.perPage = $event" @set-page-size="paginationConfig.perPage = $event"
......
/* eslint-disable @gitlab/require-i18n-strings */
import PaginationBar from './pagination_bar.vue';
export default {
component: PaginationBar,
title: 'vue_shared/components/pagination_bar/pagination_bar',
};
const Template = (args, { argTypes }) => ({
components: { PaginationBar },
props: Object.keys(argTypes),
template: `<pagination-bar v-bind="$props" v-on="{ 'set-page-size': setPageSize, 'set-page': setPage }" />`,
});
export const Default = Template.bind({});
Default.args = {
pageInfo: {
perPage: 20,
page: 2,
total: 83,
totalPages: 5,
},
pageSizes: [20, 50, 100],
};
Default.argTypes = {
pageInfo: {
description: 'Page info object',
control: { type: 'object' },
},
pageSizes: {
description: 'Array of possible page sizes',
control: { type: 'array' },
},
// events
setPageSize: { action: 'set-page-size' },
setPage: { action: 'set-page' },
};
...@@ -23,10 +23,6 @@ export default { ...@@ -23,10 +23,6 @@ export default {
type: Array, type: Array,
default: () => DEFAULT_PAGE_SIZES, default: () => DEFAULT_PAGE_SIZES,
}, },
itemsCount: {
required: true,
type: Number,
},
}, },
computed: { computed: {
...@@ -35,9 +31,10 @@ export default { ...@@ -35,9 +31,10 @@ export default {
}, },
paginationInfo() { paginationInfo() {
const { page, perPage } = this.pageInfo; const { page, perPage, totalPages, total } = this.pageInfo;
const itemsCount = page === totalPages ? total - (page - 1) * perPage : perPage;
const start = (page - 1) * perPage + 1; const start = (page - 1) * perPage + 1;
const end = start + this.itemsCount - 1; const end = start + itemsCount - 1;
return { start, end }; return { start, end };
}, },
...@@ -45,8 +42,24 @@ export default { ...@@ -45,8 +42,24 @@ export default {
methods: { methods: {
setPage(page) { setPage(page) {
// eslint-disable-next-line spaced-comment
/**
* Emitted when selected page is updated
*
* @event set-page
**/
this.$emit('set-page', page); this.$emit('set-page', page);
}, },
setPageSize(pageSize) {
// eslint-disable-next-line spaced-comment
/**
* Emitted when page size is updated
*
* @event set-page-size
**/
this.$emit('set-page-size', pageSize);
},
}, },
}; };
</script> </script>
...@@ -54,7 +67,7 @@ export default { ...@@ -54,7 +67,7 @@ export default {
<template> <template>
<div class="gl-display-flex gl-align-items-center"> <div class="gl-display-flex gl-align-items-center">
<pagination-links :change="setPage" :page-info="pageInfo" class="gl-m-0" /> <pagination-links :change="setPage" :page-info="pageInfo" class="gl-m-0" />
<gl-dropdown category="tertiary" class="gl-ml-auto"> <gl-dropdown category="tertiary" class="gl-ml-auto" data-testid="page-size">
<template #button-content> <template #button-content>
<span class="gl-font-weight-bold"> <span class="gl-font-weight-bold">
<gl-sprintf :message="__('%{count} items per page')"> <gl-sprintf :message="__('%{count} items per page')">
...@@ -65,7 +78,7 @@ export default { ...@@ -65,7 +78,7 @@ export default {
</span> </span>
<gl-icon class="gl-button-icon dropdown-chevron" name="chevron-down" /> <gl-icon class="gl-button-icon dropdown-chevron" name="chevron-down" />
</template> </template>
<gl-dropdown-item v-for="size in pageSizes" :key="size" @click="$emit('set-page-size', size)"> <gl-dropdown-item v-for="size in pageSizes" :key="size" @click="setPageSize(size)">
<gl-sprintf :message="__('%{count} items per page')"> <gl-sprintf :message="__('%{count} items per page')">
<template #count> <template #count>
{{ size }} {{ size }}
......
...@@ -25258,9 +25258,6 @@ msgstr "" ...@@ -25258,9 +25258,6 @@ msgstr ""
msgid "Page settings" msgid "Page settings"
msgstr "" msgstr ""
msgid "Page size"
msgstr ""
msgid "PagerDutySettings|Active" msgid "PagerDutySettings|Active"
msgstr "" msgstr ""
......
...@@ -38,7 +38,7 @@ describe('import table', () => { ...@@ -38,7 +38,7 @@ describe('import table', () => {
wrapper.findAll('button').wrappers.find((w) => w.text() === 'Import selected'); wrapper.findAll('button').wrappers.find((w) => w.text() === 'Import selected');
const findImportButtons = () => const findImportButtons = () =>
wrapper.findAll('button').wrappers.filter((w) => w.text() === 'Import'); wrapper.findAll('button').wrappers.filter((w) => w.text() === 'Import');
const findPaginationDropdown = () => wrapper.find('[aria-label="Page size"]'); const findPaginationDropdown = () => wrapper.find('[data-testid="page-size"]');
const findPaginationDropdownText = () => findPaginationDropdown().find('button').text(); const findPaginationDropdownText = () => findPaginationDropdown().find('button').text();
const findSelectionCount = () => wrapper.find('[data-test-id="selection-count"]'); const findSelectionCount = () => wrapper.find('[data-test-id="selection-count"]');
...@@ -209,7 +209,12 @@ describe('import table', () => { ...@@ -209,7 +209,12 @@ describe('import table', () => {
const otherOption = findPaginationDropdown().findAll('li p').at(1); const otherOption = findPaginationDropdown().findAll('li p').at(1);
expect(otherOption.text()).toMatchInterpolatedText('50 items per page'); expect(otherOption.text()).toMatchInterpolatedText('50 items per page');
bulkImportSourceGroupsQueryMock.mockResolvedValue({
nodes: [FAKE_GROUP],
pageInfo: { ...FAKE_PAGE_INFO, perPage: 50 },
});
await otherOption.trigger('click'); await otherOption.trigger('click');
await waitForPromises(); await waitForPromises();
expect(findPaginationDropdownText()).toMatchInterpolatedText('50 items per page'); expect(findPaginationDropdownText()).toMatchInterpolatedText('50 items per page');
......
...@@ -2,7 +2,7 @@ import { GlEmptyState, GlLoadingIcon, GlTable } from '@gitlab/ui'; ...@@ -2,7 +2,7 @@ import { GlEmptyState, GlLoadingIcon, GlTable } from '@gitlab/ui';
import { mount, shallowMount } from '@vue/test-utils'; import { mount, shallowMount } from '@vue/test-utils';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import PaginationBar from '~/import_entities/components/pagination_bar.vue'; import PaginationBar from '~/vue_shared/components/pagination_bar/pagination_bar.vue';
import BulkImportsHistoryApp from '~/pages/import/bulk_imports/history/components/bulk_imports_history_app.vue'; import BulkImportsHistoryApp from '~/pages/import/bulk_imports/history/components/bulk_imports_history_app.vue';
import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import { extendedWrapper } from 'helpers/vue_test_utils_helper';
......
import { GlPagination, GlDropdown, GlDropdownItem } from '@gitlab/ui'; import { GlPagination, GlDropdown, GlDropdownItem } from '@gitlab/ui';
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import PaginationBar from '~/import_entities/components/pagination_bar.vue'; import PaginationBar from '~/vue_shared/components/pagination_bar/pagination_bar.vue';
import PaginationLinks from '~/vue_shared/components/pagination_links.vue'; import PaginationLinks from '~/vue_shared/components/pagination_links.vue';
describe('Pagination bar', () => { describe('Pagination bar', () => {
const DEFAULT_PROPS = { const DEFAULT_PROPS = {
pageInfo: { pageInfo: {
total: 50, total: 50,
page: 1, totalPages: 3,
page: 3,
perPage: 20, perPage: 20,
}, },
itemsCount: 17,
}; };
let wrapper; let wrapper;
...@@ -73,7 +73,7 @@ describe('Pagination bar', () => { ...@@ -73,7 +73,7 @@ describe('Pagination bar', () => {
createComponent(); createComponent();
expect(wrapper.find('[data-testid="information"]').text()).toMatchInterpolatedText( expect(wrapper.find('[data-testid="information"]').text()).toMatchInterpolatedText(
'Showing 1 - 17 of 50', 'Showing 41 - 50 of 50',
); );
}); });
...@@ -82,11 +82,12 @@ describe('Pagination bar', () => { ...@@ -82,11 +82,12 @@ describe('Pagination bar', () => {
pageInfo: { pageInfo: {
...DEFAULT_PROPS.pageInfo, ...DEFAULT_PROPS.pageInfo,
total: 1200, total: 1200,
page: 2,
}, },
}); });
expect(wrapper.find('[data-testid="information"]').text()).toMatchInterpolatedText( expect(wrapper.find('[data-testid="information"]').text()).toMatchInterpolatedText(
'Showing 1 - 17 of 1000+', 'Showing 21 - 40 of 1000+',
); );
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment