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
Refs #30784 - MemoryAllocation use react helper #8413
Refs #30784 - MemoryAllocation use react helper #8413
Conversation
Issues: #30784 |
589e45d
to
61916d0
Compare
@@ -127,6 +103,16 @@ export function instanceTypeSelected(item) { | |||
} | |||
} | |||
|
|||
function setMemoryInputProps(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.
Simplifies all the usages.
</Row> | ||
</Grid> | ||
<> | ||
<RCInputNumber |
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.
Uses the external component directly, as the FormInput component takes care of the labels and other stuff.
61916d0
to
44a38e6
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.
@ezr-ondrej Thanks for the improvements :)
but I noticed a few problems:
- the label is missing both in the ovirt and libvirt pages.
- in the ovirt form whenever you choose a template or instance type it should change the value in the memory input accordingly. It is not working after these changes.
- the compute_profile_js_test is failing.
@@ -39,12 +39,7 @@ disable_mem = !new_vm || (new_vm && instance_type && instance_type.memory.presen | |||
|
|||
<%= counter_f f, :sockets, :disabled => disable_sockets, :label => _('Sockets'), :label_size => 'col-md-2' %> | |||
<div id="memory-input"> |
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.
Is the wrapper div still needed?
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, we are using it to select it and change the props (value) from legacy JS
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, we need to select it from the jquery code, so there is unfortunatelly no other way then add the wrapper.
options[:help_block] += f.hidden_field(attr, :class => "real-hidden-value", :id => nil) | ||
|
||
text_f(f, attr, options) | ||
react_form_input('memory', f, attr, options) |
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.
looks good to me, but maybe plugin owners that use it can help test if it also works for them?
@tristanrobert mind take a look for foreman_fog_proxmox, there are several usages there
@shiramax mind take a look for foreman_kubevirt?
If those are the only use cases, @ezr-ondrej how about using only react_form_input
so we won't need to maintain another wrapper?
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 the wrapper is very simple and beneficial - now we are free to change the implementation and the plugins are not required to do any changes in their code, if we would decided we want to implement this component in angular in the future, we can do so.
defaultValue: result.memory / megabyte, | ||
}) | ||
); | ||
setMemoryInputProps({ value: result.memory / megabyte }); |
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.
how about storing it as a helper at the top of the file, and using it also on line 81, e.g:
const setMemoryValue = () => setMemoryInputProps({ value: result.memory / megabyte });
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.
Sure, why not :) I think more like:
const setMemoryValue = memoryBytes => setMemoryInputProps({ value: memoryBytes / megabyte });
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've changed the component so it accepts value in bytes, so we don't need the calculation, and thus the wrapper seemed not very useful.
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.
Awesome!
44a38e6
to
d007376
Compare
d007376
to
43f3ee3
Compare
Thanks @yifatmakias for testing, I belive I've fixed all the issues, could you retest? |
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.
Thanks @ezr-ondrej ! code wise looks good to me 🚀
didn't test yet as I have some env issues, though I count on @yifatmakias with that :)
@ezr-ondrej I tested it, works for me. 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.
One small request before merging :)
...sets/javascripts/react_app/components/MemoryAllocationInput/MemoryAllocationInput.stories.js
Outdated
Show resolved
Hide resolved
In 8a9922f we've removed `byte_size_f` last usage. This is moving the byte_size_f to render the React component, to seamlessly integrate into the form without breaking any plugins that were possibly still using it. Adds posibility for InputFactory components to set validation states.
43f3ee3
to
dd3eb10
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.
Thanks Ondrej!
byte_size_f in fieldset_tag is no more enabled in form: field is ignored in form and controller. foreman_fog_proxmox plugin views using it are broken. |
Could you share more details, I believe it is working in the foreman usecases and those didn't change in view nor in the controller, so there have to be something special on the |
For example, this view: https://github.com/theforeman/foreman_fog_proxmox/blob/91ca57f45944b5ce503c4276a7859374b41d671f/app/views/compute_resources_vms/form/proxmox/server/_volume_hard_disk.html.erb#L31 |
So I think I need to replace my fieldsets with div, but it is a huge change (js, views, etc). I use fieldsets to hide or disable many grouped fields in forms. |
I've tried to nest some |
Which array? You are right it is about the nested fieldset. |
In 8a9922f we've removed
byte_size_f
last usage.This is moving the byte_size_f to render the React component, to
seamlessly integrate into the form without breaking any plugins that
were possibly still using it.
Adds posibility for InputFactory components to set validation states.