Skip to content

Commit

Permalink
B #5422: Fix issues with FireEdge Sunstone (#1979)
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederick Borges authored Apr 28, 2022
1 parent cd18e08 commit 0bfe41a
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/fireedge/src/client/components/Tables/Vms/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const useTableStyles = makeStyles({
})

const isDisabled = (action) => (rows) =>
isAvailableAction(action)(rows, ({ values }) => values?.state)
!isAvailableAction(action)(rows, ({ values }) => values?.state)

const ListVmNames = ({ rows = [] }) => {
const { data: datastores = [] } = useGetDatastoresQuery()
Expand Down
4 changes: 2 additions & 2 deletions src/fireedge/src/client/components/Tabs/Vm/Capacity/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const VmCapacityTab = ({ tabProps: { actions } = {}, id }) => {
const actionsAvailable = useMemo(() => {
const hypervisor = getHypervisor(vm)
const actionsByHypervisor = getActionsAvailable(actions, hypervisor)
const actionsByState = actionsByHypervisor.filter(
(action) => !isAvailableAction(action)(vm)
const actionsByState = actionsByHypervisor.filter((action) =>
isAvailableAction(action)(vm)
)

return actionsByState
Expand Down
4 changes: 2 additions & 2 deletions src/fireedge/src/client/components/Tabs/Vm/History/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ const VmHistoryTab = ({ tabProps: { actions } = {}, id }) => {
const [records, actionsAvailable] = useMemo(() => {
const hypervisor = getHypervisor(vm)
const actionsByHypervisor = getActionsAvailable(actions, hypervisor)
const actionsByState = actionsByHypervisor.filter(
(action) => !isAvailableAction(action)(vm)
const actionsByState = actionsByHypervisor.filter((action) =>
isAvailableAction(action)(vm)
)

return [getHistoryRecords(vm), actionsByState]
Expand Down
9 changes: 5 additions & 4 deletions src/fireedge/src/client/components/Tabs/Vm/Network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import {
import { getActionsAvailable } from 'client/models/Helper'
import { VM_ACTIONS } from 'client/constants'

const { ATTACH_NIC, DETACH_NIC, ATTACH_SEC_GROUP } = VM_ACTIONS
const { ATTACH_NIC, DETACH_NIC, ATTACH_SEC_GROUP, DETACH_SEC_GROUP } =
VM_ACTIONS

/**
* Renders the list of networks from a VM.
Expand All @@ -55,8 +56,8 @@ const VmNetworkTab = ({ tabProps: { actions } = {}, id }) => {
})
const hyperV = getHypervisor(vm)
const actionsByHypervisor = getActionsAvailable(actions, hyperV)
const actionsByState = actionsByHypervisor.filter(
(action) => !isAvailableAction(action)(vm)
const actionsByState = actionsByHypervisor.filter((action) =>
isAvailableAction(action)(vm)
)

return [groupedNics, hyperV, actionsByState]
Expand Down Expand Up @@ -93,7 +94,7 @@ const VmNetworkTab = ({ tabProps: { actions } = {}, id }) => {
)
}
securityGroupActions={({ securityGroupId }) =>
actionsAvailable.includes(DETACH_NIC) && (
actionsAvailable.includes(DETACH_SEC_GROUP) && (
<DetachSecGroupAction
nic={nic}
vmId={id}
Expand Down
4 changes: 2 additions & 2 deletions src/fireedge/src/client/components/Tabs/Vm/SchedActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ const VmSchedulingTab = ({ tabProps: { actions } = {}, id }) => {
const [scheduling, actionsAvailable] = useMemo(() => {
const hypervisor = getHypervisor(vm)
const actionsByHypervisor = getActionsAvailable(actions, hypervisor)
const actionsByState = actionsByHypervisor.filter(
(action) => !isAvailableAction(action)(vm)
const actionsByState = actionsByHypervisor.filter((action) =>
isAvailableAction(action)(vm)
)

return [getScheduleActions(vm), actionsByState]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const RevertAction = memo(({ vmId, snapshot }) => {
buttonProps={{
'data-cy': `${VM_ACTIONS.SNAPSHOT_REVERT}-${SNAPSHOT_ID}`,
icon: <UndoAction />,
tooltip: Tr(T.Revert),
}}
options={[
{
Expand Down Expand Up @@ -100,6 +101,7 @@ const DeleteAction = memo(({ vmId, snapshot }) => {
buttonProps={{
'data-cy': `${VM_ACTIONS.SNAPSHOT_DELETE}-${SNAPSHOT_ID}`,
icon: <Trash />,
tooltip: Tr(T.Delete),
}}
options={[
{
Expand Down
5 changes: 3 additions & 2 deletions src/fireedge/src/client/components/Tabs/Vm/Snapshot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ const VmSnapshotTab = ({ tabProps: { actions } = {}, id }) => {
const [snapshots, actionsAvailable] = useMemo(() => {
const hypervisor = getHypervisor(vm)
const actionsByHypervisor = getActionsAvailable(actions, hypervisor)
const actionsByState = actionsByHypervisor.filter(
(action) => !isAvailableAction(action)(vm)
const actionsByState = actionsByHypervisor.filter((action) =>
isAvailableAction(action)(vm)
)

return [getSnapshotList(vm), actionsByState]
Expand All @@ -66,6 +66,7 @@ const VmSnapshotTab = ({ tabProps: { actions } = {}, id }) => {
<Stack direction="column" gap="1em" py="0.8em">
{snapshots.map((snapshot) => (
<SnapshotCard
snapshot={snapshot}
key={snapshot.SNAPSHOT_ID}
extraActionProps={{ vmId: id }}
actions={[
Expand Down
4 changes: 2 additions & 2 deletions src/fireedge/src/client/components/Tabs/Vm/Storage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ const VmStorageTab = ({ tabProps: { actions } = {}, id }) => {
const [disks, hypervisor, actionsAvailable] = useMemo(() => {
const hyperV = getHypervisor(vm)
const actionsByHypervisor = getActionsAvailable(actions, hyperV)
const actionsByState = actionsByHypervisor.filter(
(action) => !isAvailableAction(action)(vm)
const actionsByState = actionsByHypervisor.filter((action) =>
isAvailableAction(action)(vm)
)

return [getDisks(vm), hyperV, actionsByState]
Expand Down
6 changes: 3 additions & 3 deletions src/fireedge/src/client/constants/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -926,9 +926,9 @@ export const VM_ACTIONS_BY_STATE = {
[VM_ACTIONS.DETACH_SEC_GROUP]: [STATES.POWEROFF, STATES.RUNNING],

// SNAPSHOT
[VM_ACTIONS.SNAPSHOT_CREATE]: [],
[VM_ACTIONS.SNAPSHOT_REVERT]: [],
[VM_ACTIONS.SNAPSHOT_DELETE]: [STATES.POWEROFF],
[VM_ACTIONS.SNAPSHOT_CREATE]: [STATES.RUNNING],
[VM_ACTIONS.SNAPSHOT_REVERT]: [STATES.RUNNING],
[VM_ACTIONS.SNAPSHOT_DELETE]: [STATES.POWEROFF, STATES.RUNNING],

// SCHEDULING ACTION
[VM_ACTIONS.SCHED_ACTION_CREATE]: [],
Expand Down
2 changes: 1 addition & 1 deletion src/fireedge/src/client/features/OneApi/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ const vmApi = oneApi.injectEndpoints({
* @throws Fails when response isn't code 200
*/
query: (params) => {
const name = Actions.VM_DISK_SNAP_CREATE
const name = Actions.VM_DISK_SNAP_DELETE
const command = { name, ...Commands[name] }

return { params, command }
Expand Down
6 changes: 3 additions & 3 deletions src/fireedge/src/client/models/Helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,9 @@ export const getUserInputParams = (userInputString) => {
type: params[1],
description: params[2],
options: options,
default: params[4],
min: options[0],
max: options[1],
default: params?.[4],
min: options?.[0],
max: options?.[1],
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/fireedge/src/client/models/VirtualMachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,11 @@ export const getScheduleActions = (vm) => {
export const isAvailableAction =
(action) =>
(vms = [], getVmState = (vm) => getState(vm)?.name) => {
if (VM_ACTIONS_BY_STATE[action]?.length === 0) return false
if (VM_ACTIONS_BY_STATE[action]?.length === 0) return true

const states = [vms].flat().map(getVmState)

return states?.some(
(state) => !VM_ACTIONS_BY_STATE[action]?.includes(state)
)
return states?.some((state) => VM_ACTIONS_BY_STATE[action]?.includes(state))
}

/**
Expand Down

0 comments on commit 0bfe41a

Please sign in to comment.