Permalink
Browse files

Add ability to display pilot entry from "draft" editingEntities slice

  • Loading branch information...
markerikson committed Jan 25, 2017
1 parent 018c552 commit 3cb01fc7da1242f068bd98fa3835070c213efecf
@@ -26,6 +26,9 @@ export function copyEntity(sourceEntities, destinationEntities, payload) {
const {itemID, itemType} = payload;
const newItemAttributes = readEntityData(sourceEntities, itemType, itemID);
if(newItemAttributes.name) {
newItemAttributes.name += " (copied)";
}
const creationPayload = {itemType, itemID, newItemAttributes}
const updatedEntities = createEntity(destinationEntities, creationPayload);
@@ -1 +1,11 @@
export const selectEditingEntities = state => state.editingEntities;
import {createSelector} from "reselect";
import schema from "app/schema";
export const selectEditingEntities = state => state.editingEntities;
export const getEditingEntitiesSession = createSelector(
selectEditingEntities,
editingEntities => schema.from(editingEntities)
);
@@ -3,6 +3,7 @@ import {connect} from "react-redux";
import {Form, Dropdown, Grid, Button} from "semantic-ui-react";
import {getEntitiesSession} from "features/entities/entitySelectors";
import {getEditingEntitiesSession} from "features/editing/editingSelectors";
import FormEditWrapper from "common/components/FormEditWrapper";
@@ -48,17 +49,25 @@ const mapState = (state) => {
let pilot;
const currentPilot = selectCurrentPilot(state);
const session = getEntitiesSession(state);
const {Pilot} = session;
if(Pilot.hasId(currentPilot)) {
pilot = Pilot.withId(currentPilot).ref;
}
const pilotIsSelected = Boolean(currentPilot);
const isEditingPilot = selectIsEditingPilot(state);
if(pilotIsSelected) {
const session = isEditingPilot ?
getEditingEntitiesSession(state) :
getEntitiesSession(state);
const {Pilot} = session;
if(Pilot.hasId(currentPilot)) {
pilot = Pilot.withId(currentPilot).ref;
}
}
return {pilot, pilotIsSelected, isEditingPilot}
}
@@ -87,6 +96,16 @@ export class PilotDetails extends Component {
this.props.updateEntity("Pilot", id, newValues);
}
onStartEditingClicked = () => {
const {id} = this.props.pilot;
this.props.startEditingPilot(id);
}
onStopEditingClicked = () => {
const {id} = this.props.pilot;
this.props.stopEditingPilot(id);
}
render() {
const {pilot={}, pilotIsSelected = false, isEditingPilot = false, ...actions } = this.props;
@@ -187,15 +206,15 @@ export class PilotDetails extends Component {
primary
disabled={!canStartEditing}
type="button"
onClick={actions.startEditingPilot}
onClick={this.onStartEditingClicked}
>
Start Editing
</Button>
<Button
secondary
disabled={!canStopEditing}
type="button"
onClick={actions.stopEditingPilot}
onClick={this.onStopEditingClicked}
>
Stop Editing
</Button>
@@ -1,3 +1,8 @@
import {
editExistingItem,
stopEditingItem
} from "features/editing/editingActions";
import {
PILOT_SELECT,
PILOT_EDIT_START,
@@ -11,14 +16,17 @@ export function selectPilot(pilotID) {
};
}
export function startEditingPilot() {
return {
type : PILOT_EDIT_START,
};
export function startEditingPilot(pilotID) {
return (dispatch, getState) => {
dispatch(editExistingItem("Pilot", pilotID));
dispatch({type : PILOT_EDIT_START});
}
}
export function stopEditingPilot() {
return {
type : PILOT_EDIT_STOP,
};
export function stopEditingPilot(pilotID) {
return (dispatch, getState) => {
dispatch({type : PILOT_EDIT_STOP});
dispatch(stopEditingItem("Pilot", pilotID));
}
}

0 comments on commit 3cb01fc

Please sign in to comment.