modified th api's for bin, contract and task to have as passed in as a prop and not get it ffrom the global state directly in the api

This commit is contained in:
csawatzky 2025-04-17 13:33:27 -06:00
parent 4bcac4e346
commit e2f5eb0557
31 changed files with 155 additions and 507 deletions

View file

@ -10,32 +10,36 @@ import { useGlobalState } from "providers";
import { quack } from "protobuf-ts/quack";
export interface IBinAPIContext {
addBin: (bin: pond.BinSettings) => Promise<AxiosResponse<pond.AddBinResponse>>;
updateBin: (key: string, bin: pond.BinSettings) => Promise<AxiosResponse<pond.UpdateBinResponse>>;
bulkBinUpdate: (bins: pond.BinSettings[]) => Promise<AxiosResponse<pond.BulkBinUpdateResponse>>;
addBin: (bin: pond.BinSettings, as?: string) => Promise<AxiosResponse<pond.AddBinResponse>>;
updateBin: (key: string, bin: pond.BinSettings, as?: string) => Promise<AxiosResponse<pond.UpdateBinResponse>>;
bulkBinUpdate: (bins: pond.BinSettings[], as?: string) => Promise<AxiosResponse<pond.BulkBinUpdateResponse>>;
updateBinStatus: (
key: string,
binStatus: pond.BinStatus
binStatus: pond.BinStatus,
as?: string
) => Promise<AxiosResponse<pond.UpdateBinResponse>>;
removeBin: (key: string) => Promise<AxiosResponse<pond.RemoveBinResponse>>;
getBin: (key: string) => Promise<AxiosResponse<pond.Bin>>;
removeBin: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveBinResponse>>;
getBin: (key: string, as?: string) => Promise<AxiosResponse<pond.Bin>>;
addComponent: (
bin: string,
device: number,
component: string,
preferences?: pond.BinComponentPreferences
preferences?: pond.BinComponentPreferences,
as?: string
) => Promise<AxiosResponse<pond.AddBinComponentResponse>>;
removeComponent: (
bin: string,
component: string
component: string,
as?: string
) => Promise<AxiosResponse<pond.RemoveBinComponentResponse>>;
removeAllComponents: (bin: string) => Promise<AxiosResponse<pond.RemoveAllBinComponentsResponse>>;
removeAllComponents: (bin: string, as?: string) => Promise<AxiosResponse<pond.RemoveAllBinComponentsResponse>>;
updateComponentPreferences: (
bin: string,
component: string,
preferences: pond.BinComponentPreferences
preferences: pond.BinComponentPreferences,
as?: string
) => Promise<AxiosResponse<pond.UpdateBinComponentPreferencesResponse>>;
getBinPageData: (binKey: string, userKey: string, showErrors?: boolean) => Promise<AxiosResponse<pond.GetBinPageDataResponse>>;
getBinPageData: (binKey: string, userKey: string, showErrors?: boolean, as?: string) => Promise<AxiosResponse<pond.GetBinPageDataResponse>>;
listBins: (
limit: number,
offset: number,
@ -84,13 +88,14 @@ export interface IBinAPIContext {
key: string,
start: string,
end: string,
showErrors?: boolean
showErrors?: boolean,
as?: string
) => Promise<AxiosResponse<pond.ListBinComponentsMeasurementsResponse>>;
updateBinPermissions: (
key: string,
users: User[]
) => Promise<AxiosResponse<pond.UpdateBinResponse>>;
getBinMetrics: (search?: string) => Promise<AxiosResponse<pond.GetBinMetricsResponse>>;
getBinMetrics: (search?: string, as?: string) => Promise<AxiosResponse<pond.GetBinMetricsResponse>>;
listBinLiters: (
key: string,
start: string,
@ -99,12 +104,14 @@ export interface IBinAPIContext {
plenum: string,
cable: string,
pressure: string,
fan?: string // the fan controller is optional so that if they don't have one the fan is assumed on
fan?: string, // the fan controller is optional so that if they don't have one the fan is assumed on
as?: string
) => Promise<AxiosResponse<pond.ListBinLiterResponse>>;
listBinPrefs: (key: string) => Promise<AxiosResponse<pond.ListBinComponentPreferencesResponse>>;
updateTopNodes: (
key: string,
newTopNodes: pond.NewTopNode[]
newTopNodes: pond.NewTopNode[],
as?: string
) => Promise<AxiosResponse<pond.UpdateTopNodesResponse>>;
listBinMeasurements: (
key: string,
@ -116,7 +123,8 @@ export interface IBinAPIContext {
measurementType?: number | quack.MeasurementType,
keys?: string[],
types?: string[],
showErrors?: boolean
showErrors?: boolean,
as?: string
) => Promise<AxiosResponse<pond.ListObjectMeasurementsResponse>>;
}
@ -128,9 +136,9 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
const { children } = props;
const { get, post, put, del } = useHTTP();
const permissionAPI = usePermissionAPI();
const [{ as }] = useGlobalState();
//const [{ as }] = useGlobalState();
const addBin = (bin: pond.BinSettings) => {
const addBin = (bin: pond.BinSettings, as?: string) => {
const url = "/bins" + (as ? "?as=" + as : "")
return new Promise<AxiosResponse<pond.AddBinResponse>>((resolve, reject)=>{
post<pond.AddBinResponse>(pondURL(url), bin).then(resp => {
@ -142,7 +150,7 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
})
};
const updateBin = (key: string, bin: pond.BinSettings) => {
const updateBin = (key: string, bin: pond.BinSettings, as?: string) => {
const url = "/bins/" + key + (as ? "?as=" + as : "")
return new Promise<AxiosResponse<pond.UpdateBinResponse>>((resolve, reject)=>{
put<pond.UpdateBinResponse>(pondURL(url), bin).then(resp => {
@ -154,7 +162,7 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
})
};
const bulkBinUpdate = (bins: pond.BinSettings[]) => {
const bulkBinUpdate = (bins: pond.BinSettings[], as?: string) => {
let url = "/bulkBins/update"
if (as) url = url + "?as=" + as
return new Promise<AxiosResponse<pond.BulkBinUpdateResponse>>((resolve, reject)=>{
@ -167,7 +175,7 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
})
};
const updateBinStatus = (key: string, binStatus: pond.BinStatus) => {
const updateBinStatus = (key: string, binStatus: pond.BinStatus, as?: string) => {
let url = "/bins/" + key + "/status"
if (as) url = url + "?as=" + as
return new Promise<AxiosResponse<pond.UpdateBinStatusResponse>>((resolve, reject)=>{
@ -180,7 +188,7 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
})
};
const removeBin = (key: string) => {
const removeBin = (key: string, as?: string) => {
let url = "/bins/" + key
if (as) url = url + "?as=" + as
return new Promise<AxiosResponse<pond.RemoveBinResponse>>((resolve, reject) => {
@ -193,7 +201,7 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
})
};
const getBin = (key: string) => {
const getBin = (key: string, as?: string) => {
const url = "/bins/" + key + (as ? "?as=" + as : "")
return new Promise<AxiosResponse<pond.Bin>>((resolve, reject)=>{
get<pond.Bin>(pondURL(url))
@ -211,7 +219,8 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
bin: string,
device: number,
component: string,
preferences?: pond.BinComponentPreferences
preferences?: pond.BinComponentPreferences,
as?: string
) => {
let url = "/bins/" + bin + "/addComponent/" + device + "/" + component;
if (as) {
@ -233,7 +242,7 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
})
};
const removeComponent = (bin: string, component: string) => {
const removeComponent = (bin: string, component: string, as?: string) => {
let url = "/bins/" + bin + "/removeComponent/" + component;
if (as) url = url + "?as=" + as;
return new Promise<AxiosResponse<pond.RemoveBinComponentResponse>>((resolve, reject)=>{
@ -246,7 +255,7 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
})
};
const removeAllComponents = (bin: string) => {
const removeAllComponents = (bin: string, as?: string) => {
let url = "/bins/" + bin + "/removeAllComponents";
if (as) url = url + "?as=" + as;
return new Promise<AxiosResponse<pond.RemoveAllBinComponentsResponse>>((resolve, reject)=>{
@ -262,7 +271,8 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
const updateComponentPreferences = (
bin: string,
component: string,
preferences: pond.BinComponentPreferences
preferences: pond.BinComponentPreferences,
as?: string
) => {
let url = "/bins/" + bin + "/updateComponent/" + component + "/preferences";
if (as) url = url + "/?as=" + as;
@ -280,7 +290,7 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
})
};
const getBinPageData = (binKey: string, userKey: string, showErrors = true) => {
const getBinPageData = (binKey: string, userKey: string, showErrors = true, as?: string) => {
const url = "/bins/" +
binKey +
"/users/" +
@ -419,7 +429,8 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
key: string,
start: string,
end: string,
showErrors = false
showErrors = false,
as?: string
) => {
let url = "/bins/" +
key +
@ -475,7 +486,7 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
return permissionAPI.updatePermissions(binScope(key.toString()), users);
};
const getBinMetrics = (search?: string) => {
const getBinMetrics = (search?: string, as?: string) => {
let url = "/metrics/bins" + (search ? "?search=" + search : "")
if (as) {
if (search){
@ -501,7 +512,8 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
plenum: string,
cable: string,
pressure: string,
fan?: string
fan?: string,
as?: string
) => {
const url = "/bins/" +
key +
@ -531,7 +543,7 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
})
};
const listBinPrefs = (key: string) => {
const listBinPrefs = (key: string, as?: string) => {
const url = "/bins/" + key + "/componentPreferences?as=" + as
return new Promise<AxiosResponse<pond.ListBinComponentPreferencesResponse>>((resolve, reject)=>{
get<pond.ListBinComponentPreferencesResponse>(pondURL(url))
@ -544,7 +556,7 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
})
};
const updateTopNodes = (key: string, newTopNodes: pond.NewTopNode[]) => {
const updateTopNodes = (key: string, newTopNodes: pond.NewTopNode[], as?: string) => {
let body: pond.TopNodeList = pond.TopNodeList.create({ newTopNodes: newTopNodes });
let url = "/bins/" + key + "/updateTopNodes" + (as ? "?as=" + as : "")
return new Promise<AxiosResponse<pond.UpdateTopNodesResponse>>((resolve,response) => {
@ -567,7 +579,8 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
measurementType?: number | quack.MeasurementType,
keys?: string[],
types?: string[],
showErrors?: boolean
showErrors?: boolean,
as?: string
) => {
const url = pondURL(
"/objects/" +