-
Notifications
You must be signed in to change notification settings - Fork 45
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
Table
: Multi-select bug which removes selected rows when model updates (HDS-4273)
#2650
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
||
if (rowToDeleteIndex > -1) { | ||
this._selectableRows.splice(rowToDeleteIndex, 1); | ||
} |
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 fixes what seems to be the actual problem. Would appreciate feedback though. (I'll clean up all the messy commented out & test code later.)
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
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.
Thanks, I updated the code.
I was wondering though if it's an issue if the new model has a different number of rows or different keys or something. I added another example to the Showcase page to test this and it doesn't work correctly but I don't know if it's an actual realistic concern.
9b18894
to
25aa431
Compare
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.
@KristinLBradley I added a few thoughts/comments, but I want to double check with @DingoEatingFuzz if I'm understanding correctly the problem (I may be missing something).
|
||
if (rowToDeleteIndex > -1) { | ||
this._selectableRows.splice(rowToDeleteIndex, 1); | ||
} |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
@KristinLBradley @alex-ju I had a quick call with @DingoEatingFuzz (thanks 🙏) to see if I was understanding correctly the problem and if the solution(s) proposed are be what he would expect to see, as a "consumer" of HDS. A few points below, to summarize what we discussed:
I'll leave it to him chime in, in case I've forgotten/misinterpreted something, or if he wants to add more context or his point og view as HDS "consumer". |
Re. the problem of the loss of the checkbox state when the model is updated but there is no |
This comment was marked as duplicate.
This comment was marked as duplicate.
…add default value for identityKey
Co-authored-by: Cristiano Rastelli <[email protected]>
…fter model update, add example of updating model with fewer rows, refactor Table component code to update rows instead of deleting duplicates
0f5ff78
to
e0460c1
Compare
@didoo @alex-ju + cc @DingoEatingFuzz Removing the duplicate row seems to work as long as there is a one to one correspondance between the new rows and the old rows. But it breaks if there are a different number of rows and/or key changes. So can we be certain that the rows won't change between model updates? |
@didoo In addition to the current code changes, we could also update the documentation to mention that if you want the state of the checkboxes to persist after the model updates, you'll need to add an identityKey. Do you think this the current changes together with updating the docs would be enough to address the main problem? |
@KristinLBradley I've played quite some time with the code yesterday, and I wasn't able to find an OK solution. The root of the problem is the timing of
Yes, this is something that I would do anyway, independently from this ticket/task, that is meant to fix the case for when the consumer is not adding the
See my comments above. |
How is this? I opened a PR: #2667 |
📌 Summary
If merged, this PR fixes the issue with selectableRows state not being maintained properly after model update.
(NOTE: Initial commits include test code from Michael Lange which will be removed before merge.)
👉 See related PR to update docs for multi select table used with a model.
🛠️ Detailed description
TODO: Add/update related tests.
PREVIEW: https://hds-showcase-git-hds-4273-table-multi-select-bug-hashicorp.vercel.app/components/table-multi-select-bug
Bug: Originally, clicking "Force new data" button in the first example wiped out the selectableRows array due to timing of didInsert & willDestroy calls.
Expected: SelectableRows array should have the proper set of checkbox items after model update and willDestroy calls finish.
🔗 External links
👀 Component checklist
💬 Please consider using conventional comments when reviewing this PR.