-
-
Notifications
You must be signed in to change notification settings - Fork 729
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
Convert enterprises/edit page to stimulus #9510
Convert enterprises/edit page to stimulus #9510
Conversation
f7a6b26
to
0564608
Compare
Some specs are failing. Back into |
3dcca85
to
2b61b82
Compare
Hello @jibees I know that here it's saying that two tests in |
The spec fails:
It use throw when user click on Does this help? (FYI, the spec fail locally, and when I go to |
Ok, now I see, you don't run the right spec ; the one failing is |
arghhh sorry, Should've looked at the error more carefully! |
2f47c6c
to
41430eb
Compare
@jibees Finally got the tests to pass. Could you have a look when you have the time, and let me know if any changes are required? Thanks! |
} | ||
|
||
get currentActiveTab() { | ||
return this.element.querySelector('.selected') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As .selected
is a very common class (selector), I'd vote to specify elements with target (let's say tab
target)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm yes, if we do that we can use this.tabTargets.querySelector('.${this.className})
to get the active tab which is much more specific and intentional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gave me the idea to use
const currentActiveForm = this.formTargets.find(
(form) => form.id == `${currentActiveTab.id}_form`
);
const newActiveForm = this.formTargets.find(
(form) => form.id == `${newActiveTab.id}_form`
);
in enteprise_form_controller
😄
And I've made the other changes you requested. Thanks jean!
newActiveTab: event.currentTarget | ||
}}) | ||
|
||
this.currentActiveTab.classList.remove('selected') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can add selected
as a value, to be as generic as possible?
} | ||
|
||
show({detail: { currentActiveTab, newActiveTab }}) { | ||
let currentActiveForm = this.element.querySelector(`#${currentActiveTab.id}_form`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to use const
as often as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one! I still need to look at those cableresponses things, and understand what's happening ;)
I have few comments, that should be addressed/discussed.
During this time, could you please rebase onto master? I've added a precommit hook, and prettier in the stack, in order to have all the js formatted the same way.
After fetching upstream and running Also getting this when I try to commit after changing any
It lets me commit after I run prettier manually, but thought I would ask if this is intentional 😄 |
cc39b56
to
7a82167
Compare
|
9d1e5f6
to
b5b80a1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*/ | ||
|
||
import { Application } from "stimulus"; | ||
import side_menu_controller from "../../../app/webpacker/controllers/side_menu_controller"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if there is any way to test enterprise_form_controller
controller without side_menu_controller
?
- If yes, I think it should be done. I don't think we need to click on element, but only send event.
- If no, I think
enterprise_form_controller
should be included toside_menu_controller
.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's possible to test enterprise_form
in isolation because the payload for show() { detail: { currentActiveTab, newActiveTab } }
is unique.
I did think of making these into a single controller, but I felt it was easier to understand what was happening when there were two of them working together. Especially because the elements that they are concerned with (side menu handles tabs
and enterprise form handles form
) are different.
Also, I couldn't think of an appropriate name for such a controller.
Should I try to make them into a single controller? I think this takes a hit on the readability of the code though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I re-read your code, trying to understand better how elements are interacting.
I'm now more confident that (IMHO) those two controllers should be merged into one, for example panel_controller
which handle at the same time the side menu on the left (which could be on top adctually, so I'd rename it into menu?) and the content that are displayed or not, strongly depending on what is selected/clicked on the menu.
To my opinion, it'll be easier to understand (no event between controllers will be sent, I think it's easier to understand), and will be fully generic (ie. not depending on any enterprise-something).
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I see what you mean. I think you're also thinking about the menu on the top Dashboard Products ...
and that makes sense (maybe we could use this controller to render those thing when we get there). Ok I'll convert it into a single menu_controller
. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, It can be used somewhere else (one day?!) and it should be generic.
I though about panel
because menu
makes me think that we don't talk about content (but only about clickable links).
Maybe it's better to call it tabs_and_panels_controller
? I don't know, I'm very bad about naming something...
Anyway, thanks a lot for your comprehension, and your patience!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you take a look jibbes? Sorry, it took me sometime to get this done. I always mess something up when I need to go back and do a rebase, so it takes a couple of tries to get it right! 😫
@@ -0,0 +1,25 @@ | |||
import { Controller } from "stimulus" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is not formatted as it should be. I'm wondering then how you was able to commit ...
Could you please run yarn prettier --check .
and copy/paste the output?
Thanks! 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I formatted it correctly and pushed jn. Also, I squashed those commits!
b5b80a1
to
dfa6a01
Compare
dfa6a01
to
79ba223
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work. I have to admit that I can't judge the architecture because I have no experience with Stimulus but the code is readable. 😄
Hey @binarygit, Thanks for this huge piece of work and your detailed notes on what to test. Going through them: On the
Uploading Screencast from 17-08-2022 18:04:06.webm… Had a look as well on other browsers and mobile:
Good to go 🎉 |
What? Why?
Replaces the angular code that handled rendering of admin/enterprises/<enterprise_name>/edit
More context here: https://openfoodnetwork.slack.com/archives/C03QBDHDCSY/p1658325112405699 and #9478
Closes #
What should we test?
Release notes
Changelog Category: Technical changes
The title of the pull request will be included in the release notes.
Dependencies
Documentation updates