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] Stock level popout #11811

Merged
merged 24 commits into from
Dec 5, 2023

Conversation

dacook
Copy link
Member

@dacook dacook commented Nov 15, 2023

What? Why?

We're creating a new component as described in above issue. You can preview how it behaves here: https://www.figma.com/proto/v1zbrWDZSRd3Nqoe0SJ2Sm/Engineering-Delivery---Back-Office?page-id=708%3A5152&type=design&node-id=708-5153&viewport=278%2C123%2C0.33&t=HepYfjKLR82NcjTL-1&scaling=min-zoom&mode=design

Dev notes

I was able to keep the stimulus controllers nice and generic, and I hope to combine some existing controllers into one generic controller some day.

I wanted to make a "popout" ViewComponent with this, but remembered that

ViewComponent isn’t compatible with form_for helpers by default.

Still, it would be worth at least separating the CSS to a separate file.. 🤔
Or maybe it's worth trying to use ViewComponent and seeing if it happens to be possible.

What should Mario test?

I tried to make it behave how it seemed that it should. I covered these cases:

  • the button behaves like a select dropdown.
    • A down arrow appears on hover
    • If you select it with the keyboard,
      • 🆇 the arrow should appear but I couldn't get it working yet
      • you can press enter or the down arrow key to open it
    • When you click outside of it, it closes
    • the button shows the chosen value
  • 'on demand'
    • Selecting the checkbox closes it, and the button is focused
    • De-selecting the checkbox enables the on_hand field, and focuses it for convenience
  • if any of the fields are changed, the button is marked changed
    • 🆇 note that it doesn't yet properly handle the case where a changed field is disabled
    • 🆇 also the changed checkbox isn't styled. I think it will need a css hack for that (which we might need anyway, because)
    • 🆇 the checkbox style doesn't quite match the design (see below)

Checkbox style updates

Hrmm It doesn't quite match the design, but pretty close (not quite positioned right, and the border is not dark enough). It's possible to achieve the full design with a bit more effort, perhaps we can do that later (dev can see .redesigned-input as an example)
Some checkbox labels are now un-bold.
Screen Shot 2023-11-15 at 5 09 48 pm
Screen Shot 2023-11-15 at 5 10 00 pm
Screen Shot 2023-11-15 at 5 10 18 pm
Screen Shot 2023-11-15 at 5 10 27 pm

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

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

@dacook dacook force-pushed the buu-stock-levels-11062 branch 2 times, most recently from a901542 to ef3bc57 Compare November 22, 2023 06:10
@dacook dacook force-pushed the buu-stock-levels-11062 branch 2 times, most recently from 389bc8b to 1abedae Compare November 23, 2023 02:59
@dacook dacook marked this pull request as ready for review November 23, 2023 02:59
Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

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

Very nice ! 👍 There was a couple of things I didn't understand, see my comment.

spec/javascripts/stimulus/bulk_form_controller_test.js Outdated Show resolved Hide resolved
spec/javascripts/stimulus/popout_controller_test.js Outdated Show resolved Hide resolved
Copy link
Member Author

@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.

Good questions! I will add a new commit.

spec/javascripts/stimulus/bulk_form_controller_test.js Outdated Show resolved Hide resolved
spec/javascripts/stimulus/popout_controller_test.js Outdated Show resolved Hide resolved
@dacook dacook requested a review from rioug November 24, 2023 03:22
@mariocarabotta mariocarabotta added pr-staged-au staging.openfoodnetwork.org.au and removed pr-staged-au staging.openfoodnetwork.org.au labels Nov 24, 2023
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.

Looking good to me.

import { Application } from "stimulus";
import popout_controller from "../../../app/webpacker/controllers/popout_controller";

describe("PopoutController", () => {
Copy link
Member

Choose a reason for hiding this comment

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

I was wondering if we can solve this purely with CSS. And while that's possible, it wouldn't have the same functionality of reacting to down key events.

Example: https://codepen.io/imprakash/pen/GgNMXO

Copy link
Member Author

Choose a reason for hiding this comment

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

So cool.. thanks we should keep that in mind wherever a simple popup is needed.

HTML also has a dialog method, but funnily enough it requires javascript to make it work.
I wanted to use it but had a problem so had to revert to a div.

Copy link
Member

Choose a reason for hiding this comment

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

Interesting, I didn't know that one. A shame that they didn't include another way of opening a modal, for example with an href, button attribute or label. So the minimal code would be:

<a href="javascript:document.getElementById('modal').showModal();">Open</a>

Some very simple Javascript could probably bind that to an attribute like data-modal-open="modal" on any element. But it still needs Javascript while there are non-JS solutions out there.

Copy link
Member

Choose a reason for hiding this comment

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

By the way, I just had to try it out and was quite happy to have this minimal example working:

<html>
	<a href="javascript:document.getElementById('hello').showModal();">Show me</a>
	<dialog id="hello">
		Hello!
		<form method="dialog">
			<input type="submit" value="Nod">
		</form>
	</dialog>
</html>

It creates the false impression we can handle agregated stock.
But 'Array parameters do not play well with the check_box helper.'

...
The array format is generally fine, but to properly support checkboxes, we need this format with hash keys.
https://guides.rubyonrails.org/form_helpers.html#understanding-parameter-naming-conventions
Also fixed it to line up properly. There's probably a better way to line it up but that's no my concern right now..
This doesn't _quite_ match the design, but would require a big CSS hack to customise it further, so I thought let's start with this.
Had to update the form controller a little bit to handle buttons.

But arrow not showwing on focus.
Getting some weird SCSS behaviour here.. maybe I'm trying to be too clever.
It looks like a select drop-down, so it can behave like one too.
I'm starting to think that these stimulus tests are worthless. The environment is not the same as a browser, which creates extra work to deal with the inconsistencies. And it means we're not testing real world behaviour.

So these are just unit tests, but they take extra effort to put together due to the inter-relatedness with the DOM. Hmm.
Shoulda done this at the start.
I couldn't think of a simpler way to hardcode it, so now we have a clever generic method :)

We can assume that hidden elements will stay hidden, but we need to check each time if an element is disabled or not.
This introduces a new 'toggle' controller, and we already had three\! So I created a generic interface that could be extended to potentially support all of them. I propose we try to reduce them all into the one controller, but won't go down the rabbit-hole just yet..

I have an idea on how to re-arrange and make it more contained, by assigning the controller only to the checkbox, and defining targets with aria-controls="", but chose to stick with Stimulus conventions for now.
Strangely, the spec passed when run locally, but not in CI. It's a curious case of the wrong letter case.
@dacook dacook force-pushed the buu-stock-levels-11062 branch from b683358 to f034e46 Compare November 27, 2023 23:44
@dacook
Copy link
Member Author

dacook commented Nov 27, 2023

Rebased to resolve conflict.

@mariocarabotta mariocarabotta added the pr-staged-au staging.openfoodnetwork.org.au label Nov 28, 2023
I'm not sure if we want to do this on all fields, so just scoped it here for now.
@dacook dacook force-pushed the buu-stock-levels-11062 branch from b134488 to 6bf418c Compare November 29, 2023 04:36
@dacook
Copy link
Member Author

dacook commented Nov 29, 2023

Hi @mariocarabotta , I've updated the style of the popout disabled field: the value is hidden as per the design.
Screen Shot 2023-11-29 at 3 23 14 pm

I've kept the style for other disabled fields the same for now. Let me know if you have a preferred style for those.
Screen Shot 2023-11-29 at 3 36 36 pm

edit: sorry for the contradictory message, I've fixed it now

@mariocarabotta mariocarabotta added pr-staged-au staging.openfoodnetwork.org.au and removed pr-staged-au staging.openfoodnetwork.org.au labels Nov 30, 2023
@mariocarabotta
Copy link
Collaborator

thanks @dacook just tested this and it's looking good!
re the disabled fields style: when I select on demand, does that field state become disabled?
does that mean that at the moment we have 2 types of styles for disabled fields?

I think we can push this through (at least from a visual point of view, will let testers do more testing).
just wondering if we should unify disabled styles at some point and how I should go about creating an issue for that

@mariocarabotta mariocarabotta removed the pr-staged-au staging.openfoodnetwork.org.au label Nov 30, 2023
@dacook
Copy link
Member Author

dacook commented Nov 30, 2023

Hi @mariocarabotta, sorry about the delayed response.

Yes, I've implemented as disabled (and for the sake of your design, I made the value invisible). This is how the system currently works: we disable it but keep the old value stock level stored in the database (which does nothing).

We could instead clear the stock level, which arguably makes sense. This means if you later un-check 'on demand' you would not get your old stock level back. I'm not sure if this would matter.
In any case, we probably don't want to change the backend right now!


So yes, we have two styles of disabled fields, and I agree we should unify them. I wasn't sure if this design applied everywhere else, so I didn't apply it. I think it would be a quick change to apply it everywhere, let me know if you'd like to do that.
Otherwise, I'd suggest adding to the BUU backlog with a new design.

@mariocarabotta
Copy link
Collaborator

mariocarabotta commented Dec 1, 2023

no need to change the backend.
I'll create a separate issue for unifying the disabled state, I'd like to do a bit of work on that eventually.

This issue can be tested and pushed from my side :) good work

@RachL RachL added pr-staged-fr staging.coopcircuits.fr and removed pr-staged-fr staging.coopcircuits.fr labels Dec 1, 2023
@RachL
Copy link
Contributor

RachL commented Dec 1, 2023

@RachL RachL added the pr-staged-uk staging.openfoodnetwork.org.uk label Dec 1, 2023
@RachL
Copy link
Contributor

RachL commented Dec 1, 2023

I've checked the shopfront is updated accordingly - I did not test if if it is working with inventory, but I guess we can see that even after merge.

Aside of some weird overlap between on hand and producer column (which we can fix later) we are good to go :)

No hover:

image

With hover:

image

@dacook is the error on staging FR relevant? Otherwise I let you rebase and merge :)

@RachL RachL added feedback-needed and removed pr-staged-uk staging.openfoodnetwork.org.uk labels Dec 1, 2023
@mariocarabotta
Copy link
Collaborator

@RachL we'll sort that one in a separate issue, already tracked

Aside of some weird overlap between on hand and producer column (which we can fix later) we are good to go :)

@dacook dacook added technical changes only These pull requests do not contain user facing changes and are grouped in release notes and removed feedback-needed labels Dec 5, 2023
@dacook dacook merged commit 300998a into openfoodfoundation:master Dec 5, 2023
60 of 62 checks passed
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
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants