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

Back Office Product List - Hide search field and filters when there are no products in list #12983

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

saunmanoj888
Copy link
Contributor

@saunmanoj888 saunmanoj888 commented Nov 18, 2024

What? Why?

What should we test?

  • When a new person signs up and goes to the admin for the first time, they likely won't have any product, verify that in this scenario, search filter should not be present

  • When products are present and user searches with a product name which is not present in the list, search filter should still be visible

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Part of me wonders if it should be more directly counting the number of producers that the user has access to. We could do that by re-factoring part of the query in ProductsV3Controller#fetch_products.
But this way seems reliable enough, and is actually more efficient 👍

Comment on lines 6 to 14
- if display_search_filter
.container
.sixteen.columns
= render partial: 'admin/shared/flashes', locals: { flashes: } if defined? flashes
= render partial: 'filters', locals: { search_term: search_term,
producer_id: producer_id,
producer_options: producer_options,
category_options: category_options,
category_id: category_id }
Copy link
Member

Choose a reason for hiding this comment

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

For future reference, when you have a conditional block of Haml code, it reads much nicer to move that code into a partial.

Suggested change
- if display_search_filter
.container
.sixteen.columns
= render partial: 'admin/shared/flashes', locals: { flashes: } if defined? flashes
= render partial: 'filters', locals: { search_term: search_term,
producer_id: producer_id,
producer_options: producer_options,
category_options: category_options,
category_id: category_id }
= render partial: "search_filter", locals: { flashes:, ... } if display_search_filter

There are quite a few local though. Hm, looking at the code again, we probably don't want a conditional on the flashes. What if you delete the last product and that should have a success message? You would be hiding it in your code.

So maybe we want this?

Suggested change
- if display_search_filter
.container
.sixteen.columns
= render partial: 'admin/shared/flashes', locals: { flashes: } if defined? flashes
= render partial: 'filters', locals: { search_term: search_term,
producer_id: producer_id,
producer_options: producer_options,
category_options: category_options,
category_id: category_id }
.container
.sixteen.columns
= render partial: 'admin/shared/flashes', locals: { flashes: } if defined? flashes
= render partial: 'filters', locals: {
search_term:,
producer_id:,
producer_options:,
category_options:,
category_id:
} if display_search_filter

What do you think?

Copy link
Contributor Author

@saunmanoj888 saunmanoj888 Nov 21, 2024

Choose a reason for hiding this comment

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

hii @mkllnk
Agree with you, I have now added display_search_filter condition only for filters partial

For above suggested review, shorthand syntax works fine but curly brace placement gives obscure errors. For now I have kept the curly braces placement for key locals as it is.

Could you please review the latest changes

Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

Nice! Well done.

Our testing team will look at this next.

@mkllnk mkllnk added the technical changes only These pull requests do not contain user facing changes and are grouped in release notes label Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
technical changes only These pull requests do not contain user facing changes and are grouped in release notes
Projects
Status: Test Ready 🧪
Development

Successfully merging this pull request may close these issues.

Back Office Product List - Hide search field and filters when there are no products in list
4 participants