Commit 04c7be88 authored by Stanislav Lashmanov's avatar Stanislav Lashmanov Committed by Natalia Tepluhina

Replace v-html with gl-sprintf in commits_header.vue

parent 7e2be326
<script> <script>
/* eslint-disable @gitlab/require-string-literal-i18n-helpers */ /* eslint-disable @gitlab/require-string-literal-i18n-helpers */
import { GlButton } from '@gitlab/ui'; import { GlButton, GlSprintf } from '@gitlab/ui';
import { escape } from 'lodash'; import { escape } from 'lodash';
import { __, n__, sprintf, s__ } from '~/locale'; import { __, n__, s__ } from '~/locale';
const mergeCommitCount = s__('mrWidgetCommitsAdded|1 merge commit');
export default { export default {
mergeCommitCount,
components: { components: {
GlButton, GlButton,
GlSprintf,
}, },
props: { props: {
isSquashEnabled: { isSquashEnabled: {
...@@ -47,22 +51,15 @@ export default { ...@@ -47,22 +51,15 @@ export default {
ariaLabel() { ariaLabel() {
return this.expanded ? __('Collapse') : __('Expand'); return this.expanded ? __('Collapse') : __('Expand');
}, },
targetBranchEscaped() {
return escape(this.targetBranch);
},
message() { message() {
const message = this.isFastForwardEnabled return this.isFastForwardEnabled
? s__('mrWidgetCommitsAdded|%{commitCount} will be added to %{targetBranch}.') ? s__('mrWidgetCommitsAdded|%{commitCount} will be added to %{targetBranch}.')
: s__( : s__(
'mrWidgetCommitsAdded|%{commitCount} and %{mergeCommitCount} will be added to %{targetBranch}.', 'mrWidgetCommitsAdded|%{commitCount} and %{mergeCommitCount} will be added to %{targetBranch}.',
); );
return sprintf(
message,
{
commitCount: `<strong class="commits-count-message">${this.commitsCountMessage}</strong>`,
mergeCommitCount: `<strong>${s__('mrWidgetCommitsAdded|1 merge commit')}</strong>`,
targetBranch: `<span class="label-branch">${escape(this.targetBranch)}</span>`,
},
false,
);
}, },
}, },
methods: { methods: {
...@@ -89,10 +86,19 @@ export default { ...@@ -89,10 +86,19 @@ export default {
/> />
<span v-if="expanded">{{ __('Collapse') }}</span> <span v-if="expanded">{{ __('Collapse') }}</span>
<span v-else> <span v-else>
<span <span class="vertical-align-middle">
class="vertical-align-middle" <gl-sprintf :message="message">
v-html="message /* eslint-disable-line vue/no-v-html */" <template #commitCount>
></span> <strong class="commits-count-message">{{ commitsCountMessage }}</strong>
</template>
<template #mergeCommitCount>
<strong>{{ $options.mergeCommitCount }}</strong>
</template>
<template #targetBranch>
<span class="label-branch">{{ targetBranchEscaped }}</span>
</template>
</gl-sprintf>
</span>
<gl-button variant="link" class="modify-message-button"> <gl-button variant="link" class="modify-message-button">
{{ modifyLinkMessage }} {{ modifyLinkMessage }}
</gl-button> </gl-button>
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlSprintf } from '@gitlab/ui';
import CommitsHeader from '~/vue_merge_request_widget/components/states/commits_header.vue'; import CommitsHeader from '~/vue_merge_request_widget/components/states/commits_header.vue';
describe('Commits header component', () => { describe('Commits header component', () => {
...@@ -6,6 +7,9 @@ describe('Commits header component', () => { ...@@ -6,6 +7,9 @@ describe('Commits header component', () => {
const createComponent = (props) => { const createComponent = (props) => {
wrapper = shallowMount(CommitsHeader, { wrapper = shallowMount(CommitsHeader, {
stubs: {
GlSprintf,
},
propsData: { propsData: {
isSquashEnabled: false, isSquashEnabled: false,
targetBranch: 'main', targetBranch: 'main',
......
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