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

Feat/templates filter macro #1877

Merged
merged 48 commits into from
Jul 24, 2024
Merged

Feat/templates filter macro #1877

merged 48 commits into from
Jul 24, 2024

Conversation

andrewleith
Copy link
Member

@andrewleith andrewleith commented Jun 25, 2024

Summary | Résumé

This PR:

  • adds a macro to enhance our template list and make it filterable
  • updates the template list page to use this filter when FF_TEMPLATE_CATEGORY=true

Using the macro requires a few annotations on the template list:

  1. Add a data attribute to indicate the notification type, e.g. data-notification-type="Email message"
  2. Add a data attribute to indicate the template category, e.g data-template-category="Status Update"

…uld be used. The templates list will need to be marked up with some new data attributes in order to make use of this functionality.
Copy link

<div class="template_filter" data-row-selector="{{ row_selector }}">
<details>
<summary class="cursor-pointer text-sm">Apply filters</summary>
<div class="flex p-0 pl-gutter mt-2">
Copy link
Contributor

Choose a reason for hiding this comment

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

Here, we can use gap-gutter withflex and remove ml-gutter from the children elements. This way we'll have an easier time making this responsive and potentially adding more filters later on!

Copy link

@andrewleith andrewleith marked this pull request as draft July 17, 2024 20:05
{# Ensure all required parameters are provided #}
{% if not row_selector or not notification_type_data_attribue or not template_category_data_attribute %}
<div class="text-red font-bold my-4">
Missing required parameters: <code>row_selector</code>, <code>notification_type_attribute</code>, and <code>template_category_attribute</code>. Please verify your code and try again.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this error message is targeted at devs, and not users? Are we able to log this instead of rendering it on the page on the off chance something goes awry? It could be confusing to a user if they were somehow exposed to it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes this is for devs. Solid point about accidentally showing this to users. I could add a check here to make sure its running locally.

Copy link
Contributor

Choose a reason for hiding this comment

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

I what conditions would this show up? And what would a user need to do to fix it? Unless nothing can be done from the user's perspective, we could design an empty state component for it.

Otherwise if it is just for admins (us), we could wrap this around a permission conditional.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah i just added this so if a dev in the future tried to use it and had issues it could help them. The permission conditional is also a cool idea!

@@ -29,7 +29,7 @@
<legend class="sr-only">{{ _("Select templates and folders")}}</legend>
{% endif %}
{% for item in template_list %}
<div class="template-list-item {% if display_checkboxes %}template-list-item-with-checkbox{% endif %} {% if item.ancestors %}template-list-item-hidden-by-default{% endif %} {% if not item.ancestors %}template-list-item-without-ancestors{% endif %}">
<div class="template-list-item {% if display_checkboxes %}template-list-item-with-checkbox{% endif %} {% if item.ancestors %}template-list-item-hidden-by-default{% endif %} {% if not item.ancestors %}template-list-item-without-ancestors{% endif %}" data-notification-type="{{ item.hint }}" data-template-category="{{ item.template_category[template_category_name_col] }}" data-testid="template-row">
Copy link
Contributor

Choose a reason for hiding this comment

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

Less of a suggestion, more of a discussion (that maybe we have elsewhere):

{{ 'template-list-item-with-checkbox' if display_checkboxes }} is functionally the same as {% if display_checkboxes %}template-list-item-with-checkbox{% endif %}. Thoughts on using expressions for simple inline conditionals for readability / maintainability?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think what you are proposing is way better than what we have here. I'll update it and keep this in mind going forward!

@@ -0,0 +1,128 @@
{#
This macro creates a filterable template list based on specified criteria.
Copy link
Contributor

Choose a reason for hiding this comment

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

I love this docstring so much!

<div class="template-filter" data-row-selector="{{ row_selector }}">
<details data-testid="filter">
<summary data-testid="filter-toggle">{{ _("Apply filters") }}</summary>
<nav class="flex p-0 gap-gutter pl-gutter mt-2" aria-label="{{ _('Filter by template type and category') }}" data-testid="filter-content">
Copy link
Contributor

Choose a reason for hiding this comment

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

We can remove pl gutter here to keep things aligned.

Suggested change
<nav class="flex p-0 gap-gutter pl-gutter mt-2" aria-label="{{ _('Filter by template type and category') }}" data-testid="filter-content">
<nav class="flex p-0 gap-gutter mt-2" aria-label="{{ _('Filter by template type and category') }}" data-testid="filter-content">

@amazingphilippe amazingphilippe self-requested a review July 23, 2024 15:28
Copy link
Contributor

@amazingphilippe amazingphilippe left a comment

Choose a reason for hiding this comment

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

Looks good! We can merge this so we can keep working on the template list CSS

@andrewleith andrewleith merged commit b6b9043 into main Jul 24, 2024
9 checks passed
@andrewleith andrewleith deleted the feat/templates-filter-macro branch July 24, 2024 17:43
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.

3 participants