Fix clone button bug

pull/1041/head
Rick Carlino 2018-11-12 16:13:27 -06:00
parent 9e61d07d0d
commit 8c68ea35f1
4 changed files with 14 additions and 8 deletions

View File

@ -1,6 +1,6 @@
import { TaggedSequence, SpecialStatus } from "farmbot";
import { get } from "lodash";
import { getStepTag, setStepTag } from "../sequence_tagging";
import { getStepTag, maybeTagStep } from "../sequence_tagging";
describe("tagAllSteps()", () => {
const UNTAGGED_SEQUENCE: TaggedSequence = {
@ -36,7 +36,7 @@ describe("tagAllSteps()", () => {
expect(() => {
getStepTag(body[0]);
}).toThrow();
setStepTag(body[0]);
maybeTagStep(body[0]);
expect(get(body[0], "uuid")).toBeDefined();
});
});

View File

@ -52,8 +52,13 @@ export type StepTag = string;
/** Property name where a unique ID is stored in a step. */
const TAG_PROP = "uuid";
export const setStepTag =
(node: Traversable) => !get(node, TAG_PROP) && set(node, TAG_PROP, uuid());
export const maybeTagStep =
(t: Traversable) => !get(t, TAG_PROP) && forceSetStepTag(t);
export const forceSetStepTag = <T extends Traversable>(node: T): T => {
set(node, TAG_PROP, uuid());
return node;
};
/** VERY IMPORTANT FUNCTION.
* SEE HEADER AT TOP OF FILE.

View File

@ -22,6 +22,7 @@ import { TileFindHome } from "./tile_find_home";
import { t } from "i18next";
import { MarkAs } from "./mark_as";
import { TileUnknown } from "./tile_unknown";
import { forceSetStepTag } from "../../resources/sequence_tagging";
interface MoveParams {
step: Step;
@ -52,7 +53,7 @@ interface CopyParams {
}
export function splice({ step, sequence, index }: CopyParams) {
const copy = defensiveClone(step);
const copy = forceSetStepTag(defensiveClone(step));
const next = defensiveClone(sequence);
const seq = next.body;
seq.body = seq.body || [];

View File

@ -8,7 +8,7 @@ import {
import {
SequenceResource as Sequence
} from "farmbot/dist/resources/api_resources";
import { setStepTag } from "../../../resources/sequence_tagging";
import { maybeTagStep } from "../../../resources/sequence_tagging";
// ======= TYPE DECLARATIONS =======
/** Less strict version of CeleryScript args. It's traversable, or unknown. */
@ -74,7 +74,7 @@ export const sanitizeNodes = (input: Sequence): Sequence => {
const collectUniqVariables = (id: Identifier) => used[id.args.label] = id;
climb(input, node => {
setStepTag(node);
maybeTagStep(node);
isIdentifier(node) && collectUniqVariables(node);
});
@ -82,7 +82,7 @@ export const sanitizeNodes = (input: Sequence): Sequence => {
input.args.locals.body = Object.values(used)
.map(({ args }) => declared[args.label] || newVar(args.label))
.map(node => {
setStepTag(node);
maybeTagStep(node);
return node;
});