mirror of
https://github.com/OpenNebula/one.git
synced 2025-04-01 06:50:25 +03:00
parent
87480c1790
commit
a8ab46c37f
@ -125,7 +125,7 @@ const PreConsoleButton = memo(
|
||||
|
||||
const isDisabled = useMemo(() => {
|
||||
const noAction = vmView?.actions?.[connectionType] !== true
|
||||
const noAvailable = !isAvailableAction(connectionType)(vm)
|
||||
const noAvailable = !isAvailableAction(connectionType, vm)
|
||||
const notHypervisor = !getHypervisor(vm)
|
||||
|
||||
return noAction || noAvailable || notHypervisor
|
||||
|
@ -66,7 +66,10 @@ const useTableStyles = makeStyles({
|
||||
})
|
||||
|
||||
const isDisabled = (action) => (rows) =>
|
||||
!isAvailableAction(action)(rows, ({ values }) => values?.state)
|
||||
!isAvailableAction(
|
||||
action,
|
||||
rows.map(({ original }) => original)
|
||||
)
|
||||
|
||||
const ListVmNames = ({ rows = [] }) => {
|
||||
const { data: datastores = [] } = useGetDatastoresQuery()
|
||||
|
@ -39,7 +39,7 @@ const VmCapacityTab = ({ tabProps: { actions } = {}, id }) => {
|
||||
const hypervisor = getHypervisor(vm)
|
||||
const actionsByHypervisor = getActionsAvailable(actions, hypervisor)
|
||||
const actionsByState = actionsByHypervisor.filter((action) =>
|
||||
isAvailableAction(action)(vm)
|
||||
isAvailableAction(action, vm)
|
||||
)
|
||||
|
||||
return actionsByState
|
||||
|
@ -42,7 +42,7 @@ const VmHistoryTab = ({ tabProps: { actions } = {}, id }) => {
|
||||
const hypervisor = getHypervisor(vm)
|
||||
const actionsByHypervisor = getActionsAvailable(actions, hypervisor)
|
||||
const actionsByState = actionsByHypervisor.filter((action) =>
|
||||
isAvailableAction(action)(vm)
|
||||
isAvailableAction(action, vm)
|
||||
)
|
||||
|
||||
return [getHistoryRecords(vm), actionsByState]
|
||||
|
@ -57,7 +57,7 @@ const VmNetworkTab = ({ tabProps: { actions } = {}, id }) => {
|
||||
const hyperV = getHypervisor(vm)
|
||||
const actionsByHypervisor = getActionsAvailable(actions, hyperV)
|
||||
const actionsByState = actionsByHypervisor.filter((action) =>
|
||||
isAvailableAction(action)(vm)
|
||||
isAvailableAction(action, vm)
|
||||
)
|
||||
|
||||
return [groupedNics, hyperV, actionsByState]
|
||||
|
@ -65,7 +65,7 @@ const VmSchedulingTab = ({ tabProps: { actions } = {}, id }) => {
|
||||
const hypervisor = getHypervisor(vm)
|
||||
const actionsByHypervisor = getActionsAvailable(actions, hypervisor)
|
||||
const actionsByState = actionsByHypervisor.filter((action) =>
|
||||
isAvailableAction(action)(vm)
|
||||
isAvailableAction(action, vm)
|
||||
)
|
||||
|
||||
return [getScheduleActions(vm), actionsByState]
|
||||
|
@ -51,7 +51,7 @@ const VmSnapshotTab = ({ tabProps: { actions } = {}, id }) => {
|
||||
const hypervisor = getHypervisor(vm)
|
||||
const actionsByHypervisor = getActionsAvailable(actions, hypervisor)
|
||||
const actionsByState = actionsByHypervisor.filter((action) =>
|
||||
isAvailableAction(action)(vm)
|
||||
isAvailableAction(action, vm)
|
||||
)
|
||||
|
||||
return [getSnapshotList(vm), actionsByState]
|
||||
|
@ -66,7 +66,7 @@ const VmStorageTab = ({ tabProps: { actions } = {}, id }) => {
|
||||
const hyperV = getHypervisor(vm)
|
||||
const actionsByHypervisor = getActionsAvailable(actions, hyperV)
|
||||
const actionsByState = actionsByHypervisor.filter((action) =>
|
||||
isAvailableAction(action)(vm)
|
||||
isAvailableAction(action, vm)
|
||||
)
|
||||
|
||||
return [getDisks(vm), hyperV, actionsByState]
|
||||
|
@ -317,21 +317,29 @@ export const getScheduleActions = (vm) => {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if action is available by VM state.
|
||||
* Check if action is available for **all VMs**.
|
||||
*
|
||||
* @param {object} action - VM action
|
||||
* @returns {function(Array, Function):boolean}
|
||||
* - The list of vms that will be perform the action
|
||||
* @param {VM|VM[]} vms - Virtual machines
|
||||
* @returns {boolean} If `true`, the action is available for all VMs
|
||||
*/
|
||||
export const isAvailableAction =
|
||||
(action) =>
|
||||
(vms = [], getVmState = (vm) => getState(vm)?.name) => {
|
||||
if (VM_ACTIONS_BY_STATE[action]?.length === 0) return true
|
||||
export const isAvailableAction = (action, vms = []) => {
|
||||
if (VM_ACTIONS_BY_STATE[action]?.length === 0) return true
|
||||
|
||||
const states = [vms].flat().map(getVmState)
|
||||
return [vms].flat().every((vm) => {
|
||||
const state = VM_STATES[vm.STATE]?.name
|
||||
const lcmState = VM_LCM_STATES[vm.LCM_STATE]?.name
|
||||
|
||||
return states?.some((state) => VM_ACTIONS_BY_STATE[action]?.includes(state))
|
||||
}
|
||||
return (
|
||||
(state === STATES.ACTIVE &&
|
||||
// if action includes ACTIVE state,
|
||||
// it means that the action is available in all LCM states
|
||||
(VM_ACTIONS_BY_STATE[action]?.includes(STATES.ACTIVE) ||
|
||||
VM_ACTIONS_BY_STATE[action]?.includes(lcmState))) ||
|
||||
VM_ACTIONS_BY_STATE[action]?.includes(state)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {VM} vm - Virtual machine
|
||||
|
Loading…
x
Reference in New Issue
Block a user