import * as React from "react"; import { changeStep, removeStep, pushStep } from "./actions"; import { assign } from "lodash"; import { Step } from "./interfaces"; import { Help } from "../help"; import { ExecuteBlock } from "./execute_block"; import { Sequence } from "./interfaces"; import { defensiveClone } from "../util"; import { t } from "i18next"; interface CopyParams { dispatch: Function; step: Step; } export function copy({dispatch, step}: CopyParams) { let copy = assign<{}, Step>({}, step); dispatch(pushStep(copy)); }; interface RemoveParams { index: number; dispatch: Function; } export function remove({dispatch, index}: RemoveParams) { dispatch(removeStep(index)); } interface UpdateStepParams { dispatch: Function; step: Step; index: number; field: string; // "x"|"y"|"z"|"speed"; } let updateStep = function ({ dispatch, step, index, field }: UpdateStepParams) { return (e: React.FormEvent) => { let update = defensiveClone(step); (update.command as {[name: string]: UpdateStepParams})[field] = (e.target as any).value; let action = changeStep(index, update); dispatch(action); }; }; interface IStepInput { step: Step; field: "speed" | "pin" | "value" | "mode" | "operator" | "x" | "y" | "z" | "stub" // For unimplemented features. | "variable" ; dispatch: Function; index: number; } export function StepInputBox({step, field, dispatch, index}: IStepInput) { return ; } export interface StepParams { dispatch: Function; step: Step; index: number; sequence: Sequence; sequences: Sequence[]; } export type StepTile = (input: StepParams) => JSX.Element; interface StepDictionary { [stepName: string]: StepTile; }; let Pending = ({ dispatch, index }: StepParams) => { return
Coming soon! Delete: remove({dispatch, index}) } />
; }; export let stepTiles: StepDictionary = { emergency_stop: Pending, home_all: Pending, home_x: Pending, home_y: Pending, home_z: Pending, read_status: Pending, write_parameter: Pending, read_parameter: Pending, if_statement: ExecuteBlock, execute: Pending, move_relative: function({dispatch, step, index}: StepParams) { return(
copy({dispatch, step}) } /> remove({dispatch, index}) } />
); }, "move_absolute": function({dispatch, step, index}: StepParams){ return(
copy({dispatch, step}) } /> remove({dispatch, index}) } />
); }, "pin_write": function({dispatch, step, index}: StepParams){ return(
copy({dispatch, step}) } /> remove({dispatch, index}) } />
); }, "wait": function({dispatch, step, index}: StepParams){ return(
copy({dispatch, step}) } /> remove({dispatch, index}) } />
); }, "send_message": function({dispatch, step, index}: StepParams){ return(
copy({dispatch, step}) } /> remove({dispatch, index}) } />
); }, "read_pin": function({dispatch, step, index}: StepParams){ return(
copy({dispatch, step}) } /> remove({dispatch, index}) } />
); }, };