Fix the tool action verbiage bug.

pull/979/head
Rick Carlino 2018-09-10 14:23:52 -05:00
parent ece46bd857
commit 5629079ff4
4 changed files with 24 additions and 22 deletions

View File

@ -10,6 +10,7 @@ import { resourceList } from "./mark_as/resource_list";
import { actionList } from "./mark_as/action_list";
import { editStep } from "../../api/crud";
import { packStep } from "./mark_as/pack_step";
import { fancyDebug } from "../../util";
interface MarkAsState { nextResource: DropDownItem | undefined }
@ -19,7 +20,6 @@ export class MarkAs extends React.Component<StepParams, MarkAsState> {
commitSelection = (nextAction: DropDownItem) => {
const { nextResource } = this.state;
this.setState({ nextResource: undefined });
const nextStep =
packStep(this.props.currentStep as ResourceUpdate, nextResource, nextAction);
this.props.dispatch(editStep({
@ -32,17 +32,17 @@ export class MarkAs extends React.Component<StepParams, MarkAsState> {
c.args.value = nextStep.args.value;
c.args.resource_type = nextStep.args.resource_type;
c.args.resource_id = nextStep.args.resource_id;
fancyDebug(c.args);
}
}
}));
this.setState({ nextResource: undefined });
};
render() {
const step = this.props.currentStep as ResourceUpdate;
const { action, resource } =
unpackStep({ step, resourceIndex: this.props.resources });
const selectedAsOptn =
this.state.nextResource ? { label: "", value: "" } : action;
return <StepWrapper>
<StepHeader
className={this.className}
@ -67,15 +67,10 @@ export class MarkAs extends React.Component<StepParams, MarkAsState> {
<FBSelect
list={actionList(this.state.nextResource, step, this.props.resources)}
onChange={this.commitSelection}
key={JSON.stringify(selectedAsOptn)}
selectedItem={selectedAsOptn} />
key={JSON.stringify(action) + JSON.stringify(this.state)}
selectedItem={action} />
</Col>
</Row>
<Row>
<pre>
{step.args.resource_type}#{step.args.resource_id}.{step.args.label} = {step.args.value}
</pre>
</Row>
</StepContent>
</StepWrapper>;
}

View File

@ -6,7 +6,7 @@ import { selectAllTools } from "../../../resources/selectors";
const DEFAULT = "Default";
const DISMOUNT = { label: "Not Mounted", value: 0 };
const MOUNTED_TO = "Mounted to tool: ";
export const MOUNTED_TO = "Mounted to:";
const PLANT_OPTIONS = [
{ label: "Planned", value: "planned" },
{ label: "Planted", value: "planted" },
@ -19,7 +19,7 @@ const allToolsAsDDI = (i: ResourceIndex) => {
.filter(x => !!x.body.id)
.map(x => {
return {
label: MOUNTED_TO + x.body.name,
label: `${MOUNTED_TO} ${x.body.name}`,
value: x.body.id || 0
};
});

View File

@ -7,7 +7,7 @@ const value = 0; // Not used in headings.
const TOP_HALF = [
{ headingId: "Device", label: "Device", value, heading: true, },
{ headingId: "Device", label: "Tool Mount", value },
{ headingId: "Plant", label: "Plant", value, heading: true, }
{ headingId: "Plant", label: "Plants", value, heading: true, }
];
const isSaved = (x: TaggedResource) => !!x.body.id;

View File

@ -3,22 +3,30 @@ import { DropDownItem } from "../../../ui";
import { ResourceIndex } from "../../../resources/interfaces";
import { findToolById, findByKindAndId } from "../../../resources/selectors";
import { point2ddi } from "../tile_move_absolute/format_selected_dropdown";
import { capitalize } from "lodash";
import { MOUNTED_TO } from "./action_list";
interface InputData { step: ResourceUpdate; resourceIndex: ResourceIndex; }
interface OutputData { resource: DropDownItem; action: DropDownItem; }
const TOOL_MOUNT: DropDownItem = { label: "Tool Mount", value: "tool_mount" };
const NOT_IN_USE: DropDownItem = { label: "Not in use", value: 0 };
const NOT_IN_USE: DropDownItem = { label: "Not Mounted", value: 0 };
const DISMOUNTED: OutputData = { resource: TOOL_MOUNT, action: NOT_IN_USE };
const DEFAULT_TOOL_NAME = "Untitled Tool";
const REMOVED_ACTION = { label: "Removed", value: "removed" };
const mountedTo = (name = DEFAULT_TOOL_NAME): DropDownItem =>
({ label: `mounted to '${name}'`, value: "mounted" });
({ label: `${MOUNTED_TO} ${name}`, value: "mounted" });
function mountTool(i: InputData): OutputData {
const tool = findToolById(i.resourceIndex, i.step.args.resource_id);
return { resource: TOOL_MOUNT, action: mountedTo(tool.body.name) };
const { value } = i.step.args;
if (typeof value == "number" && value > 0) {
const tool = findToolById(i.resourceIndex, value);
return { resource: TOOL_MOUNT, action: mountedTo(tool.body.name) };
} else {
return DISMOUNTED;
}
}
function unknownOption(i: InputData): OutputData {
@ -44,19 +52,18 @@ function plantStage(i: InputData): OutputData {
const { resource_id, value } = i.step.args;
const r = findByKindAndId(i.resourceIndex, "Point", resource_id);
if (r.kind !== "Point") { throw new Error("Always expecting Point"); }
// .body;
const a = value as string;
return {
resource: { label: r.body.name, value: r.uuid },
action: { label: a, value: a }
action: { label: capitalize(a), value: a }
};
}
export function unpackStep(i: InputData): OutputData {
const { label, resource_id } = i.step.args;
const { label } = i.step.args;
switch (label) {
case "mounted_tool_id":
return resource_id && (resource_id > 0) ? mountTool(i) : DISMOUNTED;
case "mounted_tool_id": return mountTool(i);
case "discarded_at": return discardPoint(i);
case "plant_stage": return plantStage(i);
default: