forked from hawtio/hawtio-next
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip(hawtio#125): Progress on multiattribute table. Have to implement …
…a better way to know which are JMX nodes
- Loading branch information
Showing
3 changed files
with
86 additions
and
1 deletion.
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
3 changes: 3 additions & 0 deletions
3
packages/hawtio/src/plugins/shared/attributes/AttributeTable.css
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,3 @@ | ||
.attribute-table > tr > th { | ||
max-width: none | ||
} |
79 changes: 79 additions & 0 deletions
79
packages/hawtio/src/plugins/shared/attributes/AttributeTable.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,79 @@ | ||
import { useContext, useEffect, useState } from 'react' | ||
import { Card, CardBody, Text } from '@patternfly/react-core' | ||
import { InfoCircleIcon } from '@patternfly/react-icons' | ||
import { OnRowClick, Table, TableBody, TableHeader, TableProps } from '@patternfly/react-table' | ||
import { PluginNodeSelectionContext } from '@hawtiosrc/plugins/selectionNodeContext' | ||
import { AttributeValues } from '@hawtiosrc/plugins/connect/jolokia-service' | ||
import { attributeService } from './attribute-service' | ||
import './AttributeTable.css' | ||
|
||
export const AttributeTable: React.FunctionComponent = () => { | ||
const { selectedNode, setSelectedNode } = useContext(PluginNodeSelectionContext) | ||
const [attributes, setAttributes] = useState<AttributeValues[]>([{}]) | ||
const [isReading, setIsReading] = useState<boolean>(false) | ||
|
||
useEffect(() => { | ||
if (!selectedNode) { | ||
return | ||
} | ||
|
||
const childrenMbeansAttributes : AttributeValues[] = [] | ||
const readAttributes = async () => { | ||
setIsReading(true) | ||
if(selectedNode.children) | ||
for(let mbean of selectedNode.children) { | ||
const objectName = mbean.objectName | ||
if (objectName) { | ||
const attrs = await attributeService.read(objectName) | ||
childrenMbeansAttributes.push(attrs) | ||
} | ||
} | ||
setAttributes([...childrenMbeansAttributes]) | ||
setIsReading(false) | ||
} | ||
readAttributes() | ||
}, [selectedNode]) | ||
|
||
if (!selectedNode) { | ||
return null | ||
} | ||
|
||
if (isReading) { | ||
return ( | ||
<Card> | ||
<CardBody> | ||
<Text component='p'>Reading attributes...</Text> | ||
</CardBody> | ||
</Card> | ||
) | ||
} | ||
|
||
const tidyLabels = (str : string) => str | ||
.replace(/([a-z])([A-Z])/g, '$1 $2') | ||
.replace(/\b([A-Z]+)([A-Z])([a-z])/, '$1 $2$3') | ||
.replace(/^./, function(str){ return str.toUpperCase(); }) | ||
|
||
const columns: TableProps['cells'] = Object.keys(attributes[0]).map(label => tidyLabels(label)) | ||
const rows: TableProps['rows'] = attributes.map(attribute => Object.values(attribute).flatMap(value => JSON.stringify(value))) | ||
|
||
if (rows.length === 0) { | ||
return ( | ||
<Card> | ||
<CardBody> | ||
<Text component='p'> | ||
<InfoCircleIcon /> This node has no MBeans. | ||
</Text> | ||
</CardBody> | ||
</Card> | ||
) | ||
} | ||
|
||
return ( | ||
<Card isFullHeight> | ||
<Table aria-label='MBeans' variant='compact' cells={columns} rows={rows} > | ||
<TableHeader className={'attribute-table'} /> | ||
<TableBody /> | ||
</Table> | ||
</Card> | ||
) | ||
} |