Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieu committed Mar 19, 2024
1 parent d6702ca commit 7467e16
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/xo-web/src/common/intl/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ const messages = {
hostRemoteSyslog: 'Remote syslog',
hostIommu: 'IOMMU',
hostNoCertificateInstalled: 'No certificates installed on this host',
'onlyAvailableXcp8.3OrHighter': 'Only available for XCP-ng 8.3.0 or highter',
'onlyAvailableXcp8.3OrHigher': 'Only available for XCP-ng 8.3.0 or higher',
pciDevices: 'PCI Devices',
pciId: 'PCI ID',
pcisEnable: 'PCI{nPcis, plural, one {} other {s}} enable',
Expand Down
2 changes: 1 addition & 1 deletion packages/xo-web/src/common/xo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ export const installSupplementalPackOnAllHosts = (pool, file) => {
)
}

export const pcisHide = async (pcis, hide) => {
export const hidePcis = async (pcis, hide) => {
try {
await confirm({
body: _('applyChangeOnPcis', { nPcis: pcis.length }),
Expand Down
56 changes: 39 additions & 17 deletions packages/xo-web/src/xo-app/host/tab-advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
enableAdvancedLiveTelemetry,
enableHost,
forgetHost,
pcisHide,
hidePcis,
installSupplementalPack,
isHyperThreadingEnabledHost,
isPciHidden,
Expand Down Expand Up @@ -109,30 +109,43 @@ const PCIS_COLUMNS = [
},
{
name: _('enabled'),
itemRenderer: (pci, { isPciHiddenById, isPciPassthroughAvailable }) => {
if (isPciHiddenById === undefined) {
itemRenderer: (pci, { pciStateById, isPciPassthroughAvailable }) => {
if (pciStateById === undefined) {
return <Icon icon='loading' />
}
const isHidden = isPciHiddenById[pci.id]
const _pcisHide = value => pcisHide([pci], value)
return (
<Tooltip content={isPciPassthroughAvailable ? undefined : _('onlyAvailableXcp8.3OrHighter')}>
<Toggle value={isHidden} onChange={_pcisHide} disabled={!isPciPassthroughAvailable} />
</Tooltip>
)

if (!isPciPassthroughAvailable) {
return (
<Tooltip content={_('onlyAvailableXcp8.3OrHigher')}>
<Toggle disabled />
</Tooltip>
)
}

const { error, isHidden } = pciStateById[pci.id]
if (error !== undefined) {
return (
<Tooltip content={error}>
<Icon icon='alarm' color='text-danger' />
</Tooltip>
)
}

const _hidePcis = value => hidePcis([pci], value)
return <Toggle value={isHidden} onChange={_hidePcis} />
},
sortCriteria: (pci, { isPciHiddenById }) => isPciHiddenById?.[pci.id],
sortCriteria: (pci, { pciStateById }) => pciStateById?.[pci.id]?.isHidden,
},
]
const PCIS_ACTIONS = [
{
handler: pcis => pcisHide(pcis, false),
handler: pcis => hidePcis(pcis, false),
icon: 'toggle-off',
label: _('disable'),
level: 'primary',
},
{
handler: pcis => pcisHide(pcis, true),
handler: pcis => hidePcis(pcis, true),
icon: 'toggle-on',
label: _('enable'),
level: 'primary',
Expand Down Expand Up @@ -290,19 +303,28 @@ export default class extends Component {
}

const _isPciPassthroughAvailable = isPciPassthroughAvailable(host)
const isPciHiddenById = {}
const pciStateById = {}
if (_isPciPassthroughAvailable) {
await Promise.all(
Object.keys(this.props.pcis).map(async id => (isPciHiddenById[id] = await isPciHidden(id).catch(console.error)))
Object.keys(this.props.pcis).map(async id => {
const pciSate = {}
try {
pciSate.isHidden = await isPciHidden(id)
} catch (error) {
console.error(error)
pciSate.error = error.message
}
pciStateById[id] = pciSate
})
)
}

this.setState({
isHtEnabled: await isHyperThreadingEnabledHost(host).catch(() => null),
isSmartctlHealthEnabled,
pciStateById,
smartctlUnhealthyDevices,
unhealthyDevicesAlerts,
isPciHiddenById,
isPciPassthroughAvailable: _isPciPassthroughAvailable,
})
}
Expand Down Expand Up @@ -677,7 +699,7 @@ export default class extends Component {
groupedActions={PCIS_ACTIONS}
collection={pcis}
columns={PCIS_COLUMNS}
data-isPciHiddenById={this.state.isPciHiddenById}
data-pciStateById={this.state.pciStateById}
data-isPciPassthroughAvailable={this.state.isPciPassthroughAvailable}
stateUrlParam='s_pcis'
/>
Expand Down

0 comments on commit 7467e16

Please sign in to comment.