-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
hide internal labels from UI #18638
hide internal labels from UI #18638
Conversation
8fc1c0f
to
309497b
Compare
lib/web/ui/app.go
Outdated
for name, value := range teleApp.GetAllLabels() { | ||
if strings.HasPrefix(name, "teleport.internal/") { | ||
continue | ||
} |
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.
Instead of repeating the same filtering logic in all locations and writing tests for each, why not create a function that removes labels from the map returned by GetAllLabels
? That way we'd only need to test the new function rather than adding tests for all the places that require this logic.
func removeHiddenLabels(m map[string]string) map[string]string {
for name := range m {
if strings.HasPrefix(name, "teleport.internal/") {
delete(m, name)
}
}
return m // return map so it can be used directly in for loops
}
// ... then
for name, value := range removeHiddenLabels(teleApp.GetAllLabels()) {
This would isolate all testing to this new func - no need to test all places where the labels are hidden. Also makes it much easier to add new scenarios for hidden labels.
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 that function would be good, I could go even deeper because there is no need to repeat logic appending Labels to slice. It looks exactly the same everywhere.
About tests, I actually would like to keep them. I would even love to add more unit tests for those functions, as they are not tested that way. Unless there is a reason not to.
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.
So with a bit of refactoring, I have added makeLabels
function that does all the repetitive stuff related to labels.
- transforming from maps to slice
- filtering
- sorting
I have also added tests for this function.
All that taken into account I would actually like to leave tests for MakeServers
etc. as they are. If for no other reason than just to test that makeLabels
is used.
You've got a healthy number of active reviewers already, so I'm sitting this one out. (Feel free to re-add me if you need an extra pair of eyes.) |
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.
lgtm after remaining comments are addressed
Closes gravitational/webapps#1081