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

Namespace selector #352

Merged
merged 15 commits into from
Sep 27, 2023

Conversation

fabiovincenzi
Copy link
Collaborator

fixes #202

@fabiovincenzi fabiovincenzi linked an issue Sep 20, 2023 that may be closed by this pull request
2 tasks
@fabiovincenzi fabiovincenzi marked this pull request as ready for review September 20, 2023 11:38
@@ -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) {

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?

Copy link
Collaborator Author

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) {
Copy link
Collaborator

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?

Copy link
Collaborator Author

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")
Copy link
Collaborator

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?

Copy link
Member

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

Copy link
Member

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

Copy link
Member

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) {
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

Root: http.FS(sub),
}))
// engine and app for template rendering
engine := html.NewFileSystem(http.FS(sub), ".html")
Copy link
Collaborator

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)
Copy link
Collaborator

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.

dsuhinin
dsuhinin previously approved these changes Sep 21, 2023
Copy link
Collaborator

@dsuhinin dsuhinin left a 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)
Copy link
Member

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

Copy link
Collaborator

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.

<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>
Copy link
Member

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

Copy link
Member

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

Comment on lines 79 to 93

<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>
Copy link
Member

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

Copy link
Collaborator Author

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?

Copy link
Member

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

Comment on lines 34 to 37
sub, err := fs.Sub(content, "embed")
if err != nil {
return err
}
Copy link
Member

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

Comment on lines 43 to 58
// 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
Copy link
Member

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

Copy link
Member

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

Comment on lines 79 to 93

<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>
Copy link
Member

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

@jgiannuzzi
Copy link
Member

future improvement ideas:

  • show the active namespace in the top right corner
  • when this gets clicked, show the list of namespaces
  • (maybe) when there is only one namespace, don't display any namespace-related stuff

@jgiannuzzi jgiannuzzi merged commit 9ecd985 into G-Research:features/namespaces Sep 27, 2023
jgiannuzzi added a commit that referenced this pull request Oct 16, 2023
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>
suprjinx added a commit to suprjinx/fasttrackml that referenced this pull request Oct 23, 2023
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>
@fabiovincenzi fabiovincenzi deleted the ns-selector branch November 2, 2023 09:07
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.

Add namespace selection UI under /ns
4 participants