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

FormButtons component, with redux #3509

Merged
merged 7 commits into from
Jul 20, 2018
Merged

FormButtons component, with redux #3509

merged 7 commits into from
Jul 20, 2018

Conversation

himdel
Copy link
Contributor

@himdel himdel commented Mar 2, 2018

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 except alt is implied when title is set) - shows a button with enabled/disabled, titles, and actions

  • FormButtons - a react implementation of our angular generic_form_buttons partial - does not deal with finding out the form state but when it gets it, it renders the buttons

  • FormButtonsRedux - 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

      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'),
      }})
    

Cc @ZitaNemeckova, @Hyperkid123 , @martinpovolny

@himdel himdel added the wip label Mar 2, 2018
@himdel
Copy link
Contributor Author

himdel commented Mar 2, 2018

TODO (separate PRs):

start using it from the problematic angular forms
start using it from the rest of angular forms
start using it from non-angular forms

@miq-bot
Copy link
Member

miq-bot commented Mar 2, 2018

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

himdel added 2 commits July 19, 2018 09:21
should be a 1:1 match to the existing miqButton component
meant for new react form buttons
@himdel
Copy link
Contributor Author

himdel commented Jul 19, 2018

override cancelclicked..

    cancelClicked: () => {
      props.cancelClicked();
      props.dispatch({type: 'FormButtons.customLabel', payload: "karel"});
    },

@himdel
Copy link
Contributor Author

himdel commented Jul 19, 2018

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

himdel added 2 commits July 19, 2018 12:13
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'),
    }})
@himdel himdel changed the title [WIP] FormButtons component, with redux FormButtons component, with redux Jul 19, 2018
@himdel
Copy link
Contributor Author

himdel commented Jul 19, 2018

(Testing, on dashboard screen:

ManageIQ.component.componentFactory('FormButtonsRedux', '#main-content')

ManageIQ.redux.store.dispatch({ type: 'FormButtons.customLabel', payload: 'magic' })
...

)

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
@himdel
Copy link
Contributor Author

himdel commented Jul 19, 2018

Added an easier way to override the callbacks (callbackOverrides), used in ProviderDialogs modal to close the window once saved, added or cancelled.

@martinpovolny
Copy link
Member

@Hyperkid123 : can you, please, test this together with your form?

@miq-bot
Copy link
Member

miq-bot commented Jul 19, 2018

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

@himdel himdel deleted the form-buttons-react branch July 20, 2018 11:53
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.

3 participants