-
Notifications
You must be signed in to change notification settings - Fork 42
Variables: Add natural sort from core grafana to query variables #459
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
Conversation
} else if (sortType === 4) { | ||
// Sort by natural sort | ||
options.sort((a, b) => { | ||
if (!a.text) { | ||
return -1; | ||
} | ||
|
||
if (!b.text) { | ||
return 1; | ||
} | ||
|
||
return a.text.localeCompare(b.text, undefined, { numeric: true }); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const sortType = Math.ceil(sortOrder / 2);
and these if statements are pure cryptic gold, can we switch to using the enum VariableSort (and switch/case statement)? (you will have to add a //@ts-expect-error for the newly added enum that, add a TODO for that so we can find it and remove the ts-expect-error when we update the schema package in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with that, it's confusing , I will do the changes 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@torkelo I did the refactor, but I couldn't find a way to avoid hardcoding the value of the new options. Also, there is some //ts-ignore
around because options is any[]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Do much easier to read and understand now!!
🚀 PR was released in |
In core grafana we received a community contribution to implement natural sort. grafana/grafana#78024
This PR just adds their changes and a few unit tests.