Skip to content
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

remove useEffect from state management in useDraggableTableControlled #3161

Merged

Conversation

christianvogt
Copy link
Contributor

https://issues.redhat.com/browse/RHOAIENG-12561

Description

useDraggableTableControlled was using useEffect to keep track of draggable items internally. While this was functional it would also lead to a double render whenever the incoming items array changed. The negative side effect of this is that the first render would supply data to the consumer that was stale until the next render. As a result, components which rely on object identity of the table items would be rendering against stale data until the new state was applied in the useEffect.

As noted in the linked issue, the connection type field would "blip" render an error icon indicating that the field's env var was a duplicate. The cause of this is because the check for duplicates would filter the given row data from the full set of table row data by object identity. Since the component was using stale data on the first render pass, the object identity check would fail until the 2nd pass.

The fix here is to eliminate the use of useEffect for setting state. The internal state is only required when dragging because it's a temporary state held by the hook until the drag completes.

How Has This Been Tested?

  • Create a new connection type
  • Create a field
  • Toggle the required switch and observe no error icon is rendered

To ensure the error icon still renders, create two fields with the same env var value.

  • Create multiple fields and test dragging them to reorder.
  • Save the connection type and edit it again
  • Ensure the order is maintained as previously dragged.

Test Impact

Tests already exist for testing drag.

Request review criteria:

Self checklist (all need to be checked):

  • The developer has manually tested the changes and verified that the changes work
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has added tests or explained why testing cannot be added (unit or cypress tests for related changes)

If you have UI changes:

  • Included any necessary screenshots or gifs if it was a UI change.
  • Included tags to the UX team if it was a UI/UX change.

After the PR is posted & before it merges:

  • The developer has tested their solution on a cluster by using the image produced by the PR to main

Copy link

codecov bot commented Sep 6, 2024

Codecov Report

Attention: Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.

Project coverage is 85.19%. Comparing base (575959e) to head (64b5a2b).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...ntend/src/utilities/useDraggableTableControlled.ts 92.30% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3161      +/-   ##
==========================================
+ Coverage   85.18%   85.19%   +0.01%     
==========================================
  Files        1253     1253              
  Lines       27539    27542       +3     
  Branches     7335     7336       +1     
==========================================
+ Hits        23458    23465       +7     
+ Misses       4081     4077       -4     
Files with missing lines Coverage Δ
...ntend/src/utilities/useDraggableTableControlled.ts 80.23% <92.30%> (-0.50%) ⬇️

... and 4 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 575959e...64b5a2b. Read the comment docs.

@emilys314
Copy link
Contributor

The code looks good. I also tested the image and the table and the dropdown items both worked correctly

@emilys314
Copy link
Contributor

/lgtm

Copy link
Contributor

openshift-ci bot commented Sep 6, 2024

[APPROVALNOTIFIER] This PR is APPROVED

Approval requirements bypassed by manually added approval.

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit 7813220 into opendatahub-io:main Sep 6, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants