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

Riverlea - add Stream entity and previewer #32127

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ufundo
Copy link
Contributor

@ufundo ufundo commented Feb 18, 2025

Overview

Move the Stream definitions in Riverlea from hard-coded to a new entity.

This enables a "Previewer" which allows you to switch streams locally, without changing the site settings.

Paves the way for future UI to a) pick a stream based on what it looks like on your site; b) editing and creating custom streams through the UI (AKA "Customiser").

Before

  • available streams are hard-coded in riverlea.php

After

  • streams are provided by a new entity RiverleaStream
  • streams can be viewed with Search Kit, edited with FormBuilder etc
  • external extensions can provide RiverLea streams using managed entity
  • dark mode option can be set at the stream level (though will fallback to the global setting if unset)
  • you can create a stream on one site and then export it using the ManagedEntity export (like you can with SearchKits)
  • you can open the console and type CRM.riverlea.previewer() to open a previewer widget, which allows you to switch between streams on the fly
  • streams can include custom_css, which allows for easy adding fixes. these are then cached via assetbuilder (essentially using the stream name and last modified as key) which overcomes the performance concerns with previous attempt at Customiser
  • streams can include vars defined using php, which could then be validated/updated automatically etc
Screencast.from.2025-02-18.14-27-34.mp4

(note all previewer changes are on the frontend and local to your current session - the site theme setting isn't touched. It does require starting with a Riverlea theme selected)

Work in progress

Need to add upgrader to create the new table on existing installs. I think this goes in the core upgrade step for core extensions?

Would be good to get some feedback on how it's working / overall schema.

Known Limitation

  • Previewer can't handle the civicrm.css override in Thames and Walbrook (it can only switch the var values on the fly). At this stage it's a dev tool, so I think it's reasonable. (I also think the overrides in Thames and Walbrook don't need to be in civicrm.css - they could be moved into the stream specific css file)
  • Asset builder cache buster on river.css will only track changes to the entity, but if you use css_file and modify the file it won't necessarily know. Again, I think this is reasonable. It's not expected to edit css files directly in production - and you (will soon) be able to edit custom_css on the entity if you need to.

Technical Details

  • Use a WebComponent <civi-riverlea-previewer>. I'm not sure how we feel about these but I think it's very nice for a self contained component that can use the API and talk to the browser.

Copy link

civibot bot commented Feb 18, 2025

🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷

Introduction for new contributors...
  • If this is your first PR, an admin will greenlight automated testing with the command ok to test or add to whitelist.
  • A series of tests will automatically run. You can see the results at the bottom of this page (if there are any problems, it will include a link to see what went wrong).
  • A demo site will be built where anyone can try out a version of CiviCRM that includes your changes.
  • If this process needs to be repeated, an admin will issue the command test this please to rerun tests and build a new demo site.
  • Before this PR can be merged, it needs to be reviewed. Please keep in mind that reviewers are volunteers, and their response time can vary from a few hours to a few weeks depending on their availability and their knowledge of this particular part of CiviCRM.
  • A great way to speed up this process is to "trade reviews" with someone - find an open PR that you feel able to review, and leave a comment like "I'm reviewing this now, could you please review mine?" (include a link to yours). You don't have to wait for a response to get started (and you don't have to stop at one!) the more you review, the faster this process goes for everyone 😄
  • To ensure that you are credited properly in the final release notes, please add yourself to contributor-key.yml
  • For more information about contributing, see CONTRIBUTING.md.
Quick links for reviewers...

➡️ Online demo of this PR 🔗

@ufundo
Copy link
Contributor Author

ufundo commented Feb 18, 2025

@vingle @totten @colemanw would be interested in your feedback on this.

@ufundo
Copy link
Contributor Author

ufundo commented Feb 18, 2025

(Just a note, if testing locally on a pre-existing site you will need to uninstall and then reinstall Riverlea in order to create the DB table)

@vingle
Copy link
Contributor

vingle commented Feb 18, 2025

I'm not in a position (skills-wise) to comment on the code changes here - I can't comment on other consequences they might have. I can only really look at this from a product perspective:

Firstly a previewer is definitely really nice - ThemeTest would benefit from that (I spend quantifiable time moving back and forth from Display Setting).

But this is more than that…

At present:

  • the path to creating custom streams is to create a subtheme extension, pointing to RiverLea. It's in the docs and it's a way to make Streams that survive upgrades.
  • from a css designer's perspective that's an appealing approach as it's relatively straightforward (ie low-coding skills) to clone a subtheme extension, then find and replace the name to your Stream name. As a method it survives upgrades to RiverLea (unless you rename all RL's variables, lol). It can then be moved from dev to production site, stored on a git repo, version controlled, offered to the public, etc

With this proposal:

  • a Stream is an entity… where are its files? What if it wants to bundle fonts or images? Would it still be a subtheme extension, but just that it would create a new entity on creation? Delete on uninstall?

And the benefit of all of this change is the previewer? Or Something else ("paves the way for future UI to a) pick a stream based on what it looks like on your site" - ie in a realtime preview?).

Side point: as RiverLea flows towards the big C of Civi Core - maybe it's name makes less and less sense? It's no longer a theme like Greenwich and more Civi's theme engine. So maybe - at least if it becomes an entity in core, its name should be something generic like CRMThemer, or at least more generic like 'river' (as river -> stream, is helpful naming to emphasise the cascade order of css).

@ufundo
Copy link
Contributor Author

ufundo commented Feb 18, 2025

Hey @vingle

With this approach I see two ways to make new streams:

  1. "No Code" => use the UI Customiser, hit an export button and get a Managed Entity text file. This can be
    a) copied and pasted into another site
    b) included in an extension
    c) stored in git
    (one day) d) uploaded to a library of community-contributed streams, which are then previewable on your site (without downloading anything)
    It's the same format as used for sharing Search Kits, so relatively familiar to folks who've worked with that.

  2. Code => similar to what you describe, you can basically copy the existing files for one of the existing streams into your own extension, change the minetta to yourstreamname and then you can work with the .css files directly. We could make a template extension to simplify the process. Previously you had to register the theme using hook_civicrm_themes - now you have to register it by creating a MyTheme.mgd.php but the contents are very similar. I can make template extension if you like?

The only advantage implemented in this PR is the previewer.

But it's a fairly small step from here to:

  • a stream-picker UI where you can choose which theme you want to use, with a preview before you activate it - "realtime preview" 👍
  • add snippets for hot-fixes
  • set colours and other vars through the UI
  • copy a stream through the UI, make some edits, flick back and forth between the original and your edited version

@vingle
Copy link
Contributor

vingle commented Feb 18, 2025

hit an export button and get a Managed Entity text file

So all of a stream's custom css (variables, darkmode versions) would be stored within the Entity?

If I store it in Git, someone else changes a bunch of variables, can I get that back into my system? Presumably any part of the entity can be edited?

I can make template extension if you like?

That'd be cool. I created an empty SubTheme extension at the end of last year which I think still works - I just made it public: https://github.com/vingle/branch with a Stream called 'Albany'. Might need a tiny bit more testing/docs before becomming a template.

I used the name 'branch' as that seems like a subsidiary water-system from a stream. But obvs branches have other meanings on git so perhaps another name works (I thought about 'estuary', 'tributary', 'source', 'channel', 'canal', 'brook' - branch seems the most accurate, but probably confusing).

set colours and other vars through the UI

That's interesting - maybe overlaps with the oembed stuff… ie for the example of someone creating a 'join newsletter' or 'petition' widget they want to embed on a dozen different sites, each with a different font and bg-colour… then giving each embed some unique class could let you save a unique variable… ie .crm-embed.website1 .afform-directive { --crm-font: "Times New Roman", serif; } and then .crm-embed.website2 .afform-directive { --crm-font: "Courier", monospace; } etc.

@ufundo
Copy link
Contributor Author

ufundo commented Feb 18, 2025

If I store it in Git, someone else changes a bunch of variables, can I get that back into my system? Presumably any part of the entity can be edited?

The standard way managed entities work is you a file version (which can be checked in to git). Then you have a database (database) version. These start in sync.

If you make edits to the database version (using the UI), you then have the option to a) export them - ie make the same changes to the file version; b) revert the database changes, go back to the file version.

If you make edits to the file version they will generally be synced to your database version (unless that has local changes - which you might not want to lose. In that case you have the option to revert to the file version to get the latest changes from the file.)

template extension

https://lab.civicrm.org/ufundo/river_rea/-/tree/dev . I called it river_rea which is obviously way too close to River Lea 🤦

estuary', 'tributary', 'source', 'channel', 'canal', 'brook' - branch

My thinking was that we don't need to create another hierarchy, and we should use stream for all the variations within River Lea. A stream = River Lea Theme = super easy to maintain theme.

(I've started seeing it the other way round, the stream is the little drops of ink you add to the river at the beginning, and then the river takes that and spreads it all over the UI :))

'petition' widget they want to embed on a dozen different sites, e

I think this approach would lend itself to adding a url parameter ie. https://mycivi.com/contribution-page?stream=my_blue_stream and https://mycivi.com/contribution-page?stream=my_green_stream which then loads the appropriate vars on that page (without having to add css classes programmatically, which would be hard I think).

@vingle
Copy link
Contributor

vingle commented Feb 18, 2025 via email

@ufundo
Copy link
Contributor Author

ufundo commented Feb 18, 2025

Further possibility with this kind of model: automating contrast checks between vars we know need to contrast. IE messages in the editor like "your crm-c-primary and crm-c-primary-text currently have contrast rating 5:1 which meets AA but you should increase for AAA"

@vingle
Copy link
Contributor

vingle commented Feb 19, 2025

automating contrast checks

Sold!

@ufundo
Copy link
Contributor Author

ufundo commented Feb 28, 2025

https://lab.civicrm.org/extensions/deptfordcreek/-/merge_requests/1 demonstrates the change in what "external streams" would look like before/after the core change.

The "external stream" could also put all it's var in the Managed file, and not have any separate css files.

@ufundo
Copy link
Contributor Author

ufundo commented Feb 28, 2025

I think we need thel change to _riverlea_is_active in this PR whether or not we go the entity route, so I've made a separate PR for it: #32263

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants