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 { TaggedSequence, SpecialStatus } from "farmbot";
import { get } from "lodash"; import { get } from "lodash";
import { getStepTag, setStepTag } from "../sequence_tagging"; import { getStepTag, maybeTagStep } from "../sequence_tagging";
describe("tagAllSteps()", () => { describe("tagAllSteps()", () => {
const UNTAGGED_SEQUENCE: TaggedSequence = { const UNTAGGED_SEQUENCE: TaggedSequence = {
@ -36,7 +36,7 @@ describe("tagAllSteps()", () => {
expect(() => { expect(() => {
getStepTag(body[0]); getStepTag(body[0]);
}).toThrow(); }).toThrow();
setStepTag(body[0]); maybeTagStep(body[0]);
expect(get(body[0], "uuid")).toBeDefined(); 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. */ /** Property name where a unique ID is stored in a step. */
const TAG_PROP = "uuid"; const TAG_PROP = "uuid";
export const setStepTag = export const maybeTagStep =
(node: Traversable) => !get(node, TAG_PROP) && set(node, TAG_PROP, uuid()); (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. /** VERY IMPORTANT FUNCTION.
* SEE HEADER AT TOP OF FILE. * SEE HEADER AT TOP OF FILE.

View File

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

View File

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