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

Add debounce to query update #88

Merged
merged 15 commits into from
Jan 29, 2024
Merged

Conversation

TalMalka123
Copy link
Contributor

@TalMalka123 TalMalka123 commented Jan 25, 2024

Fix the issue with the toggle
Add debounce to onChange func
Fix the issue with infinite warnings on the Mui autocomplete- "value provided to Autocomplete is invalid"

@TalMalka123 TalMalka123 self-assigned this Jan 25, 2024
@TalMalka123 TalMalka123 requested a review from simonlsk January 25, 2024 10:45
Copy link
Contributor

@simonlsk simonlsk left a comment

Choose a reason for hiding this comment

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

Do another round of simplification if possible.
Maybe get rid of the redundant state of "forceSimpleMode".

Copy link
Contributor

@simonlsk simonlsk left a comment

Choose a reason for hiding this comment

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

LGTM in general.
I was thinking maybe to delegate the debounce to the text input component, WDYT?

checkIfConditionIsDisplayableInSimpleMode(queryInput.query)
);
const [isSimpleMode, setIsSimpleMode] = useState<boolean>(isDisplayableInSimpleMode);
Copy link
Contributor

Choose a reason for hiding this comment

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

useState hooks should be in the top of the hook, heres why:

https://legacy.reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level

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'm not sure I understand. My use-state hooks are at the top. Before them there are just functions that the state uses, so they must be defined before the state itself, for them to be recognized.
According to the article, it doesn't seem to break any rule cause there is no prior return statement within the component itself (unless I miss something), and the hooks are not within any function/condition.

@elad-n Let me know if I miss something, and what I need to do

function onToggleQueryMode() {
setIsSimpleMode(!isSimpleMode);
setIsSimpleMode((isSimpleMode) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
setIsSimpleMode((isSimpleMode) => {
setIsSimpleMode(!isSimpleMode)

I also didnt get the correlation between the isDisplayinSimpleMode / isSimpleMode. it cant be the same value ?

Copy link
Contributor Author

@TalMalka123 TalMalka123 Jan 29, 2024

Choose a reason for hiding this comment

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

@elad-n - Regarding your suggested change, @simonlsk told me that when I want to change the state, I should not use the variable from the state definition (ie. setBool(!bool)), but use the prev from the function instead, so there won't be race conditioning

@elad-n And regarding your question - isDisplayinSimpleMode just holds whether it is possible to switch the toggle to compound mode, but it doesn't say anything about the current query builder mode state, unlike isSimpleMode, which is the state itself. So they are not the same.

Copy link
Contributor

@simonlsk simonlsk Jan 29, 2024

Choose a reason for hiding this comment

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

In that case I think both will work correctly, but following the official docs using previous state is preferable if the set function can be called multiple times.
I personally prefer erring on the safe side an always use previous state.

}

useEffect(() => {
setMetadataFieldsList(metadataFields);
}, [metadataFields]);
setIsSimpleMode((isSimpleMode) => {
Copy link
Contributor

@elad-n elad-n Jan 28, 2024

Choose a reason for hiding this comment

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

Suggested change
setIsSimpleMode((isSimpleMode) => {
const updatedIsSimpleMode = isSimpleMode ? false : isDisplayableInSimpleMode)
setIsSimpleMode(updatedIsSimpleMode)

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 guess its the same comment like before: #88 (comment)

@TalMalka123 TalMalka123 merged commit 389e4ab into main Jan 29, 2024
3 checks 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.

3 participants