2018-09-07 13:30:31 -06:00
|
|
|
import { Dictionary } from "farmbot";
|
2018-09-11 15:53:27 -06:00
|
|
|
import { DropDownItem } from "../../../ui";
|
|
|
|
import { ListBuilder } from "./interfaces";
|
2018-09-07 13:30:31 -06:00
|
|
|
import { ResourceIndex } from "../../../resources/interfaces";
|
2018-09-11 17:17:30 -06:00
|
|
|
import { ResourceUpdate } from "farmbot";
|
2018-09-07 13:30:31 -06:00
|
|
|
import { selectAllTools } from "../../../resources/selectors";
|
2018-09-11 15:53:27 -06:00
|
|
|
import {
|
|
|
|
MOUNTED_TO,
|
|
|
|
DISMOUNT,
|
|
|
|
PLANT_OPTIONS,
|
2020-02-28 09:35:32 -07:00
|
|
|
POINT_OPTIONS,
|
2018-09-11 15:53:27 -06:00
|
|
|
} from "./constants";
|
2018-09-07 13:30:31 -06:00
|
|
|
|
|
|
|
const allToolsAsDDI = (i: ResourceIndex) => {
|
|
|
|
return selectAllTools(i)
|
|
|
|
.filter(x => !!x.body.id)
|
|
|
|
.map(x => {
|
|
|
|
return {
|
2020-04-02 10:53:55 -06:00
|
|
|
label: `${MOUNTED_TO()} ${x.body.name}`,
|
2018-09-07 13:30:31 -06:00
|
|
|
value: x.body.id || 0
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-09-11 15:53:27 -06:00
|
|
|
const DEFAULT = "Default";
|
2018-09-07 13:30:31 -06:00
|
|
|
|
|
|
|
const ACTION_LIST: Dictionary<ListBuilder> = {
|
2020-04-02 10:53:55 -06:00
|
|
|
"Device": (i) => [DISMOUNT(), ...allToolsAsDDI(i)],
|
|
|
|
"Plant": () => PLANT_OPTIONS(),
|
2018-09-11 12:11:57 -06:00
|
|
|
"GenericPointer": () => POINT_OPTIONS,
|
2020-04-02 10:53:55 -06:00
|
|
|
"Weed": () => POINT_OPTIONS,
|
2018-09-07 13:30:31 -06:00
|
|
|
[DEFAULT]: () => []
|
|
|
|
};
|
|
|
|
|
|
|
|
const getList =
|
2018-09-11 12:11:57 -06:00
|
|
|
(t = DEFAULT): ListBuilder => (ACTION_LIST[t] || ACTION_LIST[DEFAULT]);
|
2018-09-07 13:30:31 -06:00
|
|
|
|
|
|
|
export const actionList = (d: DropDownItem | undefined,
|
|
|
|
r: ResourceUpdate,
|
|
|
|
i: ResourceIndex): DropDownItem[] => {
|
|
|
|
return getList(d ? d.headingId : r.args.resource_type)(i);
|
|
|
|
};
|