-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
194 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 26 additions & 17 deletions
43
@xen-orchestra/lite/src/components/vm/VmActionItems/VmActionDeleteItem.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,47 @@ | ||
<template> | ||
<MenuItem | ||
v-tooltip="areSomeVmsInExecution && $t('selected-vms-in-execution')" | ||
:disabled="isDisabled" | ||
:icon="faTrashCan" | ||
@click="openDeleteModal" | ||
> | ||
<VtsMenuItem :icon="faTrashCan" v-bind="menuItem"> | ||
{{ $t('delete') }} | ||
</MenuItem> | ||
</VtsMenuItem> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { useModal } from '@/composables/modal.composable' | ||
import { VM_POWER_STATE } from '@/libs/xen-api/xen-api.enums' | ||
import type { XenApiVm } from '@/libs/xen-api/xen-api.types' | ||
import { useVmStore } from '@/stores/xen-api/vm.store' | ||
import MenuItem from '@core/components/menu/MenuItem.vue' | ||
import { vTooltip } from '@core/directives/tooltip.directive' | ||
import VtsMenuItem from '@core/components/menu/VtsMenuItem.vue' | ||
import { type MenuLike, useMenuAction } from '@core/packages/menu' | ||
import { faTrashCan } from '@fortawesome/free-solid-svg-icons' | ||
import { computed } from 'vue' | ||
import { useI18n } from 'vue-i18n' | ||
const props = defineProps<{ | ||
menu: MenuLike | ||
vmRefs: XenApiVm['$ref'][] | ||
}>() | ||
const { getByOpaqueRef: getVm } = useVmStore().subscribe() | ||
const { t } = useI18n() | ||
const vms = computed<XenApiVm[]>(() => props.vmRefs.map(getVm).filter((vm): vm is XenApiVm => vm !== undefined)) | ||
const { getByOpaqueRefs: getVms } = useVmStore().subscribe() | ||
const areSomeVmsInExecution = computed(() => vms.value.some(vm => vm.power_state !== VM_POWER_STATE.HALTED)) | ||
const vms = computed(() => getVms(props.vmRefs)) | ||
const isDisabled = computed(() => vms.value.length === 0 || areSomeVmsInExecution.value) | ||
const menuItem = useMenuAction({ | ||
parent: props.menu, | ||
handler: () => | ||
useModal(() => import('@/components/modals/VmDeleteModal.vue'), { | ||
vmRefs: props.vmRefs, | ||
}), | ||
disabled: computed(() => { | ||
if (vms.value.length === 0) { | ||
return true | ||
} | ||
const openDeleteModal = () => | ||
useModal(() => import('@/components/modals/VmDeleteModal.vue'), { | ||
vmRefs: props.vmRefs, | ||
}) | ||
if (vms.value.some(vm => vm.power_state !== VM_POWER_STATE.HALTED)) { | ||
return t('selected-vms-in-execution') | ||
} | ||
return false | ||
}), | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.