Merge branch 'libracart' into 'dev_environment'

minor updates

See merge request brandx/bxt-app!2
This commit is contained in:
Saiyida Noor 2025-08-06 17:08:59 +00:00
commit 27a8cc35e4
4 changed files with 247 additions and 95 deletions

View file

@ -6,7 +6,7 @@ import {
DialogActions,
DialogContent,
DialogTitle,
Grid,
Grid2 as Grid,
InputAdornment,
MenuItem,
Slider,
@ -19,7 +19,7 @@ import { DevicePreset } from "models/DevicePreset";
import { ObjectTypeString } from "objects/ObjectDescriber";
import { pond } from "protobuf-ts/pond";
import { useSnackbar } from "providers";
// import { useDevicePresetAPI } from "providers/pond/devicePresetAPI";
import { useDevicePresetAPI } from "providers/pond/devicePresetAPI";
import React, { useEffect, useState } from "react";
import { getTemperatureUnit } from "utils";
@ -43,7 +43,7 @@ export default function DevicePresetCard(props: Props) {
removeCallback,
updateCallback
} = props;
// const devicePresetAPI = useDevicePresetAPI();
const devicePresetAPI = useDevicePresetAPI();
const [presetName, setPresetName] = useState("");
const [presetType, setPresetType] = useState<pond.PresetType>(1);
const [controllerType, setControllerType] = useState<pond.ControllerType>(1);
@ -81,22 +81,22 @@ export default function DevicePresetCard(props: Props) {
p.settings.temperature = tempC;
p.settings.humidity = hum;
// devicePresetAPI
// .addDevicePreset(p.name, p.settings, objectKey, typestring)
// .then(resp => {
// //get the temp key from the preset
// let temp = p.key;
// //update the key in the preset with the key that came back from the add
// p.key = resp.data.key;
// //use the callback function passing in the preset and the temp key
// if (addCallback) {
// addCallback(p, temp);
// }
// openSnack("New preset saved");
// })
// .catch(err => {
// openSnack("Failed to save new preset");
// });
devicePresetAPI
.addDevicePreset(p.name, p.settings, objectKey, typestring)
.then(resp => {
//get the temp key from the preset
let temp = p.key;
//update the key in the preset with the key that came back from the add
p.key = resp.data.key;
//use the callback function passing in the preset and the temp key
if (addCallback) {
addCallback(p, temp);
}
openSnack("New preset saved");
})
.catch(err => {
openSnack("Failed to save new preset");
});
};
const updatePreset = () => {
@ -108,32 +108,32 @@ export default function DevicePresetCard(props: Props) {
newPreset.settings.temperature = tempC;
newPreset.settings.humidity = hum;
// devicePresetAPI
// .updateDevicePreset(newPreset.key, newPreset.name, newPreset.settings)
// .then(resp => {
// if (updateCallback) {
// updateCallback(oldPreset, newPreset);
// }
// openSnack("Preset Updated");
// })
// .catch(err => {
// openSnack("There was a problem updating the preset");
// });
devicePresetAPI
.updateDevicePreset(newPreset.key, newPreset.name, newPreset.settings)
.then(resp => {
if (updateCallback) {
updateCallback(oldPreset, newPreset);
}
openSnack("Preset Updated");
})
.catch(err => {
openSnack("There was a problem updating the preset");
});
};
const removePreset = () => {
// devicePresetAPI
// .removeDevicePreset(preset.key)
// .then(resp => {
// openSnack("Preset has been deleted");
// setOpenDeleteConfirmation(false);
// if (removeCallback) {
// removeCallback(preset);
// }
// })
// .catch(err => {
// openSnack("There was a problem deleting this preset");
// });
devicePresetAPI
.removeDevicePreset(preset.key)
.then(resp => {
openSnack("Preset has been deleted");
setOpenDeleteConfirmation(false);
if (removeCallback) {
removeCallback(preset);
}
})
.catch(err => {
openSnack("There was a problem deleting this preset");
});
};
const deleteConfirmation = () => {
@ -192,7 +192,7 @@ export default function DevicePresetCard(props: Props) {
<Card raised style={{ padding: 10, width: "100%" }}>
{deleteConfirmation()}
<Grid container direction="row" alignContent="center" alignItems="center">
<Grid item xs={12} sm={6}>
<Grid size={{xs:12, sm:6}}>
<TextField
variant="outlined"
margin="normal"
@ -203,7 +203,7 @@ export default function DevicePresetCard(props: Props) {
}}
/>
</Grid>
<Grid item xs={12} sm={6}>
<Grid size={{xs:12, sm:6}}>
{presetType !== pond.PresetType.PRESET_TYPE_UNKNOWN &&
controllerType !== pond.ControllerType.CONTROLLER_TYPE_UNKNOWN && (
<Box paddingLeft={2}>
@ -216,7 +216,7 @@ export default function DevicePresetCard(props: Props) {
</Box>
)}
</Grid>
<Grid item xs={6}>
<Grid size={6}>
{/* type */}
<TextField
style={{ width: "100%", marginRight: 5 }}
@ -250,7 +250,7 @@ export default function DevicePresetCard(props: Props) {
</MenuItem>
</TextField>
</Grid>
<Grid item xs={6}>
<Grid size={6}>
{/* controller type */}
<TextField
style={{ width: "100%", marginLeft: 5 }}
@ -281,7 +281,7 @@ export default function DevicePresetCard(props: Props) {
</Grid>
{/* temp slider */}
{isMobile ? (
<Grid item xs={12}>
<Grid size={12}>
<Box
display="flex"
alignContent="center"
@ -338,10 +338,10 @@ export default function DevicePresetCard(props: Props) {
</Grid>
) : (
<React.Fragment>
<Grid item xs={2}>
<Grid size={2}>
<Typography>Temperature</Typography>
</Grid>
<Grid item xs={7}>
<Grid size={7}>
<Box paddingRight={2}>
<Slider
//orientation="vertical"
@ -362,7 +362,7 @@ export default function DevicePresetCard(props: Props) {
/>
</Box>
</Grid>
<Grid item xs={3}>
<Grid size={3}>
<TextField
style={{ width: "100%" }}
margin="dense"
@ -395,7 +395,7 @@ export default function DevicePresetCard(props: Props) {
)}
{/* humidity slider */}
{isMobile ? (
<Grid item xs={12}>
<Grid size={12}>
<Box
display="flex"
alignContent="center"
@ -437,10 +437,10 @@ export default function DevicePresetCard(props: Props) {
</Grid>
) : (
<React.Fragment>
<Grid item xs={2}>
<Grid size={2}>
<Typography>Humidity</Typography>
</Grid>
<Grid item xs={7}>
<Grid size={7}>
<Box paddingRight={2}>
<Slider
//orientation="vertical"
@ -456,7 +456,7 @@ export default function DevicePresetCard(props: Props) {
/>
</Box>
</Grid>
<Grid item xs={3}>
<Grid size={3}>
<TextField
style={{ width: "100%" }}
margin="dense"

View file

@ -32,9 +32,9 @@ export default function LibraCart() {
libracartAPI
.listAccounts(0, 0, as)
.then(resp => {
let tempOrgs: Map<string, pond.JDAccount> = new Map();
let tempOrgs: Map<string, pond.LibraCartAccount> = new Map();
resp.data.accounts.forEach(org => {
let organization = pond.JDAccount.fromObject(org);
let organization = pond.LibraCartAccount.fromObject(org);
tempOrgs.set(organization.key, organization);
});
setOrganizations(tempOrgs);
@ -70,40 +70,40 @@ export default function LibraCart() {
});
};
const fieldOptions = () => {
return (
<React.Fragment>
<Accordion
expanded={fieldAccordion}
onChange={(_, expanded) => {
setFieldAccordion(expanded);
}}>
<AccordionSummary expandIcon={<ExpandMore />}>Field Data</AccordionSummary>
<AccordionDetails>
<Grid container direction="row" spacing={2} alignItems="center" alignContent="center">
<Grid size={6}>
<FormControlLabel
label="Field Boundaries"
control={
<Checkbox
checked={dataOptions.includes(pond.DataOption.DATA_OPTION_FIELDS)}
onChange={(_, checked) => {
//setFields(!fields);
updateOrgData(checked, pond.DataOption.DATA_OPTION_FIELDS);
}}
/>
}
/>
</Grid>
<Grid size={6}>
View your data from Libra Cart on your visual Farm
</Grid>
</Grid>
</AccordionDetails>
</Accordion>
</React.Fragment>
);
};
// const fieldOptions = () => {
// return (
// <React.Fragment>
// <Accordion
// expanded={fieldAccordion}
// onChange={(_, expanded) => {
// setFieldAccordion(expanded);
// }}>
// <AccordionSummary expandIcon={<ExpandMore />}>Field Data</AccordionSummary>
// <AccordionDetails>
// <Grid container direction="row" spacing={2} alignItems="center" alignContent="center">
// <Grid size={6}>
// <FormControlLabel
// label="Field Boundaries"
// control={
// <Checkbox
// checked={dataOptions.includes(pond.DataOption.DATA_OPTION_FIELDS)}
// onChange={(_, checked) => {
// //setFields(!fields);
// updateOrgData(checked, pond.DataOption.DATA_OPTION_FIELDS);
// }}
// />
// }
// />
// </Grid>
// <Grid size={6}>
// View your data from Libra Cart
// </Grid>
// </Grid>
// </AccordionDetails>
// </Accordion>
// </React.Fragment>
// );
// };
return (
<PageContainer>
<LibraCartAccess />
@ -117,7 +117,7 @@ export default function LibraCart() {
<Grid>
<Select
//style={{ maxWidth: 110 }}
title="John Deer Account"
title="LibraCart Account"
displayEmpty
disableUnderline={true}
value={currentOrg}
@ -136,13 +136,13 @@ export default function LibraCart() {
})}
</Select>
</Grid>
<Grid>
{/* <Grid>
<Button onClick={submit} variant="contained" color="primary">
Update
</Button>
</Grid> */}
</Grid>
</Grid>
<Box style={{ padding: 10 }}>{fieldOptions()}</Box>
{/* <Box style={{ padding: 10 }}>{fieldOptions()}</Box> */}
</PageContainer>
);
}

View file

@ -0,0 +1,150 @@
import { useHTTP } from "hooks";
import { createContext, PropsWithChildren, useContext } from "react";
import { pond } from "protobuf-ts/pond";
import { pondURL } from "./pond";
import { AxiosResponse } from "axios";
import { useGlobalState } from "providers";
export interface IDevicePresetInterface {
//add
addDevicePreset: (
name: string,
settings: pond.DevicePresetSettings,
parentKey?: string,
parentTypes?: string
) => Promise<AxiosResponse<pond.AddDevicePresetResponse>>;
//list
listDevicePresets: (
limit: number,
offset: number,
order?: "asc" | "desc",
orderBy?: string,
search?: string,
keys?: string[],
types?: string[]
) => Promise<AxiosResponse<pond.ListDevicePresetResponse>>;
//update
updateDevicePreset: (
key: string,
name: string,
settings: pond.DevicePresetSettings
) => Promise<AxiosResponse<pond.UpdateDevicePresetResponse>>;
//remove
removeDevicePreset: (key: string) => Promise<AxiosResponse<pond.DeleteDevicePresetResponse>>;
//get
getDevicePreset: (key: string) => Promise<AxiosResponse<pond.GetDevicePresetResponse>>;
}
export const DevicePresetAPIcontext = createContext<IDevicePresetInterface>(
{} as IDevicePresetInterface
);
interface Props {}
export default function DevicePresetProvider(props: PropsWithChildren<Props>) {
const { children } = props;
const { get, del, post, put } = useHTTP();
const [{ as }] = useGlobalState();
//add
const addDevicePreset = (
name: string,
settings: pond.DevicePresetSettings,
parentKey?: string,
parentType?: string
) => {
let key = "";
let type = "";
if (parentKey && parentType) {
key = "&parentKey=" + parentKey;
type = "&parentType=" + parentType;
}
if (as) {
return post<pond.AddDevicePresetResponse>(
pondURL("/devicePreset?name=" + name + "&as=" + as + key + type),
settings
);
}
return post<pond.AddDevicePresetResponse>(
pondURL("/devicePreset?name=" + name + key + type),
settings
);
};
//list
const listDevicePresets = (
limit: number,
offset: number,
order?: "asc" | "desc",
orderBy?: string,
search?: string,
keys?: string[],
types?: string[]
) => {
let asText = "";
if (as) asText = "&as=" + as;
return get<pond.ListDevicePresetResponse>(
pondURL(
"/devicePresets?limit=" +
limit +
"&offset=" +
offset +
("&order=" + (order ? order : "asc")) +
("&by=" + (orderBy ? orderBy : "key")) +
(search ? "&search=" + search : "") +
(keys ? "&keys=" + keys.toString() : "") +
(types ? "&types=" + types.toString() : "") +
asText
)
);
};
//update
const updateDevicePreset = (key: string, name: string, settings: pond.DevicePresetSettings) => {
if (as) {
return put<pond.UpdateDevicePresetResponse>(
pondURL("/devicePreset/" + key + "?as=" + as + "&name=" + name),
settings
);
}
return put<pond.UpdateDevicePresetResponse>(
pondURL("/devicePreset/" + key + "?name=" + name),
settings
);
};
//remove
const removeDevicePreset = (key: string) => {
if (as) {
return del<pond.DeleteDevicePresetResponse>(pondURL("/devicePreset/" + key + "?as=" + as));
}
return del<pond.DeleteDevicePresetResponse>(pondURL("/devicePreset/" + key + "?as=" + as));
};
//get
const getDevicePreset = (key: string) => {
if (as) {
return del<pond.GetDevicePresetResponse>(pondURL("/devicePreset/" + key + "?as=" + as));
}
return del<pond.GetDevicePresetResponse>(pondURL("/devicePreset/" + key + "?as=" + as));
};
return (
<DevicePresetAPIcontext.Provider
value={{
//add
addDevicePreset,
//list
listDevicePresets,
//update
updateDevicePreset,
//remove
removeDevicePreset,
//get
getDevicePreset
}}>
{children}
</DevicePresetAPIcontext.Provider>
);
}
export const useDevicePresetAPI = () => useContext(DevicePresetAPIcontext);

View file

@ -37,6 +37,7 @@ import KeyManagerProvider, { useKeyManagerAPI } from "./keyManagerAPI";
import JohnDeereProvider, { useJohnDeereProxyAPI } from "./johnDeereProxyAPI";
import LibraCartProvider, { useLibraCartProxyAPI } from "./libracartProxyAPI";
import CNHiProvider, { useCNHiProxyAPI } from "./cnhiProxyAPI";
import DevicePresetProvider, { useDevicePresetAPI } from "./devicePresetAPI";
// import NoteProvider from "providers/noteAPI";
export const pondURL = (partial: string, demo: boolean = false): string => {
@ -167,5 +168,6 @@ export {
useKeyManagerAPI,
useJohnDeereProxyAPI,
useCNHiProxyAPI,
useLibraCartProxyAPI
useLibraCartProxyAPI,
useDevicePresetAPI
};