updated all uses of as in the api files to use the global state as well as a passed in value, will give priority to the passed in value and fall back to the state if it is undefined.

This commit is contained in:
csawatzky 2025-04-28 10:47:59 -06:00
parent b404c45a4f
commit 59f7f7f4e1
25 changed files with 673 additions and 535 deletions

View file

@ -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<AxiosResponse<pond.AddInteractionResponse>>;
addMultiInteractions: (device: number, settings: pond.MultiInteractionSettings, as?: string) => Promise<AxiosResponse<pond.AddMultiInteractionsResponse>>;
addInteraction: (device: number, settings: pond.IInteractionSettings, otherTeam?: string) => Promise<AxiosResponse<pond.AddInteractionResponse>>;
addMultiInteractions: (device: number, settings: pond.MultiInteractionSettings, otherTeam?: string) => Promise<AxiosResponse<pond.AddMultiInteractionsResponse>>;
addInteractionToComponents: (
fullComponentLocations: string[],
settings: pond.IInteractionSettings,
as?: string
otherTeam?: string
) => Promise<AxiosResponse<pond.AddInteractionToComponentsResponse>>;
updateInteraction: (device: number, settings: pond.IInteractionSettings, as?: string) => Promise<AxiosResponse<pond.UpdateInteractionResponse>>;
updateInteraction: (device: number, settings: pond.IInteractionSettings, otherTeam?: string) => Promise<AxiosResponse<pond.UpdateInteractionResponse>>;
updateInteractionPondSettings: (
device: number,
interaction: string,
settings: pond.IInteractionPondSettings,
as?: string
otherTeam?: string
) => Promise<AxiosResponse<pond.UpdateInteractionPondSettingsResponse>>;
removeInteraction: (device: number, interaction: string, as?: string) => Promise<AxiosResponse<pond.RemoveInteractionResponse>>;
listInteractionsByDevice: (device: number | string, demo?: boolean, as?: string) => Promise<Interaction[]>;
removeInteraction: (device: number, interaction: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveInteractionResponse>>;
listInteractionsByDevice: (device: number | string, demo?: boolean, otherTeam?: string) => Promise<Interaction[]>;
listInteractionsByComponent: (
device: number,
component: quack.ComponentID,
demo?: boolean,
as?: string
otherTeam?: string
) => Promise<Interaction[]>;
setAlertInteractions: (
alerts: pond.AlertData[],
as?: string
otherTeam?: string
) => Promise<AxiosResponse<pond.SetAlertInteractionsResponse>>;
}
@ -60,12 +60,13 @@ function sanitizeInteraction(interaction: pond.IInteractionSettings): pond.IInte
export default function InteractionProvider(props: PropsWithChildren<Props>) {
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<AxiosResponse<pond.AddInteractionResponse>>((resolve, reject) => {
post<pond.AddInteractionResponse>(
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<Props>) {
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<AxiosResponse<pond.AddInteractionToComponentsResponse>>((resolve, reject) => {
post<pond.AddInteractionToComponentsResponse>(url,sanitizeInteraction(settings)).then(resp => {
@ -103,8 +105,9 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
})
};
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<AxiosResponse<pond.AddMultiInteractionsResponse>>((resolve, reject) => {
post<pond.AddMultiInteractionsResponse>(url,settings).then(resp => {
resp.data = pond.AddMultiInteractionsResponse.fromObject(resp.data)
@ -115,7 +118,8 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
})
};
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<Props>) {
[device] +
"&types=" +
["device"] +
(as ? "&as=" + as : "")
(view ? "&as=" + view : "")
)
return new Promise<AxiosResponse<pond.UpdateInteractionResponse>>((resolve, reject) => {
put<pond.UpdateInteractionResponse>(url,sanitizeInteraction(settings)).then(resp => {
@ -139,8 +143,9 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
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<Props>) {
[device] +
"&types=" +
["device"] +
(as ? "&as=" + as : "")
(view ? "&as=" + view : "")
)
return new Promise<AxiosResponse<pond.UpdateInteractionPondSettingsResponse>>((resolve, reject) => {
put<pond.UpdateInteractionPondSettingsResponse>(url, sanitizeInteraction(settings)).then(resp => {
@ -162,8 +167,9 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
})
};
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<AxiosResponse<pond.RemoveInteractionResponse>>((resolve, reject) => {
del<pond.RemoveInteractionResponse>(url).then(resp => {
resp.data = pond.RemoveInteractionResponse.fromObject(resp.data)
@ -178,10 +184,11 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
const listInteractionsByDevice = (
device: number | string,
demo: boolean = false,
as?: string
otherTeam?: string
): Promise<Interaction[]> => {
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<Props>) {
device: number,
component: quack.ComponentID,
demo: boolean = false,
as?: string
otherTeam?: string
): Promise<Interaction[]> => {
const view = otherTeam ? otherTeam : as
return new Promise((resolve, reject) => {
get(
pondURL(
@ -227,7 +235,7 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
"/components/" +
componentIDToString(component) +
"/interactions" +
(as ? "?as=" + as : ""),
(view ? "?as=" + view : ""),
demo
)
)
@ -264,9 +272,10 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
const setAlertInteractions = (
alerts: pond.AlertData[],
as?: string
otherTeam?: string
): Promise<AxiosResponse<pond.SetAlertInteractionsResponse>> => {
let url = pondURL("/interactions/setAlerts" + (as ? "?as=" + as : ""))
const view = otherTeam ? otherTeam : as
let url = pondURL("/interactions/setAlerts" + (view ? "?as=" + view : ""))
return new Promise<AxiosResponse<pond.SetAlertInteractionsResponse>>((resolve, reject) => {
post<pond.SetAlertInteractionsResponse>(url, { data: alerts }).then(resp => {
resp.data = pond.SetAlertInteractionsResponse.fromObject(resp.data)