New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vm overview boot order summary #3560
Changes from 1 commit
8c6b136
d0671a8
abf9fa1
0f3c4a9
06fe0f9
892b22c
63bebab
ae1d442
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.kubevirt-boot-order-suammary__expandable.pf-c-expandable .pf-c-expandable__content { | ||
margin-top: 0; | ||
} | ||
|
||
.kubevirt-boot-order-suammary__empty-text { | ||
margin-bottom: 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import * as React from 'react'; | ||
import * as _ from 'lodash'; | ||
import { List, ListItem, Expandable, Text, TextVariants } from '@patternfly/react-core'; | ||
import { BootableDeviceType } from '../../types'; | ||
import { deviceLabel, deviceKey, bootOrderEmptyTitle, bootOrderEmptyMessage } from './constants'; | ||
|
||
import './boot-order-summary.scss'; | ||
|
||
export const BootOrderSummary = ({ devices }: BootOrderSummaryProps) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. + here |
||
const [isExpanded, setIsExpanded] = React.useState<boolean>(false); | ||
|
||
const sources = _.sortBy(devices.filter((device) => device.value.bootOrder), 'value.bootOrder'); | ||
const options = devices.filter((device) => !device.value.bootOrder); | ||
|
||
const onToggle = () => { | ||
setIsExpanded(!isExpanded); | ||
}; | ||
|
||
// Note(Yaacov): className='text-secondary' is a hack to fix TextVariants being overriden. | ||
const EmptyState: React.FC = () => ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can't we make a real component out of this? |
||
<> | ||
<Text component={TextVariants.p} className="kubevirt-boot-order-suammary__empty-text"> | ||
{bootOrderEmptyTitle} | ||
</Text> | ||
<Text component={TextVariants.small} className="text-secondary"> | ||
{bootOrderEmptyMessage} | ||
</Text> | ||
{options.length > 0 && ( | ||
<Expandable | ||
toggleText={isExpanded ? 'Hide default boot disks' : 'Show default boot disks'} | ||
onToggle={onToggle} | ||
isExpanded={isExpanded} | ||
className="kubevirt-boot-order-suammary__expandable" | ||
> | ||
<List> | ||
{options.map((option) => ( | ||
<ListItem key={deviceKey(option)}>{deviceLabel(option)}</ListItem> | ||
))} | ||
</List> | ||
</Expandable> | ||
)} | ||
</> | ||
); | ||
|
||
return ( | ||
<> | ||
{sources.length === 0 ? ( | ||
<EmptyState /> | ||
) : ( | ||
<List> | ||
{sources.map((source) => ( | ||
<ListItem key={deviceKey(source)}>{deviceLabel(source)}</ListItem> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. + here |
||
))} | ||
</List> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export type BootOrderSummaryProps = { | ||
devices: BootableDeviceType[]; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const bootOrderEmptyTitle = 'No resource selected'; | ||
export const bootOrderEmptyMessage = | ||
'VM will attempt to boot from disks by order of apearance in YAML file'; | ||
|
||
export const deviceKey = (device) => `${device.type}-${device.value.name}`; | ||
export const deviceLabel = (device) => `${device.value.name} (${device.typeLabel})`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './boot-order-summary'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,8 @@ import { getFlavorText } from '../flavor-text'; | |
import { EditButton } from '../edit-button'; | ||
import { VMDetailsItem } from '../vms/vm-resource'; | ||
import { DiskSummary } from '../vm-disks/disk-summary'; | ||
import { asVM, getBootableDevicesInOrder } from '../../selectors/vm'; | ||
import { BootOrder } from '../boot-order'; | ||
import { asVM, getDevices } from '../../selectors/vm'; | ||
import { BootOrderSummary } from '../boot-order'; | ||
import { VMTemplateLink } from './vm-template-link'; | ||
import { TemplateSource } from './vm-template-source'; | ||
|
||
|
@@ -79,18 +79,14 @@ export const VMTemplateDetailsList: React.FC<VMTemplateResourceListProps> = ({ | |
canUpdateTemplate, | ||
}) => { | ||
const id = getBasicID(template); | ||
const sortedBootableDevices = getBootableDevicesInOrder(template); | ||
const devices = getDevices(asVM(template)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getDevices already expects VmLikeEntity There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🌔 🌃 🕙 |
||
const cds = getCDRoms(asVM(template)); | ||
const flavorText = getFlavorText(template); | ||
|
||
return ( | ||
<dl className="co-m-pane__details"> | ||
<VMDetailsItem | ||
title="Boot Order" | ||
idValue={prefixedID(id, 'boot-order')} | ||
isNotAvail={sortedBootableDevices.length === 0} | ||
> | ||
<BootOrder bootableDevices={sortedBootableDevices} /> | ||
<VMDetailsItem title="Boot Order" idValue={prefixedID(id, 'boot-order')}> | ||
<BootOrderSummary devices={devices} /> | ||
</VMDetailsItem> | ||
|
||
<VMDetailsItem | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import { VMKind, VMLikeEntityKind, BootableDeviceType } from '../../types'; | ||
import * as _ from 'lodash'; | ||
import { VMLikeEntityKind, BootableDeviceType } from '../../types'; | ||
import { DiskWrapper } from '../../k8s/wrapper/vm/disk-wrapper'; | ||
import { DEVICE_TYPE_DISK, DEVICE_TYPE_INTERFACE } from '../../constants'; | ||
import { getDisks, getInterfaces } from './selectors'; | ||
import { asVM } from './vmlike'; | ||
|
@@ -9,18 +11,27 @@ export const getBootDeviceIndex = (devices, bootOrder) => | |
export const getDeviceBootOrder = (device, defaultValue?): number => | ||
device && device.bootOrder === undefined ? defaultValue : device.bootOrder; | ||
|
||
const getBootableDevices = (vm: VMKind): BootableDeviceType[] => { | ||
const disks = getDisks(vm) | ||
.filter((disk) => disk.bootOrder) | ||
.map((disk) => ({ type: DEVICE_TYPE_DISK, value: disk })); | ||
const nics = getInterfaces(vm) | ||
.filter((nic) => nic.bootOrder) | ||
.map((nic) => ({ type: DEVICE_TYPE_INTERFACE, value: nic })); | ||
export const getDevices = (vm: VMLikeEntityKind): BootableDeviceType[] => { | ||
const disks = getDisks(asVM(vm)).map((disk) => ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done ❗ |
||
type: DEVICE_TYPE_DISK, | ||
typeLabel: DiskWrapper.initialize(disk) | ||
.getType() | ||
.toString(), | ||
value: disk, | ||
})); | ||
const nics = getInterfaces(asVM(vm)).map((nic) => ({ | ||
type: DEVICE_TYPE_INTERFACE, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we convert these into plain string enum? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure 👍 |
||
typeLabel: 'NIC', | ||
value: nic, | ||
})); | ||
|
||
return [...disks, ...nics]; | ||
}; | ||
|
||
export const getBootableDevicesInOrder = (vmLike: VMLikeEntityKind): BootableDeviceType[] => { | ||
const vm = asVM(vmLike); | ||
return getBootableDevices(vm).sort((a, b) => a.value.bootOrder - b.value.bootOrder); | ||
export const getBootableDevices = (vm: VMLikeEntityKind): BootableDeviceType[] => { | ||
const devices = getDevices(vm).filter((device) => device.value.bootOrder); | ||
return [...devices]; | ||
}; | ||
|
||
export const getBootableDevicesInOrder = (vm: VMLikeEntityKind): BootableDeviceType[] => | ||
_.sortBy(getBootableDevices(vm), 'value.bootOrder'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,6 @@ export type VMMultiStatus = { | |
|
||
export type BootableDeviceType = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: missing typeLabel There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice ! added |
||
type: string; | ||
typeLabel: string; | ||
value: V1Disk | V1NetworkInterface; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: suammary