opensafely-core / job-server

A server for mediating jobs that can be run in an OpenSAFELY secure environment. q.v. job-runner
https://jobs.opensafely.org
Other
5 stars 10 forks source link

Investigate HTMX #820

Closed ghickman closed 2 years ago

ghickman commented 3 years ago

HTMX is a return to previously-popular method of sending snippets of HTML down the wire for reactive UI elements and patterns. There are a handful of places where it might be a useful tool in our UI, eg #473

sebbacon commented 3 years ago

I never even knew it went away

ghickman commented 3 years ago

Had a go with this on an initial version of #852, trying to trigger on change of the repo dropdown (filtering on the changed condition). Didn't get very far with it because I realised the backend has to generate a single field of a form which just complicates a lot of things.

However! I spent some time reading the docs and the reactive nature of the tool seems very useful to fill the gap between no-JS and full SPA. I could definitely seem interactions like adding another related item to a form (as we've done in opencodelists) making good use of this, we often use template partials for that already.

Leaving this open to track more attemps at it with further interactions.

ghickman commented 3 years ago

Good article (in particular the examples for create/update forms) on using HTMX with Django and dynamic forms. My particular takeaway is HTMX requires one stops using FormSets since you can't modify the management form with it, I'm not sure this is a bad thing.

ghickman commented 2 years ago

I'd like us to investigate replacing the outputs viewer SPA with this too. That section is currently reactive to user input so on the surface it seems like it might be possible. We should take into account:

This thought brought to you by our very regular dependabot updates/dependency churn for a small piece of the service.

I expect a timeboxed spike/investigation would give us enough knowledge to make a call.

bloodearnest commented 2 years ago

Hmm, this might be a bit outside of htmx's regular path I think.

The key aspect of the SPA is the CORS element. Can HTMX do CORS request?

https://htmx.org/docs/#cors

We'd have to support htmx responses in both release-hatch and job-server.

Looks doable, but not trivial.

ghickman commented 2 years ago

Oh that might kill it, but this is why I'd like to have it investigated 😉

ghickman commented 2 years ago

We've tried out HTMX in a couple of places now (#1566 & #1678) and it's certianly a useful tool in our toolbox for UI enhancements that we can lean on going forward.