Commit 265da8d3 authored by Filipa Lacerda's avatar Filipa Lacerda

Handles link to open tab without reloading the page

parent 6f2668e4
<script> <script>
import { sprintf, s__ } from '~/locale'; import { n__, s__ } from '~/locale';
import ciIcon from '~/vue_shared/components/ci_icon.vue'; import ciIcon from '~/vue_shared/components/ci_icon.vue';
export default { export default {
...@@ -19,25 +19,21 @@ ...@@ -19,25 +19,21 @@
}, },
}, },
computed: { computed: {
summarySastText() { sastText() {
let text;
let link;
if (this.unresolvedIssues.length) { if (this.unresolvedIssues.length) {
text = s__('ciReport|SAST degraded on %{link}'); return s__('ciReport|SAST degraded on');
link = this.unresolvedIssues.length > 1 ?
this.getLink(sprintf(
s__('ciReport|%{d} security vulnerabilities'),
{ d: this.unresolvedIssues.length },
true,
)) :
this.getLink(s__('ciReport|1 security vulnerability'));
} else {
text = s__('ciReport|SAST detected %{link}');
link = this.getLink(s__('ciReport|no security vulnerabilities'));
} }
return s__('ciReport|SAST detected');
return sprintf(text, { link }, false); },
sastLink() {
if (this.unresolvedIssues.length) {
return n__(
'%d security vulnerability',
'%d security vulnerabilities',
this.unresolvedIssues.length,
);
}
return s__('ciReport|no security vulnerabilities');
}, },
statusIcon() { statusIcon() {
if (this.unresolvedIssues) { if (this.unresolvedIssues) {
...@@ -53,8 +49,11 @@ ...@@ -53,8 +49,11 @@
}, },
}, },
methods: { methods: {
getLink(text) { openTab() {
return `<a href="${this.link}" class="prepend-left-5">${text}</a>`; // This opens a tab outside of this Vue application
// It opens the securty report tab in the pipelines page and updates the URL
// This is needed because the tabs are built in haml+jquery
$('.pipelines-tabs a[data-action="security"]').tab('show');
}, },
}, },
}; };
...@@ -68,8 +67,15 @@ ...@@ -68,8 +67,15 @@
<span <span
class="prepend-left-10 flex flex-align-self-center" class="prepend-left-10 flex flex-align-self-center"
v-html="summarySastText"
> >
{{ sastText }}
<a
:href="link"
class="prepend-left-5"
@click="openTab"
>
{{ sastLink }}
</a>
</span> </span>
</div> </div>
</template> </template>
...@@ -24,7 +24,7 @@ describe('SAST report summary widget', () => { ...@@ -24,7 +24,7 @@ describe('SAST report summary widget', () => {
}); });
it('renders summary text with link for the security tab', () => { it('renders summary text with link for the security tab', () => {
expect(vm.$el.textContent.trim()).toEqual('SAST degraded on 2 security vulnerabilities'); expect(vm.$el.textContent.trim().replace(/\s\s+/g, ' ')).toEqual('SAST degraded on 2 security vulnerabilities');
expect(vm.$el.querySelector('a').getAttribute('href')).toEqual('group/project/pipelines/2/security'); expect(vm.$el.querySelector('a').getAttribute('href')).toEqual('group/project/pipelines/2/security');
}); });
}); });
...@@ -37,7 +37,7 @@ describe('SAST report summary widget', () => { ...@@ -37,7 +37,7 @@ describe('SAST report summary widget', () => {
}); });
it('render summary text with link for the security tab', () => { it('render summary text with link for the security tab', () => {
expect(vm.$el.textContent.trim()).toEqual('SAST detected no security vulnerabilities'); expect(vm.$el.textContent.trim().replace(/\s\s+/g, ' ')).toEqual('SAST detected no security vulnerabilities');
expect(vm.$el.querySelector('a').getAttribute('href')).toEqual('group/project/pipelines/2/security'); expect(vm.$el.querySelector('a').getAttribute('href')).toEqual('group/project/pipelines/2/security');
}); });
}); });
......
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