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

feat(query-bar): allow users to set the default sort to be recent first COMPASS-6706 #6663

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

djechlin-mongodb
Copy link
Contributor

Description

Checklist

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 Jan 28, 2025
/**
* Set the default sort.
*/
showRecentDocumentsFirst: {
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 how in progress this PR is, but just in case, this doesn't seem to match the ticket. Latest design show a dropdown with three choices, not a boolean option

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep it's the dropdown now

@@ -199,6 +208,8 @@ type PreferenceDefinition<K extends keyof AllPreferences> = {
? boolean
: false
: boolean;

selectableValues?: ReadonlyArray<{ value: string; label: string }>;
Copy link
Collaborator

@gribnoysup gribnoysup Jan 30, 2025

Choose a reason for hiding this comment

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

I don't think you need a separate prop to keep values around, this is also disconnected from the actual type which can end up in issues. You already defined them in the schema validator and they can be extracted from validator if needed (something your get settings method can use):

var a = z.enum(['foo', 'bar']);
a.options // ['foo', 'bar']

I like the idea of storing option descriptions here, we already do this for property descriptions so it fits near. I think we can make this type stricter to make sure you're only providing labels for existing expected values:

optionDescription?: AllPreferences[K] extends string ? { [k in AllPreferences[K]]: string } : never;

(maybe even integrate it into exiting description field)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • options is up to the description now
  • I'm hardcoding the dropdown that it's for defaultSortOrder and pulling in the array directly. I guess you can unpack it from the validator. This feels a little complicated in a way, like are you supposed to be having the validator pulled into the settings? And the type math is hard to pass the validator around. And there wasn't a lot gained from slightly less direct data access.

I'm a little interested in fully data-driving the setting but there seems to be something genuinely tricky about having these things compile-time forced to be equal:

  • the dropdown options
  • the legal options via the union type
  • the validator options

I'm also new-ish to zod and this level of type validation so maybe it's easier than I think? Let me know if I should take another look at getting the types through the validator.

@djechlin-mongodb djechlin-mongodb marked this pull request as ready for review January 30, 2025 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants