-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(xo-web/SR): list resource in a xostor tab
- Loading branch information
mathieu
committed
Apr 9, 2024
1 parent
f8a6774
commit 7ed882a
Showing
5 changed files
with
128 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import _ from 'intl' | ||
import Component from 'base-component' | ||
import Icon from 'icon' | ||
import React from 'react' | ||
import SortedTable from 'sorted-table' | ||
|
||
import { addSubscriptions, connectStore } from 'utils' | ||
import { Card, CardHeader, CardBlock } from 'card' | ||
import { Container, Row, Col } from 'grid' | ||
import { createSelector, createGetObjectsOfType } from 'selectors' | ||
import { Host, Vdi } from 'render-xo-item' | ||
import { subscribeXostorHealthCheck } from 'xo' | ||
|
||
const RESOURCE_COLUMNS = [ | ||
{ | ||
name: 'Resource name', | ||
itemRenderer: ({ resourceName }) => resourceName, | ||
sortCriteria: ({ resourceName }) => resourceName, | ||
}, | ||
{ | ||
name: _('node'), | ||
itemRenderer: ({ host }) => <Host id={host.id} link />, | ||
sortCriteria: ({ host }) => host.name_label, | ||
}, | ||
{ | ||
name: _('nodeStatus'), | ||
itemRenderer: ({ nodeStatus }) => nodeStatus, | ||
sortCriteria: ({ nodeStatus }) => nodeStatus, | ||
}, | ||
{ | ||
name: _('vdi'), | ||
itemRenderer: ({ volume }) => <Vdi id={volume.uuid} />, | ||
}, | ||
{ | ||
name: _('inUse'), | ||
itemRenderer: resource => <Icon icon={String(resource['in-use'])} />, | ||
sortCriteria: resource => resource['in-use'], | ||
}, | ||
{ | ||
name: _('diskState'), | ||
itemRenderer: ({ volume }) => volume['disk-state'], | ||
sortCriteria: ({ volume }) => volume['disk-state'], | ||
}, | ||
] | ||
|
||
@connectStore({ | ||
hostByHostname: createGetObjectsOfType('host') | ||
.filter((_, props) => host => host.$pool === props.sr.$pool) | ||
.groupBy('hostname'), | ||
}) | ||
@addSubscriptions(({ sr }) => ({ | ||
healthCheck: subscribeXostorHealthCheck(sr.id), | ||
})) | ||
export default class TabXostor extends Component { | ||
getResourceInfos = createSelector( | ||
() => this.props.healthCheck, | ||
healthCheck => { | ||
if (healthCheck === undefined) { | ||
return [] | ||
} | ||
|
||
return Object.entries(healthCheck.resources).flatMap(([resourceName, resourceByHostname]) => { | ||
return Object.entries(resourceByHostname).map(([hostname, resource]) => { | ||
const host = this.props.hostByHostname[hostname][0] | ||
const nodeStatus = healthCheck.nodes[hostname] | ||
const volume = resource.volumes[0] // Always only one volume | ||
delete resource.volumes | ||
|
||
return { | ||
...resource, | ||
host, | ||
nodeStatus, | ||
resourceName, | ||
volume, | ||
} | ||
}) | ||
}) | ||
} | ||
) | ||
|
||
render() { | ||
const resourceInfos = this.getResourceInfos() | ||
|
||
return ( | ||
<Container> | ||
<Row> | ||
<Col> | ||
<Card> | ||
<CardHeader> | ||
<Icon icon='disk' /> Resource list | ||
</CardHeader> | ||
<CardBlock> | ||
<SortedTable collection={resourceInfos} columns={RESOURCE_COLUMNS} /> | ||
</CardBlock> | ||
</Card> | ||
</Col> | ||
</Row> | ||
</Container> | ||
) | ||
} | ||
} |