-
Notifications
You must be signed in to change notification settings - Fork 72
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
feat: DataTable selections clean up and improvements #1804
Conversation
✅ Deploy Preview for paragon-openedx ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
@@ -42,7 +42,7 @@ const CardFooter = React.forwardRef(({ | |||
|
|||
CardFooter.propTypes = { | |||
/** Specifies contents of the component. */ | |||
children: PropTypes.node.isRequired, | |||
children: PropTypes.node, |
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.
turns out it is a valid use case to use Card.Footer
without children
@@ -45,7 +45,7 @@ CardSection.propTypes = { | |||
/** Specifies class name to append to the base element. */ | |||
className: PropTypes.string, | |||
/** Specifies contents of the component. */ | |||
children: PropTypes.node.isRequired, | |||
children: PropTypes.node, |
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.
turns out it is a valid use case to use Card.Section
without children
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.
Love the built in spacers of the Card.Section
:)
src/DataTable/CardView.jsx
Outdated
className={classNames('pgn__data-table-card-view', className)} | ||
columnSizes={columnSizes} | ||
> | ||
{[...new Array(8)].map(() => <SkeletonCardComponent key={nanoid()} />)} |
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.
note: might consider allowing consumers to override the number of loading skeleton cards to display
[dir="ltr"] & { | ||
margin-right: map_get($spacers, 2); |
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.
[clarification] This style wasn't applying in MFEs since the dev build doesn't compile SCSS/CSS with the same PostCSS RTL plugin as production builds.
<> | ||
<RowStatus /> | ||
<TablePagination /> | ||
<TablePaginationMinimal /> | ||
</> |
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.
moved from default props to be explicit in the component
src/DataTable/hooks.jsx
Outdated
@@ -27,14 +26,15 @@ export const useSelectionActions = ( | |||
) => { | |||
const [{ selectedRows, isEntireTableSelected }, dispatch] = controlledTableSelections; | |||
|
|||
const clearSelection = () => { | |||
const clearSelection = useCallback(() => { |
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 exported function should be memoized so it's not responsible for any erroneous component re-renders in consuming components.
const { | ||
pageSize: tableStatePageSize, | ||
pageIndex: tableStatePageIndex, | ||
sortBy: tableStateSortBy, | ||
filters: tableStateFilters, | ||
selectedRowIds: tableStateSelectedRowIds, | ||
} = instance.state; |
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.
These data are the same fields as were previously passed as arguments to fetchData
below, so it is not a breaking change from that perspective. This change was necessary to prevent the useEffect
that calls fetchData
below from calling when selections were being made and allows us to move away from the more risky/hacky delete
approach in the previous implementation.
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.
Also note, the original "controlled" selections implementation co-exists with this new approach. Need to sanity check that other uses of DataTable
selections relying on the original selections implementations won't break as a result of this change.
Long term, we'll probably want to move away from or otherwise deprecate the current selections strategy, where "controlled" selections are not really controlled.
|
||
useEffect(() => { | ||
if (onSelectedRowsChanged) { | ||
onSelectedRowsChanged(tableStateSelectedRowIds); |
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.
Inform the parent/consuming component that row selections were changed in some way.
@@ -134,6 +148,7 @@ function DataTable({ | |||
disableElevation, | |||
isLoading, | |||
isSelectable, | |||
manualSelectColumn, |
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 needed to be exposed in DataTableContext
for it to be accessible by the CardView
.
src/Skeleton/Skeleton.scss
Outdated
@@ -0,0 +1,3 @@ | |||
.react-loading-skeleton { | |||
z-index: unset; |
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.
react-loading-skeleton
puts z-index: 1
on their skeletons. This negatively impacted the shadow layering within a FullscreenModal
and Stepper
. Unsetting removes the styling from react-loading-skeleton
.
e4ce442
to
c2ef781
Compare
Codecov ReportBase: 90.74% // Head: 90.77% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #1804 +/- ##
==========================================
+ Coverage 90.74% 90.77% +0.03%
==========================================
Files 212 212
Lines 3726 3739 +13
Branches 876 882 +6
==========================================
+ Hits 3381 3394 +13
Misses 343 343
Partials 2 2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
e12c438
to
7bb44c3
Compare
// use the same component for card selection that is used for row selection | ||
// otherwise view switching might break if row selection uses component that supports backend filtering / sorting | ||
const selectionComponent = manualSelectColumn?.Cell || selectColumn.Cell; | ||
const SelectionComponent = manualSelectColumn?.Cell || selectColumn.Cell; |
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.
[curious]
Would rewriting the logic as const SelectionComponent = manualSelectColumn?.Cell || selectColumn?.Cell;
prevent non-loading page instances if selectColumn
happens to be undefined?
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.
@brobro10000 The selectColumn
variable (defined in getVisibleColumns
) is a constant, so it'll always exist :)
@@ -45,7 +45,7 @@ CardSection.propTypes = { | |||
/** Specifies class name to append to the base element. */ | |||
className: PropTypes.string, | |||
/** Specifies contents of the component. */ | |||
children: PropTypes.node.isRequired, | |||
children: PropTypes.node, |
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.
Love the built in spacers of the Card.Section
:)
🎉 This PR is included in version 20.21.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 21.0.0-alpha.12 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Description
DataTable
callsfetchData
as well as what data it passes in its arguments.children
optional forCard.Section
andCard.Footer
.CardView
; consumer may override the skeleton card component to use with theSkeletonCardComponent
prop toCardView
.onSelectedRowsChanged
prop toDataTable
as a way to inform parent/consuming components whenDataTable
selections has changed in some way (e.g., a row was selected/unselected).TableFooter
adheres to whetherRowStatus
is overridden by theRowStatusComponent
prop onDataTable
.Deploy Preview
https://deploy-preview-1804--paragon-openedx.netlify.app/components/card/
https://deploy-preview-1804--paragon-openedx.netlify.app/components/datatable/
Merge Checklist
example
app?wittjeff
andadamstankiewicz
as reviewers on this PR.Post-merge Checklist