Skip to content

Commit

Permalink
refactor(front): compute colors in JobStatusBadge
Browse files Browse the repository at this point in the history
Use computed ref instead of function in order to execute it only once
when props value is loaded.
  • Loading branch information
rezib committed Nov 21, 2024
1 parent 69e9544 commit 3a78a61
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions frontend/src/components/job/JobStatusBadge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
-->

<script setup lang="ts">
import { computed } from 'vue'

const props = defineProps({
status: String,
large: {
Expand All @@ -23,8 +25,8 @@ interface JobLabelColors {
circle: string
}

function getStatusColor(status: string): JobLabelColors {
switch (status) {
const statusColor = computed<JobLabelColors>(() => {
switch (props.status) {
case 'RUNNING':
return {
span: 'bg-green-100 text-green-700',
Expand All @@ -46,22 +48,18 @@ function getStatusColor(status: string): JobLabelColors {
circle: 'fill-gray-400'
}
}
}
})
</script>

<template>
<span
:class="[
props.large ? 'max-h-10 text-sm' : 'max-h-6 text-xs',
'inline-flex items-center gap-x-1.5 rounded-md px-2 py-1 font-medium',
getStatusColor(props.status as string).span
statusColor.span
]"
>
<svg
:class="['h-1.5 w-1.5', getStatusColor(props.status as string).circle]"
viewBox="0 0 6 6"
aria-hidden="true"
>
<svg :class="['h-1.5 w-1.5', statusColor.circle]" viewBox="0 0 6 6" aria-hidden="true">
<circle cx="3" cy="3" r="3" />
</svg>
<template v-if="label">
Expand Down

0 comments on commit 3a78a61

Please sign in to comment.