Skip to content

feat: Fix the state management for the two flows (disabled state, displaying covered queries) CLOUDP-325467 #7036

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 16 commits into from
Jun 18, 2025

Conversation

rubydong
Copy link
Collaborator

@rubydong rubydong commented Jun 18, 2025

Description

  • Moved a lot of the logic to redux to keep track of state management since the states were not maintained properly between the two flows.
  • The button for suggested index was not maintained between switching
  • Covered queries example and the covered queries button states were also not maintained
Screen.Recording.2025-06-17.at.9.48.19.PM.mov

https://jira.mongodb.org/browse/CLOUDP-325467

Checklist

  • New tests and/or benchmarks are included
  • Documentation is changed or added
  • If this change updates the UI, screenshots/videos are added and a design review is requested
  • I have signed the MongoDB Contributor License Agreement (https://www.mongodb.com/legal/contributor-agreement)

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Open Questions

Dependents

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

@github-actions github-actions bot added the feat label Jun 18, 2025
@rubydong rubydong added no release notes Fix or feature not for release notes labels Jun 18, 2025
@rubydong rubydong marked this pull request as ready for review June 18, 2025 04:36
@rubydong rubydong requested a review from a team as a code owner June 18, 2025 04:36
}, []);
const handleQueryInputChange = useCallback(
(text: string) => {
onQueryUpdated({ query: text, hasQueryChanges: true });
Copy link
Collaborator

@gribnoysup gribnoysup Jun 18, 2025

Choose a reason for hiding this comment

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

I mentioned a few times, with redux you really want your reducer and action types to be the driver of the logic, sort of (sorry, it's a bit vague). So the actual driver for this value changing is the fact of the action itself, query changed by the user so hasQueryChanges is now true, right? And so reducer can set it to true when it's reacting to the query updated action, it doesn't need to be passed as an argument. You can think about this also from this perspective: does it ever make sense to dispatch this action and have hasQueryChanges be set to false? As far as I can see it should never be the case, so shouldn't be something that action calls is driving

Comment on lines +786 to +787
// get it from the current query or initial query from insights nudge
query: state.query || parsedInitialQuery,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure, but shouldn't parsedInitialQuery take precedence here? Like if something triggered opening a modal with a new query, it should replace whatever we had in the state before?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i believe state.query should take priority because user can end up changing the query. parsedInitialQuery is only relevant when opening from the nudge so in that case state.query would be '' anyway

collectionName: string;
inputQuery: string;
}): IndexesThunkAction<
query,
Copy link
Collaborator

@gribnoysup gribnoysup Jun 18, 2025

Choose a reason for hiding this comment

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

Not that important, but even this value you have in the state, so it can be removed from the arguments here if you want to make the interface even more enclosed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i'll keep it because i dont think that the one in state is the most updated one

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is always the most updated just by the nature of how redux works (and if it's not we're in trouble) 🙂 In case where you dispatch it inside the open thunk action, the previous action dispatch sets it in the store. In the UI where user dispatches it by clicking a button, it's always synced to store with queryUpdated action. Just FYI to understand the flow better

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh wait yeah you're right i got it confused with something el se. but in this case:
query: JSON.stringify(initialQuery, null, 2) || '',

we are passing in the initialQuery instead of the query so maybe good to have it for distinction?

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's kinda fair! You can look at it from different perspectives, I'd say from my perspective that the action is something that always fetches suggestions for the current query in the input, this also matches your open action handling logic in the reducer that sets initial query as both initial and current query in the state. But as I mentioned, having it as an argument also makes sense

@rubydong rubydong merged commit c58db3c into main Jun 18, 2025
51 of 53 checks passed
@rubydong rubydong deleted the cloudp-325467 branch June 18, 2025 17:11
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
feat no release notes Fix or feature not for release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants