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

Refs #30784 - MemoryAllocation use react helper #8413

Merged
merged 1 commit into from Apr 19, 2021

Conversation

ezr-ondrej
Copy link
Member

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.

@theforeman-bot
Copy link
Member

Issues: #30784

@@ -127,6 +103,16 @@ export function instanceTypeSelected(item) {
}
}

function setMemoryInputProps(props) {
Copy link
Member Author

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
Copy link
Member Author

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.

Copy link
Contributor

@yifatmakias yifatmakias left a 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:

  1. the label is missing both in the ovirt and libvirt pages.
  2. 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.
  3. 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">
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member Author

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)
Copy link
Member

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?

Copy link
Member Author

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

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 });

Copy link
Member Author

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 });

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

Awesome!

@ezr-ondrej
Copy link
Member Author

Thanks @yifatmakias for testing, I belive I've fixed all the issues, could you retest?
@LaViro I've answered your comments, could you take another look? :)

Ron-Lavi
Ron-Lavi previously approved these changes Apr 18, 2021
Copy link
Member

@Ron-Lavi Ron-Lavi left a 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 :)

@yifatmakias
Copy link
Contributor

@ezr-ondrej I tested it, works for me. Thanks

Copy link
Member

@MariaAga MariaAga left a 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 :)

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.
Copy link
Member

@MariaAga MariaAga left a comment

Choose a reason for hiding this comment

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

Thanks Ondrej!

@MariaAga MariaAga merged commit b264a1e into theforeman:develop Apr 19, 2021
@ezr-ondrej ezr-ondrej deleted the improve_memory_allocation branch April 20, 2021 07:17
@tristanrobert
Copy link
Contributor

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.

@ezr-ondrej
Copy link
Member Author

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 foreman_fog_proxmox usecase, would you happen to know what that is?

@tristanrobert
Copy link
Contributor

tristanrobert commented Oct 27, 2021

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
is called by HostsController#interfaces. But the form host parameters in the controller do not include host[compute_attributes][volumes_attributes][0][size], other fields are included except this one because it is a byte_size_f nested in a fieldset_tag. If it is moved outside the fieldset it works and it is in the parameters form.

@tristanrobert
Copy link
Contributor

tristanrobert commented Oct 27, 2021

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.

@ezr-ondrej
Copy link
Member Author

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 byte_size_f under fieldset_tag, but it still worked. It's little bit weird, can't that be something about the array? or the double nesting?

@tristanrobert
Copy link
Contributor

tristanrobert commented Nov 16, 2021

Which array? You are right it is about the nested fieldset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants