toolslot: load current bot position

This commit is contained in:
gabrielburnworth 2017-08-14 18:31:02 -07:00
parent 89e9200ac2
commit 3dcf1f89c6
5 changed files with 46 additions and 8 deletions

View file

@ -9,25 +9,43 @@ describe("<ToolBayForm/>", () => {
let state = fakeState();
let toggle = jest.fn();
let props = mapStateToProps(state);
let dispatch = jest.fn();
return {
state,
toggle,
props,
dispatch,
component: mount(<ToolBayForm
toggle={toggle}
dispatch={state.dispatch}
dispatch={dispatch}
toolSlots={props.toolSlots}
getToolSlots={props.getToolSlots}
getChosenToolOption={props.getChosenToolOption}
getToolOptions={props.getToolOptions}
changeToolSlot={props.changeToolSlot} />)
changeToolSlot={props.changeToolSlot}
position={{ x: 1, y: 2, z: 3 }} />)
};
}
it("renders", () => {
let test = bootstrapTest();
expect(test.component.find("input").length).toEqual(3);
it("renders ToolSlot", () => {
let test = bootstrapTest();
let inputs = test.component.find("input");
expect(inputs.length).toEqual(3);
expect(test.component.text()).toContain("Trench Digging Tool");
expect(inputs.at(0).props().value).toEqual("10");
expect(inputs.at(1).props().value).toEqual("10");
expect(inputs.at(2).props().value).toEqual("10");
});
it("fills inputs with bot position", () => {
let test = bootstrapTest();
let buttons = test.component.find("button");
expect(buttons.length).toEqual(6);
buttons.at(3).simulate("click");
let argList = test.dispatch.mock.calls;
expect(argList[0][0].payload.update.x).toEqual(1);
expect(argList[1][0].payload.update.y).toEqual(2);
expect(argList[2][0].payload.update.z).toEqual(3);
});
});

View file

@ -36,7 +36,16 @@ export class ToolBayForm extends React.Component<ToolBayFormProps, {}> {
}
render() {
let { toggle, dispatch, toolSlots } = this.props;
let { toggle, dispatch, toolSlots, position } = this.props;
function useCurrentPosition(slot: TaggedToolSlotPointer) {
dispatch(edit(slot, { x: position.x }));
dispatch(edit(slot, { y: position.y }));
dispatch(edit(slot, { z: position.z }));
}
let positionButtonTitle =
`use current location (${position.x}, ${position.y}, ${position.z})`;
let isSaving = toolSlots && toolSlots
.filter(x => x.saving).length !== 0;
@ -59,7 +68,7 @@ export class ToolBayForm extends React.Component<ToolBayFormProps, {}> {
isSaving={isSaving}
isSaved={!isDirty && !isSaving}
onClick={() => {
dispatch(saveAll(toolSlots, () => { toggle(); }))
dispatch(saveAll(toolSlots, () => { toggle(); }));
}}
/>
<button
@ -75,6 +84,12 @@ export class ToolBayForm extends React.Component<ToolBayFormProps, {}> {
return <Row key={index}>
<Col xs={2}>
<label>{index + 1}</label>
<button
className="blue fb-button"
title={positionButtonTitle}
onClick={() => useCurrentPosition(slot)}>
<i className="fa fa-crosshairs" />
</button>
</Col>
<Col xs={2}>
<BlurableInput

View file

@ -30,6 +30,7 @@ export class Tools extends React.Component<Props, Partial<ToolsState>> {
<ToolBayForm
toggle={this.toggle("editingBays")}
dispatch={this.props.dispatch}
position={this.props.botPosition}
toolSlots={this.props.toolSlots}
getToolSlots={this.props.getToolSlots}
getChosenToolOption={this.props.getChosenToolOption}

View file

@ -3,6 +3,7 @@ import {
TaggedTool,
TaggedToolSlotPointer,
} from "../resources/tagged_resources";
import { BotPosition } from "../devices/interfaces";
export interface ToolsState {
editingTools: boolean;
@ -19,6 +20,7 @@ export interface Props {
dispatch: Function;
isActive: (tool: TaggedTool) => boolean;
changeToolSlot(t: TaggedToolSlotPointer, dispatch: Function): (d: DropDownItem) => void;
botPosition: BotPosition;
}
export interface Tool {
@ -36,6 +38,7 @@ export interface ToolBayListProps {
export interface ToolBayFormProps {
dispatch: Function;
toolSlots: TaggedToolSlotPointer[];
position: BotPosition;
toggle(): void;
getToolOptions(): DropDownItem[];
getChosenToolOption(uuid: string): DropDownItem;

View file

@ -74,7 +74,8 @@ export function mapStateToProps(props: Everything): Props {
getToolByToolSlotUUID,
changeToolSlot,
isActive,
dispatch: _.noop
dispatch: _.noop,
botPosition: props.bot.hardware.location_data.position
};
}