-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Render VMs power state as icon with tooltip
Signed-off-by: Radoslaw Szwajkowski <[email protected]>
- Loading branch information
Showing
15 changed files
with
173 additions
and
23 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
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
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
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
28 changes: 28 additions & 0 deletions
28
...odules/Providers/views/details/tabs/VirtualMachines/components/PowerStateCellRenderer.tsx
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import { TableIconCell } from 'src/modules/Providers/utils'; | ||
import { useForkliftTranslation } from 'src/utils/i18n'; | ||
|
||
import { Tooltip } from '@patternfly/react-core'; | ||
import { OffIcon, PowerOffIcon, UnknownIcon } from '@patternfly/react-icons'; | ||
|
||
import { getVmPowerState } from '../utils'; | ||
import { PowerState } from '../utils/helpers/getVmPowerState'; | ||
|
||
import { VMCellProps } from './VMCellProps'; | ||
|
||
export const PowerStateCellRenderer: React.FC<VMCellProps> = ({ data, providerType }) => { | ||
const { t } = useForkliftTranslation(); | ||
const powerState = getVmPowerState(providerType, data?.vm); | ||
const states: { [key in PowerState]: [JSX.Element, string, string] } = { | ||
on: [<PowerOffIcon color="green" key="on" />, t('Powered on'), t('On')], | ||
off: [<OffIcon color="red" key="off" />, t('Powered off'), t('Off')], | ||
unknown: [<UnknownIcon key="unknown" />, t('Unknown power state'), t('Unknown')], | ||
}; | ||
const [icon, tooltipText, shortText] = states[powerState] || states.unknown; | ||
|
||
return ( | ||
<TableIconCell icon={<Tooltip content={tooltipText}>{icon}</Tooltip>}> | ||
{shortText} | ||
</TableIconCell> | ||
); | ||
}; |
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
1 change: 1 addition & 0 deletions
1
...nsole-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/index.ts
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
58 changes: 58 additions & 0 deletions
58
...src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/getVmPowerState.ts
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { | ||
OpenshiftVM, | ||
OpenstackVM, | ||
OVirtVM, | ||
ProviderType, | ||
ProviderVirtualMachine, | ||
VSphereVM, | ||
} from '@kubev2v/types'; | ||
|
||
export type PowerState = 'on' | 'off' | 'unknown'; | ||
|
||
// moved from packages/legacy/src/common/components/VMNameWithPowerState.tsx | ||
export const getVmPowerState = ( | ||
providerType: ProviderType, | ||
vm?: ProviderVirtualMachine, | ||
): PowerState => { | ||
let powerStatus: PowerState = 'unknown'; | ||
if (!vm) return powerStatus; | ||
switch (providerType) { | ||
case 'ovirt': { | ||
if ((vm as OVirtVM).status === 'up') powerStatus = 'on'; | ||
if ((vm as OVirtVM).status === 'down') powerStatus = 'off'; | ||
break; | ||
} | ||
case 'vsphere': { | ||
if ((vm as VSphereVM).powerState === 'poweredOn') powerStatus = 'on'; | ||
if ((vm as VSphereVM).powerState === 'poweredOff') powerStatus = 'off'; | ||
break; | ||
} | ||
case 'openstack': { | ||
const status = (vm as OpenstackVM).status; | ||
if (status === 'ACTIVE') { | ||
powerStatus = 'on'; | ||
} | ||
if (status === 'SHUTOFF') { | ||
powerStatus = 'off'; | ||
} | ||
break; | ||
} | ||
case 'openshift': { | ||
const status = (vm as OpenshiftVM)?.object?.status?.printableStatus; | ||
if (status === 'Running') { | ||
powerStatus = 'on'; | ||
} else { | ||
powerStatus = 'off'; | ||
} | ||
break; | ||
} | ||
case 'ova': { | ||
powerStatus = 'off'; | ||
break; | ||
} | ||
default: { | ||
powerStatus = 'unknown'; | ||
} | ||
} | ||
return powerStatus; | ||
}; |
1 change: 1 addition & 0 deletions
1
...le-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/index.ts
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,3 +1,4 @@ | ||
// @index(['./*', /style/g], f => `export * from '${f.path}';`) | ||
export * from './getHighestPriorityConcern'; | ||
export * from './getVmPowerState'; | ||
// @endindex |