Skip to content

Commit

Permalink
interface cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielburnworth committed Jul 1, 2019
1 parent 83c06b8 commit bec7cc2
Show file tree
Hide file tree
Showing 16 changed files with 26 additions and 80 deletions.
2 changes: 1 addition & 1 deletion frontend/__test_support__/user.ts
@@ -1,4 +1,4 @@
import { User } from "../auth/interfaces";
import { User } from "farmbot/dist/resources/api_resources";
import { TaggedUser, SpecialStatus } from "farmbot";

export let user: User = {
Expand Down
6 changes: 3 additions & 3 deletions frontend/__tests__/controls_popup_test.tsx
Expand Up @@ -45,15 +45,15 @@ describe("<ControlsPopup />", () => {
expect(button.props().title).toBe("move x axis (100)");
button.simulate("click");
expect(mockDevice.moveRelative)
.toHaveBeenCalledWith({ speed: 100, x: 100, y: 0, z: 0 });
.toHaveBeenCalledWith({ x: 100, y: 0, z: 0 });
});

it("y axis is not inverted", () => {
const button = wrapper.find("button").at(1);
expect(button.props().title).toBe("move y axis (100)");
button.simulate("click");
expect(mockDevice.moveRelative)
.toHaveBeenCalledWith({ speed: 100, x: 0, y: 100, z: 0 });
.toHaveBeenCalledWith({ x: 0, y: 100, z: 0 });
});

it("disabled when closed", () => {
Expand All @@ -72,7 +72,7 @@ describe("<ControlsPopup />", () => {
expect(button.props().title).toBe("move x axis (100)");
button.simulate("click");
expect(mockDevice.moveRelative)
.toHaveBeenCalledWith({ speed: 100, x: 100, y: 0, z: 0 });
.toHaveBeenCalledWith({ x: 100, y: 0, z: 0 });
});

it("takes photo", () => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/account/index.tsx
Expand Up @@ -6,7 +6,7 @@ import {
import { Props } from "./interfaces";
import { Page, Row, Col } from "../ui";
import { mapStateToProps } from "./state_to_props";
import { User } from "../auth/interfaces";
import { User } from "farmbot/dist/resources/api_resources";
import { edit, save } from "../api/crud";
import { updateNO } from "../resources/actions";
import { deleteUser, resetAccount } from "./actions";
Expand Down
9 changes: 0 additions & 9 deletions frontend/account/interfaces.ts
@@ -1,4 +1,3 @@
import { User } from "../auth/interfaces";
import { TaggedUser } from "farmbot";
import { GetWebAppConfigValue } from "../config_storage/actions";
import { Thunk } from "../redux/interfaces";
Expand All @@ -9,14 +8,6 @@ export interface Props {
getConfigValue: GetWebAppConfigValue;
}

/** JSON form that gets POSTed to the API when user updates their info. */
export interface UserInfo extends Record<keyof User, string> {
password: string;
new_password: string;
new_password_confirmation: string;
password_deletion_confirmation: string;
}

export interface DeletionRequest {
password: string;
}
Expand Down
12 changes: 2 additions & 10 deletions frontend/auth/interfaces.ts
@@ -1,4 +1,4 @@
export interface Token {
interface Token {
unencoded: UnencodedToken;
encoded: string;
}
Expand All @@ -7,7 +7,7 @@ export interface AuthState {
token: Token;
}

export interface UnencodedToken {
interface UnencodedToken {
/** ISSUER - Where token came from (API URL). */
iss: string;
/** Where to download RPi software */
Expand All @@ -17,11 +17,3 @@ export interface UnencodedToken {
/** JSON Token Identifier- auto sync needs this to hear its echo on MQTT */
jti: string;
}

export interface User {
id: number;
name: string;
email: string;
created_at?: string;
updated_at?: string;
}
2 changes: 1 addition & 1 deletion frontend/connectivity/device_is_throttled.ts
@@ -1,4 +1,4 @@
import { DeviceAccountSettings } from "../devices/interfaces";
import { DeviceAccountSettings } from "farmbot/dist/resources/api_resources";

/** Determines if the device was forced to wait due to log flooding. */
export const deviceIsThrottled =
Expand Down
2 changes: 1 addition & 1 deletion frontend/controls/move/__tests__/direction_button_test.tsx
Expand Up @@ -54,7 +54,7 @@ describe("<DirectionButton/>", function () {
const btn = mount(<DirectionButton {...buttonProps} />);
btn.simulate("click");
expect(mockDevice.moveRelative)
.toHaveBeenCalledWith({ speed: 100, x: 0, y: 1000, z: 0 });
.toHaveBeenCalledWith({ x: 0, y: 1000, z: 0 });
});
});

Expand Down
4 changes: 2 additions & 2 deletions frontend/controls/move/__tests__/jog_buttons_test.tsx
Expand Up @@ -77,7 +77,7 @@ describe("<JogButtons/>", function () {
expect(button.props().title).toBe("move x axis (100)");
button.simulate("click");
expect(mockDevice.moveRelative)
.toHaveBeenCalledWith({ speed: 100, x: 100, y: 0, z: 0 });
.toHaveBeenCalledWith({ x: 100, y: 0, z: 0 });
});

it("has swapped xy jog buttons", () => {
Expand All @@ -89,6 +89,6 @@ describe("<JogButtons/>", function () {
expect(button.props().title).toBe("move y axis (100)");
button.simulate("click");
expect(mockDevice.moveRelative)
.toHaveBeenCalledWith({ speed: 100, x: 0, y: 100, z: 0 });
.toHaveBeenCalledWith({ x: 0, y: 100, z: 0 });
});
});
6 changes: 3 additions & 3 deletions frontend/controls/move/direction_button.tsx
@@ -1,8 +1,8 @@
import * as React from "react";
import { moveRelative } from "../../devices/actions";
import { DirectionButtonProps, Payl } from "./interfaces";
import { CONFIG_DEFAULTS } from "farmbot/dist/config";
import { DirectionButtonProps } from "./interfaces";
import { t } from "../../i18next_wrapper";
import { MoveRelProps } from "../../devices/interfaces";

export function directionDisabled(props: DirectionButtonProps): boolean {
const {
Expand Down Expand Up @@ -41,7 +41,7 @@ export function calculateDistance(props: DirectionButtonProps) {

export class DirectionButton extends React.Component<DirectionButtonProps, {}> {
sendCommand = () => {
const payload: Payl = { speed: CONFIG_DEFAULTS.speed, x: 0, y: 0, z: 0 };
const payload: MoveRelProps = { x: 0, y: 0, z: 0 };
payload[this.props.axis] = calculateDistance(this.props);
moveRelative(payload);
}
Expand Down
7 changes: 0 additions & 7 deletions frontend/controls/move/interfaces.ts
Expand Up @@ -31,13 +31,6 @@ export interface DirectionButtonProps {
disabled: boolean | undefined;
}

export interface Payl {
speed: number;
x: number;
y: number;
z: number;
}

export interface StepSizeSelectorProps {
choices: number[];
selected: number;
Expand Down
Expand Up @@ -33,6 +33,14 @@ describe("<PinNumberDropdown />", () => {
it("renders undefined", () => {
const wrapper = mount(<PinNumberDropdown {...fakeProps()} />);
expect(wrapper.text()).toEqual("Select a pin");
expect(wrapper.find(FBSelect).props().extraClass).toEqual("");
});

it("renders when inconsistent", () => {
const p = fakeProps();
p.sourceFwConfig = () => ({ value: 0, consistent: false });
const wrapper = mount(<PinNumberDropdown {...p} />);
expect(wrapper.find(FBSelect).props().extraClass).toEqual("dim");
});

it("renders pin label", () => {
Expand Down
1 change: 1 addition & 0 deletions frontend/devices/components/pin_number_dropdown.tsx
Expand Up @@ -31,6 +31,7 @@ export const PinNumberDropdown = (props: PinNumberDropdownProps) => {
const peripheralIds = peripheralDictionary(resources);
const pinNumberNode = pinNumOrNamedPin(pinNumberValue, peripheralIds);
return <FBSelect
extraClass={props.sourceFwConfig(pinNumKey).consistent ? "" : "dim"}
selectedItem={pinNumberValue
? celery2DropDown(pinNumberNode, resources)
: undefined}
Expand Down
20 changes: 0 additions & 20 deletions frontend/devices/interfaces.ts
Expand Up @@ -87,21 +87,6 @@ export enum Feature {
/** Object fetched from FEATURE_MIN_VERSIONS_URL. */
export type MinOsFeatureLookup = Partial<Record<Feature, string>>;

/** How the device is stored in the API side.
* This is what comes back from the API as JSON.
*/
export interface DeviceAccountSettings {
id: number;
name: string;
timezone?: string | undefined;
tz_offset_hrs: number;
throttled_until?: string;
throttled_at?: string;
fbos_version?: string | undefined;
last_saw_api?: string | undefined;
last_saw_mq?: string | undefined;
}

export interface BotState {
/** The browser optimistically overwrites FBOS sync status to "syncing..."
* to reduce UI latency. When AJAX/sync operations fail, we need
Expand Down Expand Up @@ -160,11 +145,6 @@ export type BotLocationData = Record<LocationName, BotPosition>;

export type StepsPerMmXY = Record<"x" | "y", (number | undefined)>;

export interface CalibrationButtonProps {
disabled: boolean;
axis: Axis;
}

export type UserEnv = Record<string, string | undefined>;

export interface FarmbotOsProps {
Expand Down
14 changes: 2 additions & 12 deletions frontend/farm_designer/farm_events/calendar/interfaces.ts
@@ -1,6 +1,6 @@
import { Regimen } from "../../../regimens/interfaces";
import { Sequence } from "../../../sequences/interfaces";
import { ExecutableType, FarmEvent } from "farmbot/dist/resources/api_resources";
import { FarmEvent } from "farmbot/dist/resources/api_resources";

/** Would it be better to make a fully formed farm event? Join regimen, sequence, etc. */

Expand All @@ -22,14 +22,4 @@ export interface FarmEventWithRegimen extends FarmEvent {
}

/** STEP 2: Once all the resource queries are done, create data that looks
* like this: */
export interface NewCalendarItem {
dayOfMonth: number;
month: string;
executable_id: number;
executable_type: ExecutableType;
farm_event_id: number;
label: string;
sortKey: number;
timeStr: string;
}
* like `CalendarDay`. */
5 changes: 0 additions & 5 deletions frontend/farm_designer/interfaces.ts
Expand Up @@ -269,8 +269,3 @@ export interface CurrentPointPayl {
r: number;
color?: string;
}

export interface SavedGarden {
id?: number;
name?: string;
}
6 changes: 1 addition & 5 deletions frontend/farm_designer/map/interfaces.ts
Expand Up @@ -24,10 +24,6 @@ export interface PlantLayerProps {
animate: boolean;
}

export interface CropSpreadDict {
[key: string]: number | undefined;
}

export interface GardenMapLegendProps {
zoom: (value: number) => () => void;
toggle: (property: keyof State) => () => void;
Expand Down Expand Up @@ -76,7 +72,7 @@ export interface GardenPointProps {
point: TaggedGenericPointer;
}

export interface DragHelpersBaseProps {
interface DragHelpersBaseProps {
dragging: boolean;
mapTransformProps: MapTransformProps;
zoomLvl: number;
Expand Down

0 comments on commit bec7cc2

Please sign in to comment.