diff --git a/src/bin/BinSettings.tsx b/src/bin/BinSettings.tsx index e280917..b61bb2e 100644 --- a/src/bin/BinSettings.tsx +++ b/src/bin/BinSettings.tsx @@ -344,7 +344,7 @@ export default function BinSettings(props: Props) { setBinYardOptions(y); } else { binYardAPI - .listBinYards(350, 0, "desc", as ? as : userID, undefined, undefined, undefined, as) + .listBinYards(350, 0, "desc", as ? as : userID, undefined, undefined, as) .then(resp => { let data = resp.data.yard ? resp.data.yard : []; let yards: Option[] = data.map((yard: pond.BinYard) => { diff --git a/src/grain/GrainTransaction.tsx b/src/grain/GrainTransaction.tsx index e35f84a..f39cdf4 100644 --- a/src/grain/GrainTransaction.tsx +++ b/src/grain/GrainTransaction.tsx @@ -147,7 +147,7 @@ export default function GrainTransaction(props: Props) { if (!bagsLoading) { setBagsLoading(true); grainBagAPI - .listGrainBags(0, 0, undefined, undefined, undefined, undefined, undefined, undefined, undefined, as) + .listGrainBags(0, 0, undefined, undefined, undefined, undefined, undefined, undefined, as) .then(resp => { //let sourceOps: Option[] = sourceOptions let bagOps: Option[] = []; diff --git a/src/maps/mapObjectControllers/AgMapController.tsx b/src/maps/mapObjectControllers/AgMapController.tsx index 497a842..da9a94d 100644 --- a/src/maps/mapObjectControllers/AgMapController.tsx +++ b/src/maps/mapObjectControllers/AgMapController.tsx @@ -304,7 +304,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder"; const loadGrainBags = useCallback(() => { grainBagAPI - .listGrainBags(100, 0, undefined, undefined, undefined, undefined, undefined, undefined, undefined, as) + .listGrainBags(100, 0, undefined, undefined, undefined, undefined, undefined, undefined, as) .then(resp => { let bags: Map = new Map(); let bagOp: BagModel[] = []; @@ -376,7 +376,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder"; let yardEntries: Result[] = []; binYardAPI - .listBinYards(400, 0, "asc", undefined, undefined, undefined, undefined, as) + .listBinYards(400, 0, "asc", undefined, undefined, undefined, as) .then(resp => { resp.data.yard.forEach(yard => { if (yard.settings) { diff --git a/src/pages/Contracts.tsx b/src/pages/Contracts.tsx index c4a8e3e..606651f 100644 --- a/src/pages/Contracts.tsx +++ b/src/pages/Contracts.tsx @@ -34,7 +34,6 @@ export default function Contracts() { undefined, undefined, undefined, - undefined, year, as ) diff --git a/src/providers/pond/ObjectHeaterAPI.tsx b/src/providers/pond/ObjectHeaterAPI.tsx index 4722e05..e4f9d2f 100644 --- a/src/providers/pond/ObjectHeaterAPI.tsx +++ b/src/providers/pond/ObjectHeaterAPI.tsx @@ -10,9 +10,9 @@ export interface IObjectHeaterAPIContext { addObjectHeater: ( name: string, heater: pond.ObjectHeaterSettings, - as?: string + otherTeam?: string ) => Promise>; - getObjectHeater: (key: string, as?: string) => Promise>; + getObjectHeater: (key: string, otherTeam?: string) => Promise>; listObjectHeaters: ( limit: number, offset: number, @@ -20,17 +20,17 @@ export interface IObjectHeaterAPIContext { orderBy?: string, search?: string, asRoot?: boolean, - as?: string, + otherTeam?: string, keys?: string[], types?: string[], numerical?: boolean ) => Promise>; - removeObjectHeater: (key: string, as?: string) => Promise>; + removeObjectHeater: (key: string, otherTeam?: string) => Promise>; updateObjectHeater: ( key: string, name: string, settings: pond.ObjectHeaterSettings, - as?: string + otherTeam?: string ) => Promise>; updateLink: ( parentKey: string, @@ -38,7 +38,7 @@ export interface IObjectHeaterAPIContext { objectID: string, objectType: string, permissions: string[], - as?: string + otherTeam?: string ) => Promise; listObjectHeatersPageData: ( limit: number, @@ -46,7 +46,7 @@ export interface IObjectHeaterAPIContext { order?: "asc" | "desc", orderBy?: string, search?: string, - as?: string, + otherTeam?: string, asRoot?: boolean ) => Promise>; } @@ -60,27 +60,30 @@ interface Props {} export default function ObjectHeaterProvider(props: PropsWithChildren) { const { children } = props; const { get, del, post, put } = useHTTP(); - //const [{ as }] = useGlobalState(); + const [{ as }] = useGlobalState(); - const addObjectHeater = (name: string, settings: pond.ObjectHeaterSettings, as?: string) => { - if (as) + const addObjectHeater = (name: string, settings: pond.ObjectHeaterSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return post( - pondURL("/objectHeaters?name=" + name + "&as=" + as), + pondURL("/objectHeaters?name=" + name + "&as=" + view), settings ); return post(pondURL("/objectHeaters?name=" + name), settings); }; - const getObjectHeater = (key: string, as?: string) => { - if (as) { - return get(pondURL("/objectHeaters/" + key + "?as=" + as)); + const getObjectHeater = (key: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) { + return get(pondURL("/objectHeaters/" + key + "?as=" + view)); } return get(pondURL("/objectHeaters/" + key)); }; - const removeObjectHeater = (key: string, as?: string) => { - if (as) - return del(pondURL("/objectHeaters/" + key + "?as=" + as)); + const removeObjectHeater = (key: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) + return del(pondURL("/objectHeaters/" + key + "?as=" + view)); return del(pondURL("/objectHeaters/" + key)); }; @@ -91,11 +94,12 @@ export default function ObjectHeaterProvider(props: PropsWithChildren) { orderBy?: string, search?: string, asRoot?: boolean, - as?: string, + otherTeam?: string, keys?: string[], types?: string[], numerical?: boolean ) => { + const view = otherTeam ? otherTeam : as return get( pondURL( "/objectHeaters" + @@ -108,17 +112,18 @@ export default function ObjectHeaterProvider(props: PropsWithChildren) { (search ? "&search=" + search : "") + (numerical ? "&numerical=true" : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") + - (as ? "&as=" + as : "") + + (view ? "&as=" + view : "") + (keys ? "&keys=" + keys.toString() : "") + (types ? "&types=" + types.toString() : "") ) ); }; - const updateObjectHeater = (key: string, name: string, settings: pond.ObjectHeaterSettings, as?: string) => { - if (as) { + const updateObjectHeater = (key: string, name: string, settings: pond.ObjectHeaterSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) { return put( - pondURL("/objectHeaters/" + key + "?as=" + as + "&name=" + name), + pondURL("/objectHeaters/" + key + "?as=" + view + "&name=" + name), settings ); } @@ -134,10 +139,11 @@ export default function ObjectHeaterProvider(props: PropsWithChildren) { objectID: string, objectType: string, permissions: string[], - as?: string + otherTeam?: string ) => { - if (as) - return post(pondURL(`/objectHeaters/` + parentID + `/link?as=${as}`), { + const view = otherTeam ? otherTeam : as + if (view) + return post(pondURL(`/objectHeaters/` + parentID + `/link?as=${view}`), { Key: objectID, Type: objectType, Parent: parentID, @@ -159,9 +165,10 @@ export default function ObjectHeaterProvider(props: PropsWithChildren) { order?: "asc" | "desc", orderBy?: string, search?: string, - as?: string, + otherTeam?: string, asRoot?: boolean ) => { + const view = otherTeam ? otherTeam : as return get( pondURL( "/objectHeatersWithData" + @@ -171,7 +178,7 @@ export default function ObjectHeaterProvider(props: PropsWithChildren) { offset + ("&order=" + or(order, "asc")) + ("&by=" + or(orderBy, "key")) + - (as ? "&as=" + as : "") + + (view ? "&as=" + view : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") + (search ? "&search=" + search : "") ) diff --git a/src/providers/pond/binAPI.tsx b/src/providers/pond/binAPI.tsx index db92c09..ea626c1 100644 --- a/src/providers/pond/binAPI.tsx +++ b/src/providers/pond/binAPI.tsx @@ -10,43 +10,43 @@ import { useGlobalState } from "providers"; import { quack } from "protobuf-ts/quack"; export interface IBinAPIContext { - addBin: (bin: pond.BinSettings, as?: string) => Promise>; - updateBin: (key: string, bin: pond.BinSettings, as?: string) => Promise>; - bulkBinUpdate: (bins: pond.BinSettings[], as?: string) => Promise>; + addBin: (bin: pond.BinSettings, otherTeam?: string) => Promise>; + updateBin: (key: string, bin: pond.BinSettings, otherTeam?: string) => Promise>; + bulkBinUpdate: (bins: pond.BinSettings[], otherTeam?: string) => Promise>; updateBinStatus: ( key: string, binStatus: pond.BinStatus, - as?: string + otherTeam?: string ) => Promise>; - removeBin: (key: string, as?: string) => Promise>; - getBin: (key: string, as?: string) => Promise>; + removeBin: (key: string, otherTeam?: string) => Promise>; + getBin: (key: string, otherTeam?: string) => Promise>; addComponent: ( bin: string, device: number, component: string, preferences?: pond.BinComponentPreferences, - as?: string + otherTeam?: string ) => Promise>; removeComponent: ( bin: string, component: string, - as?: string + otherTeam?: string ) => Promise>; - removeAllComponents: (bin: string, as?: string) => Promise>; + removeAllComponents: (bin: string, otherTeam?: string) => Promise>; updateComponentPreferences: ( bin: string, component: string, preferences: pond.BinComponentPreferences, - as?: string + otherTeam?: string ) => Promise>; - getBinPageData: (binKey: string, userKey: string, showErrors?: boolean, as?: string) => Promise>; + getBinPageData: (binKey: string, userKey: string, showErrors?: boolean, otherTeam?: string) => Promise>; listBins: ( limit: number, offset: number, order?: "asc" | "desc", orderBy?: string, search?: string, - as?: string, + otherTeam?: string, asRoot?: boolean, numerical?: boolean, keys?: string[], @@ -58,7 +58,7 @@ export interface IBinAPIContext { order?: "asc" | "desc", orderBy?: string, search?: string, - as?: string, + otherTeam?: string, asRoot?: boolean, keys?: string[], types?: string[] @@ -89,13 +89,13 @@ export interface IBinAPIContext { start: string, end: string, showErrors?: boolean, - as?: string + otherTeam?: string ) => Promise>; updateBinPermissions: ( key: string, users: User[] ) => Promise>; - getBinMetrics: (search?: string, as?: string) => Promise>; + getBinMetrics: (search?: string, otherTeam?: string) => Promise>; listBinLiters: ( key: string, start: string, @@ -105,13 +105,13 @@ export interface IBinAPIContext { cable: string, pressure: string, fan?: string, // the fan controller is optional so that if they don't have one the fan is assumed on - as?: string + otherTeam?: string ) => Promise>; listBinPrefs: (key: string) => Promise>; updateTopNodes: ( key: string, newTopNodes: pond.NewTopNode[], - as?: string + otherTeam?: string ) => Promise>; listBinMeasurements: ( key: string, @@ -124,7 +124,7 @@ export interface IBinAPIContext { keys?: string[], types?: string[], showErrors?: boolean, - as?: string + otherTeam?: string ) => Promise>; } @@ -136,10 +136,11 @@ export default function BinProvider(props: PropsWithChildren) { const { children } = props; const { get, post, put, del } = useHTTP(); const permissionAPI = usePermissionAPI(); - //const [{ as }] = useGlobalState(); + const [{ as }] = useGlobalState(); - const addBin = (bin: pond.BinSettings, as?: string) => { - const url = "/bins" + (as ? "?as=" + as : "") + const addBin = (bin: pond.BinSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + const url = "/bins" + (view ? "?as=" + view : "") return new Promise>((resolve, reject)=>{ post(pondURL(url), bin).then(resp => { resp.data = pond.AddBinResponse.fromObject(resp.data) @@ -150,8 +151,9 @@ export default function BinProvider(props: PropsWithChildren) { }) }; - const updateBin = (key: string, bin: pond.BinSettings, as?: string) => { - const url = "/bins/" + key + (as ? "?as=" + as : "") + const updateBin = (key: string, bin: pond.BinSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + const url = "/bins/" + key + (view ? "?as=" + view : "") return new Promise>((resolve, reject)=>{ put(pondURL(url), bin).then(resp => { resp.data = pond.UpdateBinResponse.fromObject(resp.data) @@ -162,9 +164,10 @@ export default function BinProvider(props: PropsWithChildren) { }) }; - const bulkBinUpdate = (bins: pond.BinSettings[], as?: string) => { + const bulkBinUpdate = (bins: pond.BinSettings[], otherTeam?: string) => { let url = "/bulkBins/update" - if (as) url = url + "?as=" + as + const view = otherTeam ? otherTeam : as + if (view) url = url + "?as=" + view return new Promise>((resolve, reject)=>{ put(pondURL(url), { bins: bins }).then(resp => { resp.data = pond.BulkBinUpdateResponse.fromObject(resp.data) @@ -175,9 +178,10 @@ export default function BinProvider(props: PropsWithChildren) { }) }; - const updateBinStatus = (key: string, binStatus: pond.BinStatus, as?: string) => { + const updateBinStatus = (key: string, binStatus: pond.BinStatus, otherTeam?: string) => { let url = "/bins/" + key + "/status" - if (as) url = url + "?as=" + as + const view = otherTeam ? otherTeam : as + if (view) url = url + "?as=" + view return new Promise>((resolve, reject)=>{ put(pondURL(url), binStatus).then(resp=>{ resp.data = pond.UpdateBinStatusResponse.fromObject(resp.data) @@ -188,9 +192,10 @@ export default function BinProvider(props: PropsWithChildren) { }) }; - const removeBin = (key: string, as?: string) => { + const removeBin = (key: string, otherTeam?: string) => { let url = "/bins/" + key - if (as) url = url + "?as=" + as + const view = otherTeam ? otherTeam : as + if (view) url = url + "?as=" + view return new Promise>((resolve, reject) => { del(pondURL(url)).then(resp => { resp.data = pond.RemoveBinResponse.fromObject(resp.data) @@ -201,8 +206,9 @@ export default function BinProvider(props: PropsWithChildren) { }) }; - const getBin = (key: string, as?: string) => { - const url = "/bins/" + key + (as ? "?as=" + as : "") + const getBin = (key: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + const url = "/bins/" + key + (view ? "?as=" + view : "") return new Promise>((resolve, reject)=>{ get(pondURL(url)) .then(resp => { @@ -220,14 +226,15 @@ export default function BinProvider(props: PropsWithChildren) { device: number, component: string, preferences?: pond.BinComponentPreferences, - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as let url = "/bins/" + bin + "/addComponent/" + device + "/" + component; - if (as) { + if (view) { url = url + "?as=" + - as + + view + (preferences ? "&binPref=" + preferences.type + "&fillNode=" + preferences.node : ""); } else if (preferences) { url = url + "?binPref=" + preferences.type + "&fillNode=" + preferences.node; @@ -242,9 +249,10 @@ export default function BinProvider(props: PropsWithChildren) { }) }; - const removeComponent = (bin: string, component: string, as?: string) => { + const removeComponent = (bin: string, component: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as let url = "/bins/" + bin + "/removeComponent/" + component; - if (as) url = url + "?as=" + as; + if (view) url = url + "?as=" + view; return new Promise>((resolve, reject)=>{ post(pondURL(url)).then(resp => { resp.data = pond.RemoveBinComponentResponse.fromObject(resp.data) @@ -255,9 +263,10 @@ export default function BinProvider(props: PropsWithChildren) { }) }; - const removeAllComponents = (bin: string, as?: string) => { + const removeAllComponents = (bin: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as let url = "/bins/" + bin + "/removeAllComponents"; - if (as) url = url + "?as=" + as; + if (view) url = url + "?as=" + view; return new Promise>((resolve, reject)=>{ post(pondURL(url)).then(resp => { resp.data = pond.RemoveAllBinComponentsResponse.fromObject(resp.data) @@ -272,10 +281,11 @@ export default function BinProvider(props: PropsWithChildren) { bin: string, component: string, preferences: pond.BinComponentPreferences, - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as let url = "/bins/" + bin + "/updateComponent/" + component + "/preferences"; - if (as) url = url + "/?as=" + as; + if (view) url = url + "/?as=" + view; interface request { preferences: Object; } @@ -290,13 +300,14 @@ export default function BinProvider(props: PropsWithChildren) { }) }; - const getBinPageData = (binKey: string, userKey: string, showErrors = true, as?: string) => { + const getBinPageData = (binKey: string, userKey: string, showErrors = true, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as const url = "/bins/" + binKey + "/users/" + userKey + (showErrors ? "?showErrors=true" : "?showErrors=false") + - (as ? "&as=" + as : "") + (view ? "&as=" + view : "") return new Promise>((resolve, reject)=>{ get(pondURL(url)) .then(resp => { @@ -315,13 +326,14 @@ export default function BinProvider(props: PropsWithChildren) { order?: "asc" | "desc", orderBy?: string, search?: string, - as?: string, + otherTeam?: string, asRoot?: boolean, numerical?: boolean, keys?: string[], types?: string[] ) => { return new Promise>((resolve, reject)=>{ + const view = otherTeam ? otherTeam : as get( pondURL( "/bins" + @@ -332,7 +344,7 @@ export default function BinProvider(props: PropsWithChildren) { ("&order=" + or(order, "asc")) + ("&by=" + or(orderBy, "key")) + (numerical ? "&numerical=true" : "") + - (as ? "&as=" + as : "") + + (view ? "&as=" + view : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") + (search ? "&search=" + search : "") + (keys ? "&keys=" + keys.join(",") : "") + @@ -353,11 +365,12 @@ export default function BinProvider(props: PropsWithChildren) { order?: "asc" | "desc", orderBy?: string, search?: string, - as?: string, + otherTeam?: string, asRoot?: boolean, keys?: string[], types?: string[] ) => { + const view = otherTeam ? otherTeam : as const url = "/binsAndData" + "?limit=" + limit + @@ -365,7 +378,7 @@ export default function BinProvider(props: PropsWithChildren) { offset + ("&order=" + or(order, "asc")) + ("&by=" + or(orderBy, "key")) + - (as ? "&as=" + as : "") + + (view ? "&as=" + view : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") + (search ? "&search=" + search : "") + (keys ? "&keys=" + keys.join(",") : "") + @@ -430,15 +443,16 @@ export default function BinProvider(props: PropsWithChildren) { start: string, end: string, showErrors = false, - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as let url = "/bins/" + key + "/components/measurements?start=" + start + "&end=" + end + - (as ? "&as=" + as : "") + + (view ? "&as=" + view : "") + (showErrors ? "&showErrors=true" : "&showErrors=false") return new Promise>((resolve, reject) => { @@ -486,13 +500,14 @@ export default function BinProvider(props: PropsWithChildren) { return permissionAPI.updatePermissions(binScope(key.toString()), users); }; - const getBinMetrics = (search?: string, as?: string) => { + const getBinMetrics = (search?: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as let url = "/metrics/bins" + (search ? "?search=" + search : "") - if (as) { + if (view) { if (search){ - url = "/metrics/bins/?search=" + search + "&as=" + as + url = "/metrics/bins/?search=" + search + "&as=" + view } - url = "/metrics/bins/?as=" + as; + url = "/metrics/bins/?as=" + view; } return new Promise>((resolve, reject)=>{ get(pondURL(url)).then(resp => { @@ -513,8 +528,9 @@ export default function BinProvider(props: PropsWithChildren) { cable: string, pressure: string, fan?: string, - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as const url = "/bins/" + key + "/liters?start=" + @@ -530,7 +546,7 @@ export default function BinProvider(props: PropsWithChildren) { "&pressure=" + pressure + (fan ? "&fan=" + fan : "") + - (as ? "&as=" + as : "") + (view ? "&as=" + view : "") return new Promise>((resolve, reject)=>{ get(pondURL(url)) @@ -543,8 +559,9 @@ export default function BinProvider(props: PropsWithChildren) { }) }; - const listBinPrefs = (key: string, as?: string) => { - const url = "/bins/" + key + "/componentPreferences?as=" + as + const listBinPrefs = (key: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + const url = "/bins/" + key + "/componentPreferences?as=" + view return new Promise>((resolve, reject)=>{ get(pondURL(url)) .then(resp => { @@ -556,9 +573,10 @@ export default function BinProvider(props: PropsWithChildren) { }) }; - const updateTopNodes = (key: string, newTopNodes: pond.NewTopNode[], as?: string) => { + const updateTopNodes = (key: string, newTopNodes: pond.NewTopNode[], otherTeam?: string) => { let body: pond.TopNodeList = pond.TopNodeList.create({ newTopNodes: newTopNodes }); - let url = "/bins/" + key + "/updateTopNodes" + (as ? "?as=" + as : "") + const view = otherTeam ? otherTeam : as + let url = "/bins/" + key + "/updateTopNodes" + (view ? "?as=" + view : "") return new Promise>((resolve,response) => { post(pondURL(url),body).then(resp => { resp.data = pond.UpdateTopNodesResponse.fromObject(resp.data) @@ -580,8 +598,9 @@ export default function BinProvider(props: PropsWithChildren) { keys?: string[], types?: string[], showErrors?: boolean, - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as const url = pondURL( "/objects/" + key + @@ -594,7 +613,7 @@ export default function BinProvider(props: PropsWithChildren) { "&order=" + order + (measurementType ? "&type=" + measurementType : "") + - (as ? "&as=" + as : "") + + (view ? "&as=" + view : "") + (keys ? "&keys=" + keys : "") + (types ? "&types=" + types : "") + (showErrors ? "&showErrors=true" : "&showErrors=false") diff --git a/src/providers/pond/binYardAPI.tsx b/src/providers/pond/binYardAPI.tsx index 263f88c..b8d270e 100644 --- a/src/providers/pond/binYardAPI.tsx +++ b/src/providers/pond/binYardAPI.tsx @@ -7,15 +7,15 @@ import { AxiosResponse } from "axios"; import { useGlobalState } from "providers"; export interface IBinYardAPIContext { - addBinYard: (bin: pond.BinYardSettings, as?: string) => Promise>; + addBinYard: (bin: pond.BinYardSettings, otherTeam?: string) => Promise>; updateBinYard: ( key: string, binYard: pond.BinYardSettings, asRoot?: true, - as?: string + otherTeam?: string ) => Promise>; - removeBinYard: (key: string, as?: string) => Promise>; - getBinYard: (key: string, as?: string) => Promise>; + removeBinYard: (key: string, otherTeam?: string) => Promise>; + getBinYard: (key: string, otherTeam?: string) => Promise>; listBinYards: ( limit: number, offset: number, @@ -23,8 +23,7 @@ export interface IBinYardAPIContext { orderBy?: string, search?: string, asRoot?: boolean, - specificUser?: string, - as?: string + otherTeam?: string ) => Promise>; } @@ -35,24 +34,26 @@ interface Props {} export default function BinYardProvider(props: PropsWithChildren) { const { children } = props; const { get, post, put, del } = useHTTP(); - //const [{ as }] = useGlobalState(); + const [{ as }] = useGlobalState(); - const addBinYard = (binYard: pond.BinYardSettings, as?: string) => { - if (as) return post(pondURL(`/binyard?as=${as}`), binYard); + const addBinYard = (binYard: pond.BinYardSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (as) return post(pondURL(`/binyard?as=${view}`), binYard); return post(pondURL("/binyard"), binYard); }; - const updateBinYard = (key: string, binYard: pond.BinYardSettings, asRoot?: boolean, as?: string) => { - if (as) { + const updateBinYard = (key: string, binYard: pond.BinYardSettings, asRoot?: boolean, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) { if (asRoot) { return put( pondURL( - "/binyards/" + key + (asRoot ? "?asRoot=" + asRoot.toString() : "") + "&as=" + as + "/binyards/" + key + (asRoot ? "?asRoot=" + asRoot.toString() : "") + "&as=" + view ), binYard ); } - return put(pondURL("/binyards/" + key + "?as=" + as), binYard); + return put(pondURL("/binyards/" + key + "?as=" + view), binYard); } return put( pondURL("/binyards/" + key + (asRoot ? "?asRoot=" + asRoot.toString() : "")), @@ -60,13 +61,15 @@ export default function BinYardProvider(props: PropsWithChildren) { ); }; - const removeBinYard = (key: string, as?: string) => { - if (as) return del(pondURL("/binyard/" + key + "?as=" + as)); + const removeBinYard = (key: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return del(pondURL("/binyard/" + key + "?as=" + view)); return del(pondURL("/binyard/" + key)); }; - const getBinYard = (key: string, as?: string) => { - if (as) return get(pondURL("/binYard/" + key + "?as=" + as)); + const getBinYard = (key: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return get(pondURL("/binYard/" + key + "?as=" + view)); return get(pondURL("/binYard/" + key)); }; @@ -77,12 +80,11 @@ export default function BinYardProvider(props: PropsWithChildren) { orderBy?: string, search?: string, asRoot?: boolean, - specificUser?: string, - as?: string + otherTeam?: string ) => { - let asText = ""; - if (as) asText = "&as=" + as; - if (specificUser) asText = "&as=" + specificUser; + let asText = "" + const view = otherTeam ? otherTeam : as + if (view) asText = "&as=" + view; return get( pondURL( "/binYards" + diff --git a/src/providers/pond/componentAPI.tsx b/src/providers/pond/componentAPI.tsx index 5c97f30..0717c74 100644 --- a/src/providers/pond/componentAPI.tsx +++ b/src/providers/pond/componentAPI.tsx @@ -1,7 +1,7 @@ import { useHTTP } from "hooks"; // import { useWebsocket } from "websocket"; import { pond } from "protobuf-ts/pond"; -import React, { createContext, PropsWithChildren, useContext } from "react"; +import { createContext, PropsWithChildren, useContext } from "react"; import { dateRange } from "providers/http"; import { getComponentIDString } from "pbHelpers/Component"; import { Component } from "models"; @@ -18,33 +18,33 @@ export interface IComponentAPIContext { url: string, componentKey: string ) => Promise; - add: (device: number, settings: pond.ComponentSettings, as?: string) => Promise>; + add: (device: number, settings: pond.ComponentSettings, otherTeam?: string) => Promise>; addMultiComponents: ( device: number, components: pond.MultiComponentSettings, - as?: string + otherTeam?: string ) => Promise>; update: ( device: number, settings: pond.ComponentSettings, keys?: string[], types?: string[], - as?: string + otherTeam?: string ) => Promise>; - remove: (device: number, component: string, keys?: string[], types?: string[], as?: string) => Promise>; - get: (device: number, component: string, keys?: string[], types?: string[], as?: string) => Promise>; + remove: (device: number, component: string, keys?: string[], types?: string[], otherTeam?: string) => Promise>; + get: (device: number, component: string, keys?: string[], types?: string[], otherTeam?: string) => Promise>; list: ( device: number | string, demo?: boolean, keys?: string[], types?: string[], comprehensive?: boolean, - as?: string + otherTeam?: string ) => Promise>; listForObject: ( keys: string[], types: string[], - as?:string + otherTeam?:string ) => Promise>; listComponentCardData: ( device: number | string, @@ -52,7 +52,7 @@ export interface IComponentAPIContext { keys?: string[], types?: string[], comprehensive?: boolean, - as?: string + otherTeam?: string ) => Promise>; listHistory: ( deviceId: string | number, @@ -86,7 +86,7 @@ export interface IComponentAPIContext { // demo?: boolean, // keys?: string[], // types?: string[], - // as?: string + // otherTeam?: string // ) => Promise>; sampleUnitMeasurements: ( device: number | string, @@ -98,7 +98,7 @@ export interface IComponentAPIContext { keys?: string[], types?: string[], showErrors?: boolean, - as?: string + otherTeam?: string ) => Promise>; // possibly a deprecated function as it is not used anywhere updateComponentPreferences: ( @@ -120,7 +120,7 @@ export interface IComponentAPIContext { keys?: string[], types?: string[], showErrors?: boolean, - as?: string + otherTeam?: string ) => Promise>; } @@ -131,7 +131,7 @@ interface Props {} export default function ComponentProvider(props: PropsWithChildren) { const { children } = props; const { get, post, put, del } = useHTTP(); - //const [{ as }] = useGlobalState(); + const [{ as }] = useGlobalState(); const newCron = ( device: number, @@ -156,9 +156,10 @@ export default function ComponentProvider(props: PropsWithChildren) { ); }; - const addComponent = (device: number, settings: pond.ComponentSettings, as?: string) => { + const addComponent = (device: number, settings: pond.ComponentSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as let url = "/devices/" + device + "/components" - if (as) url = url + `?as=${as}` + if (view) url = url + `?as=${view}` return new Promise>((resolve, reject) => { post(pondURL(url), settings).then(resp => { resp.data = pond.AddComponentResponse.fromObject(resp.data) @@ -169,9 +170,10 @@ export default function ComponentProvider(props: PropsWithChildren) { }) }; - const addMultiComponents = (device: number, components: pond.MultiComponentSettings, as?: string) => { + const addMultiComponents = (device: number, components: pond.MultiComponentSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as let url = "/devices/" + device + "/multiComponents" - if (as) url = url + `?as=${as}` + if (view) url = url + `?as=${view}` return new Promise>((resolve, reject)=>{ post(pondURL(url), components).then(resp => { resp.data = pond.AddMultiComponentsResponse.fromObject(resp.data) @@ -187,12 +189,13 @@ export default function ComponentProvider(props: PropsWithChildren) { settings: pond.ComponentSettings, keys?: string[], types?: string[], - as?: string + otherTeam?: string ) => { let k: string[] = keys ? keys : []; if (!k.includes(device.toString())) k.push(device.toString()); //if the device id is already in the keys do not add it again let t: string[] = types ? types : []; if (!t.includes("device")) t.push("device"); // if "device" is already in the types do not add it again + const view = otherTeam ? otherTeam : as const url = pondURL( "/devices/" + device + @@ -201,7 +204,7 @@ export default function ComponentProvider(props: PropsWithChildren) { "/update" + ("?keys=" + k) + ("&types=" + t) + - (as ? "&as=" + as : "") + (view ? "&as=" + view : "") ); return new Promise>((resolve, reject)=>{ put(url, settings).then(resp => { @@ -218,12 +221,13 @@ export default function ComponentProvider(props: PropsWithChildren) { component: string, keys?: string[], types?: string[], - as?: string + otherTeam?: string ) => { let k: string[] = keys ? keys : []; if (!k.includes(device.toString())) k.push(device.toString()); //if the device id is already in the keys do not add it again let t: string[] = types ? types : []; if (!t.includes("device")) t.push("device"); // if "device" is already in the types do not add it again + const view = otherTeam ? otherTeam : as const url = pondURL( "/devices/" + device + @@ -231,7 +235,7 @@ export default function ComponentProvider(props: PropsWithChildren) { component + ("?keys=" + k) + ("&types=" + t) + - (as ? "&as=" + as : "") + (view ? "&as=" + view : "") ); return new Promise>((resolve, reject) => { del(url).then(resp => { @@ -243,11 +247,12 @@ export default function ComponentProvider(props: PropsWithChildren) { }) }; - const getComponent = (device: number, component: string, keys?: string[], types?: string[], as?: string) => { + const getComponent = (device: number, component: string, keys?: string[], types?: string[], otherTeam?: string) => { let k: string[] = keys ? keys : []; if (!k.includes(device.toString())) k.push(device.toString()); //if the device id is already in the keys do not add it again let t: string[] = types ? types : []; if (!t.includes("device")) t.push("device"); // if "device" is already in the types do not add it again + const view = otherTeam ? otherTeam : as const url = pondURL( "/devices/" + device + @@ -255,7 +260,7 @@ export default function ComponentProvider(props: PropsWithChildren) { component + ("?keys=" + k) + ("&types=" + t) + - (as ? "&as=" + as : "") + (view ? "&as=" + view : "") ); return new Promise>((resolve, reject) => { get(url).then(resp => { @@ -273,10 +278,11 @@ export default function ComponentProvider(props: PropsWithChildren) { keys?: string[], types?: string[], comprehensive?: boolean, - as?: string + otherTeam?: string ) => { let k = keys ? keys : []; let t = types ? types : []; + const view = otherTeam ? otherTeam : as let url = pondURL( "/devices/" + device + @@ -287,9 +293,9 @@ export default function ComponentProvider(props: PropsWithChildren) { (comprehensive ? "&comprehensive=" + comprehensive.toString() : ""), demo ); - if (as) + if (view) url = pondURL( - `/devices/${device}/components?as=${as}&keys=${k}&types=${t}` + + `/devices/${device}/components?as=${view}&keys=${k}&types=${t}` + (comprehensive ? "&comprehensive=" + comprehensive.toString() : ""), demo ); @@ -303,8 +309,9 @@ export default function ComponentProvider(props: PropsWithChildren) { }) }; - const listComponentsForObject = (keys: string[], types: string[], as?: string) => { - let url = pondURL("/components/forObject?keys=" + keys + "&types=" + types + (as ? "&as=" + as : "")) + const listComponentsForObject = (keys: string[], types: string[], otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + let url = pondURL("/components/forObject?keys=" + keys + "&types=" + types + (view ? "&as=" + view : "")) return new Promise>((resolve, reject) => { get(url).then(resp => { resp.data = pond.ListComponentsResponse.fromObject(resp.data) @@ -321,8 +328,9 @@ export default function ComponentProvider(props: PropsWithChildren) { keys?: string[], types?: string[], comprehensive = false, - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as let url = pondURL( "/devices/" + device + @@ -334,9 +342,9 @@ export default function ComponentProvider(props: PropsWithChildren) { demo ); - if (as) + if (view) url = pondURL( - `/devices/${device}/componentCards?as=${as}` + + `/devices/${device}/componentCards?as=${view}` + (keys ? "&keys=" + keys : "&keys=" + [device.toString()]) + (types ? "&types=" + types : "&types=" + ["device"]), demo @@ -393,7 +401,7 @@ export default function ComponentProvider(props: PropsWithChildren) { // demo: boolean = false, // keys?: string[], // types?: string[], - // as?: string + // otherTeam?: string // // exportMeasurements: boolean = false // ) => { // const url = pondURL( @@ -436,7 +444,7 @@ export default function ComponentProvider(props: PropsWithChildren) { // demo: boolean = false, // keys?: string[], // types?: string[], - // as?: string + // otherTeam?: string // ) => { // const url = pondURL( // "/devices/" + @@ -472,8 +480,9 @@ export default function ComponentProvider(props: PropsWithChildren) { keys?: string[], types?: string[], showErrors: boolean = true, - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as const url = pondURL( "/devices/" + device + @@ -483,7 +492,7 @@ export default function ComponentProvider(props: PropsWithChildren) { dateRange(startDate, endDate) + "&size=" + sampleSize + - (as ? "&as=" + as : "") + + (view ? "&as=" + view : "") + (keys ? "&keys=" + keys : "&keys=" + [device]) + (types ? "&types=" + types : "&types=" + ["device"]) + (showErrors ? "&showErrors=true" : "&showErrors=false"), @@ -536,8 +545,9 @@ export default function ComponentProvider(props: PropsWithChildren) { keys?: string[], types?: string[], showErrors?: boolean, - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as const url = pondURL( "/devices/" + device + @@ -552,7 +562,7 @@ export default function ComponentProvider(props: PropsWithChildren) { "&order=" + order + (measurementType ? "&type=" + measurementType : "") + - (as ? "&as=" + as : "") + + (view ? "&as=" + view : "") + (keys ? "&keys=" + keys : "&keys=" + [device]) + (types ? "&types=" + types : "&types=" + ["device"]) + (showErrors ? "&showErrors=true" : "&showErrors=false") diff --git a/src/providers/pond/contractAPI.tsx b/src/providers/pond/contractAPI.tsx index fad0c22..3569b52 100644 --- a/src/providers/pond/contractAPI.tsx +++ b/src/providers/pond/contractAPI.tsx @@ -1,5 +1,5 @@ import { useHTTP } from "hooks"; -import React, { createContext, PropsWithChildren, useContext } from "react"; +import { createContext, PropsWithChildren, useContext } from "react"; import { pond } from "protobuf-ts/pond"; import { pondURL } from "./pond"; import { AxiosResponse } from "axios"; @@ -9,7 +9,7 @@ export interface IContractInterface { addContract: ( name: string, settings: pond.ContractSettings, - as?: string + otherTeam?: string ) => Promise>; listContracts: ( limit: number, @@ -21,15 +21,15 @@ export interface IContractInterface { types?: string[], numerical?: boolean, specificUser?: string, - as?: string, + otherTeam?: string, ) => Promise>; updateContract: ( key: string, name: string, settings: pond.ContractSettings, - as?: string + otherTeam?: string ) => Promise>; - removeContract: (key: string, as?: string) => Promise>; + removeContract: (key: string, otherTeam?: string) => Promise>; listContractsByYear: ( limit: number, offset: number, @@ -41,10 +41,10 @@ export interface IContractInterface { numerical?: boolean, specificUser?: string, contractYear?: string, - as?: string + otherTeam?: string ) => Promise>; //list contract page data - getContractPageData: (key: string, as?: string) => Promise>; + getContractPageData: (key: string, otherTeam?: string) => Promise>; //for the moment however simply passing the contract from the earlier list is sufficient } @@ -55,13 +55,14 @@ interface Props {} export default function ContractProvider(props: PropsWithChildren) { const { children } = props; const { get, del, post, put } = useHTTP(); - //const [{ as }] = useGlobalState(); + const [{ as }] = useGlobalState(); //add - const addContract = (name: string, settings: pond.ContractSettings, as?: string) => { - if (as) { + const addContract = (name: string, settings: pond.ContractSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) { return post( - pondURL("/contracts?name=" + name + "&as=" + as), + pondURL("/contracts?name=" + name + "&as=" + view), settings ); } @@ -77,12 +78,11 @@ export default function ContractProvider(props: PropsWithChildren) { keys?: string[], types?: string[], numerical?: boolean, - specificUser?: string, - as?: string + otherTeam?: string ) => { let asText = ""; - if (as) asText = "&as=" + as; - if (specificUser) asText = "&as=" + specificUser; + const view = otherTeam ? otherTeam : as + if (view) asText = "&as=" + view; return get( pondURL( "/contracts?limit=" + @@ -108,13 +108,12 @@ export default function ContractProvider(props: PropsWithChildren) { keys?: string[], types?: string[], numerical?: boolean, - specificUser?: string, contractYear?: string, - as?: string, + otherTeam?: string, ) => { let asText = ""; - if (as) asText = "&as=" + as; - if (specificUser) asText = "&as=" + specificUser; + const view = otherTeam ? otherTeam : as + if (view) asText = "&as=" + view; return get( pondURL( "/contractsByYear?limit=" + @@ -133,10 +132,11 @@ export default function ContractProvider(props: PropsWithChildren) { ); }; //update - const updateContract = (key: string, name: string, settings: pond.ContractSettings, as?: string) => { - if (as) { + const updateContract = (key: string, name: string, settings: pond.ContractSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) { return put( - pondURL("/contracts/" + key + "?as=" + as + "&name=" + name), + pondURL("/contracts/" + key + "?as=" + view + "&name=" + name), settings ); } @@ -146,16 +146,18 @@ export default function ContractProvider(props: PropsWithChildren) { ); }; //remove - const removeContract = (key: string, as?: string) => { - if (as) { - return del(pondURL("/contracts/" + key + "?as=" + as)); + const removeContract = (key: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) { + return del(pondURL("/contracts/" + key + "?as=" + view)); } - return del(pondURL("/contracts/" + key + "?as=" + as)); + return del(pondURL("/contracts/" + key)); }; - const getContractPageData = (key: string, as?: string) => { - if (as) { - return get(pondURL("/contractsPage/" + key + "?as=" + as)); + const getContractPageData = (key: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) { + return get(pondURL("/contractsPage/" + key + "?as=" + view)); } return get(pondURL("/contractsPage/" + key)); diff --git a/src/providers/pond/deviceAPI.tsx b/src/providers/pond/deviceAPI.tsx index 201df88..84ed346 100644 --- a/src/providers/pond/deviceAPI.tsx +++ b/src/providers/pond/deviceAPI.tsx @@ -12,19 +12,19 @@ import { dateRange } from "providers/http"; // import { reject, result } from "lodash"; export interface IDeviceAPIContext { - add: (name: string, description: string, backpack: pond.BackpackSettings, as?: string) => Promise>; - update: (id: number, settings: pond.DeviceSettings, as?: string) => Promise>; - remove: (id: number, as?: string) => Promise>; - get: (id: number | string, demo?: boolean, keys?: string[], types?: string[], as?: string) => Promise> + add: (name: string, description: string, backpack: pond.BackpackSettings, otherTeam?: string) => Promise>; + update: (id: number, settings: pond.DeviceSettings, otherTeam?: string) => Promise>; + remove: (id: number, otherTeam?: string) => Promise>; + get: (id: number | string, demo?: boolean, keys?: string[], types?: string[], otherTeam?: string) => Promise> getPageData: ( id: number | string, keys?: string[], types?: string[], - as?: string + otherTeam?: string ) => Promise>; - getMulti: (ids: number[] | string[], as?: string) => Promise>; - getGeoJson: (id: number | string, demo?: boolean, as?: string) => Promise; - getMultiGeoJson: (ids: number[] | string[], as?: string) => Promise; + getMulti: (ids: number[] | string[], otherTeam?: string) => Promise>; + getGeoJson: (id: number | string, demo?: boolean, otherTeam?: string) => Promise; + getMultiGeoJson: (ids: number[] | string[], otherTeam?: string) => Promise; list: ( limit: number, offset: number, @@ -41,7 +41,7 @@ export interface IDeviceAPIContext { types?: string[], fieldContains?: Map, prefixSearch?: string, - as?: string + otherTeam?: string ) => Promise>; listForUser: ( asRoot: boolean, @@ -65,7 +65,7 @@ export interface IDeviceAPIContext { preferences: pond.DevicePreferences, keys?: string[], types?: string[], - as?: string + otherTeam?: string ) => Promise; updateComponentPreferences: ( id: number | string, @@ -73,13 +73,13 @@ export interface IDeviceAPIContext { preferences: pond.DeviceComponentPreferences, keys?: string[], types?: string[], - as?: string + otherTeam?: string ) => Promise>; listDeviceComponentPreferences: ( id: number | string, keys?: string[], types?: string[], - as?: string + otherTeam?: string ) => Promise>; updateStatus: ( id: number | string, @@ -99,7 +99,7 @@ export interface IDeviceAPIContext { newCap: number ) => Promise>; resume: (id: number) => Promise; - getUpgradeStatus: (id: number, keys?: string[], types?: string[], as?: string) => Promise; + getUpgradeStatus: (id: number, keys?: string[], types?: string[], otherTeam?: string) => Promise; loadBackpack: (id: number, backpack: number) => Promise; setTags: (id: number, tags: string[]) => Promise; setWifi: ( @@ -108,7 +108,7 @@ export interface IDeviceAPIContext { password: string, keys?: string[], types?: string[], - as?: string + otherTeam?: string ) => Promise; statistics: ( keys?: string[], @@ -129,9 +129,9 @@ export interface IDeviceAPIContext { offset: number, order: string, orderBy: string, - as?: string + otherTeam?: string ) => Promise>; - listSimpleJSON: (device: number, as?: string) => Promise; + listSimpleJSON: (device: number, otherTeam?: string) => Promise; resetQuackCount: (id: number) => Promise; resetQuackCountTx: (id: number) => Promise; resetQuackCountTx1000: (id: number) => Promise; @@ -157,11 +157,12 @@ export default function DeviceProvider(props: PropsWithChildren) { const { children } = props; const { get, post, put, del } = useHTTP(); const permissionAPI = usePermissionAPI(); - //const [{ as, team }] = useGlobalState(); + const [{ as, team }] = useGlobalState(); - const add = (name: string, description: string, backpack: pond.BackpackSettings, as?: string) => { + const add = (name: string, description: string, backpack: pond.BackpackSettings, otherTeam?: string) => { let url = pondURL("/devices") - if (as) url = pondURL("/devices?as=" + as) + const view = otherTeam ? otherTeam : as + if (view) url = pondURL("/devices?as=" + view) return new Promise>((resolve, reject) => { post(url, { name, description, backpack }).then(resp => { resp.data = pond.AddDeviceResponse.fromObject(resp.data) @@ -177,8 +178,9 @@ export default function DeviceProvider(props: PropsWithChildren) { demo: boolean = false, keys?: string[], types?: string[], - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as let url = pondURL( "/devices/" + id + @@ -186,11 +188,11 @@ export default function DeviceProvider(props: PropsWithChildren) { (types ? "&types=" + types.toString() : ""), demo ); - if (as) { + if (view) { url = pondURL( "/devices/" + id + - "?as=" + as + + "?as=" + view + (keys ? "&keys=" + keys.toString() : "") + (types ? "&types=" + types.toString() : ""), demo @@ -231,20 +233,21 @@ export default function DeviceProvider(props: PropsWithChildren) { id: number | string, keys?: string[], types?: string[], - as?: string + otherTeam?: string ): Promise> => { + const view = otherTeam ? otherTeam : as let url = pondURL( "/devicePageData/" + id + (keys ? "?keys=" + keys.toString() : "") + (types ? "&types=" + types.toString() : "") ); - if (as && !(types && types.length > 0 && types[0] === "team")) { + if (view && !(types && types.length > 0 && types[0] === "team")) { url = pondURL( "/devicePageData/" + id + "?as=" + - as + + view + (keys ? "&keys=" + keys.toString() : "") + (types ? "&types=" + types.toString() : "") ) @@ -259,9 +262,10 @@ export default function DeviceProvider(props: PropsWithChildren) { }) }; - const getDeviceGeoJSON = (id: number | string, demo: boolean = false, as?: string) => { + const getDeviceGeoJSON = (id: number | string, demo: boolean = false, otherTeam?: string) => { let url = pondURL("/devices/" + id + "/geojson", demo); - if (as) url = pondURL("/devices/" + id + "/geojson?as=" + as, demo) + const view = otherTeam ? otherTeam : as + if (view) url = pondURL("/devices/" + id + "/geojson?as=" + view, demo) return new Promise((resolve, reject) => { get(url).catch(resp => { return resolve(resp) @@ -271,7 +275,7 @@ export default function DeviceProvider(props: PropsWithChildren) { }) }; - const getMulti = (ids: number[] | string[], as?: string) => { + const getMulti = (ids: number[] | string[], otherTeam?: string) => { let idString = ""; ids.forEach((id: number | string, i: number) => { if (i === 0) { @@ -280,7 +284,8 @@ export default function DeviceProvider(props: PropsWithChildren) { idString = idString + "," + id; } }); - let url = pondURL("/multidevices?devices=" + idString + (as ? "&as=" + as : "")) + const view = otherTeam ? otherTeam : as + let url = pondURL("/multidevices?devices=" + idString + (view ? "&as=" + view : "")) return new Promise>((resolve, reject) => { get(url).then(resp => { resp.data = pond.GetMultiDeviceResponse.fromObject(resp.data) @@ -291,7 +296,7 @@ export default function DeviceProvider(props: PropsWithChildren) { }) }; - const getMultiDevicesGeoJSON = (ids: number[] | string[], as?: string) => { + const getMultiDevicesGeoJSON = (ids: number[] | string[], otherTeam?: string) => { let idString = ""; ids.forEach((id: number | string, i: number) => { if (i === 0) { @@ -300,7 +305,8 @@ export default function DeviceProvider(props: PropsWithChildren) { idString = idString + "," + id; } }); - let url = pondURL("/geojson/devices?devices=" + idString + (as ? "&as=" + as : "")) + const view = otherTeam ? otherTeam : as + let url = pondURL("/geojson/devices?devices=" + idString + (view ? "&as=" + view : "")) return new Promise((resolve, reject) => { get(url).then(resp => { return resolve(resp) @@ -326,8 +332,9 @@ export default function DeviceProvider(props: PropsWithChildren) { types?: string[], fieldContains?: Map, prefixSearch?: string, - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as const url = pondURL( "/devices" + "?limit=" + @@ -341,7 +348,7 @@ export default function DeviceProvider(props: PropsWithChildren) { (status ? "&status=" + status : "") + (ids ? "&ids=" + ids.join(",") : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") + - (as && !(types && types.length > 0 && types[0] === "team") ? "&as=" + as : "") + + (view && !(types && types.length > 0 && types[0] === "team") ? "&as=" + view : "") + (comprehensive ? "&comprehensive=" + comprehensive.toString() : "") + (withMeasurements ? "&measurements=" + withMeasurements.toString() : "") + (keys ? "&keys=" + keys.toString() : "") + @@ -385,8 +392,9 @@ export default function DeviceProvider(props: PropsWithChildren) { }) }; - const remove = (id: number, as?: string) => { - const url = pondURL("/devices/" + id + (as ? "?as=" + as : "")) + const remove = (id: number, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + const url = pondURL("/devices/" + id + (view ? "?as=" + view : "")) return new Promise>((resolve, reject) => { del(url).then(resp => { resp.data = pond.RemoveDeviceResponse.fromObject(resp.data) @@ -397,8 +405,9 @@ export default function DeviceProvider(props: PropsWithChildren) { }) }; - const update = (id: number, settings: pond.DeviceSettings, as?: string) => { - const url = pondURL("/devices/" + id + "/update" + (as ? "?as=" + as : "")); + const update = (id: number, settings: pond.DeviceSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + const url = pondURL("/devices/" + id + "/update" + (view ? "?as=" + view : "")); return new Promise>((resolve, reject) => { put(url, settings).then(resp => { resp.data = pond.UpdateDeviceResponse.fromObject(resp) @@ -463,14 +472,15 @@ export default function DeviceProvider(props: PropsWithChildren) { preferences: pond.DevicePreferences, keys?: string[], types?: string[], - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as let url = pondURL( "/devices/" + id + "/preferences" + "?as=" + - or(as, "") + + or(view, "") + (keys ? "&keys=" + keys.toString() : "") + (types ? "&types=" + types.toString() : "") ) @@ -489,8 +499,9 @@ export default function DeviceProvider(props: PropsWithChildren) { preferences: pond.DeviceComponentPreferences, keys?: string[], types?: string[], - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as let url = pondURL( "/devices/" + id + @@ -498,7 +509,7 @@ export default function DeviceProvider(props: PropsWithChildren) { component + "/componentPreferences" + "?as=" + - as + + view + (keys ? "&keys=" + keys.toString() : "") + (types ? "&types=" + types.toString() : "") ) @@ -516,8 +527,9 @@ export default function DeviceProvider(props: PropsWithChildren) { id: number | string, keys?: string[], types?: string[], - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as let url = pondURL( "/devices/" + id + @@ -525,11 +537,11 @@ export default function DeviceProvider(props: PropsWithChildren) { (keys ? "?keys=" + keys.toString() : "") + (types ? "&types=" + types.toString() : "") ) - if (as) { + if (view) { url = pondURL( "/devices/" + id + - "/componentPreferences?as=" + as + + "/componentPreferences?as=" + view + (keys ? "&keys=" + keys.toString() : "") + (types ? "&types=" + types.toString() : "") ) @@ -549,14 +561,15 @@ export default function DeviceProvider(props: PropsWithChildren) { status: pond.DeviceStatus, keys?: string[], types?: string[], - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as let url = pondURL( "/devices/" + id + "/updateStatus" + "?as=" + - as + + view + (keys ? "&keys=" + keys.toString() : "") + (types ? "&types=" + types.toString() : "") ) @@ -640,10 +653,11 @@ export default function DeviceProvider(props: PropsWithChildren) { }) }; - const getUpgradeStatus = (id: number, keys?: string[], types?: string[], as?: string) => { - let a = as ? "?as=" + as : ""; + const getUpgradeStatus = (id: number, keys?: string[], types?: string[], otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + let a = view ? "?as=" + view : ""; if (keys && keys.length > 0 && types && types.length > 0) { - a = as ? a + "&keys=" + keys + "&types=" + types : "?keys=" + keys + "&types=" + types; + a = view ? a + "&keys=" + keys + "&types=" + types : "?keys=" + keys + "&types=" + types; } let url = pondURL("/devices/" + id + "/firmware" + a); return new Promise((resolve, reject) => { @@ -681,11 +695,12 @@ export default function DeviceProvider(props: PropsWithChildren) { password: string, keys?: string[], types?: string[], - as?: string + otherTeam?: string ) => { - let a = as ? "?as=" + as : ""; + const view = otherTeam ? otherTeam : as + let a = view ? "?as=" + view : ""; if (keys && keys.length > 0 && types && types.length > 0) { - a = as ? a + "&keys=" + keys + "&types=" + types : "?keys=" + keys + "&types=" + types; + a = view ? a + "&keys=" + keys + "&types=" + types : "?keys=" + keys + "&types=" + types; } return new Promise((resolve, reject) => { put(pondURL("/devices/" + id + "/wifi" + a), { gateway, password }).then(resp => { @@ -780,7 +795,7 @@ export default function DeviceProvider(props: PropsWithChildren) { offset: number, order: string, orderBy: string, - as?: string + otherTeam?: string ) => { let keyString = ""; components.forEach((comp, i) => { @@ -790,7 +805,8 @@ export default function DeviceProvider(props: PropsWithChildren) { keyString = keyString + "," + comp.key(); } }); - if (as) { + const view = otherTeam ? otherTeam : as + if (view) { return get( pondURL( "/devices/" + @@ -808,7 +824,7 @@ export default function DeviceProvider(props: PropsWithChildren) { "&orderBy=" + orderBy + "&as=" + - as + view ) ); } @@ -832,9 +848,10 @@ export default function DeviceProvider(props: PropsWithChildren) { ); }; - const listSimpleJSON = (device: number, as?: string) => { + const listSimpleJSON = (device: number, otherTeam?: string) => { let url = "/devices/" + device + "/measurements/exportSimple" - if(as) url = url + "?as=" + as + const view = otherTeam ? otherTeam : as + if(view) url = url + "?as=" + view return new Promise((resolve, reject) => { get(pondURL(url)).then(resp => { return resolve(resp) @@ -894,11 +911,11 @@ export default function DeviceProvider(props: PropsWithChildren) { source?: string, keys?: string[], types?: string[], - as?: string, - team?: Team + otherTeam?: string ) => { let url = "/devices/" + id + "/buyData?MB=" + MB; - if (as === team?.key()) url = url + "&team=" + team?.key(); + const view = otherTeam ? otherTeam : as + if (view === team?.key()) url = url + "&team=" + team?.key(); if (source) url = url + "&source=" + source; if (keys) url = url + "&keys=" + keys; if (types) url = url + "&types=" + types; @@ -956,7 +973,7 @@ export default function DeviceProvider(props: PropsWithChildren) { getDataUsage, buyData, updateComponentPreferences, - listDeviceComponentPreferences//as + listDeviceComponentPreferences }}> {children} diff --git a/src/providers/pond/fieldAPI.tsx b/src/providers/pond/fieldAPI.tsx index 77c8f31..37be160 100644 --- a/src/providers/pond/fieldAPI.tsx +++ b/src/providers/pond/fieldAPI.tsx @@ -7,23 +7,23 @@ import { or } from "utils"; import { pondURL } from "./pond"; export interface IFieldAPIContext { - addField: (field: pond.FieldSettings, as?: string) => Promise; - getField: (fieldId: string, as?: string) => Promise; + addField: (field: pond.FieldSettings, otherTeam?: string) => Promise; + getField: (fieldId: string, otherTeam?: string) => Promise; listFields: ( limit: number, offset: number, order?: "asc" | "desc", orderBy?: string, search?: string, - as?: string, + otherTeam?: string, asRoot?: boolean ) => Promise>; - removeField: (key: string, as?: string) => Promise>; + removeField: (key: string, otherTeam?: string) => Promise>; updateField: ( key: string, field: pond.FieldSettings, asRoot?: true, - as?: string + otherTeam?: string ) => Promise>; } @@ -34,20 +34,23 @@ interface Props {} export default function FieldProvider(props: PropsWithChildren) { const { children } = props; const { get, del, post, put } = useHTTP(); - //const [{ as }] = useGlobalState(); + const [{ as }] = useGlobalState(); - const addField = (field: pond.FieldSettings, as?: string) => { - if (as) return post(pondURL("/fields?as=" + as), field); + const addField = (field: pond.FieldSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return post(pondURL("/fields?as=" + view), field); return post(pondURL("/fields"), field); }; - const getField = (fieldId: string, as?: string) => { - if (as) return get(pondURL("/field/" + fieldId + "?as=" + as)); + const getField = (fieldId: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return get(pondURL("/field/" + fieldId + "?as=" + view)); return get(pondURL("/field/" + fieldId)); }; - const removeField = (key: string, as?: string) => { - if (as) return del(pondURL("/fields/" + key + "?as=" + as)); + const removeField = (key: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return del(pondURL("/fields/" + key + "?as=" + view)); return del(pondURL("/fields/" + key)); }; @@ -57,9 +60,10 @@ export default function FieldProvider(props: PropsWithChildren) { order?: "asc" | "desc", orderBy?: string, search?: string, - as?: string, + otherTeam?: string, asRoot?: boolean ) => { + const view = otherTeam ? otherTeam : as return get( pondURL( "/fields" + @@ -69,17 +73,18 @@ export default function FieldProvider(props: PropsWithChildren) { offset + ("&order=" + or(order, "asc")) + ("&by=" + or(orderBy, "key")) + - (as ? "&as=" + as : "") + + (view ? "&as=" + view : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") + (search ? "&search=" + search : "") ) ); }; - const updateField = (key: string, field: pond.FieldSettings, asRoot?: boolean, as?: string) => { - if (as) + const updateField = (key: string, field: pond.FieldSettings, asRoot?: boolean, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return put( - pondURL("/fields/" + key + "?as=" + as + (asRoot ? "&asRoot=" + asRoot.toString() : "")), + pondURL("/fields/" + key + "?as=" + view + (asRoot ? "&asRoot=" + asRoot.toString() : "")), field ); return put( diff --git a/src/providers/pond/fieldMarkerAPI.tsx b/src/providers/pond/fieldMarkerAPI.tsx index 642ada5..f66f616 100644 --- a/src/providers/pond/fieldMarkerAPI.tsx +++ b/src/providers/pond/fieldMarkerAPI.tsx @@ -8,9 +8,9 @@ import { pondURL } from "./pond"; export interface IFieldMarkerAPIContext { addFieldMarker: ( fieldMarker: pond.FieldMarkerSettings, - as?: string + otherTeam?: string ) => Promise>; - getFieldMarker: (fieldMarkerID: string) => Promise>; + getFieldMarker: (fieldMarkerID: string, otherTeam?: string) => Promise>; listFieldMarkers: ( limit: number, offset: number, @@ -18,17 +18,17 @@ export interface IFieldMarkerAPIContext { orderBy?: string, search?: string, asRoot?: boolean, - as?: string + otherTeam?: string ) => Promise>; removeFieldMarker: ( fieldMarkerID: string, - as?: string + otherTeam?: string ) => Promise>; updateFieldMarker: ( key: string, fieldMarker: pond.FieldMarkerSettings, asRoot?: true, - as?: string + otherTeam?: string ) => Promise>; } @@ -41,22 +41,25 @@ interface Props {} export default function FieldMarkerProvider(props: PropsWithChildren) { const { children } = props; const { get, del, post, put } = useHTTP(); - //const [{ as }] = useGlobalState(); + const [{ as }] = useGlobalState(); - const addFieldMarker = (fieldMarker: pond.FieldMarkerSettings, as?: string) => { - if (as) - return post(pondURL("/fieldMarkers?as=" + as), fieldMarker); + const addFieldMarker = (fieldMarker: pond.FieldMarkerSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) + return post(pondURL("/fieldMarkers?as=" + view), fieldMarker); return post(pondURL("/fieldMarkers"), fieldMarker); }; - const getFieldMarker = (fieldMarkerId: string, as?: string) => { - if (as) return get(pondURL("/fieldMarkers/" + fieldMarkerId + "?as=" + as)); + const getFieldMarker = (fieldMarkerId: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return get(pondURL("/fieldMarkers/" + fieldMarkerId + "?as=" + view)); return get(pondURL("/fieldMarkers/" + fieldMarkerId)); }; - const removeFieldMarker = (key: string, as?: string) => { - if (as) - return del(pondURL("/fieldMarkers/" + key + "?as=" + as)); + const removeFieldMarker = (key: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) + return del(pondURL("/fieldMarkers/" + key + "?as=" + view)); return del(pondURL("/fieldMarkers/" + key)); }; @@ -67,8 +70,9 @@ export default function FieldMarkerProvider(props: PropsWithChildren) { orderBy?: string, search?: string, asRoot?: boolean, - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as return get( pondURL( "/fieldMarkers" + @@ -80,16 +84,17 @@ export default function FieldMarkerProvider(props: PropsWithChildren) { ("&by=" + (orderBy ? orderBy : "key")) + (search ? "&search=" + search : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") + - (as ? "&as=" + as : "") + (view ? "&as=" + view : "") ) ); }; - const updateFieldMarker = (key: string, hm: pond.FieldMarkerSettings, asRoot?: boolean, as?: string) => { - if (as) + const updateFieldMarker = (key: string, hm: pond.FieldMarkerSettings, asRoot?: boolean, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return put( pondURL( - "/fieldMarkers/" + key + "?as=" + as + (asRoot ? "&asRoot=" + asRoot.toString() : "") + "/fieldMarkers/" + key + "?as=" + view + (asRoot ? "&asRoot=" + asRoot.toString() : "") ), hm ); diff --git a/src/providers/pond/gateAPI.tsx b/src/providers/pond/gateAPI.tsx index 72035e5..5b07606 100644 --- a/src/providers/pond/gateAPI.tsx +++ b/src/providers/pond/gateAPI.tsx @@ -9,7 +9,7 @@ export interface IGateInterface { addGate: ( name: string, settings: pond.GateSettings, - as?: string + otherTeam?: string ) => Promise>; listGates: ( limit: number, @@ -22,23 +22,23 @@ export interface IGateInterface { types?: string[], numerical?: boolean, specificUser?: string, - as?: string + otherTeam?: string ) => Promise>; updateGate: ( key: string, name: string, settings: pond.GateSettings, - as?: string + otherTeam?: string ) => Promise>; - getGate: (key: string, as?: string) => Promise>; - removeGate: (key: string, as?: string) => Promise>; + getGate: (key: string, otherTeam?: string) => Promise>; + removeGate: (key: string, otherTeam?: string) => Promise>; updateLink: ( parentKey: string, parentType: string, objectID: string, objectType: string, permissions: string[], - as?: string + otherTeam?: string ) => Promise; updatePrefs: ( gateKey: string, @@ -47,9 +47,9 @@ export interface IGateInterface { gatePref: pond.GateComponentType | pond.GateDeviceType, keys?: string[], types?: string[], - as?: string + otherTeam?: string ) => Promise>; - getGatePageData: (key: string, as?: string) => Promise>; + getGatePageData: (key: string, otherTeam?: string) => Promise>; listGateAirflow: ( gate: string, device: number | string, @@ -59,7 +59,7 @@ export interface IGateInterface { end: string, keys?: string[], types?: string[], - as?: string + otherTeam?: string ) => Promise>; listGateFlowEvents: ( gate: string, @@ -72,13 +72,13 @@ export interface IGateInterface { flowVariance: number, keys?: string[], types?: string[], - as?: string + otherTeam?: string ) => Promise>; listGateMeasurements: ( key: string, start: string, end: string, - as?: string + otherTeam?: string ) => Promise>; } @@ -89,10 +89,11 @@ interface Props {} export default function GateProvider(props: PropsWithChildren) { const { children } = props; const { get, del, post, put } = useHTTP(); - //const [{ as }] = useGlobalState(); + const [{ as }] = useGlobalState(); - const addGate = (name: string, settings: pond.GateSettings, as?: string) => { - let url = pondURL("/gates?name=" + name + (as ? "&as=" + as : "")) + const addGate = (name: string, settings: pond.GateSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + let url = pondURL("/gates?name=" + name + (view ? "&as=" + view : "")) return new Promise>((resolve, reject) => { post(url, settings).then(resp => { resp.data = pond.AddGateResponse.fromObject(resp.data) @@ -114,10 +115,11 @@ export default function GateProvider(props: PropsWithChildren) { types?: string[], numerical?: boolean, specificUser?: string, - as?: string + otherTeam?: string ) => { let asText = ""; - if (as) asText = "&as=" + as; + const view = otherTeam ? otherTeam : as + if (view) asText = "&as=" + view; if (specificUser) asText = "&as=" + specificUser; let url = pondURL( "/gates?limit=" + @@ -143,8 +145,9 @@ export default function GateProvider(props: PropsWithChildren) { }) }; - const updateGate = (key: string, name: string, settings: pond.GateSettings, as?: string) => { - let url = pondURL("/gates/" + key + "?name=" + name + (as ? "&as=" + as : "")) + const updateGate = (key: string, name: string, settings: pond.GateSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + let url = pondURL("/gates/" + key + "?name=" + name + (view ? "&as=" + view : "")) return new Promise>((resolve, reject) => { put(url, settings).then(resp => { resp.data = pond.UpdateGateResponse.fromObject(resp.data) @@ -155,8 +158,9 @@ export default function GateProvider(props: PropsWithChildren) { }) }; - const removeGate = (key: string, as?: string) => { - let url = pondURL("/gates/" + key + (as ? "?as=" + as : "")) + const removeGate = (key: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + let url = pondURL("/gates/" + key + (view ? "?as=" + view : "")) return new Promise>((resolve, reject) => { del(url).then(resp => { resp.data = pond.RemoveGateResponse.fromObject(resp.data) @@ -167,8 +171,9 @@ export default function GateProvider(props: PropsWithChildren) { }) }; - const getGate = (key: string, as?: string) => { - let url = pondURL("/gates/" + key + (as ? "?as=" + as : "")) + const getGate = (key: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + let url = pondURL("/gates/" + key + (view ? "?as=" + view : "")) return new Promise>((resolve, reject) => { get(url).then(resp => { resp.data = pond.GetGateResponse.fromObject(resp.data) @@ -179,8 +184,9 @@ export default function GateProvider(props: PropsWithChildren) { }) }; - const getGatePageData = (key: string, as?: string) => { - let url = pondURL("/gatePage/" + key + (as ? "?as=" + as : "")) + const getGatePageData = (key: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + let url = pondURL("/gatePage/" + key + (view ? "?as=" + view : "")) return new Promise>((resolve, reject) => { get(url).then(resp => { resp.data = pond.GetGatePageDataResponse.fromObject(resp.data) @@ -197,9 +203,10 @@ export default function GateProvider(props: PropsWithChildren) { objectID: string, objectType: string, permissions: string[], - as?: string + otherTeam?: string ) => { - let url = pondURL(`/gates/` + parentID + "/link" + (as ? `?as=${as}` : "")) + const view = otherTeam ? otherTeam : as + let url = pondURL(`/gates/` + parentID + "/link" + (view ? `?as=${view}` : "")) return new Promise((resolve, reject) => { post(url, { Key: objectID, @@ -223,8 +230,9 @@ export default function GateProvider(props: PropsWithChildren) { gatePref: pond.GateComponentType | pond.GateDeviceType, keys?: string[], types?: string[], - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as let url = pondURL( `/gatePrefs/` + gateKey + @@ -234,7 +242,7 @@ export default function GateProvider(props: PropsWithChildren) { childKey + "&gatePreference=" + gatePref + - (as ? `&as=` + as : "") + + (view ? `&as=` + view : "") + (keys ? "&keys=" + keys.toString() : "") + (types ? "&types=" + types.toString() : "") ) @@ -257,8 +265,9 @@ export default function GateProvider(props: PropsWithChildren) { end: string, keys?: string[], types?: string[], - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as let url = pondURL( "/gates/" + gate + @@ -272,7 +281,7 @@ export default function GateProvider(props: PropsWithChildren) { start + "&end=" + end + - (as ? "&as=" + as : "") + + (view ? "&as=" + view : "") + (keys ? "&keys=" + keys.toString() : "") + (types ? "&types=" + types.toString() : "") ) @@ -286,8 +295,9 @@ export default function GateProvider(props: PropsWithChildren) { }) }; - const listGateMeasurements = (key: string, start: string, end: string, as?: string) => { - let url = pondURL("/gates/" + key + "/measurements?start=" + start + "&end=" + end + "&as=" + as) + const listGateMeasurements = (key: string, start: string, end: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + let url = pondURL("/gates/" + key + "/measurements?start=" + start + "&end=" + end + "&as=" + view) return new Promise>((resolve, reject) => { get(url).then(resp => { resp.data = pond.ListGateMeasurementsResponse.fromObject(resp.data) @@ -309,8 +319,9 @@ export default function GateProvider(props: PropsWithChildren) { flowVariance: number, keys?: string[], types?: string[], - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as return get( pondURL( "/gates/" + @@ -329,7 +340,7 @@ export default function GateProvider(props: PropsWithChildren) { idleFlow + "&variance=" + flowVariance + - (as ? "&as=" + as : "") + + (view ? "&as=" + view : "") + (keys ? "&keys=" + keys.toString() : "") + (types ? "&types=" + types.toString() : "") ) diff --git a/src/providers/pond/grainBagAPI.tsx b/src/providers/pond/grainBagAPI.tsx index 34c471d..cae88b8 100644 --- a/src/providers/pond/grainBagAPI.tsx +++ b/src/providers/pond/grainBagAPI.tsx @@ -4,13 +4,12 @@ import { pond } from "protobuf-ts/pond"; import { pondURL } from "./pond"; import { AxiosResponse } from "axios"; import { useGlobalState } from "providers"; -import { GrainBag } from "models/GrainBag"; export interface IGrainBagInterface { addGrainBag: ( name: string, settings: pond.GrainBagSettings, - as?: string + otherTeam?: string ) => Promise>; listGrainBags: ( limit: number, @@ -21,28 +20,27 @@ export interface IGrainBagInterface { keys?: string[], types?: string[], numerical?: boolean, - specificUser?: string, - as?: string + otherTeam?: string ) => Promise>; updateGrainBag: ( key: string, name: string, settings: pond.GrainBagSettings, - as?: string + otherTeam?: string ) => Promise>; bulkUpdateGrainBags: ( bags: pond.GrainBag[], - as?: string + otherTeam?: string ) => Promise>; - getGrainBag: (key: string, as?: string) => Promise>; - removeGrainBag: (key: string, as?: string) => Promise>; + getGrainBag: (key: string, otherTeam?: string) => Promise>; + removeGrainBag: (key: string, otherTeam?: string) => Promise>; listHistory: ( id: string, limit: number, offset: number, start?: string, end?: string, - as?: string + otherTeam?: string ) => Promise>; } @@ -53,12 +51,13 @@ interface Props {} export default function GrainBagProvider(props: PropsWithChildren) { const { children } = props; const { get, del, post, put } = useHTTP(); - //const [{ as }] = useGlobalState(); + const [{ as }] = useGlobalState(); - const addGrainBag = (name: string, settings: pond.GrainBagSettings, as?: string) => { - if (as) { + const addGrainBag = (name: string, settings: pond.GrainBagSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) { return post( - pondURL("/grainbags?name=" + name + "&as=" + as), + pondURL("/grainbags?name=" + name + "&as=" + view), settings ); } @@ -74,12 +73,11 @@ export default function GrainBagProvider(props: PropsWithChildren) { keys?: string[], types?: string[], numerical?: boolean, - specificUser?: string, - as?: string + otherTeam?: string ) => { let asText = ""; - if (as) asText = "&as=" + as; - if (specificUser) asText = "&as=" + specificUser; + const view = otherTeam ? otherTeam : as + if (view) asText = "&as=" + view; return get( pondURL( "/grainbags?limit=" + @@ -97,10 +95,11 @@ export default function GrainBagProvider(props: PropsWithChildren) { ); }; - const updateGrainBag = (key: string, name: string, settings: pond.GrainBagSettings, as?: string) => { - if (as) { + const updateGrainBag = (key: string, name: string, settings: pond.GrainBagSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) { return put( - pondURL("/grainbags/" + key + "?as=" + as + "&name=" + name), + pondURL("/grainbags/" + key + "?as=" + view + "&name=" + name), settings ); } @@ -110,29 +109,33 @@ export default function GrainBagProvider(props: PropsWithChildren) { ); }; - const bulkUpdateGrainBags = (bags: pond.GrainBag[], as?: string) => { - if (as) - return put(pondURL("/bulkGrainBags/update?as=" + as), { + const bulkUpdateGrainBags = (bags: pond.GrainBag[], otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) + return put(pondURL("/bulkGrainBags/update?as=" + view), { bags: bags }); return put(pondURL("/bulkGrainBags/update"), { bags: bags }); }; - const removeGrainBag = (key: string, as?: string) => { - if (as) { - return del(pondURL("/grainbags/" + key + "?as=" + as)); + const removeGrainBag = (key: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) { + return del(pondURL("/grainbags/" + key + "?as=" + view)); } - return del(pondURL("/grainbags/" + key + "?as=" + as)); + return del(pondURL("/grainbags/" + key)); }; - const getGrainBag = (key: string, as?: string) => { - if (as) { - return get(pondURL("/grainbags/" + key + "?as=" + as)); + const getGrainBag = (key: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) { + return get(pondURL("/grainbags/" + key + "?as=" + view)); } return get(pondURL("/grainbags/" + key)); }; - const listHistory = (id: string, limit: number, offset: number, start?: string, end?: string, as?: string) => { + const listHistory = (id: string, limit: number, offset: number, start?: string, end?: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as let url = pondURL( "/grainbags/" + id + @@ -143,8 +146,8 @@ export default function GrainBagProvider(props: PropsWithChildren) { (start && "&start=" + start) + (end && "&end=" + end) ) - if (as) { - url = url + "?as=" + as + if (view) { + url = url + "?as=" + view } return get(url); }; diff --git a/src/providers/pond/harvestPlanAPI.tsx b/src/providers/pond/harvestPlanAPI.tsx index 605283e..6c0fbb4 100644 --- a/src/providers/pond/harvestPlanAPI.tsx +++ b/src/providers/pond/harvestPlanAPI.tsx @@ -7,15 +7,15 @@ import { or } from "utils"; import { pondURL } from "./pond"; export interface IHarvestPlanAPIContext { - addHarvestPlan: (harvestPlan: pond.HarvestPlanSettings, as?: string) => Promise; - getHarvestPlan: (harvestPlanId: string, as?: string) => Promise; + addHarvestPlan: (harvestPlan: pond.HarvestPlanSettings, otherTeam?: string) => Promise; + getHarvestPlan: (harvestPlanId: string, otherTeam?: string) => Promise; listHarvestPlans: ( limit: number, offset: number, order?: "asc" | "desc", orderBy?: string, search?: string, - as?: string, + otherTeam?: string, asRoot?: boolean ) => Promise>; listHistory: ( @@ -25,13 +25,13 @@ export interface IHarvestPlanAPIContext { ) => Promise>; removeHarvestPlan: ( harvestPlanId: string, - as?: string + otherTeam?: string ) => Promise>; updateHarvestPlan: ( key: string, harvestPlan: pond.HarvestPlanSettings, asRoot?: true, - as?: string + otherTeam?: string ) => Promise>; } @@ -44,21 +44,24 @@ interface Props {} export default function HarvestPlanProvider(props: PropsWithChildren) { const { children } = props; const { get, del, post, put } = useHTTP(); - //const [{ as }] = useGlobalState(); + const [{ as }] = useGlobalState(); - const addHarvestPlan = (harvestPlan: pond.HarvestPlanSettings, as?: string) => { - if (as) return post(pondURL("/harvestPlans?as=" + as), harvestPlan); + const addHarvestPlan = (harvestPlan: pond.HarvestPlanSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return post(pondURL("/harvestPlans?as=" + view), harvestPlan); return post(pondURL("/harvestPlans"), harvestPlan); }; - const getHarvestPlan = (harvestPlanId: string, as?: string) => { - if (as) return get(pondURL("/harvestPlans/" + harvestPlanId + "?as=" + as)); + const getHarvestPlan = (harvestPlanId: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return get(pondURL("/harvestPlans/" + harvestPlanId + "?as=" + view)); return get(pondURL("/harvestPlans/" + harvestPlanId)); }; - const removeHarvestPlan = (key: string, as?: string) => { - if (as) - return del(pondURL("/harvestPlans/" + key + "?as=" + as)); + const removeHarvestPlan = (key: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) + return del(pondURL("/harvestPlans/" + key + "?as=" + view)); return del(pondURL("/harvestPlans/" + key)); }; @@ -68,9 +71,10 @@ export default function HarvestPlanProvider(props: PropsWithChildren) { order?: "asc" | "desc", orderBy?: string, search?: string, - as?: string, + otherTeam?: string, asRoot?: boolean ) => { + const view = otherTeam ? otherTeam : as return get( pondURL( "/harvestPlans" + @@ -82,7 +86,7 @@ export default function HarvestPlanProvider(props: PropsWithChildren) { ("&by=" + or(orderBy, "key")) + (asRoot ? "&asRoot=" + asRoot.toString() : "") + (search ? "&search=" + search : "") + - (as ? "&as=" + as : "") + (view ? "&as=" + view : "") ) ); }; @@ -97,14 +101,15 @@ export default function HarvestPlanProvider(props: PropsWithChildren) { key: string, harvestPlan: pond.HarvestPlanSettings, asRoot?: boolean, - as?: string + otherTeam?: string ) => { - if (as) + const view = otherTeam ? otherTeam : as + if (view) return put( pondURL( "/harvestPlans/" + key + - (as ? "?as=" + as : "") + + (view ? "?as=" + view : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") ), harvestPlan diff --git a/src/providers/pond/homeMarkerAPI.tsx b/src/providers/pond/homeMarkerAPI.tsx index 16eb723..165cf73 100644 --- a/src/providers/pond/homeMarkerAPI.tsx +++ b/src/providers/pond/homeMarkerAPI.tsx @@ -8,7 +8,7 @@ import { pondURL } from "./pond"; export interface IHomeMarkerAPIContext { addHomeMarker: ( homeMarker: pond.HomeMarkerSettings, - as?: string + otherTeam?: string ) => Promise>; getHomeMarker: (homeMarkerID: string) => Promise>; listHomeMarkers: ( @@ -18,14 +18,14 @@ export interface IHomeMarkerAPIContext { orderBy?: string, search?: string, asRoot?: boolean, - as?: string + otherTeam?: string ) => Promise>; removeHomeMarker: (homeMarkerID: string) => Promise>; updateHomeMarker: ( key: string, homeMarker: pond.HomeMarkerSettings, asRoot?: true, - as?:string + otherTeam?:string ) => Promise>; } @@ -38,10 +38,11 @@ interface Props {} export default function HomeMarkerProvider(props: PropsWithChildren) { const { children } = props; const { get, del, post, put } = useHTTP(); - //const [{ as }] = useGlobalState(); + const [{ as }] = useGlobalState(); - const addHomeMarker = (homeMarker: pond.HomeMarkerSettings, as?: string) => { - if (as) return post(pondURL("/homeMarkers?as=" + as), homeMarker); + const addHomeMarker = (homeMarker: pond.HomeMarkerSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return post(pondURL("/homeMarkers?as=" + view), homeMarker); return post(pondURL("/homeMarkers"), homeMarker); }; @@ -60,8 +61,9 @@ export default function HomeMarkerProvider(props: PropsWithChildren) { orderBy?: string, search?: string, asRoot?: boolean, - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as return get( pondURL( "/homeMarkers" + @@ -73,16 +75,17 @@ export default function HomeMarkerProvider(props: PropsWithChildren) { ("&by=" + (orderBy ? orderBy : "key")) + (search ? "&search=" + search : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") + - (as ? "&as=" + as : "") + (view ? "&as=" + view : "") ) ); }; - const updateHomeMarker = (key: string, hm: pond.HomeMarkerSettings, asRoot?: boolean, as?: string) => { - if (as) + const updateHomeMarker = (key: string, hm: pond.HomeMarkerSettings, asRoot?: boolean, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return put( pondURL( - "/homeMarkers/" + key + "?as=" + as + (asRoot ? "&asRoot=" + asRoot.toString() : "") + "/homeMarkers/" + key + "?as=" + view + (asRoot ? "&asRoot=" + asRoot.toString() : "") ), hm ); diff --git a/src/providers/pond/interactionsAPI.tsx b/src/providers/pond/interactionsAPI.tsx index c9413da..bf9da13 100644 --- a/src/providers/pond/interactionsAPI.tsx +++ b/src/providers/pond/interactionsAPI.tsx @@ -10,31 +10,31 @@ import { has } from "utils/types"; import { pondURL } from "./pond"; export interface IInteractionsAPIContext { - addInteraction: (device: number, settings: pond.IInteractionSettings, as?: string) => Promise>; - addMultiInteractions: (device: number, settings: pond.MultiInteractionSettings, as?: string) => Promise>; + addInteraction: (device: number, settings: pond.IInteractionSettings, otherTeam?: string) => Promise>; + addMultiInteractions: (device: number, settings: pond.MultiInteractionSettings, otherTeam?: string) => Promise>; addInteractionToComponents: ( fullComponentLocations: string[], settings: pond.IInteractionSettings, - as?: string + otherTeam?: string ) => Promise>; - updateInteraction: (device: number, settings: pond.IInteractionSettings, as?: string) => Promise>; + updateInteraction: (device: number, settings: pond.IInteractionSettings, otherTeam?: string) => Promise>; updateInteractionPondSettings: ( device: number, interaction: string, settings: pond.IInteractionPondSettings, - as?: string + otherTeam?: string ) => Promise>; - removeInteraction: (device: number, interaction: string, as?: string) => Promise>; - listInteractionsByDevice: (device: number | string, demo?: boolean, as?: string) => Promise; + removeInteraction: (device: number, interaction: string, otherTeam?: string) => Promise>; + listInteractionsByDevice: (device: number | string, demo?: boolean, otherTeam?: string) => Promise; listInteractionsByComponent: ( device: number, component: quack.ComponentID, demo?: boolean, - as?: string + otherTeam?: string ) => Promise; setAlertInteractions: ( alerts: pond.AlertData[], - as?: string + otherTeam?: string ) => Promise>; } @@ -60,12 +60,13 @@ function sanitizeInteraction(interaction: pond.IInteractionSettings): pond.IInte export default function InteractionProvider(props: PropsWithChildren) { const { children } = props; const { get, post, put, del } = useHTTP(); - //const [{ as }] = useGlobalState(); + const [{ as }] = useGlobalState(); - const addInteraction = (device: number, settings: pond.IInteractionSettings, as?: string) => { + const addInteraction = (device: number, settings: pond.IInteractionSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as return new Promise>((resolve, reject) => { post( - pondURL("/devices/" + device + "/interactions" + (as ? "?as=" + as : "")), + pondURL("/devices/" + device + "/interactions" + (view ? "?as=" + view : "")), sanitizeInteraction(settings) ).then(resp => { resp.data = pond.AddInteractionResponse.fromObject(resp) @@ -85,13 +86,14 @@ export default function InteractionProvider(props: PropsWithChildren) { const addInteractionToComponents = ( fullComponentLocations: string[], settings: pond.IInteractionSettings, - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as let url = pondURL( "/interactions/forComponents/" + "?componentIds=" + fullComponentLocations.toString() + - (as ? "&as=" + as : "") + (view ? "&as=" + view : "") ) return new Promise>((resolve, reject) => { post(url,sanitizeInteraction(settings)).then(resp => { @@ -103,8 +105,9 @@ export default function InteractionProvider(props: PropsWithChildren) { }) }; - const addMultiInteractions = (device: number, settings: pond.MultiInteractionSettings, as?: string) => { - let url = pondURL("/devices/" + device + "/interactions/multi" + (as ? "?as=" + as : "")) + const addMultiInteractions = (device: number, settings: pond.MultiInteractionSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + let url = pondURL("/devices/" + device + "/interactions/multi" + (view ? "?as=" + view : "")) return new Promise>((resolve, reject) => { post(url,settings).then(resp => { resp.data = pond.AddMultiInteractionsResponse.fromObject(resp.data) @@ -115,7 +118,8 @@ export default function InteractionProvider(props: PropsWithChildren) { }) }; - const updateInteraction = (device: number, settings: pond.IInteractionSettings, as?: string) => { + const updateInteraction = (device: number, settings: pond.IInteractionSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as let url = pondURL( "/devices/" + device + @@ -123,7 +127,7 @@ export default function InteractionProvider(props: PropsWithChildren) { [device] + "&types=" + ["device"] + - (as ? "&as=" + as : "") + (view ? "&as=" + view : "") ) return new Promise>((resolve, reject) => { put(url,sanitizeInteraction(settings)).then(resp => { @@ -139,8 +143,9 @@ export default function InteractionProvider(props: PropsWithChildren) { device: number, interaction: string, settings: pond.IInteractionPondSettings, - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as let url = pondURL( "/devices/" + device + @@ -150,7 +155,7 @@ export default function InteractionProvider(props: PropsWithChildren) { [device] + "&types=" + ["device"] + - (as ? "&as=" + as : "") + (view ? "&as=" + view : "") ) return new Promise>((resolve, reject) => { put(url, sanitizeInteraction(settings)).then(resp => { @@ -162,8 +167,9 @@ export default function InteractionProvider(props: PropsWithChildren) { }) }; - const removeInteraction = (device: number, interaction: string, as?: string) => { - let url = pondURL("/devices/" + device + "/interactions/" + interaction + (as ? "?as=" + as : "")) + const removeInteraction = (device: number, interaction: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + let url = pondURL("/devices/" + device + "/interactions/" + interaction + (view ? "?as=" + view : "")) return new Promise>((resolve, reject) => { del(url).then(resp => { resp.data = pond.RemoveInteractionResponse.fromObject(resp.data) @@ -178,10 +184,11 @@ export default function InteractionProvider(props: PropsWithChildren) { const listInteractionsByDevice = ( device: number | string, demo: boolean = false, - as?: string + otherTeam?: string ): Promise => { + const view = otherTeam ? otherTeam : as return new Promise((resolve, reject) => { - get(pondURL("/devices/" + device + "/interactions" + (as ? "?as=" + as : ""), demo)) + get(pondURL("/devices/" + device + "/interactions" + (view ? "?as=" + view : ""), demo)) .then((response: any) => { if (!has(response, "data.interactions")) { return resolve([]); @@ -217,8 +224,9 @@ export default function InteractionProvider(props: PropsWithChildren) { device: number, component: quack.ComponentID, demo: boolean = false, - as?: string + otherTeam?: string ): Promise => { + const view = otherTeam ? otherTeam : as return new Promise((resolve, reject) => { get( pondURL( @@ -227,7 +235,7 @@ export default function InteractionProvider(props: PropsWithChildren) { "/components/" + componentIDToString(component) + "/interactions" + - (as ? "?as=" + as : ""), + (view ? "?as=" + view : ""), demo ) ) @@ -264,9 +272,10 @@ export default function InteractionProvider(props: PropsWithChildren) { const setAlertInteractions = ( alerts: pond.AlertData[], - as?: string + otherTeam?: string ): Promise> => { - let url = pondURL("/interactions/setAlerts" + (as ? "?as=" + as : "")) + const view = otherTeam ? otherTeam : as + let url = pondURL("/interactions/setAlerts" + (view ? "?as=" + view : "")) return new Promise>((resolve, reject) => { post(url, { data: alerts }).then(resp => { resp.data = pond.SetAlertInteractionsResponse.fromObject(resp.data) diff --git a/src/providers/pond/mineAPI.tsx b/src/providers/pond/mineAPI.tsx index 50dc6a0..ad55e52 100644 --- a/src/providers/pond/mineAPI.tsx +++ b/src/providers/pond/mineAPI.tsx @@ -7,15 +7,15 @@ import { createContext, PropsWithChildren, useContext } from "react"; import { pondURL } from "./pond"; export interface IMineAPIContext { - addMine: (mine: pond.MineSettings, as?: string) => Promise>; - getMine: (key: string, as?: string) => Promise>; - addDevice: (key: string, deviceID: string, permissions: pond.Permission[], as?: string) => Promise; + addMine: (mine: pond.MineSettings, otherTeam?: string) => Promise>; + getMine: (key: string, otherTeam?: string) => Promise>; + addDevice: (key: string, deviceID: string, permissions: pond.Permission[], otherTeam?: string) => Promise; addComponent: ( key: string, deviceID: string, componentKey: string, permissions: pond.Permission[], - as?: string + otherTeam?: string ) => Promise; listMines: ( limit: number, @@ -24,7 +24,7 @@ export interface IMineAPIContext { orderBy?: string, search?: string, asRoot?: boolean, - as?: string + otherTeam?: string ) => Promise>; listMinesSimple: ( limit: number, @@ -33,9 +33,9 @@ export interface IMineAPIContext { orderBy?: string, search?: string, asRoot?: boolean, - as?: string + otherTeam?: string ) => Promise>; - removeMine: (key: string, as?: string) => Promise>; + removeMine: (key: string, otherTeam?: string) => Promise>; updateMine: ( mine: pond.MineSettings, componentPreferences: Map @@ -49,14 +49,16 @@ interface Props {} export default function MineProvider(props: PropsWithChildren) { const { children } = props; const { get, del, post, put } = useHTTP(); - //const [{ as }] = useGlobalState(); + const [{ as }] = useGlobalState(); - const addMine = (mine: pond.MineSettings, as?: string) => { - return post(pondURL("/mines" + (as ? "?as=" + as : "")), mine); + const addMine = (mine: pond.MineSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + return post(pondURL("/mines" + (view ? "?as=" + view : "")), mine); }; - const getMine = (key: string, as?: string) => { - return get(pondURL("/mines/" + key + (as ? "?as=" + as : ""))); + const getMine = (key: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + return get(pondURL("/mines/" + key + (view ? "?as=" + view : ""))); }; const listMines = ( @@ -68,8 +70,9 @@ export default function MineProvider(props: PropsWithChildren) { asRoot?: boolean, keys?: string, types?: string, - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as const url = pondURL( "/mines" + "?limit=" + @@ -80,7 +83,7 @@ export default function MineProvider(props: PropsWithChildren) { ("&by=" + (orderBy ? orderBy : "deviceId")) + (search ? "&search=" + search : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") + - (as ? "&as=" + as : "") + + (view ? "&as=" + view : "") + (keys ? "&keys=" + keys : "") + (types ? "&types=" + types : "") ); @@ -94,8 +97,9 @@ export default function MineProvider(props: PropsWithChildren) { orderBy?: string, search?: string, asRoot?: boolean, - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as const url = pondURL( "/minesSimple" + "?limit=" + @@ -106,13 +110,14 @@ export default function MineProvider(props: PropsWithChildren) { ("&by=" + (orderBy ? orderBy : "deviceId")) + (search ? "&search=" + search : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") + - (as ? "&as=" + as : "") + (view ? "&as=" + view : "") ); return get(url); }; - const removeMine = (key: string, as?: string) => { - return del(pondURL("/mines/" + key + (as ? "?as=" + as : ""))); + const removeMine = (key: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + return del(pondURL("/mines/" + key + (view ? "?as=" + view : ""))); }; const updateMine = ( @@ -132,9 +137,10 @@ export default function MineProvider(props: PropsWithChildren) { return put(pondURL("/mines"), request); }; - const addDevice = (key: string, deviceID: string, permissions: pond.Permission[], as?: string) => { - if (as) - return post(pondURL(`/mines/` + key + `/addDevice/` + deviceID + `?as=${as}`), { + const addDevice = (key: string, deviceID: string, permissions: pond.Permission[], otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) + return post(pondURL(`/mines/` + key + `/addDevice/` + deviceID + `?as=${view}`), { permissions: permissions.map(permission => permissionToString(permission)) }); return post(pondURL(`/mines/` + key + `/addDevice/` + deviceID), { @@ -147,11 +153,12 @@ export default function MineProvider(props: PropsWithChildren) { deviceID: string, componentKey: string, permissions: pond.Permission[], - as?: string + otherTeam?: string ) => { - if (as) + const view = otherTeam ? otherTeam : as + if (view) return post( - pondURL(`/mines/` + key + `/addComponent/` + deviceID + "/" + componentKey + `?as=${as}`), + pondURL(`/mines/` + key + `/addComponent/` + deviceID + "/" + componentKey + `?as=${view}`), { permissions: permissions.map(permission => permissionToString(permission)) } @@ -169,8 +176,8 @@ export default function MineProvider(props: PropsWithChildren) { addDevice, addComponent, listMines, - listMinesSimple,// - removeMine,// + listMinesSimple, + removeMine, updateMine }}> {children} diff --git a/src/providers/pond/noteAPI.tsx b/src/providers/pond/noteAPI.tsx index 8280ac4..259cd61 100644 --- a/src/providers/pond/noteAPI.tsx +++ b/src/providers/pond/noteAPI.tsx @@ -1,6 +1,7 @@ import { AxiosResponse } from "axios"; import { useHTTP } from "hooks"; import { pond } from "protobuf-ts/pond"; +import { useGlobalState } from "providers"; import { createContext, PropsWithChildren, useContext } from "react"; import { pondURL } from "./pond"; @@ -15,7 +16,7 @@ export interface INoteAPIContext { orderBy?: string, search?: string, asRoot?: boolean, - as?: string + otherTeam?: string ) => Promise>; listChats: ( limit: number, @@ -24,7 +25,7 @@ export interface INoteAPIContext { orderBy?: string, search?: string, asRoot?: boolean, - as?: string + otherTeam?: string ) => Promise>; removeNote: (noteID: string) => Promise>; } @@ -36,6 +37,7 @@ interface Props {} export default function NoteProvider(props: PropsWithChildren) { const { children } = props; const { get, del, post, put } = useHTTP(); + const [{as}] = useGlobalState() const addNote = (note: pond.NoteSettings, attachments?: string[]) => { let url = pondURL("/notes" + (attachments ? "?attachments=" + attachments.toString() : "")) @@ -86,8 +88,9 @@ export default function NoteProvider(props: PropsWithChildren) { orderBy?: string, search?: string, asRoot?: boolean, - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as let url = pondURL( "/notes" + "?limit=" + @@ -98,7 +101,7 @@ export default function NoteProvider(props: PropsWithChildren) { ("&by=" + (orderBy ? orderBy : "key")) + (search ? "&search=" + search : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") + - (as ? "&as=" + as : "") + (view ? "&as=" + view : "") ) return new Promise>((resolve, reject) => { get(url).then(resp => { @@ -117,8 +120,9 @@ export default function NoteProvider(props: PropsWithChildren) { orderBy?: string, search?: string, asRoot?: boolean, - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as let url = pondURL( "/chats" + "?limit=" + @@ -129,7 +133,7 @@ export default function NoteProvider(props: PropsWithChildren) { ("&by=" + (orderBy ? orderBy : "key")) + (search ? "&search=" + search : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") + - (as ? "&as=" + as : "") + (view ? "&as=" + view : "") ) return new Promise>((resolve, reject) => { get(url).then(resp => { diff --git a/src/providers/pond/notificationAPI.tsx b/src/providers/pond/notificationAPI.tsx index 2b23adb..7af3bfe 100644 --- a/src/providers/pond/notificationAPI.tsx +++ b/src/providers/pond/notificationAPI.tsx @@ -4,6 +4,7 @@ import { pond } from "protobuf-ts/pond"; import { or } from "utils/types"; import { pondURL } from "./pond"; import { AxiosResponse } from "axios"; +import { useGlobalState } from "providers"; export interface INotificationAPIContext { listNotifications: ( @@ -12,7 +13,7 @@ export interface INotificationAPIContext { order?: "asc" | "desc", orderBy?: string, search?: string, - as?: string, + otherTeam?: string, asRoot?: boolean ) => Promise>; hideNotification: (keys: string[]) => Promise>; @@ -24,7 +25,7 @@ export interface INotificationAPIContext { order?: "asc" | "desc", orderBy?: string, search?: string, - as?: string + otherTeam?: string ) => Promise>; } @@ -37,6 +38,7 @@ interface Props {} export default function NotificationProvider(props: PropsWithChildren) { const { children } = props; const { get, put } = useHTTP(); + const [{as}] = useGlobalState(); const listNotifications = ( limit: number, @@ -44,9 +46,10 @@ export default function NotificationProvider(props: PropsWithChildren) { order?: "asc" | "desc", orderBy?: string, search?: string, - as?: string, + otherTeam?: string, asRoot?: boolean ) => { + const view = otherTeam ? otherTeam : as let url = pondURL( "/notifications" + "?limit=" + @@ -55,7 +58,7 @@ export default function NotificationProvider(props: PropsWithChildren) { offset + ("&order=" + or(order, "asc")) + ("&by=" + or(orderBy, "key")) + - (as ? "&as=" + as : "") + + (view ? "&as=" + view : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") + (search ? "&search=" + search : "") ) @@ -77,8 +80,9 @@ export default function NotificationProvider(props: PropsWithChildren) { order?: "asc" | "desc", orderBy?: string, search?: string, - as?: string + otherTeam?: string ) => { + const view = otherTeam ? otherTeam : as let url = pondURL( "/object/notifications" + "?objectKey=" + @@ -92,7 +96,7 @@ export default function NotificationProvider(props: PropsWithChildren) { ("&order=" + or(order, "asc")) + ("&by=" + or(orderBy, "key")) + (search ? "&search=" + search : "") + - (as ? "&as=" + as : "") + (view ? "&as=" + view : "") ) return new Promise>((resolve, reject) => { get(url).then(resp => { diff --git a/src/providers/pond/siteAPI.tsx b/src/providers/pond/siteAPI.tsx index 5f6ac21..95f0a45 100644 --- a/src/providers/pond/siteAPI.tsx +++ b/src/providers/pond/siteAPI.tsx @@ -2,21 +2,21 @@ import { AxiosResponse } from "axios"; import { useHTTP } from "hooks"; import { pond } from "protobuf-ts/pond"; import { useGlobalState } from "providers/StateContainer"; -import React, { createContext, PropsWithChildren, useContext } from "react"; +import { createContext, PropsWithChildren, useContext } from "react"; import { or } from "utils"; import { pondURL } from "./pond"; export interface ISiteAPIContext { - addSite: (site: pond.SiteSettings, as?: string) => Promise; - getSite: (siteID: string, as?: string) => Promise; - getSitePage: (siteID: string, as?: string) => Promise; + addSite: (site: pond.SiteSettings, otherTeam?: string) => Promise; + getSite: (siteID: string, otherTeam?: string) => Promise; + getSitePage: (siteID: string, otherTeam?: string) => Promise; listSites: ( limit: number, offset: number, order?: "asc" | "desc", orderBy?: string, search?: string, - as?: string, + otherTeam?: string, asRoot?: boolean ) => Promise>; listSitesPageData: ( @@ -25,7 +25,7 @@ export interface ISiteAPIContext { order?: "asc" | "desc", orderBy?: string, search?: string, - as?: string, + otherTeam?: string, asRoot?: boolean ) => Promise>; removeSite: (siteID: string) => Promise>; @@ -33,7 +33,7 @@ export interface ISiteAPIContext { key: string, site: pond.SiteSettings, asRoot?: true, - as?: string + otherTeam?: string ) => Promise>; updateLink: ( parentKey: string, @@ -41,7 +41,7 @@ export interface ISiteAPIContext { objectID: string, objectType: string, permissions: string[], - as?: string + otherTeam?: string ) => Promise; } @@ -52,20 +52,23 @@ interface Props {} export default function SiteProvider(props: PropsWithChildren) { const { children } = props; const { get, del, post, put } = useHTTP(); - //const [{ as }] = useGlobalState(); + const [{ as }] = useGlobalState(); - const getSitePage = (siteID: string, as?: string) => { - if (as) return get(pondURL("/sitePage/" + siteID + "?as=" + as)); + const getSitePage = (siteID: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return get(pondURL("/sitePage/" + siteID + "?as=" + view)); return get(pondURL("/sitePage/" + siteID)); }; - const addSite = (site: pond.SiteSettings, as?: string) => { - if (as) return post(pondURL("/sites?as=" + as), site); + const addSite = (site: pond.SiteSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return post(pondURL("/sites?as=" + view), site); return post(pondURL("/sites"), site); }; - const getSite = (siteID: string, as?: string) => { - if (as) return get(pondURL("/site/" + siteID + "?as=" + as)); + const getSite = (siteID: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return get(pondURL("/site/" + siteID + "?as=" + view)); return get(pondURL("/site/" + siteID)); }; @@ -79,9 +82,10 @@ export default function SiteProvider(props: PropsWithChildren) { order?: "asc" | "desc", orderBy?: string, search?: string, - as?: string, + otherTeam?: string, asRoot?: boolean ) => { + const view = otherTeam ? otherTeam : as return get( pondURL( "/sites" + @@ -91,7 +95,7 @@ export default function SiteProvider(props: PropsWithChildren) { offset + ("&order=" + or(order, "asc")) + ("&by=" + or(orderBy, "key")) + - (as ? "&as=" + as : "") + + (view ? "&as=" + view : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") + (search ? "&search=" + search : "") ) @@ -104,9 +108,10 @@ export default function SiteProvider(props: PropsWithChildren) { order?: "asc" | "desc", orderBy?: string, search?: string, - as?: string, + otherTeam?: string, asRoot?: boolean ) => { + const view = otherTeam ? otherTeam : as return get( pondURL( "/sitesWithData" + @@ -116,18 +121,19 @@ export default function SiteProvider(props: PropsWithChildren) { offset + ("&order=" + or(order, "asc")) + ("&by=" + or(orderBy, "key")) + - (as ? "&as=" + as : "") + + (view ? "&as=" + view : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") + (search ? "&search=" + search : "") ) ); }; - const updateSite = (key: string, site: pond.SiteSettings, asRoot?: boolean, as?: string) => { - if (as) + const updateSite = (key: string, site: pond.SiteSettings, asRoot?: boolean, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return put( pondURL( - "/sites/" + key + (as ? "?as=" + as : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") + "/sites/" + key + "?as=" + view + (asRoot ? "&asRoot=" + asRoot.toString() : "") ), site ); @@ -143,10 +149,11 @@ export default function SiteProvider(props: PropsWithChildren) { objectID: string, objectType: string, permissions: string[], - as?: string + otherTeam?: string ) => { - if (as) - return post(pondURL(`/sites/` + parentID + `/link?as=${as}`), { + const view = otherTeam ? otherTeam : as + if (view) + return post(pondURL(`/sites/` + parentID + `/link?as=${view}`), { Key: objectID, Type: objectType, Parent: parentID, diff --git a/src/providers/pond/taskAPI.tsx b/src/providers/pond/taskAPI.tsx index 2f9762e..126f012 100644 --- a/src/providers/pond/taskAPI.tsx +++ b/src/providers/pond/taskAPI.tsx @@ -6,8 +6,8 @@ import { createContext, PropsWithChildren, useContext } from "react"; import { pondURL } from "./pond"; export interface ITaskAPIContext { - addTask: (task: pond.TaskSettings, as?: string) => Promise>; - getTask: (taskID: string, as?: string) => Promise>; + addTask: (task: pond.TaskSettings, otherTeam?: string) => Promise>; + getTask: (taskID: string, otherTeam?: string) => Promise>; listTasks: ( limit: number, offset: number, @@ -15,18 +15,18 @@ export interface ITaskAPIContext { orderBy?: string, search?: string, asRoot?: boolean, - as?: string, + otherTeam?: string, from?: string, to?: string ) => Promise>; - removeTask: (taskID: string, as?: string) => Promise>; + removeTask: (taskID: string, otherTeam?: string) => Promise>; updateTask: ( key: string, task: pond.TaskSettings, asRoot?: true, - as?: string + otherTeam?: string ) => Promise>; - getMultiTasks: (objectKeys: string[], as?: string) => Promise>; + getMultiTasks: (objectKeys: string[], otherTeam?: string) => Promise>; } export const TaskAPIContext = createContext({} as ITaskAPIContext); @@ -36,20 +36,23 @@ interface Props {} export default function TaskProvider(props: PropsWithChildren) { const { children } = props; const { get, del, post, put } = useHTTP(); - //const [{ as }] = useGlobalState(); + const [{ as }] = useGlobalState(); - const addTask = (task: pond.TaskSettings, as?: string) => { - if (as) return post(pondURL("/tasks?as=" + as), task); + const addTask = (task: pond.TaskSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return post(pondURL("/tasks?as=" + view), task); return post(pondURL("/tasks"), task); }; - const getTask = (taskID: string, as?: string) => { - if (as) return get(pondURL("/task/" + taskID + "?as=" + as)); + const getTask = (taskID: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return get(pondURL("/task/" + taskID + "?as=" + view)); return get(pondURL("/task/" + taskID)); }; - const removeTask = (key: string, as?: string) => { - if (as) return del(pondURL("/tasks/" + key + "?as=" + as)); + const removeTask = (key: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return del(pondURL("/tasks/" + key + "?as=" + view)); return del(pondURL("/tasks/" + key)); }; @@ -60,10 +63,11 @@ export default function TaskProvider(props: PropsWithChildren) { orderBy?: string, search?: string, asRoot?: boolean, - as?: string, + otherTeam?: string, from?: string, to?: string ) => { + const view = otherTeam ? otherTeam : as return get( pondURL( "/tasks" + @@ -75,17 +79,18 @@ export default function TaskProvider(props: PropsWithChildren) { ("&by=" + (orderBy ? orderBy : "key")) + (search ? "&search=" + search : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") + - (as ? "&as=" + as : "") + + (view ? "&as=" + view : "") + (from ? "&from=" + from : "") + (to ? "&to=" + to : "") ) ); }; - const updateTask = (key: string, task: pond.TaskSettings, asRoot?: boolean, as?: string) => { - if (as) + const updateTask = (key: string, task: pond.TaskSettings, asRoot?: boolean, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return put( - pondURL("/tasks/" + key + "?as=" + as + (asRoot ? "&asRoot=" + asRoot.toString() : "")), + pondURL("/tasks/" + key + "?as=" + view + (asRoot ? "&asRoot=" + asRoot.toString() : "")), task ); return put( @@ -94,10 +99,11 @@ export default function TaskProvider(props: PropsWithChildren) { ); }; - const getMultiTasks = (objectKeys: string[], as?: string) => { - if (as) + const getMultiTasks = (objectKeys: string[], otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return get( - pondURL("/multitasks?objectKeys=" + objectKeys.join(",") + "&as=" + as) + pondURL("/multitasks?objectKeys=" + objectKeys.join(",") + "&as=" + view) ); return get( pondURL("/multitasks?objectKeys=" + objectKeys.join(",")) diff --git a/src/providers/pond/teamAPI.tsx b/src/providers/pond/teamAPI.tsx index 5c5695b..c9fa30c 100644 --- a/src/providers/pond/teamAPI.tsx +++ b/src/providers/pond/teamAPI.tsx @@ -5,6 +5,7 @@ import { pond } from "protobuf-ts/pond"; import { createContext, PropsWithChildren, useContext } from "react"; import { or } from "utils/types"; import { pondURL } from "./pond"; +import { useGlobalState } from "providers"; export interface ITeamAPIContext { addTeam: (team: pond.TeamSettings) => Promise>; @@ -27,11 +28,11 @@ export interface ITeamAPIContext { orderBy?: string, search?: string, asRoot?: boolean, - as?: string, + otherTeam?: string, prefixSearch?: string, ) => Promise>; listAllTeams: () => Promise>; - listObjectTeams: (scope: Scope, as?: string) => Promise; + listObjectTeams: (scope: Scope, otherTeam?: string) => Promise; removeTeam: (key: string) => Promise>; } @@ -42,7 +43,7 @@ interface Props {} export default function TeamProvider(props: PropsWithChildren) { const { children } = props; const { get, del, post, put } = useHTTP(); - //const [{ team }] = useGlobalState(); + const [{ as }] = useGlobalState(); const addTeam = (team: pond.TeamSettings) => { return new Promise>((resolve, reject) => { @@ -114,10 +115,11 @@ export default function TeamProvider(props: PropsWithChildren) { orderBy?: string, search?: string, asRoot?: boolean, - as?: string, + otherTeam?: string, prefixSearch?: string, ) => { //let asText = team ? "&as=" + team.key() : ""; + const view = otherTeam ? otherTeam : as let url = pondURL( "/teams" + "?limit=" + @@ -129,7 +131,7 @@ export default function TeamProvider(props: PropsWithChildren) { (search ? "&search=" + search : "") + (prefixSearch ? "&prefixSearch=" + prefixSearch : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") + - (as ? "&as=" + as : "") + (view ? "&as=" + view : "") ) return new Promise>((resolve, reject)=>{ get(url).then(resp => { @@ -152,9 +154,10 @@ export default function TeamProvider(props: PropsWithChildren) { }) }; - const listObjectTeams = (scope: Scope, as?: string) => { + const listObjectTeams = (scope: Scope, otherTeam?: string) => { let url = "/" + scope.kind + "s/" + scope.key + "/teams" - if (as) url = `/${scope.kind}s/${scope.key}/teams?as=${as}` + const view = otherTeam ? otherTeam : as + if (view) url = `/${scope.kind}s/${scope.key}/teams?as=${view}` return new Promise((resolve, reject) => { get(pondURL(url)).then(resp => { return resolve(resp) diff --git a/src/providers/pond/terminalAPI.tsx b/src/providers/pond/terminalAPI.tsx index ec8d586..26297c3 100644 --- a/src/providers/pond/terminalAPI.tsx +++ b/src/providers/pond/terminalAPI.tsx @@ -9,7 +9,7 @@ export interface ITerminalAPIContext { addTerminal: ( name: string, terminal: pond.TerminalSettings, - as?: string + otherTeam?: string ) => Promise>; listTerminals: ( limit: number, @@ -17,7 +17,7 @@ export interface ITerminalAPIContext { order?: "asc" | "desc", orderBy?: string, search?: string, - as?: string + otherTeam?: string ) => Promise>; listTerminalsAndGates: ( limit: number, @@ -25,15 +25,15 @@ export interface ITerminalAPIContext { order?: "asc" | "desc", orderBy?: string, search?: string, - as?: string + otherTeam?: string ) => Promise>; updateTerminal: ( key: string, name: string, settings: pond.TerminalSettings, - as?: string + otherTeam?: string ) => Promise>; - removeTerminal: (key: string, as?: string) => Promise>; + removeTerminal: (key: string, otherTeam?: string) => Promise>; } export const TerminalAPIContext = createContext({} as ITerminalAPIContext); @@ -43,12 +43,13 @@ interface Props {} export default function TerminalProvider(props: PropsWithChildren) { const { children } = props; const { get, del, post, put } = useHTTP(); - //const [{ as }] = useGlobalState(); + const [{ as }] = useGlobalState(); - const addTerminal = (name: string, terminal: pond.TerminalSettings, as?: string) => { - if (as) + const addTerminal = (name: string, terminal: pond.TerminalSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return post( - pondURL("/terminals?name=" + name + "&as=" + as), + pondURL("/terminals?name=" + name + "&as=" + view), terminal ); return post(pondURL("/terminals?name=" + name), terminal); @@ -60,13 +61,14 @@ export default function TerminalProvider(props: PropsWithChildren) { order?: "asc" | "desc", orderBy?: string, search?: string, - as?: string + otherTeam?: string ) => { - if (as) + const view = otherTeam ? otherTeam : as + if (view) return get( pondURL( "/terminals?as=" + - as + + view + "&limit=" + limit + "&offset=" + @@ -95,13 +97,14 @@ export default function TerminalProvider(props: PropsWithChildren) { order?: "asc" | "desc", orderBy?: string, search?: string, - as?: string + otherTeam?: string ) => { - if (as) + const view = otherTeam ? otherTeam : as + if (view) return get( pondURL( "/terminalsAndGates?as=" + - as + + view + "&limit=" + limit + "&offset=" + @@ -124,10 +127,11 @@ export default function TerminalProvider(props: PropsWithChildren) { ); }; - const updateTerminal = (key: string, name: string, settings: pond.TerminalSettings, as?: string) => { - if (as) { + const updateTerminal = (key: string, name: string, settings: pond.TerminalSettings, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) { return put( - pondURL("/terminals/" + key + "?as=" + as + "&name=" + name), + pondURL("/terminals/" + key + "?as=" + view + "&name=" + name), settings ); } @@ -137,9 +141,10 @@ export default function TerminalProvider(props: PropsWithChildren) { ); }; - const removeTerminal = (key: string, as?: string) => { - if (as) { - return del(pondURL("/terminals/" + key + "?as=" + as)); + const removeTerminal = (key: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) { + return del(pondURL("/terminals/" + key + "?as=" + view)); } return del(pondURL("/terminals/" + key)); }; diff --git a/src/providers/pond/transactionAPI.tsx b/src/providers/pond/transactionAPI.tsx index 70d8b95..7b9c671 100644 --- a/src/providers/pond/transactionAPI.tsx +++ b/src/providers/pond/transactionAPI.tsx @@ -1,5 +1,5 @@ import { useHTTP } from "hooks"; -import React, { createContext, PropsWithChildren, useContext } from "react"; +import { createContext, PropsWithChildren, useContext } from "react"; import { pond } from "protobuf-ts/pond"; import { pondURL } from "./pond"; import { AxiosResponse } from "axios"; @@ -9,12 +9,12 @@ export interface ITransactionAPIContext { addTransaction: ( transaction: pond.Transaction, fileIDs?: string[], - as?: string + otherTeam?: string ) => Promise>; transactionPageData: ( start: string, end: string, - as?: string + otherTeam?: string ) => Promise>; listTransactions: ( start: string, @@ -23,13 +23,13 @@ export interface ITransactionAPIContext { toObject?: pond.ObjectType, fromKey?: string, toKey?: string, - as?: string + otherTeam?: string ) => Promise>; - revokeTransaction: (key: string, as?: string) => Promise>; + revokeTransaction: (key: string, otherTeam?: string) => Promise>; updateTransaction: ( key: string, data: pond.TransactionData, - as?: string + otherTeam?: string ) => Promise>; } @@ -42,13 +42,14 @@ interface Props {} export default function TransactionProvider(props: PropsWithChildren) { const { children } = props; const { get, post, put } = useHTTP(); - //const [{ as }] = useGlobalState(); + const [{ as }] = useGlobalState(); - const addTransaction = (transaction: pond.Transaction, fileIDs?: string[], as?: string) => { - if (as) + const addTransaction = (transaction: pond.Transaction, fileIDs?: string[], otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return post( pondURL( - "/transactions?as=" + as + (fileIDs ? "&fileAttachments=" + fileIDs.toString() : "") + "/transactions?as=" + view + (fileIDs ? "&fileAttachments=" + fileIDs.toString() : "") ), transaction ); @@ -65,11 +66,12 @@ export default function TransactionProvider(props: PropsWithChildren) { toObject?: pond.ObjectType, fromKey?: string, toKey?: string, - as?: string + otherTeam?: string ) => { - if (as) { + const view = otherTeam ? otherTeam : as + if (view) { return get( - pondURL("/transactions?as=" + as + "&start=" + start + "&end=" + end) + pondURL("/transactions?as=" + view + "&start=" + start + "&end=" + end) ); } return get( @@ -86,19 +88,21 @@ export default function TransactionProvider(props: PropsWithChildren) { ); }; - const updateTransaction = (key: string, data: pond.TransactionData, as?: string) => { - if (as) + const updateTransaction = (key: string, data: pond.TransactionData, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) return post( - pondURL("/transactions/" + key + "/update?as=" + as), + pondURL("/transactions/" + key + "/update?as=" + view), data ); return post(pondURL("/transactions/" + key + "/update"), data); }; - const transactionPageData = (start: string, end: string, as?: string) => { - if (as) { + const transactionPageData = (start: string, end: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) { return get( - pondURL("/transactionsPage?as=" + as + "&start=" + start + "&end=" + end) + pondURL("/transactionsPage?as=" + view + "&start=" + start + "&end=" + end) ); } return get( @@ -106,10 +110,11 @@ export default function TransactionProvider(props: PropsWithChildren) { ); }; - const revokeTransaction = (key: string, as?: string) => { - if (as) { + const revokeTransaction = (key: string, otherTeam?: string) => { + const view = otherTeam ? otherTeam : as + if (view) { return put( - pondURL("/transactions/" + key + "/revoke?as=" + as) + pondURL("/transactions/" + key + "/revoke?as=" + view) ); } return put(pondURL("/transactions/" + key + "/revoke"));