Permalink
Browse files

Add the ability to reset and cancel editing a pilot

  • Loading branch information...
markerikson committed Jan 22, 2017
1 parent 09c5236 commit a4c2ce72f24841c90295f9d20c1252e0ad9eefab
Showing with 46 additions and 7 deletions.
  1. +37 −7 src/features/pilots/PilotDetails/PilotDetails.jsx
  2. +9 −0 src/features/pilots/pilotsActions.js
@@ -12,8 +12,13 @@ import {selectCurrentPilot, selectIsEditingPilot} from "../pilotsSelectors";
import {
startEditingPilot,
stopEditingPilot,
cancelEditingPilot,
} from "../pilotsActions";
import {
resetEditedItem,
} from "features/editing/editingActions";
import {editItemAttributes} from "features/editing/editingActions";
import {getValueFromEvent} from "common/utils/clientUtils";
@@ -64,11 +69,6 @@ const mapState = (state) => {
pilot = Pilot.withId(currentPilot).ref;
}
}
return {pilot, pilotIsSelected, isEditingPilot}
}
@@ -77,6 +77,8 @@ const actions = {
startEditingPilot,
stopEditingPilot,
editItemAttributes,
resetEditedItem,
cancelEditingPilot,
}
@@ -106,9 +108,14 @@ export class PilotDetails extends Component {
this.props.stopEditingPilot();
}
onResetClicked = () => {
const {id} = this.props.pilot;
this.props.resetEditedItem("Pilot", id);
}
render() {
const {pilot={}, pilotIsSelected = false, isEditingPilot = false, ...actions } = this.props;
const {pilot={}, pilotIsSelected = false, isEditingPilot = false } = this.props;
const {
name = "",
@@ -122,6 +129,8 @@ export class PilotDetails extends Component {
const canStartEditing = pilotIsSelected && !isEditingPilot;
const canStopEditing = pilotIsSelected && isEditingPilot;
const buttonWidth = 140;
return (
<Form size="large">
<FormEditWrapper
@@ -207,16 +216,37 @@ export class PilotDetails extends Component {
disabled={!canStartEditing}
type="button"
onClick={this.onStartEditingClicked}
style={{width : buttonWidth, marginRight : 10}}
>
Start Editing
</Button>
<Button
secondary
disabled={!canStopEditing}
type="button"
style={{width : buttonWidth}}
onClick={this.onStopEditingClicked}
>
Stop Editing
Save Edits
</Button>
</Grid.Row>
<Grid.Row width={16}>
<Button
disabled={!canStopEditing}
type="button"
onClick={this.onResetClicked}
style={{width : buttonWidth, marginRight : 10}}
>
Reset Values
</Button>
<Button
negative
disabled={!canStopEditing}
type="button"
style={{width : buttonWidth}}
onClick={this.props.cancelEditingPilot}
>
Cancel Edits
</Button>
</Grid.Row>
</Form>
@@ -47,3 +47,12 @@ export function stopEditingPilot() {
dispatch(stopEditingItem("Pilot", currentPilot));
}
}
export function cancelEditingPilot() {
return (dispatch, getState) => {
const currentPilot = selectCurrentPilot(getState());
dispatch({type : PILOT_EDIT_STOP});
dispatch(stopEditingItem("Pilot", currentPilot));
}
}

0 comments on commit a4c2ce7

Please sign in to comment.