-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jmx): Tabular attribute table (#215)
* wip(#125): Progress on multiattribute table. Have to implement a better way to know which are JMX nodes * feat(#125): Tabular attribute table * feat(#125): Added NodeName table and better filtering * feat(#125): Refactored filtering logic * feat(#125): Added test for helper function. Created helper function class. Simplified JMXContent component taking into account new logic * feat(#125): Removed NodeNameTable and using JMXContentMBeans. * feat(#125): Moved helper function to proper class. Redefined paths to components * feat(#125): Changed humanize labels to use function implementation * feat(#125): Removed array creation: map handles it * feat(#125): Added extra test cases. Some refactoring * feat(#125): Extra refinement * feat(#125): Added extra tests * feat(#125): Used strings isBlank function * feat(#125): Fixed logic after changing to using isBlank function
- Loading branch information
Showing
6 changed files
with
154 additions
and
14 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
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; | ||
} |
90 changes: 90 additions & 0 deletions
90
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,90 @@ | ||
import { useContext, useEffect, useState } from 'react' | ||
import { Card, CardBody, Text } from '@patternfly/react-core' | ||
import { 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' | ||
import { JmxContentMBeans } from '@hawtiosrc/plugins/shared/JmxContentMBeans' | ||
import { humanizeLabels } from '@hawtiosrc/util/strings' | ||
|
||
export const AttributeTable: React.FunctionComponent = () => { | ||
const { selectedNode } = useContext(PluginNodeSelectionContext) | ||
const [attributesList, setAttributesList] = useState<AttributeValues[]>([{}]) | ||
const [isReading, setIsReading] = useState<boolean>(false) | ||
|
||
useEffect(() => { | ||
if (!selectedNode) { | ||
return | ||
} | ||
|
||
const readAttributes = async () => { | ||
const childrenMbeansAttributes: AttributeValues[] = [] | ||
setIsReading(true) | ||
if (selectedNode.children) | ||
for (const mbean of selectedNode.children) { | ||
const objectName = mbean.objectName | ||
if (objectName) { | ||
const attrs = await attributeService.read(objectName) | ||
childrenMbeansAttributes.push(attrs) | ||
} | ||
} | ||
setAttributesList([...childrenMbeansAttributes]) | ||
setIsReading(false) | ||
} | ||
readAttributes() | ||
}, [selectedNode]) | ||
|
||
if (!selectedNode) { | ||
return null | ||
} | ||
|
||
if (isReading) { | ||
return ( | ||
<Card> | ||
<CardBody> | ||
<Text component='p'>Reading attributes...</Text> | ||
</CardBody> | ||
</Card> | ||
) | ||
} | ||
|
||
const checkIfAllMBeansHaveSameAttributes = (attributesList: AttributeValues[]) => { | ||
if (attributesList.length <= 1) { | ||
return true | ||
} | ||
|
||
const firstMBeanAttributesElements = attributesList[0].length | ||
|
||
if (!attributesList.every(mbeanAttributes => mbeanAttributes.length === firstMBeanAttributesElements)) { | ||
return false | ||
} | ||
|
||
const labelSet: Set<string> = new Set() | ||
Object.keys(attributesList[0]).forEach(label => labelSet.add(label)) | ||
|
||
return attributesList.every(attributes => Object.keys(attributes).every(label => labelSet.has(label))) | ||
} | ||
|
||
if ( | ||
attributesList.some(attribute => Object.entries(attribute).length === 0) || | ||
!checkIfAllMBeansHaveSameAttributes(attributesList) | ||
) { | ||
return <JmxContentMBeans /> | ||
} | ||
|
||
const labels = Object.keys(attributesList[0]) | ||
const columns: TableProps['cells'] = labels.map(label => humanizeLabels(label)) | ||
const rows: TableProps['rows'] = attributesList.map(attribute => | ||
labels.map(label => JSON.stringify(attribute[label])), | ||
) | ||
|
||
return ( | ||
<Card isFullHeight> | ||
<Table aria-label='MBeans' variant='compact' cells={columns} rows={rows}> | ||
<TableHeader className={'attribute-table'} /> | ||
<TableBody /> | ||
</Table> | ||
</Card> | ||
) | ||
} |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { Attributes } from './Attributes' | ||
export { AttributeModal } from './AttributeModal' | ||
export { AttributeTable } from './AttributeTable' |
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