|
| 1 | +import { DataList, DataListCell, DataListItem, DataListItemCells, DataListItemRow } from '@patternfly/react-core'; |
| 2 | +import messages from 'locales/messages'; |
| 3 | +import React from 'react'; |
| 4 | +import type { WrappedComponentProps } from 'react-intl'; |
| 5 | +import { injectIntl } from 'react-intl'; |
| 6 | +import { connect } from 'react-redux'; |
| 7 | +import type { StorageData } from 'routes/details/ocpBreakdown/virtualization/storage/storageLink'; |
| 8 | + |
| 9 | +import { styles } from './storageContent.styles'; |
| 10 | + |
| 11 | +interface StorageContentOwnProps { |
| 12 | + storageData?: StorageData[]; |
| 13 | + virtualMachine?: string; |
| 14 | +} |
| 15 | + |
| 16 | +type StorageContentProps = StorageContentOwnProps & WrappedComponentProps; |
| 17 | + |
| 18 | +class StorageContentBase extends React.Component<StorageContentProps, any> { |
| 19 | + private getDataListItems = () => { |
| 20 | + const { storageData } = this.props; |
| 21 | + const result = []; |
| 22 | + |
| 23 | + if (storageData) { |
| 24 | + Object.keys(storageData).map((key, i) => { |
| 25 | + const data = storageData[key]; |
| 26 | + const id = `data-list-${i}`; |
| 27 | + result.push( |
| 28 | + <DataListItem aria-labelledby={id} key={`${id}-item`}> |
| 29 | + <DataListItemRow> |
| 30 | + <DataListItemCells |
| 31 | + dataListCells={[ |
| 32 | + <DataListCell key={`${id}-cell1`}> |
| 33 | + <span id={id}>{data.pvc_name}</span> |
| 34 | + </DataListCell>, |
| 35 | + <DataListCell key={`${id}-cell2`}>{data.storage_class}</DataListCell>, |
| 36 | + <DataListCell key={`${id}-cell2`}>{data.usage}</DataListCell>, |
| 37 | + <DataListCell key={`${id}-cell2`}>{data.capacity}</DataListCell>, |
| 38 | + ]} |
| 39 | + /> |
| 40 | + </DataListItemRow> |
| 41 | + </DataListItem> |
| 42 | + ); |
| 43 | + }); |
| 44 | + } |
| 45 | + return result; |
| 46 | + }; |
| 47 | + |
| 48 | + public render() { |
| 49 | + const { virtualMachine, intl } = this.props; |
| 50 | + const dataListItems = this.getDataListItems(); |
| 51 | + |
| 52 | + return ( |
| 53 | + <> |
| 54 | + <div style={styles.dataListHeading}>{intl.formatMessage(messages.virtualMachine)}</div> |
| 55 | + <div style={styles.dataListSubHeading}>{virtualMachine}</div> |
| 56 | + <DataList aria-label={intl.formatMessage(messages.storage)} isCompact> |
| 57 | + <DataListItem aria-labelledby="heading1"> |
| 58 | + <DataListItemRow> |
| 59 | + <DataListItemCells |
| 60 | + dataListCells={[ |
| 61 | + <DataListCell key="primary content"> |
| 62 | + <span id="heading1" style={styles.dataListHeading}> |
| 63 | + {intl.formatMessage(messages.storageNames)} |
| 64 | + </span> |
| 65 | + </DataListCell>, |
| 66 | + <DataListCell key="secondary content"> |
| 67 | + <span id="heading2" style={styles.dataListHeading}> |
| 68 | + {intl.formatMessage(messages.storageClass)} |
| 69 | + </span> |
| 70 | + </DataListCell>, |
| 71 | + <DataListCell key="secondary content"> |
| 72 | + <span id="heading2" style={styles.dataListHeading}> |
| 73 | + {intl.formatMessage(messages.usage)} |
| 74 | + </span> |
| 75 | + </DataListCell>, |
| 76 | + <DataListCell key="secondary content"> |
| 77 | + <span id="heading2" style={styles.dataListHeading}> |
| 78 | + {intl.formatMessage(messages.capacity)} |
| 79 | + </span> |
| 80 | + </DataListCell>, |
| 81 | + ]} |
| 82 | + /> |
| 83 | + </DataListItemRow> |
| 84 | + </DataListItem> |
| 85 | + {dataListItems.map(item => item)} |
| 86 | + </DataList> |
| 87 | + </> |
| 88 | + ); |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +const StorageContent = injectIntl(connect()(StorageContentBase)); |
| 93 | + |
| 94 | +export { StorageContent }; |
0 commit comments