app setting: confirm step deletion
This commit is contained in:
parent
e115ba3ad5
commit
e9e74bc211
|
@ -82,7 +82,7 @@ describe("maybeToggleFeature()", () => {
|
|||
describe("fetchLabFeatures", () => {
|
||||
it("basically just initializes stuff", () => {
|
||||
const val = fetchLabFeatures();
|
||||
expect(val.length).toBe(1);
|
||||
expect(val.length).toBe(2);
|
||||
expect(val[0].value).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -19,6 +19,13 @@ export const fetchLabFeatures = (): LabsFeature[] => ([
|
|||
widget from the Controls page.`),
|
||||
storageKey: BooleanSetting.hideWebcamWidget,
|
||||
value: false
|
||||
},
|
||||
{
|
||||
name: "Confirm Sequence Step Deletion",
|
||||
description: trim(`Show a confirmation dialog when the sequence delete step
|
||||
icon is pressed.`),
|
||||
storageKey: BooleanSetting.confirmStepDeletion,
|
||||
value: false
|
||||
}
|
||||
].map(fetchRealValue));
|
||||
|
||||
|
|
41
webpack/sequences/step_tiles/__tests__/index_test.ts
Normal file
41
webpack/sequences/step_tiles/__tests__/index_test.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
const mockStorj: Dictionary<boolean> = {};
|
||||
|
||||
jest.mock("../../../session", () => {
|
||||
return {
|
||||
Session: {
|
||||
getBool: (k: string) => {
|
||||
mockStorj[k] = !!mockStorj[k];
|
||||
return mockStorj[k];
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
import { Dictionary } from "farmbot";
|
||||
import { remove } from "../index";
|
||||
import { fakeSequence } from "../../../__test_support__/fake_state/resources";
|
||||
import { BooleanSetting } from "../../../session_keys";
|
||||
|
||||
describe("remove()", () => {
|
||||
beforeEach(function () {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it("deletes step without confirmation", () => {
|
||||
const dispatch = jest.fn();
|
||||
mockStorj[BooleanSetting.confirmStepDeletion] = false;
|
||||
remove({ index: 0, dispatch, sequence: fakeSequence() });
|
||||
expect(dispatch).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("deletes step with confirmation", () => {
|
||||
const dispatch = jest.fn();
|
||||
mockStorj[BooleanSetting.confirmStepDeletion] = true;
|
||||
remove({ index: 0, dispatch, sequence: fakeSequence() });
|
||||
expect(dispatch).not.toHaveBeenCalled();
|
||||
// tslint:disable-next-line:no-any
|
||||
(global as any).confirm = () => true;
|
||||
remove({ index: 0, dispatch, sequence: fakeSequence() });
|
||||
expect(dispatch).toHaveBeenCalled();
|
||||
});
|
||||
});
|
|
@ -18,6 +18,9 @@ import { CeleryNode, LegalSequenceKind, LegalArgString, If, Execute, Nothing } f
|
|||
import { TaggedSequence } from "../../resources/tagged_resources";
|
||||
import { overwrite } from "../../api/crud";
|
||||
import { TileFindHome } from "./tile_find_home";
|
||||
import { t } from "i18next";
|
||||
import { Session } from "../../session";
|
||||
import { BooleanSetting } from "../../session_keys";
|
||||
|
||||
interface MoveParams {
|
||||
step: Step;
|
||||
|
@ -63,12 +66,15 @@ interface RemoveParams {
|
|||
}
|
||||
|
||||
export function remove({ dispatch, index, sequence }: RemoveParams) {
|
||||
const original = sequence;
|
||||
const update = defensiveClone(original);
|
||||
update.body.body = (update.body.body || []);
|
||||
delete update.body.body[index];
|
||||
update.body.body = _.compact(update.body.body);
|
||||
dispatch(overwrite(original, update.body));
|
||||
if (!Session.getBool(BooleanSetting.confirmStepDeletion) ||
|
||||
confirm(t("Are you sure you want to delete this step?"))) {
|
||||
const original = sequence;
|
||||
const update = defensiveClone(original);
|
||||
update.body.body = (update.body.body || []);
|
||||
delete update.body.body[index];
|
||||
update.body.body = _.compact(update.body.body);
|
||||
dispatch(overwrite(original, update.body));
|
||||
}
|
||||
}
|
||||
|
||||
export function updateStep(props: StepInputProps) {
|
||||
|
|
|
@ -14,6 +14,7 @@ export enum BooleanSetting {
|
|||
/** "Labs" feature names. */
|
||||
weedDetector = "weedDetector",
|
||||
hideWebcamWidget = "hideWebcamWidget",
|
||||
confirmStepDeletion = "confirmStepDeletion",
|
||||
}
|
||||
|
||||
export enum NumericSetting {
|
||||
|
|
Loading…
Reference in a new issue