toolslot: load current bot position
This commit is contained in:
parent
89e9200ac2
commit
3dcf1f89c6
|
@ -9,25 +9,43 @@ describe("<ToolBayForm/>", () => {
|
||||||
let state = fakeState();
|
let state = fakeState();
|
||||||
let toggle = jest.fn();
|
let toggle = jest.fn();
|
||||||
let props = mapStateToProps(state);
|
let props = mapStateToProps(state);
|
||||||
|
let dispatch = jest.fn();
|
||||||
return {
|
return {
|
||||||
state,
|
state,
|
||||||
toggle,
|
toggle,
|
||||||
props,
|
props,
|
||||||
|
dispatch,
|
||||||
component: mount(<ToolBayForm
|
component: mount(<ToolBayForm
|
||||||
toggle={toggle}
|
toggle={toggle}
|
||||||
dispatch={state.dispatch}
|
dispatch={dispatch}
|
||||||
toolSlots={props.toolSlots}
|
toolSlots={props.toolSlots}
|
||||||
getToolSlots={props.getToolSlots}
|
getToolSlots={props.getToolSlots}
|
||||||
getChosenToolOption={props.getChosenToolOption}
|
getChosenToolOption={props.getChosenToolOption}
|
||||||
getToolOptions={props.getToolOptions}
|
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(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);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -36,7 +36,16 @@ export class ToolBayForm extends React.Component<ToolBayFormProps, {}> {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
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
|
let isSaving = toolSlots && toolSlots
|
||||||
.filter(x => x.saving).length !== 0;
|
.filter(x => x.saving).length !== 0;
|
||||||
|
@ -59,7 +68,7 @@ export class ToolBayForm extends React.Component<ToolBayFormProps, {}> {
|
||||||
isSaving={isSaving}
|
isSaving={isSaving}
|
||||||
isSaved={!isDirty && !isSaving}
|
isSaved={!isDirty && !isSaving}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
dispatch(saveAll(toolSlots, () => { toggle(); }))
|
dispatch(saveAll(toolSlots, () => { toggle(); }));
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
|
@ -75,6 +84,12 @@ export class ToolBayForm extends React.Component<ToolBayFormProps, {}> {
|
||||||
return <Row key={index}>
|
return <Row key={index}>
|
||||||
<Col xs={2}>
|
<Col xs={2}>
|
||||||
<label>{index + 1}</label>
|
<label>{index + 1}</label>
|
||||||
|
<button
|
||||||
|
className="blue fb-button"
|
||||||
|
title={positionButtonTitle}
|
||||||
|
onClick={() => useCurrentPosition(slot)}>
|
||||||
|
<i className="fa fa-crosshairs" />
|
||||||
|
</button>
|
||||||
</Col>
|
</Col>
|
||||||
<Col xs={2}>
|
<Col xs={2}>
|
||||||
<BlurableInput
|
<BlurableInput
|
||||||
|
|
|
@ -30,6 +30,7 @@ export class Tools extends React.Component<Props, Partial<ToolsState>> {
|
||||||
<ToolBayForm
|
<ToolBayForm
|
||||||
toggle={this.toggle("editingBays")}
|
toggle={this.toggle("editingBays")}
|
||||||
dispatch={this.props.dispatch}
|
dispatch={this.props.dispatch}
|
||||||
|
position={this.props.botPosition}
|
||||||
toolSlots={this.props.toolSlots}
|
toolSlots={this.props.toolSlots}
|
||||||
getToolSlots={this.props.getToolSlots}
|
getToolSlots={this.props.getToolSlots}
|
||||||
getChosenToolOption={this.props.getChosenToolOption}
|
getChosenToolOption={this.props.getChosenToolOption}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import {
|
||||||
TaggedTool,
|
TaggedTool,
|
||||||
TaggedToolSlotPointer,
|
TaggedToolSlotPointer,
|
||||||
} from "../resources/tagged_resources";
|
} from "../resources/tagged_resources";
|
||||||
|
import { BotPosition } from "../devices/interfaces";
|
||||||
|
|
||||||
export interface ToolsState {
|
export interface ToolsState {
|
||||||
editingTools: boolean;
|
editingTools: boolean;
|
||||||
|
@ -19,6 +20,7 @@ export interface Props {
|
||||||
dispatch: Function;
|
dispatch: Function;
|
||||||
isActive: (tool: TaggedTool) => boolean;
|
isActive: (tool: TaggedTool) => boolean;
|
||||||
changeToolSlot(t: TaggedToolSlotPointer, dispatch: Function): (d: DropDownItem) => void;
|
changeToolSlot(t: TaggedToolSlotPointer, dispatch: Function): (d: DropDownItem) => void;
|
||||||
|
botPosition: BotPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Tool {
|
export interface Tool {
|
||||||
|
@ -36,6 +38,7 @@ export interface ToolBayListProps {
|
||||||
export interface ToolBayFormProps {
|
export interface ToolBayFormProps {
|
||||||
dispatch: Function;
|
dispatch: Function;
|
||||||
toolSlots: TaggedToolSlotPointer[];
|
toolSlots: TaggedToolSlotPointer[];
|
||||||
|
position: BotPosition;
|
||||||
toggle(): void;
|
toggle(): void;
|
||||||
getToolOptions(): DropDownItem[];
|
getToolOptions(): DropDownItem[];
|
||||||
getChosenToolOption(uuid: string): DropDownItem;
|
getChosenToolOption(uuid: string): DropDownItem;
|
||||||
|
|
|
@ -74,7 +74,8 @@ export function mapStateToProps(props: Everything): Props {
|
||||||
getToolByToolSlotUUID,
|
getToolByToolSlotUUID,
|
||||||
changeToolSlot,
|
changeToolSlot,
|
||||||
isActive,
|
isActive,
|
||||||
dispatch: _.noop
|
dispatch: _.noop,
|
||||||
|
botPosition: props.bot.hardware.location_data.position
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue