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

Add HTMX to activity stream #8160

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

aleeexgreeen
Copy link

Fixes #8129

Proposed fixes:

Use HTMX in activity stream's select element and navigating between pages instead of full page reload.

Features:

  • includes tests covering changes
  • includes updated documentation
  • includes user-visible changes
  • includes API changes
  • includes bugfix for possible backport

Please [X] all the boxes above that apply

@wardi wardi assigned wardi and pdelboca and unassigned wardi Apr 9, 2024
@pdelboca
Copy link
Member

pdelboca commented Apr 9, 2024

Hello @aleeexgreeen ! As a first approach it is good but let's be a little bit more specific on the interaction to take full advantage of HTMX.

The "problem" with this PR is that we are rendering all the full template again and then replacing the body. Re-rendering the whole template might not be ideal since it needs to call a lot of logic for things that are not going to change (followers, dashboard, login menu, breadcrumb, etc).

The pattern we want to follow here is the following:

def my_view(request):
    if request.htmx:
        template_name = "partial.html"
    else:
        template_name = "complete.html"
    return render(template_name, ...)

Usually, while working with HTMX we look for two workflows:

  1. The first request will render the whole template
  2. The subsequent HTMX interactions will render just snippets and replace parts of the page.

So, what can we do to achieve this? We will need to do some work on out templates.

  1. Make activity_stream.html a snippet (do not extend from organization/read_base.html)
  2. Move the subtitle block to organization/read_base.html
  3. Leave only {% block primary_content_inner %} in organization/activity_stream.html
  4. Call {% snippet activity_stream.html, ...., ...., .... %} from organization/read_base.html.
  5. In the group_activity view, at the end, add an if statement to return render("activity_stream.html", ...) instead of the full template if it is an HTMX request.
  6. In the template, replace the <div class="module-content">...</div> instead of all the body

Does it makes sense?

@aleeexgreeen aleeexgreeen marked this pull request as draft April 22, 2024 23:25
@aleeexgreeen
Copy link
Author

@pdelboca Hi! Thanks for the guidance, it all made sense! I came across a couple problems/questions that I wanted to bring up to you.

  1. Moving the subtitle block to organization/read_base.html instead of extending it from organization/read_base.html causes the organization page (/organization/<organization_name>) to have the activity stream subtitle
  2. The groups' and organizations' activity streams are nearly identical, except for some parameters (object_type and blueprint) being passed to the snippets. I'm thinking using group_type as object_type and adding an if statement or line in group_activity such as blueprint = "activity.{}_activity".format(group_type) for blueprint to be added to extra_vars, would work. Does that make sense and seem like a good idea?

I've pushed my progress so far, so you could take a look

@aleeexgreeen aleeexgreeen marked this pull request as ready for review May 7, 2024 20:42
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.

Leverage HTMX in CKAN's Activity Stream
3 participants