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

Replaced ror form with react form component #3856

Merged
merged 11 commits into from Jun 12, 2018

Conversation

Hyperkid123
Copy link
Contributor

@Hyperkid123 Hyperkid123 commented Apr 26, 2018

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.

  • added react-ui-components to dependencies

Before

screenshot from 2018-05-07 11-48-27

After

screenshot from 2018-06-07 09-51-21

When the i18n PR in react-ui-components is merged, will remove the strings from props.

@Hyperkid123
Copy link
Contributor Author

@miq-bot assign @martinpovolny
@miq-bot add_label wip

if(values.snap_memory) {
values.snap_memory = 1;
}
miqAjaxButton('#{url_for_only_path(:action => "snap_vm", :id => @record.id, :button => @edit ? "create" : nil)}', values);
Copy link
Member

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';
Copy link
Member

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

Copy link
Contributor Author

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 => (
Copy link
Member

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?

@Hyperkid123
Copy link
Contributor Author

Hyperkid123 commented Apr 26, 2018

@ohadlevy yep i know i did this to mostly test the component. Refactoring is coming

@Hyperkid123
Copy link
Contributor Author

cc @karelhala

@karelhala
Copy link
Contributor

@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 vm-snapshot-form-common.js so it' loaded on every page. Then have some class/id/attribute which you'd try to load from DOM if such thing is present run specific code for this form.

@Hyperkid123
Copy link
Contributor Author

@karelhala that sucks

@ohadlevy
Copy link
Member

@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)?

);
};

$(() => {
Copy link
Member

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:

  1. expose the top level / high level react component so its available to the registry
  2. 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.

Copy link
Contributor

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.

@Hyperkid123
Copy link
Contributor Author

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

"data-name-required" => !!@record.try(:snapshot_name_optional?)}

:javascript
ManageIQ.component.componentFactory('VmSnapshotForm', 'snap-form');
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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?

@Hyperkid123 Hyperkid123 force-pushed the snap-form branch 2 times, most recently from f0c3060 to 5c14bdb Compare May 3, 2018 13:08
@Hyperkid123 Hyperkid123 changed the title [WIP] Replaced ror form with react form component Replaced ror form with react form component May 7, 2018
@Hyperkid123 Hyperkid123 changed the title Replaced ror form with react form component [WIP] Replaced ror form with react form component May 7, 2018
@Hyperkid123 Hyperkid123 changed the title [WIP] Replaced ror form with react form component Replaced ror form with react form component May 7, 2018
@Hyperkid123
Copy link
Contributor Author

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

@miq-bot miq-bot removed the wip label May 7, 2018
: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),
Copy link
Member

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

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.

: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),

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.

@Hyperkid123 Hyperkid123 force-pushed the snap-form branch 2 times, most recently from 892e293 to 4b4b514 Compare May 14, 2018 11:20
@miq-bot
Copy link
Member

miq-bot commented May 14, 2018

This pull request is not mergeable. Please rebase and repush.

@Hyperkid123 Hyperkid123 force-pushed the snap-form branch 2 times, most recently from 97221cf to fc6bc00 Compare May 14, 2018 11:46
@Hyperkid123
Copy link
Contributor Author

@hstastna helped me to test this form in UI and it is working. I think it can be merged.

@miq-bot
Copy link
Member

miq-bot commented Jun 7, 2018

This pull request is not mergeable. Please rebase and repush.

@Hyperkid123 Hyperkid123 force-pushed the snap-form branch 2 times, most recently from 044663a to 0c2921d Compare June 7, 2018 12:42
@Hyperkid123
Copy link
Contributor Author

Hyperkid123 commented Jun 7, 2018

@miq-bot remove_label unmergeable

@miq-bot
Copy link
Member

miq-bot commented Jun 12, 2018

This pull request is not mergeable. Please rebase and repush.

@miq-bot
Copy link
Member

miq-bot commented Jun 12, 2018

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
3 files checked, 0 offenses detected
Everything looks fine. 🍪

@Hyperkid123
Copy link
Contributor Author

@miq-bot remove_label unmergeable

@martinpovolny martinpovolny merged commit 024a68b into ManageIQ:master Jun 12, 2018
@martinpovolny martinpovolny added this to the Sprint 88 Ending Jun 18, 2018 milestone Jun 12, 2018
@Hyperkid123 Hyperkid123 deleted the snap-form branch July 10, 2018 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants