Commit 1e60e3c1 authored by Nick Kipling's avatar Nick Kipling

Updated with custom empty message

Displays a custom empty message when no filter results
Updated tests
parent 39e416cf
...@@ -18,12 +18,15 @@ export default { ...@@ -18,12 +18,15 @@ export default {
}, },
computed: { computed: {
...mapState({ ...mapState({
resourceId: state => state.config.resourceId,
emptyListIllustration: state => state.config.emptyListIllustration, emptyListIllustration: state => state.config.emptyListIllustration,
emptyListHelpUrl: state => state.config.emptyListHelpUrl, emptyListHelpUrl: state => state.config.emptyListHelpUrl,
totalItems: state => state.pagination.total, filterQuery: state => state.filterQuery,
}), }),
emptyListText() { emptyListText() {
if (this.filterQuery) {
return s__('PackageRegistry|To widen your search, change or remove the filters above.');
}
return sprintf( return sprintf(
s__( s__(
'PackageRegistry|Learn how to %{noPackagesLinkStart}publish and share your packages%{noPackagesLinkEnd} with GitLab.', 'PackageRegistry|Learn how to %{noPackagesLinkStart}publish and share your packages%{noPackagesLinkEnd} with GitLab.',
...@@ -57,6 +60,10 @@ export default { ...@@ -57,6 +60,10 @@ export default {
this.requestPackagesList(); this.requestPackagesList();
}, },
emptyStateTitle({ title, type }) { emptyStateTitle({ title, type }) {
if (this.filterQuery) {
return s__('PackageRegistry|Sorry, your filter produced no results');
}
if (type) { if (type) {
return sprintf(s__('PackageRegistry|There are no %{packageType} packages yet'), { return sprintf(s__('PackageRegistry|There are no %{packageType} packages yet'), {
packageType: title, packageType: title,
......
...@@ -43,4 +43,8 @@ export default () => ({ ...@@ -43,4 +43,8 @@ export default () => ({
sort: 'desc', sort: 'desc',
orderBy: 'created_at', orderBy: 'created_at',
}, },
/**
* The search query that is used to filter packages by name
*/
filterQuery: '',
}); });
...@@ -17,9 +17,25 @@ describe('packages_list_app', () => { ...@@ -17,9 +17,25 @@ describe('packages_list_app', () => {
const GlLoadingIcon = { name: 'gl-loading-icon', template: '<div>loading</div>' }; const GlLoadingIcon = { name: 'gl-loading-icon', template: '<div>loading</div>' };
const emptyListHelpUrl = 'helpUrl'; const emptyListHelpUrl = 'helpUrl';
const findEmptyState = () => wrapper.find(GlEmptyState);
const findListComponent = () => wrapper.find(PackageList); const findListComponent = () => wrapper.find(PackageList);
const findTabComponent = (index = 0) => wrapper.findAll(GlTab).at(index); const findTabComponent = (index = 0) => wrapper.findAll(GlTab).at(index);
const createStore = (filterQuery = '') => {
store = new Vuex.Store({
state: {
isLoading: false,
config: {
resourceId: 'project_id',
emptyListIllustration: 'helpSvg',
emptyListHelpUrl,
},
filterQuery,
},
});
store.dispatch = jest.fn();
};
const mountComponent = () => { const mountComponent = () => {
wrapper = shallowMount(PackageListApp, { wrapper = shallowMount(PackageListApp, {
localVue, localVue,
...@@ -35,17 +51,7 @@ describe('packages_list_app', () => { ...@@ -35,17 +51,7 @@ describe('packages_list_app', () => {
}; };
beforeEach(() => { beforeEach(() => {
store = new Vuex.Store({ createStore();
state: {
isLoading: false,
config: {
resourceId: 'project_id',
emptyListIllustration: 'helpSvg',
emptyListHelpUrl,
},
},
});
store.dispatch = jest.fn();
mountComponent(); mountComponent();
}); });
...@@ -73,7 +79,7 @@ describe('packages_list_app', () => { ...@@ -73,7 +79,7 @@ describe('packages_list_app', () => {
}); });
it('includes the right content on the default tab', () => { it('includes the right content on the default tab', () => {
const heading = findListComponent().find('h4'); const heading = findEmptyState().find('h4');
expect(heading.text()).toBe('There are no packages yet'); expect(heading.text()).toBe('There are no packages yet');
}); });
...@@ -110,4 +116,18 @@ describe('packages_list_app', () => { ...@@ -110,4 +116,18 @@ describe('packages_list_app', () => {
expect(store.dispatch).toHaveBeenCalledWith('requestPackagesList'); expect(store.dispatch).toHaveBeenCalledWith('requestPackagesList');
}); });
}); });
describe('filter without results', () => {
beforeEach(() => {
createStore('foo');
mountComponent();
});
it('should show specific empty message', () => {
expect(findEmptyState().text()).toContain('Sorry, your filter produced no results');
expect(findEmptyState().text()).toContain(
'To widen your search, change or remove the filters above',
);
});
});
}); });
...@@ -14017,6 +14017,9 @@ msgstr "" ...@@ -14017,6 +14017,9 @@ msgstr ""
msgid "PackageRegistry|Remove package" msgid "PackageRegistry|Remove package"
msgstr "" msgstr ""
msgid "PackageRegistry|Sorry, your filter produced no results"
msgstr ""
msgid "PackageRegistry|There are no %{packageType} packages yet" msgid "PackageRegistry|There are no %{packageType} packages yet"
msgstr "" msgstr ""
...@@ -14026,6 +14029,9 @@ msgstr "" ...@@ -14026,6 +14029,9 @@ msgstr ""
msgid "PackageRegistry|There was a problem fetching the details for this package." msgid "PackageRegistry|There was a problem fetching the details for this package."
msgstr "" msgstr ""
msgid "PackageRegistry|To widen your search, change or remove the filters above."
msgstr ""
msgid "PackageRegistry|Unable to load package" msgid "PackageRegistry|Unable to load package"
msgstr "" msgstr ""
......
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