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

fixes #1589: debounce and read snackbar for assignment planning #1623

Conversation

jaydonkrooss
Copy link
Contributor

@jaydonkrooss jaydonkrooss commented Sep 13, 2024

Use the debounce package to delay opening the snackbar, also modify the snackbar component to alert screen readers instead of being hidden previously.

@jaydonkrooss jaydonkrooss self-assigned this Sep 13, 2024
@zqian zqian linked an issue Sep 16, 2024 that may be closed by this pull request
@jaydonkrooss jaydonkrooss marked this pull request as ready for review September 16, 2024 17:06
@pushyamig
Copy link
Contributor

pushyamig commented Sep 16, 2024

One usecase to test is the change of events like setting a Mini course goal, individual assignment goal, lock goal etc Is being logged in the backend with eventlog_logand only once. Since this change GraphiQL mutation API, so we want to make that is functional as well

I did not test this, but that is the important usecase to test.

@@ -13,22 +14,27 @@ function UserSettingSnackbar (props) {
saved,
response,
successMessage = 'Setting saved successfully!',
failureMessage = 'Setting not saved.'
failureMessage = 'Setting not saved.',
debounceAmount = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment the purpose of this variable?

Copy link
Member

Choose a reason for hiding this comment

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

same question. Not sure why we need this debounceAmount param.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a new comment to clarify in the new version of this file. There are other areas of the app that use this snackbar that we don't want to add a debounce to, at least for this issue. For instance, the grade filter setting for the resources accessed page triggers the snackbar. I've left it customizable for the future in case other pages would like a debounce

@@ -32,7 +32,7 @@ function AssignmentGoalInput (props) {
} = props

const [goalGradeInternal, setGoalGradeInternal] = useState(goalGrade)
const debouncedGoalGrade = useRef(debounce(q => setGoalGrade(q), 500)).current
const debouncedGoalGrade = useRef(debounce(q => setGoalGrade(q), 250)).current
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was the number reduced?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I added a long debounce to the snackbar, the duration of this save would stack on top of the duration for the snackbar pop up. It felt quite long compared to other inputs on the page, so I reduced this debounce amount. I didn't consider if there was any drawback to lowering this, other than the visualizations and input amounts rendering slightly faster

Copy link
Contributor

Choose a reason for hiding this comment

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

If it improve overall objective of the view that it is fine

@@ -293,6 +293,7 @@ function AssignmentPlanningV2 (props) {
<UserSettingSnackbar
saved={!mutationError && !mutationLoading && settingChanged}
response={{ default: 'success' }}
debounceAmount={750}
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

This is milli second i suppose? why is this number chosen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not much thought went into it other than to add a buffer approximately around the duration of the other debounced input we had (originally 500ms). I ran it by @gsilver, and the 500-1000ms option seemed to be a good range. I'm also open to other guidance on this (and we can customize it later)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think 750 seems fine, I just want to understand the reason.

Copy link
Contributor

@pushyamig pushyamig left a comment

Choose a reason for hiding this comment

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

I have left minor comment for documenting. The Review is pre-approved by @gsilver and I have tested i locally. I see the logging is working as expected

@zqian
Copy link
Member

zqian commented Sep 16, 2024

To Pushyami's comment "One usecase to test is the change of events like setting a Mini course goal, individual assignment goal, lock goal etc Is being logged in the backend with eventlog_logand only once. Since this change GraphiQL mutation API, so we want to make that is functional as well"

I have verified the event log count is equal to the snack bar appearance. So if I updated the goal multiple times within the 750 ms, I see only one snack bar and only one new event log record.

Copy link
Member

@zqian zqian left a comment

Choose a reason for hiding this comment

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

I have tested the PR on localhost. It passes the test cases. I left a minor comment.

@@ -13,22 +14,27 @@ function UserSettingSnackbar (props) {
saved,
response,
successMessage = 'Setting saved successfully!',
failureMessage = 'Setting not saved.'
failureMessage = 'Setting not saved.',
debounceAmount = 0
Copy link
Member

Choose a reason for hiding this comment

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

same question. Not sure why we need this debounceAmount param.

@jaydonkrooss jaydonkrooss merged commit 6307829 into tl-its-umich-edu:master Sep 17, 2024
1 check passed
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.

Snack bar fires visually whenever a value changes.
3 participants