Skip to content

Commit

Permalink
update to match parent PR
Browse files Browse the repository at this point in the history
  • Loading branch information
P4l0m4 authored and ByScripts committed Jul 26, 2024
1 parent 37c8712 commit 71924c5
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 79 deletions.
76 changes: 76 additions & 0 deletions @xen-orchestra/web-core/lib/components/DonutWithLegends.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<template>
<div class="donut-with-legends">
<DonutChart :segments="donutSegments" :icon :max-value="maxValue" />
<div class="legends-and-title">
<slot />
<ul class="legends">
<UiLegend
v-for="(legendSegment, index) in legendSegments"
:key="index"
:color="legendSegment.color"
:value="legendSegment.value"
:unit="legendSegment.unit"
:tooltip="legendSegment.tooltip"
>
{{ legendSegment.label }}
</UiLegend>
</ul>
</div>
</div>
</template>

<script setup lang="ts">
import DonutChart from '@core/components/DonutChart.vue'
import UiLegend from '@core/components/UiLegend.vue'
import type { DonutSegmentColor } from '@core/types/donut-chart.type'
import type { LegendColor } from '@core/types/legend.type'
import type { IconDefinition } from '@fortawesome/fontawesome-common-types'
import { computed } from 'vue'
const props = defineProps<{
segments: {
label: string
value: number
unit?: string
color: DonutSegmentColor
tooltip?: string
}[]
icon?: IconDefinition
maxValue?: number
}>()
defineSlots<{
default: () => void
}>()
const donutSegments = computed(() =>
props.segments.map(segment => ({
value: segment.value,
color: segment.color,
}))
)
const legendSegments = computed(() =>
props.segments.map(segment => ({
label: segment.label,
value: segment.value,
unit: segment.unit,
color: segment.color === 'unknown' ? 'disabled' : (segment.color as LegendColor),
tooltip: segment.tooltip,
}))
)
</script>

<style lang="postcss" scoped>
.donut-with-legends {
display: flex;
align-items: center;
gap: 3.2rem;
}
.legends-and-title {
display: flex;
flex-direction: column;
gap: 0.8rem;
}
.legends {
display: flex;
flex-direction: column;
gap: 0.8rem;
}
</style>
4 changes: 2 additions & 2 deletions @xen-orchestra/web-core/lib/types/donut-chart.type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type DonutColor = 'success' | 'warning' | 'error' | 'unknown'
export type DonutSegmentColor = 'success' | 'warning' | 'error' | 'unknown'
export type DonutSegment = {
value: number
color: DonutColor
color: DonutSegmentColor
}
72 changes: 0 additions & 72 deletions @xen-orchestra/web/src/components/DonutWithLegends.vue

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
</template>

<script lang="ts" setup>
import DonutWithLegends from '@/components/DonutWithLegends.vue'
import { useHostStore } from '@/stores/xo-rest-api/host.store'
import type { Host } from '@/types/host.type'
import type { LegendColor } from '@core/types/ui-legend.type'
import CardTitle from '@core/components/card/CardTitle.vue'
import CardNumbers from '@core/components/CardNumbers.vue'
import DonutWithLegends from '@core/components/DonutWithLegends.vue'
import UiCard from '@core/components/UiCard.vue'
import { faServer } from '@fortawesome/free-solid-svg-icons'
import { computed } from 'vue'
Expand All @@ -37,18 +36,18 @@ const segments = computed(() => [
{
label: t('hosts-running-status'),
value: runningHostsCount.value,
color: 'success' as LegendColor,
color: 'success',
},
{
label: t('hosts-halted-status'),
value: inactiveHostsCount.value,
color: 'dark-blue' as LegendColor,
color: 'warning',
tooltip: t('hosts-halted-status-tooltip'),
},
{
label: t('hosts-unknown-status'),
value: unknownHostsCount.value,
color: 'disabled' as LegendColor,
color: 'unknown',
tooltip: t('hosts-unknown-status-tooltip'),
},
])
Expand Down

0 comments on commit 71924c5

Please sign in to comment.