vigetlabs / microcosm

Flux with actions at center stage. Write optimistic updates, cancel requests, and track changes with ease.
http://code.viget.com/microcosm/
MIT License
487 stars 29 forks source link

Add confirm prop to ActionButton and ActionForm #521

Closed nhunzaker closed 6 years ago

nhunzaker commented 6 years ago

What

This PR adds a confirm prop to ActionButton and ActionForm that allows users to bail out of action dispatch if the result is false. Like:

function askUser(value, event) {
  return confirm("Are you sure you want to do this?")
}

function ConfirmButton(props) {
  return (
    <ActionButton action={deleteItem} confirm={askUser}>
      Delete Item
    </ActionButton>
  )
}

Why

ActionButton doesn't have a great way to confirm actions like deleting a record. For symmetry, I also added this functionality to ActionForm.


Note: This is against 12.x, our stable release. I'll eventually move this over to 13.x too.

tommymarshall commented 6 years ago

Very cool!

codecov-io commented 6 years ago

Codecov Report

Merging #521 into 12-stable will increase coverage by <.01%. The diff coverage is 100%.

Impacted file tree graph

@@              Coverage Diff              @@
##           12-stable     #521      +/-   ##
=============================================
+ Coverage      99.78%   99.78%   +<.01%     
=============================================
  Files             26       26              
  Lines            936      944       +8     
=============================================
+ Hits             934      942       +8     
  Misses             2        2
Impacted Files Coverage Δ
src/addons/action-button.js 100% <100%> (ø) :arrow_up:
src/addons/action-form.js 100% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update b5603fc...f6b8210. Read the comment docs.