-
Notifications
You must be signed in to change notification settings - Fork 9
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
Uxd 1984 Data Table updates on data change #1233
Conversation
🦋 Changeset detectedLatest commit: 875d358 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
width: ${`${width}px`}; | ||
${fontSize()} | ||
|
||
overflow: ${hasInfiniteLoader ? `hidden;` : `auto;`} |
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.
ensures the vertical scroll bar is showing when data changes and rendering without the hasInfiniteLoader
sub component
const clearRowHeights = React.useCallback( | ||
(indexes: number[]) => indexes.forEach(index => delete rowHeights.current[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.
only re-evaluating the data row heights for rows that have changed
} | ||
} | ||
prevData.current = data; | ||
isLoadingMoreItemsRef.current = 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.
Ensuring there are not unnecessary calculations being done when additional rows are being added by using this flag when necessary
if (changedIndexes.length > 0) { | ||
clearRowHeights(changedIndexes); | ||
listRef.current.resetAfterIndex(changedIndexes[0]); | ||
setTimeout(resetDimension, 0); |
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.
Finding i've had to use setTimeout here to ensure the resize gets applied after the react table has finished resetting, I don't see a way to avoid it
listRef.current.resetAfterIndex(changedIndexes[0]); | ||
setTimeout(resetDimension, 0); | ||
} else if (data.length !== prevData.current.length) { | ||
resetDimension(); |
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.
Originally I only call this if the height
of the table is less that then maxHeight
(as that is when it should only need to be called), however I discovered a bug (detailed in description) where the height of the react-table isn't always evaluated the same how is is rendered (Issue will be added)
@@ -72,5 +72,5 @@ export default function useBestTableDimensions({ | |||
resize: resetDimension, | |||
})); | |||
|
|||
return dimensions; | |||
return { dimensions, resetDimension }; |
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.
Since we're adding exports here, maybe we can move shouldResizeWithViewport
out, so like { dimensions, resetDimension, shouldResizeWithViewport }
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.
Well the shouldResizeWithViewport
prop value is passed into this hook in dataTable.tsx
. I'm not sure why we would want to expose it here as it is already available in that component. Can you expand?
isItemLoaded={index => items[index] !== undefined} | ||
loadMoreItems={async () => { | ||
console.log("callign loadmore items"); | ||
// do nothing |
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.
Loading more items is kind of a data change event as well, can we enable it here?
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.
Well this story is about the data data
object changing outside of the dataComponent. The loadMoreItems
call is only triggered when the user scrolls down the table and a call to get new items can be made so isn't quite the same scenario, so I'm not sure there would be value adapting this.
if (!isEqual(row, data[index])) { | ||
changedIndexes.push(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 just feel these calculations are quite expensive, e.g. the data from the data[index]
might not always be useful. Some columns might be hidden, but the data for those columns are still in the data object passed into DataTable.
Another example is, let's say only the data of row number 2 is changed, but since we have 200 rows, we still need to check if the data for row number 3 - row number 200 have been changed
So I'd still prefer using useImperativeHandle
to let the consumer decide which indexes
they updated, or from which index
the data are newly updated. Open for discussions!
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.
Yes, It is expensive but my thoughts are if we don't do it here we will still need to evaluate which indexes have changed in the consumer. I would have thought letting the dataTable deal with that would be easier for developers using it.
Added an issue for the height bug as mentioned in the description here |
Purpose 🚀
Currently when the source data prop of a table changes:
a) A dataTable without the Infinite loader sub component will not show a vertical scrollbar
b) A dataTable with the Infinite loader will not evaluate the correct row heights, making long text strings get cut off.
This pr is a proposal to have the dataTable update when data changes and
This pr ensures that DataTable resizes and re-renders correctly when the source data is changed.
Note
Additionally discovered a bug which i'll create an issue for-
On the Data change story
Click "Add Item" button three times
Then click "Save"
The DataTable with InfiniteLoader renders with a vertical scrollbar even though it is below the
maxHeight
value.Notes ✏️
details of code change / secondary purposes of this PR
Updates 📦
If you have changed a component's source code (not stories, specs, or docs), before merging your branch run
yarn changeset
. This will prompt you to:Storybook 📕
http://storybooks.highbond-s3.com/paprika/your-branch-name
Screenshots 📸
optional but highly recommended
References 🔗
relevant Jira ticket / GitHub issues