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

[BUU] Change product columns to be shown #12546

Merged
merged 25 commits into from
Jun 18, 2024

Conversation

dacook
Copy link
Member

@dacook dacook commented Jun 4, 2024

What? Why?

  1. Add new columns dropdown selector, built with Stimulus instead of Angular (while upgrading and re-using existing styles and rails controller)
  2. Tweak column sizing

Screenshot 2024-06-13 at 11 08 42 am

What should we test?

Changing columns on the bulk products screen:
See requirements on attached issue.
All features from old screen should continue to work.

  • open/close dropdown
  • selecting columns will show/hide immediately
  • on page reload, revert to saved preferences
  • after saving preferences, they are retained after page reload/pagination/sort etc.

Other styles not broken, and a bit more consistent with v3 style:

  1. bulk orders "action" dropdown
  2. edit orders "actions" dropdown
  3. old column column selectors (eg on bulk order management page)
  4. reports "fields to show" dropdown
  5. inventory "view" dropdown

I don't know why, but even though the client sends http accept header for json, rails is treating it as html. This was being overridden in the route, but I want to support multiple formats next. So, we explicitly choose the format by adding it to the request path.
@dacook dacook force-pushed the buu/change-columns-11055 branch 2 times, most recently from 0e520b6 to 2f06333 Compare June 11, 2024 05:59
@dacook dacook changed the title [BUU] Change columns [BUU] Change product columns to be shown Jun 11, 2024
@dacook dacook added the pr-staged-au staging.openfoodnetwork.org.au label Jun 12, 2024
Ensures that the column table names match the names in the selector.

I thought 'there must be a way to set the translation scope once'. With Rails, there's usually a way. Thankfully this one was quite simple. Or is it too much magic.. 🧙

https://coderwall.com/p/dvme9q/set-scope-of-i18n-translations-in-rails-with-a-block
The cols could have been a lot cleaner with simple classnames, but I preferred to mark up in a way that reveals the purpose (otherwise they could be used for styling).

It doesn't seem to be any faster comparing querySelector('[data]') vs class, or iterating through the dom nodes.
There shouldn't normally be errors, but I got one due to bad data during development, and this helped sort it out.
Use the new design for checkboxes and fix alignment.

Removes redesigned-input, which is a small regression on the old design, but I think it's acceptable bcause we're going to shut it down soon.
This also improves the styling of the orders action dropdowns (on index and edit pages). It adds the new chevron icon, but needed some fiddling to make it look right.
@dacook dacook added pr-staged-au staging.openfoodnetwork.org.au and removed pr-staged-au staging.openfoodnetwork.org.au labels Jun 12, 2024
With some styling tweaks.
The v2 dropdown is used in various places, and now looks more in line with the new design.
Visibility was way simpler, but the table doesn't recalculate column widths until you use display:none;

This is now using the same method as the old products screen.
But we still need to update colspans..
This might be a little simpler if we move the 'new variant' button to col 0, and assume colspan cells always span the whole table.
@dacook dacook added the pr-staged-au staging.openfoodnetwork.org.au label Jun 13, 2024
For some reason, minimum widths work now (I swear they didn't before).

Hmm i would really like to shorten that stimulus controller name.
Sorry didn't have time to go back and rebase
@RachL
Copy link
Contributor

RachL commented Jun 14, 2024

@mariocarabotta I'm leaving this staged on AU: can you have a look and let me know if it fits what you had in mind? Especially I'm wondering about column position when there are only a few, currently the image is taking a huge space:

image

With the old screen we have something like this:

image

@dacook
Copy link
Member Author

dacook commented Jun 16, 2024

Thanks Rachel for testing, and Maikel for responding.
As we can see, my latest changes which rely on min-width were required to avoid the problem Rachel has pictured. I think this is worth fixing so I will try to progress it today.

@mariocarabotta mariocarabotta added pr-staged-au staging.openfoodnetwork.org.au and removed pr-staged-au staging.openfoodnetwork.org.au labels Jun 16, 2024
@mariocarabotta
Copy link
Collaborator

@mariocarabotta I'm leaving this staged on AU: can you have a look and let me know if it fits what you had in mind? Especially I'm wondering about column position when there are only a few, currently the image is taking a huge space:

image

With the old screen we have something like this:

image

you got there before me! I provided the same feedback, can see David is on it. thanks!

@dacook
Copy link
Member Author

dacook commented Jun 17, 2024

@mariocarabotta , this is ready to review again. I've re-tweaked columns and I think it's working well.

I compared with the old screen too, and I think it's a big improvement (product name and SKU were very small before).

When columns are hidden, the Name and Producer columns will grow to fill extra space. If both of those are hidden, the first column on the left will fill the space (eg image), but I think that's unlikely and acceptable.

Here's some previews I took with various

Small (1024px)

All columns (Firefox, Chrome)

You can see that in Firefox, the Price column gets cropped, but the min-width ensures more of the price shows on Chrome. (hmm I forget to check higher values like 10.00)
products-1024-all

Some columns (Firefox, Chrome)

products-1024-some

Large (1440px)

All columns (Firefox, Chrome)

products-1440-all

Some columns (Firefox, Chrome)

products-1440-some

If neither are visible, the first column on the left (eg image) will grow. But that's not a likely scenario.

Min-widths help manage sizes on smaller screens in Chrome.
The title for Inherits Properties gets cut off, but I think it's better than cutting off content.

Oh look, it fixed a spec too!
@dacook dacook added pr-staged-au staging.openfoodnetwork.org.au and removed pr-staged-au staging.openfoodnetwork.org.au labels Jun 17, 2024
@mariocarabotta
Copy link
Collaborator

looking good on my side too! tested on brave, looks shiny 🤩

@dacook
Copy link
Member Author

dacook commented Jun 18, 2024

Thanks for confirming. @RachL this is ready to test now.

@mariocarabotta
Copy link
Collaborator

mariocarabotta commented Jun 18, 2024

sorry I've just found out that this introduces

  • UI bug when adding a variant inline
  • when opening dropdown and opening another one, the columns dropdown does not close (see shots below)

Screenshot 2024-06-18 at 12 35 30

Screenshot 2024-06-18 at 12 38 07

@dacook

This comment was marked as outdated.

Well, that made the JS way simpler.

Adds a lot of classes though. Maybe we could do it based on column index instead, but this will do for now.
table.hide-col0 { td:nth-child(0) { display: none; } }
@dacook
Copy link
Member Author

dacook commented Jun 18, 2024

Fixed first issue:

  • UI bug when adding a variant inline

The second I wasn't able to fix quickly. I think we might be able to customise TomSelect to emit a standard 'click' event which would be a good generic solution.

@dacook dacook removed the pr-staged-au staging.openfoodnetwork.org.au label Jun 18, 2024
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.

Great!


this.#showHideElement(cell, element.checked);
});
this.table.classList.toggle(`hide-${name}`, !element.checked);
Copy link
Member

Choose a reason for hiding this comment

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

Now the next step would be to have the column selector be labels for hidden checkboxes in the columns and couple the visibility of the columns with the value of the hidden input in CSS. Then you won't need JS at all. 😉

Copy link
Member Author

Choose a reason for hiding this comment

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

🤯

That's so crazy it might just work

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 don't know why, but I tried it, and it worked with pretty minimal changes!
dacook@a46eded

But pretty minimal benefit too, so I won't pursue it.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I didn't know the has selector. That's clever. But as long as we need the column counter, we can't get rid of the JS. Hm, I would probably scrap the counter but I'm not the designer. 😜

Copy link
Member Author

@dacook dacook Jun 19, 2024

Choose a reason for hiding this comment

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

Haha, unfortunately the counter is needed in two places, where i've employed colspan to make rows span. One of them I think I could probably work around, but the other requires to span all visible rows. Unfortunately there isn't a builtin solution for that. (you can use an arbitrary high number like colspan="999", which automatically spans all columns, but this doesn't take into account hidden columns).
Hmm, maybe it could be hacked from within the first column...

Edit: nope, it cant.

Copy link
Member

Choose a reason for hiding this comment

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

I saw one example that used visibility: collapse which can hide entire columns. I haven't tested the effect on colspan though.

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 did use visibility: collapse initially on this PR, and it worked well to hide the columns. I think it handled the colspan too, which was a big bonus. But I couldn't get the column widths to behave properly (70fab2b)

It might be worth trying it again after the latest tweaks, but I'm not keen to add more work unless it's needed..

@dacook
Copy link
Member Author

dacook commented Jun 18, 2024

Thanks to Maikel's quick review, I think we can go straight on to testing again.

Copy link
Collaborator

@chahmedejaz chahmedejaz left a comment

Choose a reason for hiding this comment

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

Looks great 👍🏻

@RachL RachL added the pr-staged-au staging.openfoodnetwork.org.au label Jun 18, 2024
@RachL
Copy link
Contributor

RachL commented Jun 18, 2024

@dacook the bug Mario has seen appears now when selecting 6 columns or less in desktop mode:

image

If you want we can merge already and fix in a new issue? In that case I will let you merge

@RachL RachL added feedback-needed and removed pr-staged-au staging.openfoodnetwork.org.au labels Jun 18, 2024
@dacook
Copy link
Member Author

dacook commented Jun 18, 2024

@RachL thanks for testing. I accidentally missed configuring one of the columns, all fixed now, so I will merge.

@dacook dacook merged commit 2676891 into openfoodfoundation:master Jun 18, 2024
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature toggled These pull requests' changes are invisible by default and are grouped in release notes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[BUU] Change the columns to be shown in my catalogue
5 participants