Commit eddb2802 authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera

Merge branch '199986-refactor-packages-sprintf-uses-to-gitlab-ui-sprintf' into 'master'

Refactor final package components to use gl-sprintf

See merge request gitlab-org/gitlab!33942
parents e793189a ac9840d8
...@@ -11,8 +11,8 @@ import { ...@@ -11,8 +11,8 @@ import {
GlTab, GlTab,
GlTabs, GlTabs,
GlTable, GlTable,
GlSprintf,
} from '@gitlab/ui'; } from '@gitlab/ui';
import { escape } from 'lodash';
import Tracking from '~/tracking'; import Tracking from '~/tracking';
import PackageActivity from './activity.vue'; import PackageActivity from './activity.vue';
import PackageInformation from './information.vue'; import PackageInformation from './information.vue';
...@@ -28,7 +28,7 @@ import DependencyRow from './dependency_row.vue'; ...@@ -28,7 +28,7 @@ import DependencyRow from './dependency_row.vue';
import { numberToHumanSize } from '~/lib/utils/number_utils'; import { numberToHumanSize } from '~/lib/utils/number_utils';
import timeagoMixin from '~/vue_shared/mixins/timeago'; import timeagoMixin from '~/vue_shared/mixins/timeago';
import { generatePackageInfo } from '../utils'; import { generatePackageInfo } from '../utils';
import { __, s__, sprintf } from '~/locale'; import { __, s__ } from '~/locale';
import { PackageType, TrackingActions } from '../../shared/constants'; import { PackageType, TrackingActions } from '../../shared/constants';
import { packageTypeToTrackCategory } from '../../shared/utils'; import { packageTypeToTrackCategory } from '../../shared/utils';
import { mapActions, mapState } from 'vuex'; import { mapActions, mapState } from 'vuex';
...@@ -45,6 +45,7 @@ export default { ...@@ -45,6 +45,7 @@ export default {
GlTabs, GlTabs,
GlTable, GlTable,
GlIcon, GlIcon,
GlSprintf,
PackageActivity, PackageActivity,
PackageInformation, PackageInformation,
PackageTitle, PackageTitle,
...@@ -96,20 +97,6 @@ export default { ...@@ -96,20 +97,6 @@ export default {
canDeletePackage() { canDeletePackage() {
return this.canDelete && this.destroyPath; return this.canDelete && this.destroyPath;
}, },
deleteModalDescription() {
return sprintf(
s__(
`PackageRegistry|You are about to delete version %{boldStart}%{version}%{boldEnd} of %{boldStart}%{name}%{boldEnd}. Are you sure?`,
),
{
version: escape(this.packageEntity.version),
name: escape(this.packageEntity.name),
boldStart: '<b>',
boldEnd: '</b>',
},
false,
);
},
packageInformation() { packageInformation() {
return generatePackageInfo(this.packageEntity); return generatePackageInfo(this.packageEntity);
}, },
...@@ -181,6 +168,9 @@ export default { ...@@ -181,6 +168,9 @@ export default {
}, },
i18n: { i18n: {
deleteModalTitle: s__(`PackageRegistry|Delete Package Version`), deleteModalTitle: s__(`PackageRegistry|Delete Package Version`),
deleteModalContent: s__(
`PackageRegistry|You are about to delete version %{version} of %{name}. Are you sure?`,
),
}, },
filesTableHeaderFields: [ filesTableHeaderFields: [
{ {
...@@ -324,7 +314,15 @@ export default { ...@@ -324,7 +314,15 @@ export default {
<gl-modal ref="deleteModal" class="js-delete-modal" modal-id="delete-modal"> <gl-modal ref="deleteModal" class="js-delete-modal" modal-id="delete-modal">
<template #modal-title>{{ $options.i18n.deleteModalTitle }}</template> <template #modal-title>{{ $options.i18n.deleteModalTitle }}</template>
<p v-html="deleteModalDescription"></p> <gl-sprintf :message="$options.i18n.deleteModalContent">
<template #version>
<strong>{{ packageEntity.version }}</strong>
</template>
<template #name>
<strong>{{ packageEntity.name }}</strong>
</template>
</gl-sprintf>
<div slot="modal-footer" class="w-100"> <div slot="modal-footer" class="w-100">
<div class="float-right"> <div class="float-right">
......
<script> <script>
import { mapState, mapGetters } from 'vuex'; import { mapState, mapGetters } from 'vuex';
import { GlPagination, GlModal } from '@gitlab/ui'; import { GlPagination, GlModal, GlSprintf } from '@gitlab/ui';
import Tracking from '~/tracking'; import Tracking from '~/tracking';
import { s__, sprintf } from '~/locale'; import { s__ } from '~/locale';
import { TrackingActions } from '../../shared/constants'; import { TrackingActions } from '../../shared/constants';
import { packageTypeToTrackCategory } from '../../shared/utils'; import { packageTypeToTrackCategory } from '../../shared/utils';
import PackagesListLoader from '../../shared/components/packages_list_loader.vue'; import PackagesListLoader from '../../shared/components/packages_list_loader.vue';
...@@ -12,6 +12,7 @@ export default { ...@@ -12,6 +12,7 @@ export default {
components: { components: {
GlPagination, GlPagination,
GlModal, GlModal,
GlSprintf,
PackagesListLoader, PackagesListLoader,
PackagesListRow, PackagesListRow,
}, },
...@@ -44,17 +45,8 @@ export default { ...@@ -44,17 +45,8 @@ export default {
modalAction() { modalAction() {
return s__('PackageRegistry|Delete package'); return s__('PackageRegistry|Delete package');
}, },
deletePackageDescription() { deletePackageName() {
if (!this.itemToBeDeleted) { return this.itemToBeDeleted?.name ?? '';
return '';
}
return sprintf(
s__(
'PackageRegistry|You are about to delete <b>%{packageName}</b>, this operation is irreversible, are you sure?',
),
{ packageName: `${this.itemToBeDeleted.name}:${this.itemToBeDeleted.version}` },
false,
);
}, },
tracking() { tracking() {
const category = this.itemToBeDeleted const category = this.itemToBeDeleted
...@@ -81,6 +73,11 @@ export default { ...@@ -81,6 +73,11 @@ export default {
this.itemToBeDeleted = null; this.itemToBeDeleted = null;
}, },
}, },
i18n: {
deleteModalContent: s__(
'PackageRegistry|You are about to delete %{name}, this operation is irreversible, are you sure?',
),
},
}; };
</script> </script>
...@@ -121,7 +118,11 @@ export default { ...@@ -121,7 +118,11 @@ export default {
> >
<template #modal-title>{{ modalAction }}</template> <template #modal-title>{{ modalAction }}</template>
<template #modal-ok>{{ modalAction }}</template> <template #modal-ok>{{ modalAction }}</template>
<p v-html="deletePackageDescription"></p> <gl-sprintf :message="$options.i18n.deleteModalContent">
<template #name>
<strong>{{ deletePackageName }}</strong>
</template>
</gl-sprintf>
</gl-modal> </gl-modal>
</template> </template>
</div> </div>
......
<script> <script>
import { mapActions, mapState } from 'vuex'; import { mapActions, mapState } from 'vuex';
import { GlEmptyState, GlTab, GlTabs } from '@gitlab/ui'; import { GlEmptyState, GlTab, GlTabs, GlLink, GlSprintf } from '@gitlab/ui';
import { s__, sprintf } from '~/locale'; import { s__, sprintf } from '~/locale';
import PackageFilter from './packages_filter.vue'; import PackageFilter from './packages_filter.vue';
import PackageList from './packages_list.vue'; import PackageList from './packages_list.vue';
...@@ -13,6 +13,8 @@ export default { ...@@ -13,6 +13,8 @@ export default {
GlEmptyState, GlEmptyState,
GlTab, GlTab,
GlTabs, GlTabs,
GlLink,
GlSprintf,
PackageFilter, PackageFilter,
PackageList, PackageList,
PackageSort, PackageSort,
...@@ -25,22 +27,6 @@ export default { ...@@ -25,22 +27,6 @@ export default {
comingSoon: state => state.config.comingSoon, comingSoon: state => state.config.comingSoon,
filterQuery: state => state.filterQuery, filterQuery: state => state.filterQuery,
}), }),
emptyListText() {
if (this.filterQuery) {
return s__('PackageRegistry|To widen your search, change or remove the filters above.');
}
return sprintf(
s__(
'PackageRegistry|Learn how to %{noPackagesLinkStart}publish and share your packages%{noPackagesLinkEnd} with GitLab.',
),
{
noPackagesLinkStart: `<a href="${this.emptyListHelpUrl}" target="_blank">`,
noPackagesLinkEnd: '</a>',
},
false,
);
},
tabsToRender() { tabsToRender() {
return PACKAGE_REGISTRY_TABS; return PACKAGE_REGISTRY_TABS;
}, },
...@@ -78,6 +64,12 @@ export default { ...@@ -78,6 +64,12 @@ export default {
return s__('PackageRegistry|There are no packages yet'); return s__('PackageRegistry|There are no packages yet');
}, },
}, },
i18n: {
widenFilters: s__('PackageRegistry|To widen your search, change or remove the filters above.'),
noResults: s__(
'PackageRegistry|Learn how to %{noPackagesLinkStart}publish and share your packages%{noPackagesLinkEnd} with GitLab.',
),
},
}; };
</script> </script>
...@@ -95,7 +87,12 @@ export default { ...@@ -95,7 +87,12 @@ export default {
<template #empty-state> <template #empty-state>
<gl-empty-state :title="emptyStateTitle(tab)" :svg-path="emptyListIllustration"> <gl-empty-state :title="emptyStateTitle(tab)" :svg-path="emptyListIllustration">
<template #description> <template #description>
<p v-html="emptyListText"></p> <gl-sprintf v-if="filterQuery" :message="$options.i18n.widenFilters" />
<gl-sprintf v-else :message="$options.i18n.noResults">
<template #noPackagesLink="{content}">
<gl-link :href="emptyListHelpUrl" target="_blank">{{ content }}</gl-link>
</template>
</gl-sprintf>
</template> </template>
</gl-empty-state> </gl-empty-state>
</template> </template>
......
...@@ -49,16 +49,17 @@ exports[`packages_list_app renders 1`] = ` ...@@ -49,16 +49,17 @@ exports[`packages_list_app renders 1`] = `
</h1> </h1>
<p> <p>
<p> Learn how to
Learn how to <b-link-stub
<a class="gl-link"
href="helpUrl" event="click"
target="_blank" href="helpUrl"
> routertag="a"
publish and share your packages target="_blank"
</a> >
with GitLab. publish and share your packages
</p> </b-link-stub>
with GitLab.
</p> </p>
<div> <div>
...@@ -109,16 +110,17 @@ exports[`packages_list_app renders 1`] = ` ...@@ -109,16 +110,17 @@ exports[`packages_list_app renders 1`] = `
</h1> </h1>
<p> <p>
<p> Learn how to
Learn how to <b-link-stub
<a class="gl-link"
href="helpUrl" event="click"
target="_blank" href="helpUrl"
> routertag="a"
publish and share your packages target="_blank"
</a> >
with GitLab. publish and share your packages
</p> </b-link-stub>
with GitLab.
</p> </p>
<div> <div>
...@@ -169,16 +171,17 @@ exports[`packages_list_app renders 1`] = ` ...@@ -169,16 +171,17 @@ exports[`packages_list_app renders 1`] = `
</h1> </h1>
<p> <p>
<p> Learn how to
Learn how to <b-link-stub
<a class="gl-link"
href="helpUrl" event="click"
target="_blank" href="helpUrl"
> routertag="a"
publish and share your packages target="_blank"
</a> >
with GitLab. publish and share your packages
</p> </b-link-stub>
with GitLab.
</p> </p>
<div> <div>
...@@ -229,16 +232,17 @@ exports[`packages_list_app renders 1`] = ` ...@@ -229,16 +232,17 @@ exports[`packages_list_app renders 1`] = `
</h1> </h1>
<p> <p>
<p> Learn how to
Learn how to <b-link-stub
<a class="gl-link"
href="helpUrl" event="click"
target="_blank" href="helpUrl"
> routertag="a"
publish and share your packages target="_blank"
</a> >
with GitLab. publish and share your packages
</p> </b-link-stub>
with GitLab.
</p> </p>
<div> <div>
...@@ -289,16 +293,17 @@ exports[`packages_list_app renders 1`] = ` ...@@ -289,16 +293,17 @@ exports[`packages_list_app renders 1`] = `
</h1> </h1>
<p> <p>
<p> Learn how to
Learn how to <b-link-stub
<a class="gl-link"
href="helpUrl" event="click"
target="_blank" href="helpUrl"
> routertag="a"
publish and share your packages target="_blank"
</a> >
with GitLab. publish and share your packages
</p> </b-link-stub>
with GitLab.
</p> </p>
<div> <div>
...@@ -349,16 +354,17 @@ exports[`packages_list_app renders 1`] = ` ...@@ -349,16 +354,17 @@ exports[`packages_list_app renders 1`] = `
</h1> </h1>
<p> <p>
<p> Learn how to
Learn how to <b-link-stub
<a class="gl-link"
href="helpUrl" event="click"
target="_blank" href="helpUrl"
> routertag="a"
publish and share your packages target="_blank"
</a> >
with GitLab. publish and share your packages
</p> </b-link-stub>
with GitLab.
</p> </p>
<div> <div>
......
import Vuex from 'vuex'; import Vuex from 'vuex';
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import { GlEmptyState, GlTab, GlTabs } from '@gitlab/ui'; import { GlEmptyState, GlTab, GlTabs, GlSprintf, GlLink } from '@gitlab/ui';
import PackageListApp from 'ee/packages/list/components/packages_list_app.vue'; import PackageListApp from 'ee/packages/list/components/packages_list_app.vue';
const localVue = createLocalVue(); const localVue = createLocalVue();
...@@ -46,6 +46,8 @@ describe('packages_list_app', () => { ...@@ -46,6 +46,8 @@ describe('packages_list_app', () => {
PackageList, PackageList,
GlTab, GlTab,
GlTabs, GlTabs,
GlSprintf,
GlLink,
}, },
}); });
}; };
...@@ -66,16 +68,10 @@ describe('packages_list_app', () => { ...@@ -66,16 +68,10 @@ describe('packages_list_app', () => {
describe('empty state', () => { describe('empty state', () => {
it('generate the correct empty list link', () => { it('generate the correct empty list link', () => {
const link = findListComponent().find('a'); const link = findListComponent().find(GlLink);
expect(link.element).toMatchInlineSnapshot(` expect(link.attributes('href')).toBe(emptyListHelpUrl);
<a expect(link.text()).toBe('publish and share your packages');
href="${emptyListHelpUrl}"
target="_blank"
>
publish and share your packages
</a>
`);
}); });
it('includes the right content on the default tab', () => { it('includes the right content on the default tab', () => {
......
...@@ -123,15 +123,6 @@ describe('packages_list', () => { ...@@ -123,15 +123,6 @@ describe('packages_list', () => {
mountComponent(); mountComponent();
}); });
it('shows the correct deletePackageDescription', () => {
expect(wrapper.vm.deletePackageDescription).toEqual('');
wrapper.setData({ itemToBeDeleted: { name: 'foo', version: '1.0.10-beta' } });
expect(wrapper.vm.deletePackageDescription).toMatchInlineSnapshot(
`"You are about to delete <b>foo:1.0.10-beta</b>, this operation is irreversible, are you sure?"`,
);
});
it('setItemToBeDeleted sets itemToBeDeleted and open the modal', () => { it('setItemToBeDeleted sets itemToBeDeleted and open the modal', () => {
const mockModalShow = jest.spyOn(wrapper.vm.$refs.packageListDeleteModal, 'show'); const mockModalShow = jest.spyOn(wrapper.vm.$refs.packageListDeleteModal, 'show');
const item = last(wrapper.vm.list); const item = last(wrapper.vm.list);
......
...@@ -15546,10 +15546,10 @@ msgstr "" ...@@ -15546,10 +15546,10 @@ msgstr ""
msgid "PackageRegistry|Upcoming package managers" msgid "PackageRegistry|Upcoming package managers"
msgstr "" msgstr ""
msgid "PackageRegistry|You are about to delete <b>%{packageName}</b>, this operation is irreversible, are you sure?" msgid "PackageRegistry|You are about to delete %{name}, this operation is irreversible, are you sure?"
msgstr "" msgstr ""
msgid "PackageRegistry|You are about to delete version %{boldStart}%{version}%{boldEnd} of %{boldStart}%{name}%{boldEnd}. Are you sure?" msgid "PackageRegistry|You are about to delete version %{version} of %{name}. Are you sure?"
msgstr "" msgstr ""
msgid "PackageRegistry|You may also need to setup authentication using an auth token. %{linkStart}See the documentation%{linkEnd} to find out more." msgid "PackageRegistry|You may also need to setup authentication using an auth token. %{linkStart}See the documentation%{linkEnd} to find out more."
......
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