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

STCOM-1319 Selection - consolidate/reduce onChange calls #2322

Merged
merged 1 commit into from
Jul 12, 2024
Merged

Conversation

JohnC-80
Copy link
Contributor

@JohnC-80 JohnC-80 commented Jul 12, 2024

Since the implemenation for handling value props from outside of the component, we notice instances of onChange handlers happening multiple times as per STCOM-1319 where a query search will remain intact after resetAll is pressed once. This was due to a new render cycle happening even prior to the updated state of the component landing. In class-based react implementation, we had a callback for setState so that we could run logic in a space where we were assured that state had updated. It's possible for us to write a hook that could accomplish something like, but I decided to try and revisit the usage of downshift's state within the component, and if we could solely rely on that state, we could consolidate the onChange calls within its handler.

I destructured two new pieces from downshift's result, using their selectedItem and their update function selectItem - which I renamed to updateSelectedItem just to suit convention. I replaced our own state with this, and used the updateSelectedItem to update the selection when the value prop updates, so that all possible ways for the value to change will pass through downshift state handling/callback. Additionally, I checked the new selected item from state didn't match the provided value prop before calling onChange, limiting the onChange calls.

It's still important to track internal changes until the selected value comes back as the value prop, so the sentinel value awaitingChange is still necessary, but depending on downshift's state versus our own allows the chosenItem ref to be removed.

The useEffect for updating when dataOptions are updated was moved after the useCombobox hook so that it could observe the selectedItem from the hook.

Copy link

github-actions bot commented Jul 12, 2024

Jest Unit Test Statistics

0 tests  ±0   0 ✔️ ±0   0s ⏱️ ±0s
0 suites ±0   0 💤 ±0 
0 files   ±0   0 ±0 

Results for commit 4e971b3. ± Comparison against base commit f9b8805.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Jul 12, 2024

BigTest Unit Test Statistics

       1 files  ±0         1 suites  ±0   13s ⏱️ ±0s
1 477 tests +1  1 469 ✔️ +1  8 💤 ±0  0 ±0 
1 479 runs  +1  1 471 ✔️ +1  8 💤 ±0  0 ±0 

Results for commit 4e971b3. ± Comparison against base commit f9b8805.

♻️ This comment has been updated with latest results.

Copy link

sonarcloud bot commented Jul 12, 2024

@JohnC-80 JohnC-80 requested a review from vashjs July 12, 2024 19:38
@JohnC-80 JohnC-80 merged commit 32ab3da into master Jul 12, 2024
6 checks passed
@JohnC-80 JohnC-80 deleted the STCOM-1319 branch July 12, 2024 19:53
github-actions bot pushed a commit that referenced this pull request Jul 12, 2024
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.

1 participant