fix(lite): fix .value is undefined (#6469)

This commit is contained in:
Mathieu 2022-11-07 10:18:12 +01:00 committed by GitHub
parent 5723598923
commit a4c5792f9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 21 deletions

View File

@ -10,16 +10,14 @@
<script lang="ts" setup> <script lang="ts" setup>
import { type ComputedRef, computed, inject } from "vue"; import { type ComputedRef, computed, inject } from "vue";
import UsageBar from "@/components/UsageBar.vue"; import UsageBar from "@/components/UsageBar.vue";
import type { Stat } from "@/composables/fetch-stats.composable";
import { getAvgCpuUsage } from "@/libs/utils"; import { getAvgCpuUsage } from "@/libs/utils";
import type { HostStats } from "@/libs/xapi-stats"; import type { HostStats } from "@/libs/xapi-stats";
const stats: ComputedRef< const stats = inject<ComputedRef<Stat<HostStats>[]>>(
{ "hostStats",
id: string; computed(() => [])
name: string; );
stats?: HostStats;
}[]
> = inject<any>("hostStats", []);
const data = computed<{ id: string; label: string; value: number }[]>(() => { const data = computed<{ id: string; label: string; value: number }[]>(() => {
const result: { id: string; label: string; value: number }[] = []; const result: { id: string; label: string; value: number }[] = [];
@ -41,6 +39,7 @@ const data = computed<{ id: string; label: string; value: number }[]>(() => {
value: avgCpuUsage, value: avgCpuUsage,
}); });
}); });
return result; return result;
}); });
</script> </script>

View File

@ -6,19 +6,18 @@
</template> </template>
</UsageBar> </UsageBar>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { type ComputedRef, computed, inject } from "vue"; import { type ComputedRef, computed, inject } from "vue";
import UsageBar from "@/components/UsageBar.vue"; import UsageBar from "@/components/UsageBar.vue";
import type { Stat } from "@/composables/fetch-stats.composable";
import { getAvgCpuUsage } from "@/libs/utils"; import { getAvgCpuUsage } from "@/libs/utils";
import type { VmStats } from "@/libs/xapi-stats"; import type { VmStats } from "@/libs/xapi-stats";
const stats: ComputedRef< const stats = inject<ComputedRef<Stat<VmStats>[]>>(
{ "vmStats",
id: string; computed(() => [])
name: string; );
stats?: VmStats;
}[]
> = inject<any>("vmStats", []);
const data = computed<{ id: string; label: string; value: number }[]>(() => { const data = computed<{ id: string; label: string; value: number }[]>(() => {
const result: { id: string; label: string; value: number }[] = []; const result: { id: string; label: string; value: number }[] = [];

View File

@ -10,13 +10,18 @@ const STORES_BY_OBJECT_TYPE = {
vm: useVmStore, vm: useVmStore,
}; };
export type Stat<T> = {
id: string;
name: string;
stats?: T;
pausable: Pausable;
};
export default function useFetchStats<T extends XenApiHost | XenApiVm, S>( export default function useFetchStats<T extends XenApiHost | XenApiVm, S>(
type: "host" | "vm", type: "host" | "vm",
granularity: GRANULARITY granularity: GRANULARITY
) { ) {
const stats = ref< const stats = ref<Map<string, Stat<S>>>(new Map());
Map<string, { id: string; name: string; stats?: S; pausable: Pausable }>
>(new Map());
const register = (object: T) => { const register = (object: T) => {
if (stats.value.has(object.uuid)) { if (stats.value.has(object.uuid)) {
@ -63,6 +68,6 @@ export default function useFetchStats<T extends XenApiHost | XenApiVm, S>(
return { return {
register, register,
unregister, unregister,
stats: computed(() => Array.from(stats.value.values())), stats: computed<Stat<S>[]>(() => Array.from(stats.value.values())),
}; };
} }

View File

@ -8,7 +8,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { differenceBy } from "lodash-es"; import { differenceBy } from "lodash-es";
import { computed, onMounted, provide, readonly, watch } from "vue"; import { computed, onMounted, provide, watch } from "vue";
import PoolDashboardCpuUsage from "@/components/pool/dashboard/PoolDashboardCpuUsage.vue"; import PoolDashboardCpuUsage from "@/components/pool/dashboard/PoolDashboardCpuUsage.vue";
import PoolDashboardStatus from "@/components/pool/dashboard/PoolDashboardStatus.vue"; import PoolDashboardStatus from "@/components/pool/dashboard/PoolDashboardStatus.vue";
import PoolDashboardStorageUsage from "@/components/pool/dashboard/PoolDashboardStorageUsage.vue"; import PoolDashboardStorageUsage from "@/components/pool/dashboard/PoolDashboardStorageUsage.vue";
@ -38,8 +38,8 @@ const runningVms = computed(() =>
vmStore.allRecords.filter((vm) => vm.power_state === "Running") vmStore.allRecords.filter((vm) => vm.power_state === "Running")
); );
provide("hostStats", readonly(hostStats)); provide("hostStats", hostStats);
provide("vmStats", readonly(vmStats)); provide("vmStats", vmStats);
watch(runningHosts, (hosts, previousHosts) => { watch(runningHosts, (hosts, previousHosts) => {
// turned On // turned On