fix step drag bugs

pull/516/head
gabrielburnworth 2017-10-25 17:03:59 -07:00
parent 2dafdacb30
commit 0ca9b427fb
2 changed files with 26 additions and 23 deletions

View File

@ -65,7 +65,7 @@ describe("onDrop()", () => {
it("step_splice", () => {
const dispatch = jest.fn();
onDrop(dispatch, fakeSequence())(0, "");
onDrop(dispatch, fakeSequence())(0, "fakeUuid");
dispatch.mock.calls[0][0](() => {
return { value: 1, intent: "step_splice", draggerId: 2 };
});
@ -76,7 +76,7 @@ describe("onDrop()", () => {
it("step_move", () => {
const dispatch = jest.fn();
onDrop(dispatch, fakeSequence())(3, "");
onDrop(dispatch, fakeSequence())(3, "fakeUuid");
dispatch.mock.calls[0][0](() => {
return { value: 4, intent: "step_move", draggerId: 5 };
});
@ -85,4 +85,10 @@ describe("onDrop()", () => {
expect(argsList.to).toEqual(3);
expect(argsList.from).toEqual(5);
});
it("not a valid step object", () => {
const dispatch = jest.fn();
onDrop(dispatch, fakeSequence())(0, "");
expect(dispatch).not.toHaveBeenCalled();
});
});

View File

@ -1,5 +1,5 @@
import * as React from "react";
import { DataXferObj, ActiveMiddleProps } from "./interfaces";
import { ActiveMiddleProps } from "./interfaces";
import { execSequence } from "../devices/actions";
import { editCurrentSequence } from "./actions";
import { splice, move } from "./step_tiles/index";
@ -8,7 +8,6 @@ import { t } from "i18next";
import { BlurableInput, Row, Col, SaveBtn } from "../ui";
import { DropArea } from "../draggable/drop_area";
import { stepGet } from "../draggable/actions";
import { pushStep } from "./actions";
import { copySequence } from "./actions";
import { TaggedSequence } from "../resources/tagged_resources";
import { save, edit, destroy } from "../api/crud";
@ -20,20 +19,22 @@ import { AllSteps } from "./all_steps";
export const onDrop =
(dispatch1: Function, sequence: TaggedSequence) =>
(index: number, key: string) => {
dispatch1(function (dispatch2: Function, getState: GetState) {
const dataXferObj = dispatch2(stepGet(key));
const step = dataXferObj.value;
switch (dataXferObj.intent) {
case "step_splice":
return dispatch2(splice({ step, sequence, index }));
case "step_move":
const action =
move({ step, sequence, to: index, from: dataXferObj.draggerId });
return dispatch2(action);
default:
throw new Error("Got unexpected data transfer object.");
}
});
if (key.length > 0) {
dispatch1(function (dispatch2: Function, getState: GetState) {
const dataXferObj = dispatch2(stepGet(key));
const step = dataXferObj.value;
switch (dataXferObj.intent) {
case "step_splice":
return dispatch2(splice({ step, sequence, index }));
case "step_move":
const action =
move({ step, sequence, to: index, from: dataXferObj.draggerId });
return dispatch2(action);
default:
throw new Error("Got unexpected data transfer object.");
}
});
}
};
const copy = function (dispatch: Function, sequence: TaggedSequence) {
@ -45,10 +46,6 @@ export class SequenceEditorMiddleActive extends
React.Component<ActiveMiddleProps, {}> {
render() {
const { dispatch, sequence } = this.props;
const fixThisToo = function (key: string) {
const xfer = dispatch(stepGet(key)) as DataXferObj;
pushStep(xfer.value, dispatch, sequence);
};
return (
<div className="sequence-editor-content">
@ -90,7 +87,7 @@ export class SequenceEditorMiddleActive extends
<Row>
<Col xs={12}>
<DropArea isLocked={true}
callback={fixThisToo}>
callback={(key) => onDrop(dispatch, sequence)(Infinity, key)}>
{t("DRAG COMMAND HERE")}
</DropArea>
</Col>