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

Render and mange admin pages tabs server side #5855

Closed
wants to merge 1 commit into from
Closed

Conversation

marcospri
Copy link
Member

  • Create one route and template per tab
  • A macro renders the tab headers in each new template

Base automatically changed from org-template-renames to main November 23, 2023 15:09
- Create one route and template per tab
- A macro renders the tab headers in each new template
@@ -161,6 +161,7 @@ def includeme(config): # pylint:disable=too-many-statements
config.add_route("admin.role.override.delete", "/admin/role/overrides/{id_}/delete")

config.add_route("admin.organization", "/admin/org/{id_}")
config.add_route("admin.organization.danger", "/admin/org/{id_}/danger")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New route/url per tab. /usage already existed.

@@ -37,23 +37,6 @@
integrity="sha512-IOebNkvA/HZjMM7MxL0NYeLYEalloZ8ckak+NDtOViP7oiYzG5vn6WVXyrJDiJPhl4yRdmNAG49iuLmhkUdVsQ=="
crossorigin="anonymous"
referrerpolicy="no-referrer"></script>
<script src="https://cdn.jsdelivr.net/npm/@vizuaalog/[email protected]/dist/bulma.min.js"></script>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing all the stuff added to manage them JS side.

I reckon it was interacting wierdly with this PR.

Of course if we went this route we'd need to adapt the AI pages as well.

@@ -201,3 +201,33 @@
</div>
{% endcall %}
{% endmacro %}
{% macro tab_headers(request, tabs, active) %}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably the less nice part of this PR.

Having one route render one tab is pretty easy but this deals mostly with setting the "is-active" in the right tab.

@@ -0,0 +1,3 @@
{% extends "lms:templates/admin/base.html.jinja2" %}
{% block header %}Organization {{ org.id }}{% endblock %}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I had the tab headers rendered here but now it's each tab that calls the macro.

This base template doesn't add much right now but it useful to have it.

{% import "lms:templates/admin/macros.html.jinja2" as macros %}
{% extends "lms:templates/admin/organization/base.html.jinja2" %}
{% block content %}
{{ macros.organization_tabs(request, org, "admin.organization.danger") }}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Render the headers, set the active one using the route name 🤷

request_method="GET",
renderer="lms:templates/admin/organization/danger.html.jinja2",
)
def danger(self): # pragma: no cover
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could create a little abstraction around this type of view. Not for this PR.

Copy link
Contributor

@acelaya acelaya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The biggest mental block about this is the fact that it currently requires a lot of refactoring. My previous PRs (#5842 and #5845) were going in the direction of getting something working with as fewest changes as possible.

However, if we are honest with ourselves, the LMS admin is not a SPA, and adding pieces of a SPA to it is a bit of a hack. From my point of view, the proper way to have routing in the admin is this, using good ol' server-side template partials and macros.

They can get a bit messy, but they are straightforward and easy to understand when you have to add more routes and look at existing code to follow the same pattern.

With the other PRs it was easier to forget something. With this one, it won't work until you get it right because there's less magic involved.

@marcospri
Copy link
Member Author

Going for the FE approach for now, let's revisit if that gets complicated.

@marcospri marcospri closed this Dec 5, 2023
@marcospri marcospri deleted the ssr-org-tabs branch February 28, 2024 16:11
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.

2 participants