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

🐛 Shows client side loading state for jira tracker #1409

Merged
merged 5 commits into from
Oct 5, 2023

Conversation

ibolton336
Copy link
Member

@ibolton336 ibolton336 changed the title 🐛 Shows client side loading state to allow backend time to connec… 🐛 Shows client side loading state for jira tracker Sep 27, 2023
@codecov
Copy link

codecov bot commented Sep 27, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (7690380) 41.07% compared to head (03e0c4b) 41.07%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1409   +/-   ##
=======================================
  Coverage   41.07%   41.07%           
=======================================
  Files         139      139           
  Lines        4404     4404           
  Branches     1010     1010           
=======================================
  Hits         1809     1809           
  Misses       2583     2583           
  Partials       12       12           
Flag Coverage Δ
client 41.07% <ø> (ø)
server ∅ <ø> (∅)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sjd78 sjd78 self-requested a review September 29, 2023 21:01
Copy link
Member

@sjd78 sjd78 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind the artificial spinner after kicking off the create or update.

The hook should be able to cancel the timers that are set. So maybe change the setUpdatingTrackerId() to addUpdatingTrackerId() and adjust a few calls?

connected={tracker.connected}
message={tracker.message}
/>
{updatingTrackerId === tracker.id ? (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be "the most recently updated/created tracker". Might want to track an array of tracker ids just to be sure that you get a spinner on multiple trackers if they're both edited very close together.

Maybe a Set would work better? But then since a Set is mutable, getting useState() to track changes would be a bit of a challenge. Some stackoverflow discussion: https://stackoverflow.com/questions/58806883/how-to-use-set-with-reacts-usestate

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converted to use a set internal to the hook but exported the readonly state as an array. Interesting on the mutable workaround. Updated the hook to use the approach you linked.

client/src/app/pages/external/jira/tracker-form.tsx Outdated Show resolved Hide resolved
client/src/app/pages/external/jira/tracker-form.tsx Outdated Show resolved Hide resolved
client/src/app/pages/external/jira/tracker-form.tsx Outdated Show resolved Hide resolved
Copy link
Member

@sjd78 sjd78 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested this yet, but I'm not sure updating 2 trackers will show 2 spinners.

Comment on lines 267 to 275
{updatingTrackerIds.includes(tracker.id) ? (
<Spinner size="sm" />
) : (
<TrackerStatus
name={tracker.name}
connected={tracker.connected}
message={tracker.message}
/>
)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind this setup, but you could push the spinner in to TrackerStatus and just set a prop isTrackerUpdating={updatingTrackerIds.includes(tracker.id)}. That way, all of the render code for the column is in a single component.

Comment on lines 13 to 48
if (updatingTrackerIds.size > 0) {
timerId = window.setTimeout(() => {
setUpdatingTrackerIds(new Set());
}, delay);
}

return () => {
if (timerId !== null) {
window.clearTimeout(timerId);
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work if you updated 2 trackers within the 10 second interval?

The addUpdatingTrackerId function looks right, but the removal of the ids seems off since I don't see something like new Set(prevSet.remove(expiredId)).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is actually working because on refetch this hook is remounted / cleaned up. Only works because we are routinely polling for trackers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see what you mean. The entire set is wiped when one timeout expires. Fixing.

… instance

Signed-off-by: ibolton336 <ibolton@redhat.com>
Signed-off-by: ibolton336 <ibolton@redhat.com>
@ibolton336 ibolton336 force-pushed the mta-1019 branch 2 times, most recently from eab8b43 to 07c96b1 Compare October 5, 2023 15:22
Copy link
Member

@sjd78 sjd78 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hook is a bit confusing but looks like it'll be ok. Everything else LGTM.

client/src/app/pages/external/jira/trackers.tsx Outdated Show resolved Hide resolved
Signed-off-by: ibolton336 <ibolton@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants