question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Refactor Status tag styles into UI component

See original GitHub issue

Is your proposal related to a problem?

We currently have a “status tag” component as reusable CSS styles that are copy-pasted with the relevant HTML across the admin.

Describe the solution you’d like

This feels like a good candidate to refactor to a UI component, this is an approach where we use a template tag to abstract away the HTML.

This shouldn’t change the component’s rendering in any way, just how it’s included in different places (and introduce a way for us to test the variations more easily in Storybook). For example, we will not adjust the class names, even though these are somewhat confusing.

Requirements

  • Create a new shared template partial (wagtail/admin/templates/wagtailadmin/shared/status_tag.html)
  • Create a new template tag that uses this partial in wagtail/admin/templatetags/wagtailadmin_tags.py
  • Ensure the template tag works with the classname kwarg
  • Add a Storybook stories for different variations of this new component ( similar to wagtail/admin/templates/wagtailadmin/shared/header.stories.tsx)
  • With a template partial in the shared folder for us to {% include %} where needed (update all locations)
  • Ensure that the styleguide is also updated to use the new template partial wagtail/contrib/styleguide/templates/wagtailstyleguide/base.html

Additional context

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:20 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
lb-commented, Dec 11, 2022

@salty-ivy I have put some comments on the PR but I think it would be best to start with the non-page status ones (the ones that use spans for the 80% use case).

If you search through the code for status-tag you will find about ~20 files that are quite simple status-tag variants, a span with a classname and some content inside.

I think it’s best we cover this first - and then revisit the more complex ones later. Namely wagtail/admin/templates/wagtailadmin/shared/page_status_tag.html - which uses a link & wagtail/admin/templates/wagtailadmin/shared/page_status_tag_new.html - which is a completely different approach using tailwind classes & tooltips.

Below is an example of how I anticipate we would use the generic status tag template tag, just calling it status probably makes more sense.

Example - page-title-cell

wagtail/admin/templates/wagtailadmin/chooser/tables/page_title_cell.html https://github.com/wagtail/wagtail/blob/da90061ca83170bd1da1c7ca77106690e21f7f49/wagtail/admin/templates/wagtailadmin/chooser/tables/page_title_cell.html#L9-L11

New usage

        {% if column.show_locale_labels and page.depth == 2 %}
            {% status classname="status-tag--label" %}{{ page.locale.get_display_name }}{% endstatus %}
        {% endif %}

Example - page history

wagtail/admin/templates/wagtailadmin/pages/history.html https://github.com/wagtail/wagtail/blob/da90061ca83170bd1da1c7ca77106690e21f7f49/wagtail/admin/templates/wagtailadmin/pages/history.html#L37-L44

New usage

                            {% if entry.revision %}
                                {% if entry.action == 'wagtail.publish' %}
                                    {% if entry.revision_id == page.live_revision_id %}{% status classname="primary" %}{% trans 'Live version' %}{% endstatus %}{% endif %}
                                {% elif entry.content_changed %}
                                    {% if entry.revision == page_latest_revision %}{% status classname="primary" %}{% trans 'Current draft' %}{% endstatus %}{% endif %}
                                    {% include "wagtailadmin/pages/revisions/_actions.html" with revision=entry.revision %}
                                {% endif %}
                            {% endif %}

Example template tag code

In wagtail/admin/templatetags/wagtailadmin_tags.py you will be able to see how we can easily create these block/endblock style template tags (using BlockInclusionNode). Below is a rough bit of working code (without classname support).

class StatusTagNode(BlockInclusionNode):
    template = "wagtailadmin/shared/status_tag.html"


register.tag("status", HelpBlockNode.handle)
# register.tag("status_tag", HelpBlockNode.handle) OR status_tag
1reaction
lb-commented, Nov 27, 2022

@salty-ivy good question, I might need to defer to @thibaudcolas as to the long term plan here but here’s my best guess.

From the looks of these, they are a specific usage of the status tag to show the page’s live status only.

So I think that page_status_tag would end up using the new component you create.

Then… The new one is a new design that uses Tippy for the same purpose. So I guess a long term approach would be to adopt the new design for the status tag generic component in the future. However, Tailwind makes this a bit more complex, not sure where we are heading with this approach as we are yet to provide a clear direction for new Css.

Nonetheless, I think that this issue does not conflict with those templates, the non-new one would just adopt the generic template tag.

Hope that makes sense

Links

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Style React Components | DigitalOcean
In this tutorial, you'll learn three different ways to style React components: plain Cascading Style Sheets (CSS), inline styles with ...
Read more >
Refactor and introduce generic button CSS styles for forms ...
There are various button CSS styles throughout core, which duplicate each other and are not semantic classes in the first place. Goal. Remove ......
Read more >
Refactoring Angular Apps to Component Style - Tero Parviainen
Create a directive, named after the template. Make it use a new inherited scope ( scope: true ). Move the template to the...
Read more >
CSS Architectures: Completing MetaCoax Refactoring
The MetaCoax CSS refactoring process provides a way to make changes to your CSS over time and in waves as the code gets...
Read more >
Refactoring UI: Transistor - YouTube
For this edition of Refactoring UI, we take a look at Transistors's integration page, sharing lots of tips on layout and form design....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found