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

hide internal labels from UI #18638

Merged
merged 15 commits into from
Dec 6, 2022
Merged

hide internal labels from UI #18638

merged 15 commits into from
Dec 6, 2022

Conversation

sielakos
Copy link
Contributor

@sielakos sielakos commented Nov 21, 2022

lib/web/ui/app.go Outdated Show resolved Hide resolved
@zmb3 zmb3 changed the title hide labels from UI hide internal labels from UI Nov 21, 2022
lib/web/ui/server.go Outdated Show resolved Hide resolved
Comment on lines 71 to 74
for name, value := range teleApp.GetAllLabels() {
if strings.HasPrefix(name, "teleport.internal/") {
continue
}
Copy link
Contributor

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.

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 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.

Copy link
Contributor Author

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.

  1. transforming from maps to slice
  2. filtering
  3. 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.

lib/web/ui/app.go Outdated Show resolved Hide resolved
@codingllama
Copy link
Contributor

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.)

@codingllama codingllama removed their request for review November 24, 2022 18:31
lib/web/ui/labels.go Outdated Show resolved Hide resolved
api/types/constants.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@r0mant r0mant left a 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

api/types/constants.go Outdated Show resolved Hide resolved
lib/web/ui/labels.go Show resolved Hide resolved
@sielakos sielakos merged commit f0dbc34 into master Dec 6, 2022
@sielakos sielakos deleted the mariusz/hide-labels branch December 6, 2022 08:01
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.

Hide teleport.internal labels from the UI
5 participants