Commit 440396b3 authored by Miguel Rincon's avatar Miguel Rincon

Merge branch '290233-group-migration-user-selectable-page-size' into 'master'

Group migration: User-selectable page size

See merge request gitlab-org/gitlab!54638
parents 316bacde eb6f31d2
<script> <script>
import { import {
GlEmptyState, GlEmptyState,
GlDropdown,
GlDropdownItem,
GlIcon, GlIcon,
GlLink, GlLink,
GlLoadingIcon, GlLoadingIcon,
GlSearchBoxByClick, GlSearchBoxByClick,
GlSprintf, GlSprintf,
} from '@gitlab/ui'; } from '@gitlab/ui';
import { s__ } from '~/locale'; import { s__, __ } from '~/locale';
import PaginationLinks from '~/vue_shared/components/pagination_links.vue'; import PaginationLinks from '~/vue_shared/components/pagination_links.vue';
import importGroupMutation from '../graphql/mutations/import_group.mutation.graphql'; import importGroupMutation from '../graphql/mutations/import_group.mutation.graphql';
import setNewNameMutation from '../graphql/mutations/set_new_name.mutation.graphql'; import setNewNameMutation from '../graphql/mutations/set_new_name.mutation.graphql';
...@@ -16,9 +18,14 @@ import availableNamespacesQuery from '../graphql/queries/available_namespaces.qu ...@@ -16,9 +18,14 @@ import availableNamespacesQuery from '../graphql/queries/available_namespaces.qu
import bulkImportSourceGroupsQuery from '../graphql/queries/bulk_import_source_groups.query.graphql'; import bulkImportSourceGroupsQuery from '../graphql/queries/bulk_import_source_groups.query.graphql';
import ImportTableRow from './import_table_row.vue'; import ImportTableRow from './import_table_row.vue';
const PAGE_SIZES = [20, 50, 100];
const DEFAULT_PAGE_SIZE = PAGE_SIZES[0];
export default { export default {
components: { components: {
GlEmptyState, GlEmptyState,
GlDropdown,
GlDropdownItem,
GlIcon, GlIcon,
GlLink, GlLink,
GlLoadingIcon, GlLoadingIcon,
...@@ -43,6 +50,7 @@ export default { ...@@ -43,6 +50,7 @@ export default {
return { return {
filter: '', filter: '',
page: 1, page: 1,
perPage: DEFAULT_PAGE_SIZE,
}; };
}, },
...@@ -50,13 +58,17 @@ export default { ...@@ -50,13 +58,17 @@ export default {
bulkImportSourceGroups: { bulkImportSourceGroups: {
query: bulkImportSourceGroupsQuery, query: bulkImportSourceGroupsQuery,
variables() { variables() {
return { page: this.page, filter: this.filter }; return { page: this.page, filter: this.filter, perPage: this.perPage };
}, },
}, },
availableNamespaces: availableNamespacesQuery, availableNamespaces: availableNamespacesQuery,
}, },
computed: { computed: {
humanizedTotal() {
return this.paginationInfo.total >= 1000 ? __('1000+') : this.paginationInfo.total;
},
hasGroups() { hasGroups() {
return this.bulkImportSourceGroups?.nodes?.length > 0; return this.bulkImportSourceGroups?.nodes?.length > 0;
}, },
...@@ -117,14 +129,20 @@ export default { ...@@ -117,14 +129,20 @@ export default {
variables: { sourceGroupId }, variables: { sourceGroupId },
}); });
}, },
setPageSize(size) {
this.perPage = size;
},
}, },
PAGE_SIZES,
}; };
</script> </script>
<template> <template>
<div> <div>
<div <div
class="gl-py-5 gl-border-solid gl-border-gray-200 gl-border-0 gl-border-b-1 gl-display-flex gl-align-items-center" class="gl-py-5 gl-border-solid gl-border-gray-200 gl-border-0 gl-border-b-1 gl-display-flex"
> >
<span> <span>
<gl-sprintf v-if="!$apollo.loading && hasGroups" :message="statusMessage"> <gl-sprintf v-if="!$apollo.loading && hasGroups" :message="statusMessage">
...@@ -161,7 +179,7 @@ export default { ...@@ -161,7 +179,7 @@ export default {
:title="s__('BulkImport|You have no groups to import')" :title="s__('BulkImport|You have no groups to import')"
:description="s__('Check your source instance permissions.')" :description="s__('Check your source instance permissions.')"
/> />
<div v-else class="gl-display-flex gl-flex-direction-column gl-align-items-center"> <template v-else>
<table class="gl-w-full"> <table class="gl-w-full">
<thead class="gl-border-solid gl-border-gray-200 gl-border-0 gl-border-b-1"> <thead class="gl-border-solid gl-border-gray-200 gl-border-0 gl-border-b-1">
<th class="gl-py-4 import-jobs-from-col">{{ s__('BulkImport|From source group') }}</th> <th class="gl-py-4 import-jobs-from-col">{{ s__('BulkImport|From source group') }}</th>
...@@ -183,12 +201,50 @@ export default { ...@@ -183,12 +201,50 @@ export default {
</template> </template>
</tbody> </tbody>
</table> </table>
<pagination-links <div v-if="hasGroups" class="gl-display-flex gl-mt-3 gl-align-items-center">
:change="setPage" <pagination-links
:page-info="bulkImportSourceGroups.pageInfo" :change="setPage"
class="gl-mt-3" :page-info="bulkImportSourceGroups.pageInfo"
/> class="gl-m-0"
</div> />
<gl-dropdown category="tertiary" 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>
</div> </div>
</template> </template>
...@@ -430,6 +430,9 @@ msgid_plural "%{count} issues selected" ...@@ -430,6 +430,9 @@ msgid_plural "%{count} issues selected"
msgstr[0] "" msgstr[0] ""
msgstr[1] "" msgstr[1] ""
msgid "%{count} items per page"
msgstr ""
msgid "%{count} merge request selected" msgid "%{count} merge request selected"
msgid_plural "%{count} merge requests selected" msgid_plural "%{count} merge requests selected"
msgstr[0] "" msgstr[0] ""
...@@ -1193,6 +1196,9 @@ msgstr "" ...@@ -1193,6 +1196,9 @@ msgstr ""
msgid "10-19 contributions" msgid "10-19 contributions"
msgstr "" msgstr ""
msgid "1000+"
msgstr ""
msgid "1st contribution!" msgid "1st contribution!"
msgstr "" msgstr ""
...@@ -5128,6 +5134,9 @@ msgstr "" ...@@ -5128,6 +5134,9 @@ msgstr ""
msgid "BulkImport|No parent" msgid "BulkImport|No parent"
msgstr "" msgstr ""
msgid "BulkImport|Showing %{start}-%{end} of %{total}"
msgstr ""
msgid "BulkImport|Showing %{start}-%{end} of %{total} from %{link}" msgid "BulkImport|Showing %{start}-%{end} of %{total} from %{link}"
msgstr "" msgstr ""
......
import { GlEmptyState, GlLoadingIcon, GlSearchBoxByClick, GlSprintf } from '@gitlab/ui'; import {
GlEmptyState,
GlLoadingIcon,
GlSearchBoxByClick,
GlSprintf,
GlDropdown,
GlDropdownItem,
} from '@gitlab/ui';
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import createMockApollo from 'helpers/mock_apollo_helper'; import createMockApollo from 'helpers/mock_apollo_helper';
import { stubComponent } from 'helpers/stub_component';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import { STATUSES } from '~/import_entities/constants'; import { STATUSES } from '~/import_entities/constants';
import ImportTable from '~/import_entities/import_groups/components/import_table.vue'; import ImportTable from '~/import_entities/import_groups/components/import_table.vue';
...@@ -16,10 +24,15 @@ import { availableNamespacesFixture, generateFakeEntry } from '../graphql/fixtur ...@@ -16,10 +24,15 @@ import { availableNamespacesFixture, generateFakeEntry } from '../graphql/fixtur
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(VueApollo); localVue.use(VueApollo);
const GlDropdownStub = stubComponent(GlDropdown, {
template: '<div><h1 ref="text"><slot name="button-content"></slot></h1><slot></slot></div>',
});
describe('import table', () => { describe('import table', () => {
let wrapper; let wrapper;
let apolloProvider; let apolloProvider;
const SOURCE_URL = 'https://demo.host';
const FAKE_GROUP = generateFakeEntry({ id: 1, status: STATUSES.NONE }); const FAKE_GROUP = generateFakeEntry({ id: 1, status: STATUSES.NONE });
const FAKE_GROUPS = [ const FAKE_GROUPS = [
generateFakeEntry({ id: 1, status: STATUSES.NONE }), generateFakeEntry({ id: 1, status: STATUSES.NONE }),
...@@ -27,6 +40,9 @@ describe('import table', () => { ...@@ -27,6 +40,9 @@ describe('import table', () => {
]; ];
const FAKE_PAGE_INFO = { page: 1, perPage: 20, total: 40, totalPages: 2 }; const FAKE_PAGE_INFO = { page: 1, perPage: 20, total: 40, totalPages: 2 };
const findPaginationDropdown = () => wrapper.findComponent(GlDropdown);
const findPaginationDropdownText = () => findPaginationDropdown().find({ ref: 'text' }).text();
const createComponent = ({ bulkImportSourceGroups }) => { const createComponent = ({ bulkImportSourceGroups }) => {
apolloProvider = createMockApollo([], { apolloProvider = createMockApollo([], {
Query: { Query: {
...@@ -42,11 +58,12 @@ describe('import table', () => { ...@@ -42,11 +58,12 @@ describe('import table', () => {
wrapper = shallowMount(ImportTable, { wrapper = shallowMount(ImportTable, {
propsData: { propsData: {
sourceUrl: 'https://demo.host',
groupPathRegex: /.*/, groupPathRegex: /.*/,
sourceUrl: SOURCE_URL,
}, },
stubs: { stubs: {
GlSprintf, GlSprintf,
GlDropdown: GlDropdownStub,
}, },
localVue, localVue,
apolloProvider, apolloProvider,
...@@ -152,6 +169,20 @@ describe('import table', () => { ...@@ -152,6 +169,20 @@ describe('import table', () => {
expect(wrapper.find(PaginationLinks).props().pageInfo).toStrictEqual(FAKE_PAGE_INFO); expect(wrapper.find(PaginationLinks).props().pageInfo).toStrictEqual(FAKE_PAGE_INFO);
}); });
it('renders pagination dropdown', () => {
expect(findPaginationDropdown().exists()).toBe(true);
});
it('updates page size when selected in Dropdown', async () => {
const otherOption = wrapper.findAllComponents(GlDropdownItem).at(1);
expect(otherOption.text()).toMatchInterpolatedText('50 items per page');
otherOption.vm.$emit('click');
await waitForPromises();
expect(findPaginationDropdownText()).toMatchInterpolatedText('50 items per page');
});
it('updates page when page change is requested', async () => { it('updates page when page change is requested', async () => {
const REQUESTED_PAGE = 2; const REQUESTED_PAGE = 2;
wrapper.find(PaginationLinks).props().change(REQUESTED_PAGE); wrapper.find(PaginationLinks).props().change(REQUESTED_PAGE);
...@@ -179,7 +210,7 @@ describe('import table', () => { ...@@ -179,7 +210,7 @@ describe('import table', () => {
wrapper.find(PaginationLinks).props().change(REQUESTED_PAGE); wrapper.find(PaginationLinks).props().change(REQUESTED_PAGE);
await waitForPromises(); await waitForPromises();
expect(wrapper.text()).toContain('Showing 21-21 of 38'); expect(wrapper.text()).toContain('Showing 21-21 of 38 groups from');
}); });
}); });
...@@ -225,7 +256,7 @@ describe('import table', () => { ...@@ -225,7 +256,7 @@ describe('import table', () => {
findFilterInput().vm.$emit('submit', FILTER_VALUE); findFilterInput().vm.$emit('submit', FILTER_VALUE);
await waitForPromises(); await waitForPromises();
expect(wrapper.text()).toContain('Showing 1-1 of 40 groups matching filter "foo"'); expect(wrapper.text()).toContain('Showing 1-1 of 40 groups matching filter "foo" from');
}); });
it('properly resets filter in graphql query when search box is cleared', async () => { it('properly resets filter in graphql query when search box is cleared', async () => {
......
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