-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Tree Table in DataView #19
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
<Thead data-ouia-component-id={`${ouiaId}-thead`} {...props}> | ||
<Tr ouiaId={`${ouiaId}-tr-head`}> | ||
{onSelect && isSelected && !isTreeTable && <Th key="row-select" screenReaderText='Data selection table header cell' />} | ||
{columns.map((column, index) => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably memoize this JSX.
const areAllDescendantsSelected = (node: DataViewTrTree) => getDescendants(node).every((n) => isSelected?.(n)); | ||
const areSomeDescendantsSelected = (node: DataViewTrTree) => getDescendants(node).some((n) => isSelected?.(n)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Hyperkid123 I'm just not sure what I could use as a dependency for useMemo in these cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whatever changes the outcomes. The iSnodeChecked which is using these might be a better place. Or the getDescendants. There is a lot if iterations happening in general. It can be a touch more efficient.
} | ||
}; | ||
|
||
const childRows = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
memo
<Table isTreeTable aria-label="Data table" ouiaId={ouiaId} {...props}> | ||
<DataViewTableHeader isTreeTable columns={columns} ouiaId={ouiaId} /> | ||
<Tbody> | ||
{renderRows(rows)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd store the node(s) into a variable and just use that instead of calling the function.
const isNodeChecked = (node: DataViewTrTree) => { | ||
if (areAllDescendantsSelected(node)) { | ||
return true; | ||
} | ||
if (areSomeDescendantsSelected(node)) { | ||
return null; | ||
} | ||
return false; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be done in one iteration.
@Hyperkid123 made some cleanup. The issues should be resolved now, thanks! |
); | ||
}; | ||
export const DataViewTable: React.FC<DataViewTableProps> = ({ isTreeTable, ...props }: DataViewTableProps) => ( | ||
isTreeTable ? (<DataViewTableTree {...(props as DataViewTableTreeProps)} />) : (<DataViewTableBasic {...(props as DataViewTableBasicProps)}/>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can make the type condition so you won't have to type cast the props.
🎉 This PR is included in version 5.1.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
RHCLOUD-34946