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
Replaced ror form with react form component #3856
Conversation
@miq-bot assign @martinpovolny |
app/views/vm_common/_snap.html.haml
Outdated
if(values.snap_memory) { | ||
values.snap_memory = 1; | ||
} | ||
miqAjaxButton('#{url_for_only_path(:action => "snap_vm", :id => @record.id, :button => @edit ? "create" : nil)}', values); |
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.
why split the logic? and have it inline? I would expect that if we move something to react, we don't use haml anymore?
@@ -16,6 +17,7 @@ import reactBlueprint from '../miq-component/react-blueprint'; | |||
import * as helpers from '../miq-component/helpers'; | |||
|
|||
import { rxSubject, sendDataWithRx, listenToRx } from '../miq_observable'; | |||
import { SnapshotForm } from '@manageiq/react-ui-components/dist/vm-snapshot-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.
imho better to split this logic to another file, we should try keeping application-common to a minimum / top level
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.
Yep i agree this is in early phase i just needed to consult some things with @martinpovolny
@@ -31,3 +33,9 @@ ManageIQ.component = { | |||
ManageIQ.angular.rxSubject = rxSubject; | |||
window.sendDataWithRx = sendDataWithRx; | |||
window.listenToRx = listenToRx; | |||
|
|||
$(() => { | |||
newRegistry.define('SnapshotForm', reactBlueprint(props => ( |
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.
why do you want to mount this on every page? imho the rails view should be trigging mounting the component instead?
@ohadlevy yep i know i did this to mostly test the component. Refactoring is coming |
cc @karelhala |
@Hyperkid123 the problem you are facing is known issue and it's not trivial to be fixed. The problem is how loading of packs from ruby webpack works, he basically identifies if some packs should be loaded. Your pack was loaded in partial which is rendered on server and served as html partial containing only load par of such pack, however this pack is identified as not to load on such page. When I went trough the code it looks like the best approach would be to change name of the pack to |
@karelhala that sucks |
@Hyperkid123 I personally don't see a lot of value of creating many small packs, rather unify them and have only one server roundtrip (and also caching)? |
); | ||
}; | ||
|
||
$(() => { |
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.
TBH I don't understand why we are solving the problem this way.
IMHO the right way to do this is:
- expose the top level / high level react component so its available to the registry
- use a rails view helper to mount the component on the dom as demonstrated at https://github.com/priley86/miq_v2v_ui_plugin/blob/master/app/views/migration/index.html.haml#L2
this will allow you to pass the right data in the place you would expect react to be rendering (Rather relaying on jquery functions).
You would be able to pass any ruby props at that stage as well.
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.
@Hyperkid123 is not using ReactDOM.render
directly, but trough component
's API here so using mounter might not be that great. However we should use as less jquery as possible so perhaps rewriting $(() =>{})
into document.addEventListener('DOMContentLoaded', () => {}, false);
might be better (or create helper function which does this thing, or even better use DocReady). And of course let's use document.querySelector[All]
with getAttribute
to access data attr.
Other way which might be better is to create new ruby helper function which does all these things combined.
@karelhala @ohadlevy. This is what i have come up with.What do you think? @himdel advised, that i should create a smart wrapper around the component, that will pass manageiq specific data. I have also created a simple factory, that will build the component. That should remove the JQuery code. Rest of the props is passed from the element as data propeties. Name of these properties must match the component props. |
app/views/vm_common/_snap.html.haml
Outdated
"data-name-required" => !!@record.try(:snapshot_name_optional?)} | ||
|
||
:javascript | ||
ManageIQ.component.componentFactory('VmSnapshotForm', 'snap-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.
why not simply pass json instead of an html? am i missing something or is this what https://github.com/ManageIQ/manageiq-ui-classic/blob/master/app/helpers/reactjs_helper.rb suppose to be doing.....?
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.
We are using different React API #3633. It it slightly different than your mounter. Also why not JSON. Usign element.dataset
will return JSON from data attributes, so its basically the same and that way we don't need additional ruby code.
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 its better to do it in ruby vs doing in html template (haml) if its going to be consumed as json at the end anyway, we go though an extra step?
f0c3060
to
5c14bdb
Compare
@martinpovolny can you check it out? From what i know, RHV VMs shoud have a bit different behavior than the rest. Also i have added a simple function that will initialize the component. It is very similar to the current angular way to initialize components. |
app/views/vm_common/_snap.html.haml
Outdated
:title => t, | ||
:type => "submit") | ||
= render :partial => "layouts/flash_msg" | ||
#snap-form{"data-create-url" => url_for_only_path(:action => "snap_vm", :id => @record.id, :button => @edit ? "create" : nil), |
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'll add it here again, I can't see value in using the dom as a place holder for data, we can avoid the extra dom lookup and putting data on it directly by simply passing json to the component factory.
was this done by design? /cc @himdel @vojtechszocs
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.
Does it matter? I mean, you either put the data here, and deal with the data types, escapement with HAML and Ruby or you put the data in a hash, encode it in JSON and have it in the :javascript
DOM node as code.
What's the benefit of one vs the other?
From the introspection perspective with this approach data stays data in the data-*
attribute that is meant for data ;-) Is that wrong somehow?
@ohadlevy : I am trying to understand your concern so that we don't disregard your opinion. But I really don't see the problem. Neither does @himdel or @Hyperkid123.
From my perspective it would be best if the #snap-form...
and the Manageiq.component.componentFactory....
statements where a single entity. I'd see value in that. But if these are to be 2 pieces then I don't see much difference if the data is in the former or the latter.
app/views/vm_common/_snap.html.haml
Outdated
:title => t, | ||
:type => "submit") | ||
= render :partial => "layouts/flash_msg" | ||
#snap-form{"data-create-url" => url_for_only_path(:action => "snap_vm", :id => @record.id, :button => @edit ? "create" : nil), |
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.
Does it matter? I mean, you either put the data here, and deal with the data types, escapement with HAML and Ruby or you put the data in a hash, encode it in JSON and have it in the :javascript
DOM node as code.
What's the benefit of one vs the other?
From the introspection perspective with this approach data stays data in the data-*
attribute that is meant for data ;-) Is that wrong somehow?
@ohadlevy : I am trying to understand your concern so that we don't disregard your opinion. But I really don't see the problem. Neither does @himdel or @Hyperkid123.
From my perspective it would be best if the #snap-form...
and the Manageiq.component.componentFactory....
statements where a single entity. I'd see value in that. But if these are to be 2 pieces then I don't see much difference if the data is in the former or the latter.
892e293
to
4b4b514
Compare
This pull request is not mergeable. Please rebase and repush. |
97221cf
to
fc6bc00
Compare
@hstastna helped me to test this form in UI and it is working. I think it can be merged. |
This pull request is not mergeable. Please rebase and repush. |
044663a
to
0c2921d
Compare
@miq-bot remove_label unmergeable |
This pull request is not mergeable. Please rebase and repush. |
Checked commits Hyperkid123/manageiq-ui-classic@0766d37~...59627b7 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
@miq-bot remove_label unmergeable |
compute -> infrastructure -> virtual machines (or any other VM)
select virtual machine, click on snapshot row in table
click on add snapshot button in top toolbar
fix for: https://bugzilla.redhat.com/show_bug.cgi?id=1527371
component is implemented in react-ui-components
There was no validation on client side, so the form had to be rewritten in JS.
Before
After
When the i18n PR in react-ui-components is merged, will remove the strings from props.