added fields list page, left out the harvest plan table as i would like to re-do and this is a good oppurtunity (if people want it)
This commit is contained in:
parent
cdad408152
commit
2816884771
5 changed files with 228 additions and 0 deletions
43
src/pbHelpers/HarvestPlan.ts
Normal file
43
src/pbHelpers/HarvestPlan.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import { pond } from "protobuf-ts/pond";
|
||||
import { capitalize } from "utils/strings";
|
||||
import { or } from "utils";
|
||||
import GrainDescriber from "grain/GrainDescriber";
|
||||
|
||||
//TODO handle new keys for pre/post seed
|
||||
const keyTranslator = new Map<keyof pond.HarvestPlanSettings, string>([
|
||||
["createDate", "Create Date"],
|
||||
["actualYield", "Actual Yield"],
|
||||
["cropType", "Crop Type"],
|
||||
["field", "Field"],
|
||||
["grainType", "grain"],
|
||||
["yieldTarget", "Yield Target"],
|
||||
["bushelPrice", "Price per Bushel"],
|
||||
["preSeedMaterials", "Pre-seed Material Cost (acre)"],
|
||||
["preSeedEquipment", "Pre-seed Equipment Cost (acre)"]
|
||||
]);
|
||||
|
||||
// Keys will be stringified by default if not found in the keyTranslator
|
||||
export function TranslateKey(key: keyof pond.HarvestPlanSettings): string {
|
||||
let translatedKey = keyTranslator.get(key);
|
||||
return translatedKey ? translatedKey : capitalize(key.toString());
|
||||
}
|
||||
|
||||
const valueTranslator = new Map<
|
||||
keyof pond.HarvestPlanSettings,
|
||||
(device: pond.HarvestPlanSettings) => string
|
||||
>([
|
||||
["createDate", device => new Date(device.createDate).toString()],
|
||||
["cropType", device => GrainDescriber(device.cropType).name]
|
||||
]);
|
||||
|
||||
// Values will be stringified by default if its key is not found in the valueTranslator
|
||||
export function TranslateValue(
|
||||
key: keyof pond.HarvestPlanSettings,
|
||||
device: pond.HarvestPlanSettings
|
||||
) {
|
||||
let translatorFunc = valueTranslator.get(key);
|
||||
let value: any = or(device[key], "");
|
||||
let d: string;
|
||||
d = or(value.toString(), "");
|
||||
return translatorFunc ? translatorFunc(device) : device[key] ? capitalize(d) : "";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue