Skip to content

Commit

Permalink
Merge pull request #2451 from FarmBot/staging
Browse files Browse the repository at this point in the history
v15.8.11
  • Loading branch information
gabrielburnworth authored Dec 15, 2023
2 parents 2ec973b + 1d9bad9 commit 6ca328a
Show file tree
Hide file tree
Showing 91 changed files with 932 additions and 620 deletions.
25 changes: 25 additions & 0 deletions frontend/api/__tests__/delete_points_handler_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
jest.mock("../delete_points", () => ({
deletePointsByIds: jest.fn(),
}));

import { deleteAllIds } from "../delete_points_handler";
import { deletePointsByIds } from "../delete_points";
import { fakePoint } from "../../__test_support__/fake_state/resources";

describe("deleteAllIds()", () => {
it("deletes points", () => {
window.confirm = () => true;
const points = [fakePoint(), fakePoint()];
deleteAllIds("points", points)(
{ stopPropagation: jest.fn() } as unknown as React.MouseEvent<HTMLElement>);
expect(deletePointsByIds).toHaveBeenCalledWith("points", [1, 2]);
});

it("doesn't delete points", () => {
window.confirm = () => false;
const points = [fakePoint(), fakePoint()];
deleteAllIds("points", points)(
{ stopPropagation: jest.fn() } as unknown as React.MouseEvent<HTMLElement>);
expect(deletePointsByIds).not.toHaveBeenCalled();
});
});
23 changes: 22 additions & 1 deletion frontend/api/__tests__/delete_points_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jest.mock("../../util", () => ({
trim: jest.fn(x => x),
}));

import { deletePoints } from "../delete_points";
import { deletePoints, deletePointsByIds } from "../delete_points";
import axios from "axios";
import { API } from "../api";
import { times } from "lodash";
Expand Down Expand Up @@ -82,3 +82,24 @@ describe("deletePoints()", () => {
expect(success).toHaveBeenCalledWith("Deleted 200 weeds");
});
});

describe("deletePointsByIds()", () => {
it("deletes points", async () => {
mockDelete = Promise.resolve();
await deletePointsByIds("points", [1, 2, 3]);
expect(axios.delete).toHaveBeenCalledWith(EXPECTED_BASE_URL + "1,2,3");
expect(error).not.toHaveBeenCalled();
expect(success).toHaveBeenCalledWith("Deleted 3 points");
});

it("doesn't delete points", async () => {
mockDelete = Promise.reject("error");
await deletePointsByIds("points", [1, 2, 3]);
expect(axios.delete).toHaveBeenCalledWith(EXPECTED_BASE_URL + "1,2,3");
expect(error).toHaveBeenCalledWith(expect.stringContaining(
"Some points failed to delete."));
expect(error).toHaveBeenCalledWith(expect.stringContaining(
"Are they in use by sequences?"));
expect(success).not.toHaveBeenCalled();
});
});
2 changes: 1 addition & 1 deletion frontend/api/crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ const MUST_CONFIRM_LIST: ResourceName[] = [
"PointGroup",
];

const confirmationChecker = (resourceName: ResourceName, force = false) =>
const confirmationChecker = (resourceName: ResourceName, force: boolean) =>
<T>(proceed: () => T): T | undefined => {
if (MUST_CONFIRM_LIST.includes(resourceName)) {
if (force || confirm(t("Are you sure you want to delete this item?"))) {
Expand Down
12 changes: 12 additions & 0 deletions frontend/api/delete_points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,15 @@ export function deletePoints(
});
};
}

export const deletePointsByIds = (pointName: string, ids: number[]) =>
Promise
.all(chunk(ids, 100).map(c => axios
.delete(API.current.pointsPath + c.join(","))))
.then(() =>
success(t("Deleted {{num}} {{points}}", {
num: ids.length, points: pointName,
})))
.catch(() =>
error(trim(`${t("Some {{points}} failed to delete.", { points: pointName })}
${t("Are they in use by sequences?")}`)));
16 changes: 16 additions & 0 deletions frontend/api/delete_points_handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { betterCompact } from "../util";
import { t } from "../i18next_wrapper";
import { TaggedGenericPointer, TaggedWeedPointer } from "farmbot";
import { deletePointsByIds } from "./delete_points";

export const deleteAllIds = (
pointName: string,
points: (TaggedGenericPointer | TaggedWeedPointer)[],
) =>
(event: React.MouseEvent<HTMLElement>) => {
const ids = betterCompact(points.map(p => p.body.id));
event.stopPropagation();
confirm(t("Delete all {{ count }} {{points}} in section?",
{ count: ids.length, points: pointName })) &&
deletePointsByIds(pointName, ids);
};
2 changes: 1 addition & 1 deletion frontend/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2111,7 +2111,7 @@ export enum DeviceSetting {
cameraView = `Camera view`,
uncroppedCameraView = `Uncropped Camera view`,
confirmPlantDeletion = `Confirm plant deletion`,
defaultPlantDepth = `Default plant depth`,
defaultPlantDepth = `Default plant depth (mm)`,

// Account
accountSettings = `Account`,
Expand Down
2 changes: 1 addition & 1 deletion frontend/controls/move/move_controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const MoveControls = (props: MoveControlsProps) => {
const { busy, locked } = props.bot.hardware.informational_settings;
return <div className={"move"}>
<Popover position={Position.LEFT_TOP} className={"move-settings"}
target={<i className="fa fa-gear" />}
target={<i className={"fa fa-gear fb-icon-button"} />}
content={<MoveWidgetSettingsMenu
dispatch={props.dispatch}
getConfigValue={props.getConfigValue}
Expand Down
8 changes: 8 additions & 0 deletions frontend/css/buttons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,14 @@
&.modified {
box-shadow: 0 0 0px 3px $yellow !important;
}
.fa-spinner {
margin: 0;
color: $dark_gray !important;
}
.fa-check {
margin: 0;
color: $green !important;
}
}

.front-page-button {
Expand Down
2 changes: 2 additions & 0 deletions frontend/css/colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ $translucent2: rgba(0, 0, 0, 0.2);
$translucent3: rgba(0, 0, 0, 0.3);
$translucent4: rgba(0, 0, 0, 0.4);
$translucent5: rgba(0, 0, 0, 0.5);
$translucent1_white: rgba(255, 255, 255, 0.1);
$translucent3_white: rgba(255, 255, 255, 0.3);
$white: #fff;
$off_white: #f4f4f4;
$lighter_gray: #eee;
Expand Down
11 changes: 6 additions & 5 deletions frontend/css/farm_designer/farm_designer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@
display: flex;
flex-direction: column;
flex-wrap: wrap;
max-width: 134px;
max-width: 155px;
padding: 1rem;
background: rgba(255, 255, 255, .75);
border-radius: 5px;
Expand Down Expand Up @@ -775,10 +775,12 @@
}
.caret-menu-button {
display: inline;
margin-left: 0.25rem;
font-weight: bold;
font-size: medium;
cursor: pointer;
span {
margin-left: 0.25rem;
}
}
.more-bugs,
.select-mode,
Expand Down Expand Up @@ -979,7 +981,6 @@
.fa-caret-left,
.fa-caret-right,
.fa-step-forward {
line-height: 1.3rem;
font-weight: bold;
vertical-align: middle;
}
Expand All @@ -993,11 +994,11 @@
}
.fa-step-backward,
.fa-caret-left {
margin-right: 1rem;
margin-right: 0.1rem;
}
.fa-caret-right,
.fa-step-forward {
margin-left: 1rem;
margin-left: 0.1rem;
}
}

Expand Down
Loading

0 comments on commit 6ca328a

Please sign in to comment.