43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
![]() |
import { SequenceBodyItem, TaggedSequence } from "farmbot";
|
||
![]() |
import { SelectSequence } from "./interfaces";
|
||
![]() |
import { edit, init, overwrite } from "../api/crud";
|
||
|
import { defensiveClone } from "../util";
|
||
![]() |
import { push } from "../history";
|
||
|
import { urlFriendly } from "../util";
|
||
![]() |
import { Actions } from "../constants";
|
||
![]() |
import { t } from "i18next";
|
||
![]() |
import { setActiveSequenceByName } from "./set_active_sequence_by_name";
|
||
![]() |
|
||
|
export function pushStep(step: SequenceBodyItem,
|
||
|
dispatch: Function,
|
||
|
sequence: TaggedSequence) {
|
||
![]() |
const next = defensiveClone(sequence);
|
||
![]() |
next.body.body = next.body.body || [];
|
||
![]() |
next.body.body.push(defensiveClone(step));
|
||
![]() |
dispatch(overwrite(sequence, next.body));
|
||
|
}
|
||
|
|
||
|
export function editCurrentSequence(dispatch: Function, seq: TaggedSequence,
|
||
|
update: Partial<typeof seq.body>) {
|
||
|
dispatch(edit(seq, update));
|
||
|
}
|
||
|
|
||
|
let count = 1;
|
||
![]() |
|
||
![]() |
export const copySequence = (payload: TaggedSequence) =>
|
||
|
(dispatch: Function) => {
|
||
![]() |
const copy = defensiveClone(payload);
|
||
![]() |
copy.body.id = undefined;
|
||
![]() |
copy.body.name = copy.body.name + t(" copy ") + (count++);
|
||
![]() |
dispatch(init(copy.kind, copy.body));
|
||
![]() |
push("/app/sequences/" + urlFriendly(copy.body.name));
|
||
![]() |
setActiveSequenceByName();
|
||
![]() |
};
|
||
![]() |
|
||
|
export function selectSequence(uuid: string): SelectSequence {
|
||
|
return {
|
||
![]() |
type: Actions.SELECT_SEQUENCE,
|
||
![]() |
payload: uuid
|
||
|
};
|
||
|
}
|