-
Notifications
You must be signed in to change notification settings - Fork 20
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
Namespace selector #352
Namespace selector #352
Conversation
@@ -51,3 +53,12 @@ func (r NamespaceRepository) GetByCode(ctx context.Context, code string) (*model | |||
} | |||
return &namespace, nil | |||
} | |||
|
|||
// ListNamespaces returns a list of all namespaces. | |||
func (r NamespaceRepository) ListNamespaces(ctx context.Context) ([]models.Namespace, error) { |
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.
What do we think of the stuttering implied by this naming convention, ie "namespaces" appearing twice: namespaceRepository.ListNamespaces. Maybe #List would be clear enough and shorter?
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.
Yep!
} | ||
} | ||
|
||
func (r Router) AddRoutes(fr fiber.Router) { |
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.
can you please add comments for all public methods?
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.
Yes!
} | ||
} | ||
|
||
func (r Router) AddRoutes(fr fiber.Router) { | ||
sub, _ := fs.Sub(content, "embed") |
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 think we just skip error
checking here, if so, can you please check it properly and return error to caller?
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.
as I commented below, this cannot give an error as it just wouldn't build if there was no "embed" top directory
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 I think we should keep skipping the error so we don't complicate the code further
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.
sorry for the flip-flop @fabiovincenzi!
@@ -22,5 +22,9 @@ func NewService( | |||
} | |||
|
|||
func (s Service) ListNamespaces(ctx context.Context) ([]models.Namespace, error) { |
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.
it is pretty simple now but we can create a unit
tests here. what do you think?
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.
yep, I'll do it
pkg/ui/chooser/routes.go
Outdated
Root: http.FS(sub), | ||
})) | ||
// engine and app for template rendering | ||
engine := html.NewFileSystem(http.FS(sub), ".html") |
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.
can we put initialisation right into:
app := fiber.New(fiber.Config{
Views: html.NewFileSystem(http.FS(sub), ".html"),
})
@@ -16,6 +16,8 @@ type NamespaceRepositoryProvider interface { | |||
Create(ctx context.Context, namespace *models.Namespace) error | |||
// GetByCode returns namespace by its Code. | |||
GetByCode(ctx context.Context, code string) (*models.Namespace, error) | |||
// ListNamespaces returns all the namespaces | |||
ListNamespaces(ctx context.Context) ([]models.Namespace, error) |
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.
yep, we can simplify it to be just List
.
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.
Looks good for me. but will be nice to have other eyes on that. @jgiannuzzi
func (s Service) ListNamespaces(ctx context.Context) ([]models.Namespace, error) { | ||
return nil, nil | ||
namespaces, err := s.namespaceRepository.List(ctx) |
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.
we should just return here
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.
this is probably something old. maybe It seems like I left it after my tests. yep, please remove. fresh branches have no such change.
pkg/ui/chooser/embed/index.html
Outdated
<ul id="namespaces-list"> | ||
{{ range .Data }} | ||
<li> | ||
<a href="#" onclick="window.location = (window.location.origin + {{if eq .Code "default"}}'/'{{else}}'/ns/{{.Code}}/'{{end}});">{{.Code}}</a> |
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.
the link text should be the namespace description, not its code
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.
please make the onclick
JS syntax consistent between all the links — we don't use parenthesis or semicolons above
it's fine to change it, but then change it everywhere
pkg/ui/chooser/embed/index.html
Outdated
|
||
<script> | ||
function setCurrentNamespace() { | ||
var currentUrl = window.location.href; | ||
var namespaceIndex = currentUrl.indexOf('/ns/'); | ||
var namespaceText = document.getElementById('selected-namespace') | ||
if (namespaceIndex !== -1) { | ||
namespaceText.innerText = "Selected Namespace: " + currentUrl.substring(namespaceIndex + 4).slice(0, -1); | ||
} else { | ||
namespaceText.innerText = "Selected Namespace: default" | ||
} | ||
} | ||
|
||
window.onload = setCurrentNamespace; | ||
</script> |
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.
we know the selected namespace when this page gets rendered in the backend, please use that instead
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.
How do we know the selected namespace from the backend?
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.
by using namespace.GetNamespaceFromContext
like we do in every controller
pkg/ui/chooser/routes.go
Outdated
sub, err := fs.Sub(content, "embed") | ||
if err != nil { | ||
return err | ||
} |
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.
this cannot give an error as it just wouldn't build if there was no "embed" top directory
pkg/ui/chooser/routes.go
Outdated
// app for template rendering | ||
app := fiber.New(fiber.Config{ | ||
Views: html.NewFileSystem(http.FS(sub), ".html"), | ||
}) | ||
fr.Mount("/", app) | ||
|
||
// specific routes | ||
app.Get("/", r.controller.GetNamespaces) | ||
|
||
// default route | ||
app.Use("/", etag.New(), filesystem.New(filesystem.Config{ | ||
Root: http.FS( | ||
common.NewOnlyRootFS(sub, "index.html"), | ||
), | ||
})) | ||
return nil |
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.
there is an overlap between these various routes and the last one does not get used
5842bca
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.
please add this provider to .mockery.yaml
pkg/ui/chooser/embed/index.html
Outdated
|
||
<script> | ||
function setCurrentNamespace() { | ||
var currentUrl = window.location.href; | ||
var namespaceIndex = currentUrl.indexOf('/ns/'); | ||
var namespaceText = document.getElementById('selected-namespace') | ||
if (namespaceIndex !== -1) { | ||
namespaceText.innerText = "Selected Namespace: " + currentUrl.substring(namespaceIndex + 4).slice(0, -1); | ||
} else { | ||
namespaceText.innerText = "Selected Namespace: default" | ||
} | ||
} | ||
|
||
window.onload = setCurrentNamespace; | ||
</script> |
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.
by using namespace.GetNamespaceFromContext
like we do in every controller
future improvement ideas:
|
This PR is a collaborative effort between @dsuhinin, @fabiovincenzi, @suprjinx, and @jgiannuzzi. It incorporates the following PRs: * #340 * #391 * #397 * #352 * #402 * #421 * #420 * #395 * #454 * #275 --------- Co-authored-by: dsuhinin <7852635+dsuhinin@users.noreply.github.com> Co-authored-by: fabiovincenzi <93596376+fabiovincenzi@users.noreply.github.com> Co-authored-by: Geoffrey Wilson <geoff@gr-oss.io>
This PR is a collaborative effort between @dsuhinin, @fabiovincenzi, @suprjinx, and @jgiannuzzi. It incorporates the following PRs: * G-Research#340 * G-Research#391 * G-Research#397 * G-Research#352 * G-Research#402 * G-Research#421 * G-Research#420 * G-Research#395 * G-Research#454 * G-Research#275 --------- Co-authored-by: dsuhinin <7852635+dsuhinin@users.noreply.github.com> Co-authored-by: fabiovincenzi <93596376+fabiovincenzi@users.noreply.github.com> Co-authored-by: Geoffrey Wilson <geoff@gr-oss.io>
fixes #202