-
Notifications
You must be signed in to change notification settings - Fork 356
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
FormButtons component, with redux #3509
Conversation
TODO (separate PRs): start using it from the problematic angular forms |
This pull request is not mergeable. Please rebase and repush. |
should be a 1:1 match to the existing miqButton component meant for new react form buttons
override cancelclicked.. cancelClicked: () => {
props.cancelClicked();
props.dispatch({type: 'FormButtons.customLabel', payload: "karel"});
}, |
init callbacks.. ManageIQ.redux.store.dispatch({ type: 'FormButtons.callbacks', payload: {
cancelClicked: () => console.log('cancel'),
addClicked: () => console.log('add'),
saveClicked: () => console.log('save'),
resetClicked: () => console.log('reset'),
}}); |
this is just a dumb presentation-only component it will be wrapped in another one that listens for messages from the form and updates it accordingly
reset form buttons to initial state ManageIQ.redux.store.dispatch({ type: 'FormButtons.init', payload: {} }) change the default Add/Save label ManageIQ.redux.store.dispatch({ type: 'FormButtons.customLabel', payload: __('Magic') }) set newRecord - if true, the Add button is shown (and addClicked called), else the Save and Reset buttons are shown (and saveClicked, resetClicked called) ManageIQ.redux.store.dispatch({ type: 'FormButtons.newRecord', payload: true }) set pristine - pristine form can't be reset (and shouldn't be saveable) ManageIQ.redux.store.dispatch({ type: 'FormButtons.pristine', payload: false }) set saveable - means no validation error, the submit button will be enabled based on this ManageIQ.redux.store.dispatch({ type: 'FormButtons.saveable', payload: false }) set callbacks - an object of functions - addClicked, saveClicked, resetClicked and cancelClicked are accepted ManageIQ.redux.store.dispatch({ type: 'FormButtons.callbacks', payload: { addClicked: () => console.log('add'), cancelClicked: () => console.log('cancel'), resetClicked: () => console.log('reset'), saveClicked: () => console.log('save'), }})
(Testing, on dashboard screen:
) |
the idea here is, when using FormButtonRedux from a modal, you want to change the handlers to close the modal after so, you get to replace the handler, and get the original as an argument, to call from the replacement specifically in ProviderDialogs modal, we override save, add and cancel to close the window afterwards if the original handler returns a promise, closing will wait for that promise if the orignal handler returns anything else, closing is immediate
Added an easier way to override the callbacks ( |
@Hyperkid123 : can you, please, test this together with your form? |
Checked commits https://github.com/himdel/manageiq-ui-classic/compare/a53cc5ee2d01fbf26d9cc5f7dfc4b0659da992c9~...034ad78972f10b602ed932deac1f2fe93b7887e8 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
This is in preparation of having React forms in ui-classic, and adds several components:
MiqButton
- a react reimplementation of our angular miqButton (1:1 exceptalt
is implied whentitle
is set) - shows a button with enabled/disabled, titles, and actionsFormButtons
- a react implementation of our angulargeneric_form_buttons
partial - does not deal with finding out the form state but when it gets it, it renders the buttonsFormButtonsRedux
- a wrapper for FormButtons which uses Redux for state management (so that we can trigger actions from anywhere, including angular forms)The idea is that
FormButtonsRedux
will live in the "paging" toolbar, and the forms will be sending redux actions to tell the buttons what to show, and those buttons will be sending back actions like saveClicked, resetClicked, cancelClicked so that the form can handle them.Related to: https://bugzilla.redhat.com/show_bug.cgi?id=1437800
reset form buttons to initial state
change the default Add/Save label
set newRecord - if true, the Add button is shown (and addClicked called), else the Save and Reset buttons are shown (and saveClicked, resetClicked called)
set pristine - pristine form can't be reset (and shouldn't be saveable)
set saveable - means no validation error, the submit button will be enabled based on this
set callbacks - an object of functions - addClicked, saveClicked, resetClicked and cancelClicked are accepted
Cc @ZitaNemeckova, @Hyperkid123 , @martinpovolny