updated the component and device api's to have as be a parameter for the function

This commit is contained in:
csawatzky 2025-04-22 14:33:19 -06:00
parent c617ebf868
commit b62c7dbe5c
39 changed files with 346 additions and 651 deletions

View file

@ -2,6 +2,7 @@ import { Dialog, DialogActions, DialogContent, DialogTitle, Grid2, TextField } f
import CancelSubmit from "common/CancelSubmit";
import { useComponentAPI, useSnackbar } from "hooks";
import { pond } from "protobuf-ts/pond";
import { useGlobalState } from "providers";
import { useState } from "react";
import { or } from "utils";
@ -13,12 +14,13 @@ interface Props {
export default function AddComponentManualDialog (props: Props) {
const { open, onClose, device } = props;
const [{as}] = useGlobalState();
const componentAPI = useComponentAPI();
const snackbar = useSnackbar();
const [component, setComponent] = useState<pond.ComponentSettings>(pond.ComponentSettings.create())
const onSubmit = () => {
componentAPI.add(device, component).then(() => {
componentAPI.add(device, component, as).then(() => {
snackbar.success("Component added")
})
}

View file

@ -22,7 +22,7 @@ import {
import ResponsiveDialog from "common/ResponsiveDialog";
import { Component, Device } from "models";
import { pond, quack } from "protobuf-ts/pond";
import { useComponentAPI, useSnackbar } from "providers";
import { useComponentAPI, useGlobalState, useSnackbar } from "providers";
import React, { useEffect, useState } from "react";
import { CableInfo } from "./ComponentDiagnostics";
import ComponentForm from "./ComponentForm";
@ -67,6 +67,7 @@ interface CompStep {
export default function AddCompsFromDiag(props: Props) {
const { diagComponent, port, cableInfo, open, closeDialog, device, refreshCallback } = props;
const [steps, setSteps] = useState<CompStep[]>([]);
const [{as}] = useGlobalState();
const classes = useStyles();
const [currentStep, setCurrentStep] = useState(0);
const [components, setComponents] = useState<Component[]>([]);
@ -125,7 +126,7 @@ export default function AddCompsFromDiag(props: Props) {
c.components.push(component.settings);
});
compAPI
.addMultiComponents(device.id(), c)
.addMultiComponents(device.id(), c, as)
.then(resp => {
success("Components added to Device");
})

View file

@ -82,7 +82,7 @@ export default function ComponentActions(props: Props) {
const [anchorEl, setAnchorEl] = useState<Element | null>(null);
const [componentSettingsMode, setComponentSettingsMode] = useState<string>("");
const [isJSON, setIsJSON] = useState(false);
const [{ user }] = useGlobalState();
const [{ user, as }] = useGlobalState();
const openMoreMenu = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
setAnchorEl(event.currentTarget);
@ -182,6 +182,7 @@ export default function ComponentActions(props: Props) {
isJSON={isJSON}
// newMeasurements={newStructure}
user={user}
as={as}
/>
</React.Fragment>
);

View file

@ -120,7 +120,7 @@ export default function ComponentCard(props: Props) {
const navigate = useNavigate()
const location = useLocation()
const [sensors, setSensors] = useState<Sensor[]>([]);
const [{ user, showErrors }] = useGlobalState();
const [{ user, showErrors, as }] = useGlobalState();
const updateControllerState = (checked: boolean) => {
let updatedComponent = cloneDeep(component);
@ -130,7 +130,7 @@ export default function ComponentCard(props: Props) {
let describe = controllerModeLabel(newMode);
componentAPI
.update(device.id(), updatedComponent.settings)
.update(device.id(), updatedComponent.settings, undefined, undefined, as)
.then(() => {
success(component.name() + "'s mode was set to " + describe);
refreshCallback(updatedComponent);

View file

@ -16,7 +16,7 @@ import moment from "moment";
import { getHumanReadableAddress } from "pbHelpers/AddressType";
import { pond } from "protobuf-ts/pond";
import { quack } from "protobuf-ts/quack";
import { useComponentAPI } from "providers";
import { useComponentAPI, useGlobalState } from "providers";
import React, { useEffect, useState } from "react";
// import { getThemeType } from "theme";
import AddCompsFromDiag from "./AddCompsFromDiag";
@ -60,6 +60,7 @@ const useStyles = makeStyles((theme: Theme) => {
export default function ComponentDiagnostics(props: Props) {
const { component, device, refreshCallback } = props;
const [{as}] = useGlobalState();
const [portNumber, setPortNumber] = useState("");
const compAPI = useComponentAPI();
const classes = useStyles();
@ -91,7 +92,12 @@ export default function ComponentDiagnostics(props: Props) {
moment().toISOString(),
2,
0,
"desc"
"desc",
undefined,
undefined,
undefined,
undefined,
as
)
.then(resp => {
setMeasurements(resp.data.measurements);
@ -100,7 +106,7 @@ export default function ComponentDiagnostics(props: Props) {
setLoadingMeasurements(false);
});
}
}, [component, device, compAPI]); //eslint-disable-line react-hooks/exhaustive-deps
}, [component, device, compAPI, as]); //eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => {
let cableIDs: number[] = [];

View file

@ -25,6 +25,7 @@ import { pond, quack } from "protobuf-ts/pond";
import { useEffect, useState } from "react";
import { DragDropContext, Draggable, Droppable, DropResult } from "react-beautiful-dnd";
import { useThemeType } from "../hooks/useThemeType";
import { useGlobalState } from "providers";
const useStyles = makeStyles((_theme: Theme) => {
const themeType = useThemeType()
@ -87,6 +88,7 @@ const filteredComponents = (components: Component[]) => {
export default function ComponentOrder(props: ListProps) {
const { open, close, device, devicePreferences } = props;
const [{as}] = useGlobalState();
const deviceAPI = useDeviceAPI();
const { error, success } = useSnackbar();
const prevDisplayOrder = usePrevious(devicePreferences.childDisplayOrder);
@ -113,7 +115,7 @@ export default function ComponentOrder(props: ListProps) {
let updatedPreferences = cloneDeep(devicePreferences);
updatedPreferences.childDisplayOrder = componentOrder.map(c => c.locationString());
deviceAPI
.updatePreferences(device.id(), updatedPreferences)
.updatePreferences(device.id(), updatedPreferences, undefined, undefined, as)
.then(() => success("Successfully update the component display order"))
.catch(() => {
error("Error occured while updating the component display order");

View file

@ -64,6 +64,7 @@ import {
} from "@mui/icons-material"
import CancelSubmit from "common/CancelSubmit";
import { useGlobalState } from "providers";
const useStyles = makeStyles((theme: Theme) => {
return ({
@ -158,6 +159,7 @@ export default function ComponentSettings(props: Props) {
addressTypeRestriction,
deviceComponentPrefs
} = props;
const [{as}] = useGlobalState();
const prevComponent = usePrevious(props.component);
const prevIsDialogOpen = usePrevious(isDialogOpen);
const steps = [0, 1];
@ -304,7 +306,7 @@ export default function ComponentSettings(props: Props) {
//component.settings.calibrationCoefficient = Number(form.coefficient);
if (cableID > 0) component.settings.addressType = cableID + 8;
componentAPI
.add(device.id(), component.settings)
.add(device.id(), component.settings, as)
.then((response: any) => {
success(component.name() + " was successfully added!");
refresh();
@ -318,13 +320,13 @@ export default function ComponentSettings(props: Props) {
const updateComponent = () => {
const component = formComponent;
componentAPI
.update(device.id(), component.settings, getContextKeys(), getContextTypes())
.update(device.id(), component.settings, getContextKeys(), getContextTypes(), as)
.then((response: any) => {
success(component.name() + " was successfully updated!");
let updatedPrefs = pond.DeviceComponentPreferences.create();
updatedPrefs.excludedNodes = excludedNodes;
deviceAPI
.updateComponentPreferences(device.id(), component.key(), updatedPrefs)
.updateComponentPreferences(device.id(), component.key(), updatedPrefs, undefined, undefined, as)
.then(resp => {
console.log("Preferences updated");
})
@ -343,7 +345,7 @@ export default function ComponentSettings(props: Props) {
const removeComponent = () => {
componentAPI
.remove(device.id(), formComponent.key(), getContextKeys(), getContextTypes())
.remove(device.id(), formComponent.key(), getContextKeys(), getContextTypes(), as)
.then((response: any) => {
success(formComponent.name() + " was successfully removed!");
refresh();

View file

@ -43,6 +43,7 @@ interface Props extends WithStyles<typeof styles> {
isJSON?: boolean;
newMeasurements?: boolean;
user?: User;
as?: string
}
interface State {
@ -91,9 +92,9 @@ class ExportDataSettings extends React.Component<Props, State> {
};
submit = () => {
const { device, component, user } = this.props;
const { device, component, user, as } = this.props;
const { startDate, endDate } = this.state;
const { sampleMeasurements, listUnitMeasurements } = this.context;
const { /*sampleMeasurements*/ listUnitMeasurements } = this.context;
this.setState({ isLoading: true });
// if (newMeasurements) {
@ -107,7 +108,9 @@ class ExportDataSettings extends React.Component<Props, State> {
"desc",
undefined,
[device.id().toString()],
["device"]
["device"],
undefined,
as
)
.then(resp => {
let measurements = resp.data.measurements.map(um => UnitMeasurement.any(um, user));