Skip to content

Commit

Permalink
Add the ability to reset and cancel editing a pilot
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Nov 9, 2017
1 parent c19cd77 commit de269ed
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
37 changes: 36 additions & 1 deletion src/features/pilots/PilotDetails.jsx
Expand Up @@ -20,8 +20,13 @@ import {getValueFromEvent} from "common/utils/clientUtils";
import {
startEditingPilot,
stopEditingPilot,
cancelEditingPilot,
} from "./pilotsActions";

import {
resetEditedItem,
} from "features/editing/editingActions";


const RANKS = [
{value: "Private", text : "Private"},
Expand Down Expand Up @@ -76,6 +81,8 @@ const actions = {
startEditingPilot,
stopEditingPilot,
editItemAttributes,
resetEditedItem,
cancelEditingPilot,
}

export class PilotDetails extends Component {
Expand Down Expand Up @@ -103,6 +110,11 @@ 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 } = this.props;
const {startEditingPilot, stopEditingPilot} = this.props;
Expand All @@ -119,6 +131,8 @@ export class PilotDetails extends Component {
const canStartEditing = pilotIsSelected && !isEditingPilot;
const canStopEditing = pilotIsSelected && isEditingPilot;

const buttonWidth = 140;

return (
<Form size="large">
<FormEditWrapper
Expand Down Expand Up @@ -204,16 +218,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>
Expand Down
11 changes: 10 additions & 1 deletion src/features/pilots/pilotsActions.js
Expand Up @@ -18,7 +18,7 @@ export function selectPilot(pilotID) {
const isEditing = selectIsEditingPilot(state);

if(isEditing) {
dispatch(stopEditingPilot())
dispatch(cancelEditingPilot());
}

dispatch({
Expand All @@ -45,4 +45,13 @@ export function stopEditingPilot() {
dispatch(applyItemEdits("Pilot", currentPilot));
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 de269ed

Please sign in to comment.