Permalink
Browse files

Only stop editing if the current pilot is deleted

  • Loading branch information...
markerikson committed Jan 22, 2017
1 parent 35e48d5 commit d5da05b7951b9d1e50275f4b25d540d13699c93a
Showing with 25 additions and 2 deletions.
  1. +9 −2 src/features/pilots/PilotsList/PilotsListRow.jsx
  2. +16 −0 src/features/pilots/pilotsReducer.js
@@ -59,10 +59,17 @@ const PilotsListRow = ({pilot={}, onPilotClicked=_.noop, selected, deleteEntity}
mechType = "",
} = pilot;
- const onDeleteClicked = () => deleteEntity("Pilot", id);
+ const onDeleteClicked = (e) => {
+ e.stopPropagation();
+ e.preventDefault();
+ deleteEntity("Pilot", id);
+ }
+
+ const onRowClicked = () => onPilotClicked(id);
+
return (
- <Table.Row onClick={() => onPilotClicked(id)} active={selected}>
+ <Table.Row onClick={onRowClicked} active={selected}>
<Table.Cell>
{name}
</Table.Cell>
@@ -6,6 +6,10 @@ import {
PILOT_EDIT_STOP,
} from "./pilotsConstants";
+import {
+ ENTITY_DELETE,
+} from "features/entities/entityConstants";
+
const initialState = {
currentPilot : null,
isEditing : false,
@@ -41,9 +45,21 @@ export function stopEditingPilot(state, payload) {
};
}
+export function stopEditingIfDeleted(state, payload) {
+ const {itemType, itemID} = payload;
+ const {isEditing, currentPilot} = state;
+
+ if(isEditing && itemType === "Pilot" && itemID === currentPilot) {
+ return stopEditingPilot(state, payload);
+ }
+
+ return state;
+}
+
export default createReducer(initialState, {
[PILOT_SELECT] : selectPilot,
[PILOT_EDIT_START] : startEditingPilot,
[PILOT_EDIT_STOP] : stopEditingPilot,
+ [ENTITY_DELETE] : stopEditingIfDeleted,
});

0 comments on commit d5da05b

Please sign in to comment.