Commit f5fa1cef authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch '327692-package-sort-showing-project-in-the-project-page' into 'master'

Resolve "Package sort: showing Project in the project page"

See merge request gitlab-org/gitlab!59367
parents 4e9666d1 195880bb
...@@ -3,7 +3,7 @@ import { mapState, mapActions } from 'vuex'; ...@@ -3,7 +3,7 @@ import { mapState, mapActions } from 'vuex';
import { __, s__ } from '~/locale'; import { __, s__ } from '~/locale';
import RegistrySearch from '~/vue_shared/components/registry/registry_search.vue'; import RegistrySearch from '~/vue_shared/components/registry/registry_search.vue';
import UrlSync from '~/vue_shared/components/url_sync.vue'; import UrlSync from '~/vue_shared/components/url_sync.vue';
import getTableHeaders from '../utils'; import { sortableFields } from '../utils';
import PackageTypeToken from './tokens/package_type_token.vue'; import PackageTypeToken from './tokens/package_type_token.vue';
export default { export default {
...@@ -25,7 +25,7 @@ export default { ...@@ -25,7 +25,7 @@ export default {
filter: (state) => state.filter, filter: (state) => state.filter,
}), }),
sortableFields() { sortableFields() {
return getTableHeaders(this.isGroupPage); return sortableFields(this.isGroupPage);
}, },
}, },
methods: { methods: {
......
import { LIST_KEY_PROJECT, SORT_FIELDS } from './constants'; import { LIST_KEY_PROJECT, SORT_FIELDS } from './constants';
export default (isGroupPage) => export const sortableFields = (isGroupPage) =>
SORT_FIELDS.filter((f) => f.key !== LIST_KEY_PROJECT || isGroupPage); SORT_FIELDS.filter((f) => f.orderBy !== LIST_KEY_PROJECT || isGroupPage);
/** /**
* A small util function that works out if the delete action has deleted the * A small util function that works out if the delete action has deleted the
......
<script> <script>
import { mapState, mapActions } from 'vuex'; import { mapState, mapActions } from 'vuex';
import { LIST_KEY_PACKAGE_TYPE } from '~/packages/list/constants'; import { LIST_KEY_PACKAGE_TYPE } from '~/packages/list/constants';
import getTableHeaders from '~/packages/list/utils'; import { sortableFields } from '~/packages/list/utils';
import RegistrySearch from '~/vue_shared/components/registry/registry_search.vue'; import RegistrySearch from '~/vue_shared/components/registry/registry_search.vue';
import UrlSync from '~/vue_shared/components/url_sync.vue'; import UrlSync from '~/vue_shared/components/url_sync.vue';
...@@ -14,7 +14,7 @@ export default { ...@@ -14,7 +14,7 @@ export default {
filter: (state) => state.filter, filter: (state) => state.filter,
}), }),
sortableFields() { sortableFields() {
return getTableHeaders(this.isGroupPage).filter((h) => h.orderBy !== LIST_KEY_PACKAGE_TYPE); return sortableFields(this.isGroupPage).filter((h) => h.orderBy !== LIST_KEY_PACKAGE_TYPE);
}, },
}, },
methods: { methods: {
......
---
title: Do not show sort by project in Package project page
merge_request: 59367
author:
type: fixed
...@@ -2,7 +2,7 @@ import { shallowMount, createLocalVue } from '@vue/test-utils'; ...@@ -2,7 +2,7 @@ import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex'; import Vuex from 'vuex';
import component from '~/packages/list/components/package_search.vue'; import component from '~/packages/list/components/package_search.vue';
import PackageTypeToken from '~/packages/list/components/tokens/package_type_token.vue'; import PackageTypeToken from '~/packages/list/components/tokens/package_type_token.vue';
import getTableHeaders from '~/packages/list/utils'; import { sortableFields } from '~/packages/list/utils';
import RegistrySearch from '~/vue_shared/components/registry/registry_search.vue'; import RegistrySearch from '~/vue_shared/components/registry/registry_search.vue';
import UrlSync from '~/vue_shared/components/url_sync.vue'; import UrlSync from '~/vue_shared/components/url_sync.vue';
...@@ -60,7 +60,7 @@ describe('Package Search', () => { ...@@ -60,7 +60,7 @@ describe('Package Search', () => {
tokens: expect.arrayContaining([ tokens: expect.arrayContaining([
expect.objectContaining({ token: PackageTypeToken, type: 'type', icon: 'package' }), expect.objectContaining({ token: PackageTypeToken, type: 'type', icon: 'package' }),
]), ]),
sortableFields: getTableHeaders(), sortableFields: sortableFields(),
}); });
}); });
...@@ -77,7 +77,7 @@ describe('Package Search', () => { ...@@ -77,7 +77,7 @@ describe('Package Search', () => {
tokens: expect.arrayContaining([ tokens: expect.arrayContaining([
expect.objectContaining({ token: PackageTypeToken, type: 'type', icon: 'package' }), expect.objectContaining({ token: PackageTypeToken, type: 'type', icon: 'package' }),
]), ]),
sortableFields: getTableHeaders(isGroupPage), sortableFields: sortableFields(isGroupPage),
}); });
}); });
......
import { getNewPaginationPage } from '~/packages/list/utils'; import { SORT_FIELDS } from '~/packages/list/constants';
import { getNewPaginationPage, sortableFields } from '~/packages/list/utils';
describe('Packages list utils', () => { describe('Packages list utils', () => {
describe('sortableFields', () => {
it('returns the correct list when is a project page', () => {
expect(sortableFields()).toEqual(SORT_FIELDS.filter((f) => f.orderBy !== 'project_path'));
});
it('returns the full list on the group page', () => {
expect(sortableFields(true)).toEqual(SORT_FIELDS);
});
});
describe('packageTypeDisplay', () => { describe('packageTypeDisplay', () => {
it('returns the current page when total items exceeds pagniation', () => { it('returns the current page when total items exceeds pagniation', () => {
expect(getNewPaginationPage(2, 20, 21)).toBe(2); expect(getNewPaginationPage(2, 20, 21)).toBe(2);
......
...@@ -12,6 +12,12 @@ describe('Infrastructure Search', () => { ...@@ -12,6 +12,12 @@ describe('Infrastructure Search', () => {
let store; let store;
const sortableFields = () => [ const sortableFields = () => [
{ orderBy: 'name', label: 'Name' },
{ orderBy: 'version', label: 'Version' },
{ orderBy: 'created_at', label: 'Published' },
];
const groupSortableFields = () => [
{ orderBy: 'name', label: 'Name' }, { orderBy: 'name', label: 'Name' },
{ orderBy: 'project_path', label: 'Project' }, { orderBy: 'project_path', label: 'Project' },
{ orderBy: 'version', label: 'Version' }, { orderBy: 'version', label: 'Version' },
...@@ -68,17 +74,17 @@ describe('Infrastructure Search', () => { ...@@ -68,17 +74,17 @@ describe('Infrastructure Search', () => {
}); });
it.each` it.each`
isGroupPage | page isGroupPage | page | fields
${false} | ${'project'} ${false} | ${'project'} | ${sortableFields()}
${true} | ${'group'} ${true} | ${'group'} | ${groupSortableFields()}
`('in a $page page binds the right props', ({ isGroupPage }) => { `('in a $page page binds the right props', ({ isGroupPage, fields }) => {
mountComponent(isGroupPage); mountComponent(isGroupPage);
expect(findRegistrySearch().props()).toMatchObject({ expect(findRegistrySearch().props()).toMatchObject({
filter: store.state.filter, filter: store.state.filter,
sorting: store.state.sorting, sorting: store.state.sorting,
tokens: [], tokens: [],
sortableFields: sortableFields(), sortableFields: fields,
}); });
}); });
......
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