From a95bccbc22a848fcf50ff63f7041b4888e6b4b41 Mon Sep 17 00:00:00 2001 From: csawatzky Date: Wed, 23 Apr 2025 14:03:53 -0600 Subject: [PATCH 1/7] added the usage api and put the device wizard back in the device page --- src/device/DeviceViewer.tsx | 42 +++++++------- src/hooks/index.ts | 2 +- src/pages/Device.tsx | 15 ++--- src/providers/index.ts | 2 +- src/providers/pond/pond.tsx | 8 ++- src/providers/pond/usageAPI.tsx | 99 +++++++++++++++++++++++++++++++++ 6 files changed, 136 insertions(+), 32 deletions(-) create mode 100644 src/providers/pond/usageAPI.tsx diff --git a/src/device/DeviceViewer.tsx b/src/device/DeviceViewer.tsx index b366f4d..52c9693 100644 --- a/src/device/DeviceViewer.tsx +++ b/src/device/DeviceViewer.tsx @@ -12,7 +12,7 @@ import { useDeviceAPI, useInteractionsAPI, useSnackbar, - //useUsageAPI, + useUsageAPI, useUserAPI } from "hooks"; import { cloneDeep } from "lodash"; @@ -74,7 +74,7 @@ export default function Device(props: Props) { const deviceAPI = useDeviceAPI(); const componentAPI = useComponentAPI(); const interactionsAPI = useInteractionsAPI(); - //const usageAPI = useUsageAPI(); + const usageAPI = useUsageAPI(); const userAPI = useUserAPI(); const [isLoading, setIsLoading] = useState(false); const [device, setDevice] = useState(DeviceModel.create()); @@ -147,25 +147,25 @@ export default function Device(props: Props) { error(err); }) .finally(() => setIsLoading(false)); - // usageAPI - // .getUsage(deviceID, moment().subtract(1, "days")) - // .then((res: any) => { - // let usage = res.data; - // if (usage) { - // let rCellularStatus = "active"; - // let rCellularUsage = 0; - // let sessions: any[] = []; - // if (usage.sessions) { - // sessions = usage.sessions.filter((session: any) => { - // return moment(session.begin).isAfter(moment().subtract(1, "days")); - // }); - // } - // sessions.forEach((session: any) => (rCellularUsage += Number(or(session.bytes, 0)))); - // setCellularStatus(rCellularStatus); - // setCellularUsage(rCellularUsage); - // } - // }) - // .catch(err => {}); + usageAPI + .getUsage(deviceID, moment().subtract(1, "days")) + .then((res: any) => { + let usage = res.data; + if (usage) { + let rCellularStatus = "active"; + let rCellularUsage = 0; + let sessions: any[] = []; + if (usage.sessions) { + sessions = usage.sessions.filter((session: any) => { + return moment(session.begin).isAfter(moment().subtract(1, "days")); + }); + } + sessions.forEach((session: any) => (rCellularUsage += Number(or(session.bytes, 0)))); + setCellularStatus(rCellularStatus); + setCellularUsage(rCellularUsage); + } + }) + .catch(err => {}); }, [componentAPI, props.device, deviceID, error, interactionsAPI, /*usageAPI*/, userAPI, user, as]); useEffect(() => { diff --git a/src/hooks/index.ts b/src/hooks/index.ts index 554b174..0bd5baf 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -20,7 +20,7 @@ export { // useSecurity, useSnackbar, // useTagAPI, -// useUsageAPI, + useUsageAPI, useUserAPI } from "providers"; export * from "./useDebounce"; diff --git a/src/pages/Device.tsx b/src/pages/Device.tsx index ab0a586..dd634f5 100644 --- a/src/pages/Device.tsx +++ b/src/pages/Device.tsx @@ -20,6 +20,7 @@ import { sameComponentID, sortComponents } from "pbHelpers/Component"; import { isController } from "pbHelpers/ComponentType"; import { or } from "utils"; import ComponentDiagnostics from "component/ComponentDiagnostics"; +import DeviceWizard from "device/DeviceWizard"; export default function DevicePage() { const deviceAPI = useDeviceAPI() @@ -358,16 +359,16 @@ export default function DevicePage() { - + {isMobile ? ( <> - {/* */} + refreshCallback={loadDevice} + /> {diagnosticComponents.map(comp => ( @@ -382,12 +383,12 @@ export default function DevicePage() { ) : ( <> - {/* */} + refreshCallback={loadDevice} + /> diff --git a/src/providers/index.ts b/src/providers/index.ts index dafcf34..62f551b 100644 --- a/src/providers/index.ts +++ b/src/providers/index.ts @@ -30,7 +30,7 @@ export { useTeamAPI, useImagekitAPI, useTaskAPI, //TODO: update api with resolve, reject - // useUsageAPI, + useUsageAPI,//TODO: update api with resolve, reject useUserAPI, // useStripeAPI, useDataDogProxyAPI, diff --git a/src/providers/pond/pond.tsx b/src/providers/pond/pond.tsx index bcaeaa5..6f5f1f0 100644 --- a/src/providers/pond/pond.tsx +++ b/src/providers/pond/pond.tsx @@ -32,6 +32,7 @@ import PreferenceProvider, {usePreferenceAPI} from "./preferenceAPI"; import TaskProvider, { useTaskAPI } from "./taskAPI"; import DataDogProvider, { useDataDogProxyAPI } from "./datadogProxyAPI"; import ContractProvider, { useContractAPI } from "./contractAPI"; +import UsageProvider, { useUsageAPI } from "./usageAPI"; // import NoteProvider from "providers/noteAPI"; export const pondURL = (partial: string, demo: boolean = false): string => { @@ -80,7 +81,9 @@ export default function PondProvider(props: PropsWithChildren) { - {children} + + {children} + @@ -147,5 +150,6 @@ export { usePreferenceAPI, useTaskAPI, useDataDogProxyAPI, - useContractAPI + useContractAPI, + useUsageAPI }; diff --git a/src/providers/pond/usageAPI.tsx b/src/providers/pond/usageAPI.tsx new file mode 100644 index 0000000..92de655 --- /dev/null +++ b/src/providers/pond/usageAPI.tsx @@ -0,0 +1,99 @@ +import { useHTTP } from "hooks"; +import moment from "moment"; +import { useGlobalState } from "providers"; +import { createContext, PropsWithChildren, useContext } from "react"; +import { pondURL } from "./pond"; + +export interface IUsageAPIContext { + getUsage: ( + deviceID: number | string, + startDate?: any, + demo?: boolean, + keys?: string[], + types?: string[] + ) => Promise; + getUsages: (deviceIDs: number[], startDate?: any) => Promise; + listUsages: (startDate?: any) => Promise; +} + +export const UsageAPIContext = createContext({} as IUsageAPIContext); + +function usageQuery(deviceIDs?: number[], startDate?: any): string { + let query = ""; + let symbol: "?" | "&" = "?"; + if (deviceIDs && deviceIDs.length > 0) { + query = query.concat(symbol + "ids=" + deviceIDs.join(",")); + symbol = "&"; + } + if (startDate) { + let start = moment(startDate).toISOString(); + query = query.concat(symbol + "start=" + start); + symbol = "&"; + } + return query; +} + +interface Props {} + +export default function UsageProvider(props: PropsWithChildren) { + const { children } = props; + const { get } = useHTTP(); + const [{ as }] = useGlobalState(); + + const getUsage = ( + deviceID: number | string, + startDate?: any, + demo: boolean = false, + keys?: string[], + types?: string[] + ) => { + if (as && !(types && types.length > 0 && types[0] === "team")) + return get( + pondURL( + "/devices/" + + deviceID + + "/usage" + + usageQuery(undefined, startDate) + + "&as=" + + as + + (keys ? "&keys=" + keys.toString() : "") + + (types ? "&types=" + types.toString() : ""), + demo + ) + ); + return get( + pondURL( + "/devices/" + + deviceID + + "/usage" + + usageQuery(undefined, startDate) + + (keys ? "&keys=" + keys.toString() : "") + + (types ? "&types=" + types.toString() : ""), + demo + ) + ); + }; + + const getUsages = (deviceIDs: number[], startDate?: any) => { + if (as) return get(pondURL("/usage/devices" + usageQuery(deviceIDs, startDate) + "&as=" + as)); + return get(pondURL("/usage/devices" + usageQuery(deviceIDs, startDate))); + }; + + const listUsages = (startDate?: any) => { + if (as) return get(pondURL("/usage" + usageQuery(undefined, startDate) + "&as=" + as)); + return get(pondURL("/usage" + usageQuery(undefined, startDate))); + }; + + return ( + + {children} + + ); +} + +export const useUsageAPI = () => useContext(UsageAPIContext); From 1e1152b5630a97a4937e7e218410aa5e47725beb Mon Sep 17 00:00:00 2001 From: csawatzky Date: Wed, 23 Apr 2025 14:43:42 -0600 Subject: [PATCH 2/7] fixed the textfield select menu being behind the dialog --- src/app/App.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/app/App.css b/src/app/App.css index 3d829d9..3b20b88 100644 --- a/src/app/App.css +++ b/src/app/App.css @@ -39,4 +39,8 @@ html, body, #root { .MuiPopper-root { z-index: 1501 !important; +} + +.MuiPopover-root { + z-index: 1501 !important; } \ No newline at end of file From 5c6be7c850c0fd3b9e07df7ea38257de89f5a0d3 Mon Sep 17 00:00:00 2001 From: csawatzky Date: Wed, 23 Apr 2025 15:26:03 -0600 Subject: [PATCH 3/7] fixed the padding on the maps and updated the drawer styling --- src/common/DisplayDrawer.tsx | 12 +++++++----- src/maps/MapBase.tsx | 1 + src/pages/AviationMap.tsx | 2 +- src/pages/ConstructionSiteMap.tsx | 2 +- src/pages/FieldMap.tsx | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/common/DisplayDrawer.tsx b/src/common/DisplayDrawer.tsx index cc8785c..0389473 100644 --- a/src/common/DisplayDrawer.tsx +++ b/src/common/DisplayDrawer.tsx @@ -45,9 +45,10 @@ const useStyles = makeStyles((theme: Theme) => ({ paddingBottom: 15, zIndex: 101 }, - appBar: { + titleDisplay: { position: "static", - borderRadius: 30 + borderRadius: 30, + backgroundColor: theme.palette.secondary.main }, drawerPaper: { overflowX: "hidden" @@ -91,7 +92,7 @@ export default function DisplayDrawer(props: Props) { classes={{ paper: classes.drawerPaper }}> + style={{ width: isMobile ? "100%" : width }}> @@ -118,10 +119,11 @@ export default function DisplayDrawer(props: Props) { )} - + @@ -142,7 +144,7 @@ export default function DisplayDrawer(props: Props) { - + {drawerBody} diff --git a/src/maps/MapBase.tsx b/src/maps/MapBase.tsx index dcf9482..3ae82b0 100644 --- a/src/maps/MapBase.tsx +++ b/src/maps/MapBase.tsx @@ -584,6 +584,7 @@ export default function MapBase(props: Props) { {tools()} {mapStyleDialog()} + {location.state !== undefined && location.state !== null && location.state.long !== undefined && diff --git a/src/pages/ConstructionSiteMap.tsx b/src/pages/ConstructionSiteMap.tsx index 27eaf46..8f1b690 100644 --- a/src/pages/ConstructionSiteMap.tsx +++ b/src/pages/ConstructionSiteMap.tsx @@ -6,7 +6,7 @@ export default function ConstructionSiteMap() { const location = useLocation(); return ( - + {location.state !== undefined && location.state !== null && location.state.long !== undefined && diff --git a/src/pages/FieldMap.tsx b/src/pages/FieldMap.tsx index 2fc42f4..9f8c112 100644 --- a/src/pages/FieldMap.tsx +++ b/src/pages/FieldMap.tsx @@ -5,7 +5,7 @@ import { useLocation } from "react-router"; export default function FieldMap() { const location = useLocation(); return ( - + {location.state !== undefined && location.state !== null && location.state.long !== undefined && From 9105b4be3a9187f73c32faaa882a86720cfa2849 Mon Sep 17 00:00:00 2001 From: csawatzky Date: Wed, 23 Apr 2025 16:29:41 -0600 Subject: [PATCH 4/7] added back the task viewer on the bin page, fixed up some more styling --- src/maps/mapDrawers/FieldDrawer.tsx | 10 +++++----- src/pages/Bin.tsx | 9 +++++---- src/pages/Gate.tsx | 6 +++++- src/tasks/TaskSettings.tsx | 5 +++-- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/maps/mapDrawers/FieldDrawer.tsx b/src/maps/mapDrawers/FieldDrawer.tsx index a782b02..c4029aa 100644 --- a/src/maps/mapDrawers/FieldDrawer.tsx +++ b/src/maps/mapDrawers/FieldDrawer.tsx @@ -230,12 +230,12 @@ export default function FieldDrawer(props: Props) { {field.fieldName()} Details - - + + Approximate Area: {field.acres()}ac - + Grain: {field.grain() === pond.Grain.GRAIN_CUSTOM @@ -243,11 +243,11 @@ export default function FieldDrawer(props: Props) { : GrainDescriber(field.crop()).name} - + Grain Variant: {field.settings.grainSubtype} - + Land Location: {field.landLoc()} diff --git a/src/pages/Bin.tsx b/src/pages/Bin.tsx index 15ce8db..c6c84a8 100644 --- a/src/pages/Bin.tsx +++ b/src/pages/Bin.tsx @@ -43,7 +43,6 @@ import BindaptIcon from "products/Bindapt/BindaptIcon"; import Close from "@mui/icons-material/Close"; import Chat from "chat/Chat"; import TasksIcon from "products/Construction/TasksIcon"; -// import TaskViewer from "tasks/TaskViewer"; import FieldsIcon from "products/AgIcons/FieldsIcon"; import BinComponentTypes from "bin/BinComponentTypes"; import { Plenum } from "models/Plenum"; @@ -66,6 +65,7 @@ import BinConditioningCard from "bin/BinConditioningCard"; import { makeStyles, styled } from "@mui/styles"; import { useNavigate, useParams } from "react-router-dom"; import { Controller } from "models/Controller"; +import TaskViewer from "tasks/TaskViewer"; interface TabPanelProps { children?: React.ReactNode; @@ -547,10 +547,11 @@ export default function Bin(props: Props) { }; const tasks = () => { + console.log(showTasks()) if (showTasks()) { return ( - {/* */} + ); } @@ -1144,11 +1145,11 @@ export default function Bin(props: Props) { anchor="right" classes={{ paper: classes.drawerPaper }} onClose={() => setTaskDrawer(false)}> - + setTaskDrawer(false)}> - {/* */} + )} diff --git a/src/pages/Gate.tsx b/src/pages/Gate.tsx index e45ffae..c873a76 100644 --- a/src/pages/Gate.tsx +++ b/src/pages/Gate.tsx @@ -87,7 +87,7 @@ export default function Gate(props: Props) { //const match = useRouteMatch(); //const gateID = props.gateID ?? match.params.gateID; const { gateKey } = props - const gateID = gateKey ?? useParams<{ gateID: string }>()?.gateID ?? ""; + const gateID = gateKey ?? useParams<{ gateKey: string }>()?.gateKey ?? ""; const classes = useStyles(); const gateAPI = useGateAPI(); const userAPI = useUserAPI(); @@ -115,13 +115,17 @@ export default function Gate(props: Props) { }; useEffect(() => { + console.log(gateID) let key = gateID; let kind = "gate"; if (as) { key = as; kind = "team"; } + console.log(key) + console.log(kind) userAPI.getUser(user.id(), { key: key, kind: kind } as Scope).then(resp => { + console.log(resp) setPermissions(resp.permissions); }); }, [as, gateID, userAPI, user]); diff --git a/src/tasks/TaskSettings.tsx b/src/tasks/TaskSettings.tsx index 63e800a..9f92548 100644 --- a/src/tasks/TaskSettings.tsx +++ b/src/tasks/TaskSettings.tsx @@ -19,6 +19,7 @@ import { useSnackbar, useUserAPI } from "hooks"; import { useEffect } from "react"; import { Task, teamScope, User } from "models"; import ColourPicker from "common/ColourPicker"; +import ResponsiveDialog from "common/ResponsiveDialog"; interface Props { open: boolean; @@ -159,7 +160,7 @@ export default function TaskSettings(props: Props) { }; return ( - + New Task )} - + ); } From 5d697091e09509af69e4ef305dda0b232bbe8e8c Mon Sep 17 00:00:00 2001 From: csawatzky Date: Thu, 24 Apr 2025 10:57:21 -0600 Subject: [PATCH 5/7] fixed the actions on the bin settings and the bottom navigator opening up the side when buttons other than more waere clicked --- src/app/Header.tsx | 2 +- src/bin/BinSettings.tsx | 2 +- src/teams/ObjectTeams.tsx | 40 +++++++++++++++++++++++---------------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/app/Header.tsx b/src/app/Header.tsx index 4bb8e1f..6e4dbaf 100644 --- a/src/app/Header.tsx +++ b/src/app/Header.tsx @@ -125,7 +125,7 @@ export default function Header() { {setNavOpen(true)}} onClose={() => {setNavOpen(false)}} /> - {isMobile && {setNavOpen(true)}} sideIsOpen={navOpen} />} + {isMobile && {setNavOpen(isOpen)}} sideIsOpen={navOpen} />} ) } \ No newline at end of file diff --git a/src/bin/BinSettings.tsx b/src/bin/BinSettings.tsx index 3a9f15d..e280917 100644 --- a/src/bin/BinSettings.tsx +++ b/src/bin/BinSettings.tsx @@ -2255,7 +2255,7 @@ export default function BinSettings(props: Props) { } return ( - + {mode === "add" ? ( - )} - {canManageUsers && ( - - )} - - - ); + + ) + // return ( + // + // + // + // {!cardMode && ( + // + // )} + // {canManageUsers && ( + // + // )} + // + // + // ); }; const dialogs = () => { From d610e763c30535b73b770f6a6204442563a7debb Mon Sep 17 00:00:00 2001 From: csawatzky Date: Thu, 24 Apr 2025 11:14:02 -0600 Subject: [PATCH 6/7] fixed sliders for the bin and grain bag visualizers --- src/bin/BinVisualizerV2.tsx | 3 ++- src/grainBag/grainBagVisualizer.tsx | 30 ----------------------------- 2 files changed, 2 insertions(+), 31 deletions(-) diff --git a/src/bin/BinVisualizerV2.tsx b/src/bin/BinVisualizerV2.tsx index 854c733..d380c63 100644 --- a/src/bin/BinVisualizerV2.tsx +++ b/src/bin/BinVisualizerV2.tsx @@ -153,7 +153,8 @@ const useStyles = makeStyles((theme: Theme) => { sliderValLabel: { height: 30, width: 30, - //top: -15, + left: -5, + top: -20, background: "transparent" }, }); diff --git a/src/grainBag/grainBagVisualizer.tsx b/src/grainBag/grainBagVisualizer.tsx index 794a1f3..3c76f1f 100644 --- a/src/grainBag/grainBagVisualizer.tsx +++ b/src/grainBag/grainBagVisualizer.tsx @@ -53,29 +53,6 @@ const useStyles = makeStyles((theme: Theme) => { position: "relative", width: "auto", marginRight: theme.spacing(1) - }, - sliderRoot: {}, - sliderThumb: { - left: 23 - }, - mobileSliderThumb: { - left: 28 - }, - sliderTrack: { - height: "100%", - }, - sliderRail: { - height: "100%", - }, - sliderValLabel: { - // left: -20, - height: 30, - width: 30, - top: -15, - background: "transparent" - }, - sliderLabel: { - background: "gold" } }); }); @@ -279,13 +256,6 @@ export default function GrainBagVisualizer(props: Props) { Date: Thu, 24 Apr 2025 11:35:11 -0600 Subject: [PATCH 7/7] fixed the product icon in the device wizard --- src/device/DeviceWizard.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/device/DeviceWizard.tsx b/src/device/DeviceWizard.tsx index 5a944f1..d426c21 100644 --- a/src/device/DeviceWizard.tsx +++ b/src/device/DeviceWizard.tsx @@ -210,13 +210,14 @@ export default function DeviceWizard(props: Props) { }; const setupCard = () => { + const deviceIcon = GetDeviceProductIcon(device) return (