Farmbot-Web-App/frontend/farmware/weed_detector/selectors.ts

19 lines
756 B
TypeScript

import { DropDownItem, NULL_CHOICE } from "../../ui/index";
import { SPECIAL_VALUE_DDI } from "./constants";
import { WD_ENV } from "./remote_env/interfaces";
import { envGet } from "./remote_env/selectors";
/** Convert values like SPECIAL_VALUES.TRUE to drop down items with friendly
* label/value pairs. */
export const translateSpecialValue = (input: number): DropDownItem => {
return SPECIAL_VALUE_DDI[input] || NULL_CHOICE;
};
/** Generates a lookup function to convert WeedDetector ENV items to
* DropDownItems. Used to display currently selected options within dropdown
* menus. */
export const getDropdownSelection = (env: Partial<WD_ENV>) =>
(key: keyof WD_ENV): DropDownItem => {
return translateSpecialValue(envGet(key, env));
};