Commit 83af047b authored by Kev's avatar Kev Committed by Olena Horal-Koretska

Replace v-html with GlSprintf in memory_usage.vue

parent 1ec95ad8
<script> <script>
/* eslint-disable vue/no-v-html */ import { GlLoadingIcon, GlSprintf, GlLink } from '@gitlab/ui';
import { GlLoadingIcon } from '@gitlab/ui'; import { s__ } from '~/locale';
import { sprintf, s__ } from '~/locale';
import statusCodes from '~/lib/utils/http_status'; import statusCodes from '~/lib/utils/http_status';
import { bytesToMiB } from '~/lib/utils/number_utils'; import { bytesToMiB } from '~/lib/utils/number_utils';
import { backOff } from '~/lib/utils/common_utils'; import { backOff } from '~/lib/utils/common_utils';
...@@ -13,6 +12,8 @@ export default { ...@@ -13,6 +12,8 @@ export default {
components: { components: {
MemoryGraph, MemoryGraph,
GlLoadingIcon, GlLoadingIcon,
GlSprintf,
GlLink,
}, },
props: { props: {
metricsUrl: { metricsUrl: {
...@@ -50,45 +51,22 @@ export default { ...@@ -50,45 +51,22 @@ export default {
return !this.loadingMetrics && !this.hasMetrics && !this.loadFailed; return !this.loadingMetrics && !this.hasMetrics && !this.loadFailed;
}, },
memoryChangeMessage() { memoryChangeMessage() {
const messageProps = {
memoryFrom: this.memoryFrom,
memoryTo: this.memoryTo,
metricsLinkStart: `<a href="${this.metricsMonitoringUrl}">`,
metricsLinkEnd: '</a>',
emphasisStart: '<b>',
emphasisEnd: '</b>',
};
const memoryTo = Number(this.memoryTo); const memoryTo = Number(this.memoryTo);
const memoryFrom = Number(this.memoryFrom); const memoryFrom = Number(this.memoryFrom);
let memoryUsageMsg = '';
if (memoryTo > memoryFrom) { if (memoryTo > memoryFrom) {
memoryUsageMsg = sprintf( return s__(
s__( 'mrWidget|%{metricsLinkStart} Memory %{metricsLinkEnd} usage %{emphasisStart} increased %{emphasisEnd} from %{memoryFrom}MB to %{memoryTo}MB',
'mrWidget|%{metricsLinkStart} Memory %{metricsLinkEnd} usage %{emphasisStart} increased %{emphasisEnd} from %{memoryFrom}MB to %{memoryTo}MB',
),
messageProps,
false,
); );
} else if (memoryTo < memoryFrom) { } else if (memoryTo < memoryFrom) {
memoryUsageMsg = sprintf( return s__(
s__( 'mrWidget|%{metricsLinkStart} Memory %{metricsLinkEnd} usage %{emphasisStart} decreased %{emphasisEnd} from %{memoryFrom}MB to %{memoryTo}MB',
'mrWidget|%{metricsLinkStart} Memory %{metricsLinkEnd} usage %{emphasisStart} decreased %{emphasisEnd} from %{memoryFrom}MB to %{memoryTo}MB',
),
messageProps,
false,
);
} else {
memoryUsageMsg = sprintf(
s__(
'mrWidget|%{metricsLinkStart} Memory %{metricsLinkEnd} usage is %{emphasisStart} unchanged %{emphasisEnd} at %{memoryFrom}MB',
),
messageProps,
false,
); );
} }
return memoryUsageMsg; return s__(
'mrWidget|%{metricsLinkStart} Memory %{metricsLinkEnd} usage is %{emphasisStart} unchanged %{emphasisEnd} at %{memoryFrom}MB',
);
}, },
}, },
mounted() { mounted() {
...@@ -162,11 +140,19 @@ export default { ...@@ -162,11 +140,19 @@ export default {
s__('mrWidget|Loading deployment statistics') s__('mrWidget|Loading deployment statistics')
}} }}
</p> </p>
<p <p v-if="shouldShowMemoryGraph" class="usage-info js-usage-info">
v-if="shouldShowMemoryGraph" <gl-sprintf :message="memoryChangeMessage">
class="usage-info js-usage-info" <template #metricsLink="{ content }">
v-html="memoryChangeMessage" <gl-link :href="metricsMonitoringUrl">{{ content }}</gl-link>
></p> </template>
<template #emphasis="{content}">
<strong>{{ content }}</strong>
</template>
<template #memoryFrom>{{ memoryFrom }}</template>
<template #memoryTo>{{ memoryTo }}</template>
</gl-sprintf>
</p>
<p v-if="shouldShowLoadFailure" class="usage-info js-usage-info usage-info-failed"> <p v-if="shouldShowLoadFailure" class="usage-info js-usage-info usage-info-failed">
{{ s__('mrWidget|Failed to load deployment statistics') }} {{ s__('mrWidget|Failed to load deployment statistics') }}
</p> </p>
......
---
title: Replace v-html with GlSprintf in memory_usage.vue
merge_request: 41204
author: Kev @KevSlashNull
type: other
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