-
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.
refactor(#125): Added attribute data to context for proactive fetching
- Loading branch information
Showing
6 changed files
with
104 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { AttributeValues } from './connect/jolokia-service' | ||
import { MBeanNode } from './shared' | ||
import { attributeService } from './shared/attributes/attribute-service' | ||
|
||
export type MBeanAttributeData = { | ||
nodeData: MBeanAttributes | void | ||
children: { | ||
[id: string]: MBeanAttributes | void | ||
} | ||
} | ||
|
||
export type MBeanChartData = { | ||
nodeData: MBeanChartDataEntries | void | ||
children: { | ||
[id: string]: MBeanChartDataEntries | void | ||
} | ||
} | ||
|
||
export type MBeanAttributes = { | ||
node: MBeanNode | ||
data: AttributeValues | ||
} | ||
|
||
export type MBeanChartDataEntries = { | ||
node: MBeanNode | ||
entries: MBeanChartDataEntriesTime[] | ||
} | ||
|
||
export type MBeanChartDataEntriesTime = { | ||
time: number | ||
data: AttributeValues[] | ||
} | ||
|
||
async function getAttributesForSpecificNode(node: MBeanNode): Promise<MBeanAttributes | null> { | ||
if (!node || !node?.objectName) return Promise.resolve(null) | ||
|
||
return Promise.resolve({ node, data: await attributeService.read(node.objectName) }) | ||
} | ||
|
||
export async function getAttributesForNode(node: MBeanNode | null): Promise<MBeanAttributeData> { | ||
if (!node) return Promise.resolve({ nodeData: undefined, children: {} }) | ||
|
||
return { | ||
nodeData: (await getAttributesForSpecificNode(node)) ?? undefined, | ||
children: Object.fromEntries( | ||
await Promise.all(node.getChildren().map(async child => [child.id, await getAttributesForSpecificNode(child)])), | ||
), | ||
} | ||
} |
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 |
---|---|---|
@@ -1,22 +1,41 @@ | ||
import { createContext, useState } from 'react' | ||
import { createContext, useEffect, useState } from 'react' | ||
import { MBeanNode } from '@hawtiosrc/plugins/shared' | ||
import { getAttributesForNode, MBeanAttributeData } from './SelectionNodeData' | ||
|
||
/** | ||
* Custom React hook for using JMX MBean tree. | ||
*/ | ||
export function usePluginNodeSelected() { | ||
const [selectedNode, setSelectedNode] = useState<MBeanNode | null>(null) | ||
return { selectedNode, setSelectedNode } | ||
const [selectedNodeAttributes, setSelectedNodeAttributes] = useState<MBeanAttributeData>({ | ||
nodeData: undefined, | ||
children: {}, | ||
}) | ||
const [isReadingAttributes, setIsReadingAttributes] = useState<boolean>(false) | ||
|
||
useEffect(() => { | ||
;(async () => { | ||
setIsReadingAttributes(true) | ||
setSelectedNodeAttributes(await getAttributesForNode(selectedNode)) | ||
setIsReadingAttributes(false) | ||
})() | ||
}, [selectedNode]) | ||
|
||
return { selectedNode, setSelectedNode, selectedNodeAttributes, isReadingAttributes } | ||
} | ||
|
||
type PluginNodeSelectionContext = { | ||
selectedNode: MBeanNode | null | ||
setSelectedNode: (selectedNode: MBeanNode | null) => void | ||
selectedNodeAttributes: MBeanAttributeData | ||
isReadingAttributes: boolean | ||
} | ||
|
||
export const PluginNodeSelectionContext = createContext<PluginNodeSelectionContext>({ | ||
selectedNode: null, | ||
setSelectedNode: () => { | ||
/* no-op */ | ||
}, | ||
selectedNodeAttributes: { nodeData: undefined, children: {} }, | ||
isReadingAttributes: false, | ||
}) |
45 changes: 8 additions & 37 deletions
45
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
51 changes: 3 additions & 48 deletions
51
packages/hawtio/src/plugins/shared/attributes/Attributes.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
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