forked from distributed-system-analysis/pbench
-
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.
Display Metadata (distributed-system-analysis#3464)
* PBENCH-115 Add flexible display of metadata values on row expansion in Overview page.
- Loading branch information
Showing
11 changed files
with
514 additions
and
59 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,96 @@ | ||
import * as TYPES from "./types"; | ||
|
||
import store from "store/store"; | ||
|
||
const { getState } = store; | ||
|
||
// Helper functions | ||
const isChecked = (dataItem, checkedItems) => | ||
checkedItems && checkedItems.some((item) => item === dataItem.key); | ||
const setChildNodes = (childNodes, isChecked) => { | ||
childNodes.forEach(function iter(a) { | ||
a.checkProps.checked = isChecked; | ||
Array.isArray(a.children) && a.children.forEach(iter); | ||
}); | ||
}; | ||
const getCheckedItemsKey = (ary) => | ||
ary.reduce( | ||
(a, b) => | ||
a.concat(b.key, "children" in b ? getCheckedItemsKey(b.children) : []), | ||
[] | ||
); | ||
const updateChildKeysList = (checked, checkedItems, childKeys) => | ||
checked | ||
? [...checkedItems, ...childKeys] | ||
: checkedItems.filter((x) => !childKeys.includes(x)); | ||
|
||
export const mapTree = (item) => { | ||
const retVal = { ...item }; | ||
if (item.children) { | ||
retVal.children = item.children.map((child) => mapTree(child)); | ||
item.checkProps.checked = null; | ||
let seen = undefined; | ||
for (const c of item.children) { | ||
if (c.checkProps.checked == null) { | ||
return retVal; | ||
} else if (seen === undefined) { | ||
seen = c.checkProps.checked; | ||
} else if (seen !== c.checkProps.checked) return retVal; | ||
} | ||
item.checkProps.checked = seen; | ||
} else { | ||
const checkedItems = getState().overview.checkedItems; | ||
item.checkProps.checked = isChecked(item, checkedItems); | ||
} | ||
|
||
return retVal; | ||
}; | ||
|
||
export const onCheck = | ||
(evt, treeViewItem, dataType) => async (dispatch, getState) => { | ||
const checked = evt.target.checked; | ||
const treeData = [...getState().overview.treeData]; | ||
let checkedItems = getState().overview.checkedItems; | ||
const { options } = treeData.find((item) => item.title === dataType); | ||
if ("children" in treeViewItem) { | ||
const childNodes = treeViewItem.children; | ||
const childKeys = getCheckedItemsKey(childNodes); | ||
|
||
setChildNodes(childNodes, checked); | ||
treeViewItem.checkProps.checked = checked; | ||
|
||
checkedItems = updateChildKeysList(checked, checkedItems, childKeys); | ||
} else if ("children" in options[0]) { | ||
// if first child | ||
const childNodes = options[0]["children"]; | ||
const node = childNodes.find((item) => item.key === treeViewItem.key); | ||
node.checkProps.checked = checked; | ||
// if only child of the parent, push the parent | ||
if (childNodes.length === 1) { | ||
options[0].checkProps.checked = checked; | ||
|
||
checkedItems = updateChildKeysList( | ||
checked, | ||
checkedItems, | ||
options[0].key | ||
); | ||
} | ||
} else { | ||
// leaf node | ||
const node = options.find((item) => treeViewItem.key.includes(item.key)); | ||
node.checkProps.checked = checked; | ||
} | ||
if (checked) { | ||
checkedItems = [...checkedItems, treeViewItem.key]; | ||
} else { | ||
checkedItems = checkedItems.filter((item) => item !== treeViewItem.key); | ||
} | ||
dispatch({ | ||
type: TYPES.SET_TREE_DATA, | ||
payload: treeData, | ||
}); | ||
dispatch({ | ||
type: TYPES.SET_METADATA_CHECKED_KEYS, | ||
payload: checkedItems, | ||
}); | ||
}; |
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
38 changes: 38 additions & 0 deletions
38
dashboard/src/modules/components/OverviewComponent/MetadataTreeComponent.jsx
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,38 @@ | ||
import "./index.less"; | ||
|
||
import { mapTree, onCheck } from "actions/metadataTreeActions"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
|
||
import React from "react"; | ||
import { TreeView } from "@patternfly/react-core"; | ||
|
||
const MetadataTreeView = () => { | ||
const { treeData } = useSelector((state) => state.overview); | ||
const dispatch = useDispatch(); | ||
const onCheckHandler = (evt, treeViewItem, dataType) => { | ||
dispatch(onCheck(evt, treeViewItem, dataType)); | ||
}; | ||
return ( | ||
<div className="treeview-container"> | ||
{treeData && | ||
treeData.length > 0 && | ||
treeData.map((item) => { | ||
const mapped = item.options.map((item) => mapTree(item)); | ||
return ( | ||
<div key={item.title}> | ||
<h1 className="title">{item.title}</h1> | ||
<TreeView | ||
data={mapped} | ||
hasChecks | ||
onCheck={(evt, treeItem) => | ||
onCheckHandler(evt, treeItem, item.title) | ||
} | ||
/> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
); | ||
}; | ||
|
||
export default MetadataTreeView; |
Oops, something went wrong.