diff --git a/package-lock.json b/package-lock.json
index 18ff646..79d7bf6 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -7256,7 +7256,7 @@
},
"node_modules/protobuf-ts": {
"version": "1.0.0",
- "resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#86c8ea9c667b2d01c56e0af05f77c1326f8e08fa",
+ "resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#cf0774d8aab2663916bbb0b2c44f4bb3352487b5",
"dependencies": {
"protobufjs": "^6.8.8"
}
diff --git a/src/device/DeviceOverview.tsx b/src/device/DeviceOverview.tsx
index bc29f9f..87c0c60 100644
--- a/src/device/DeviceOverview.tsx
+++ b/src/device/DeviceOverview.tsx
@@ -16,7 +16,7 @@ import { notNull, or } from "utils/types";
// import { MatchParams } from "navigation/Routes";
// import DeviceHologram from "./DeviceHologram";
import { makeStyles } from "@mui/styles";
-import { useNavigate, useParams } from "react-router-dom";
+import { useNavigate } from "react-router-dom";
const useStyles = makeStyles((_theme: Theme) => {
return ({
@@ -39,13 +39,12 @@ interface Props {
usage?: Usage;
loading?: boolean;
disableAddTag?: boolean;
- tags: pond.Tag[];
groupID?: number;
}
export default function DeviceOverview(props: Props) {
const [{ user, firmware }] = useGlobalState();
- const { device, components, groupID, usage, loading, disableAddTag, tags } = props;
+ const { device, components, groupID, usage, loading, disableAddTag } = props;
const prevComponents = usePrevious(components);
const { info } = useSnackbar();
const classes = useStyles();
@@ -156,8 +155,8 @@ export default function DeviceOverview(props: Props) {
variant={modemComponent ? "filled" : "outlined"}
clickable={modemComponent !== null}
onClick={() => {
- console.log(modemComponent)
- console.log(modemComponent?.key())
+ // console.log(modemComponent)
+ // console.log(modemComponent?.key())
if (modemComponent && modemComponent.key()) {
navigate(pathToDevice() + "/components/" + modemComponent.key());
}
@@ -234,7 +233,7 @@ export default function DeviceOverview(props: Props) {
)}
- {user.allowedTo("provision") && }
+ {user.allowedTo("provision") && }
);
};
diff --git a/src/device/DeviceSettings.tsx b/src/device/DeviceSettings.tsx
index a2c5221..91f2577 100644
--- a/src/device/DeviceSettings.tsx
+++ b/src/device/DeviceSettings.tsx
@@ -17,7 +17,6 @@ import {
Theme,
Typography
} from "@mui/material";
-// import { Theme } from "@material-ui/core/styles/createMuiTheme";
import DeleteButton from "common/DeleteButton";
import PeriodSelect from "common/time/PeriodSelect";
import ResponsiveDialog from "common/ResponsiveDialog";
@@ -27,7 +26,6 @@ import { IsExtended, ListDeviceProductDescribers } from "products/DeviceProduct"
import { pond } from "protobuf-ts/pond";
import { useGlobalState } from "providers";
import React, { useEffect, useState } from "react";
-// import { useHistory } from "react-router";
import { quack } from "protobuf-ts/quack";
import LinearMutationBuilder from "common/LinearMutationBuilder";
import { makeStyles } from "@mui/styles";
diff --git a/src/device/DeviceTags.tsx b/src/device/DeviceTags.tsx
index 83b78a0..82981d1 100644
--- a/src/device/DeviceTags.tsx
+++ b/src/device/DeviceTags.tsx
@@ -19,7 +19,7 @@ import TagSettings from "common/TagSettings";
import { Device, Tag } from "models";
import { filterByTag } from "pbHelpers/Tag";
import { useDeviceAPI, useSnackbar, useTagAPI } from "providers";
-import React, { useEffect, useState } from "react";
+import React, { useEffect, useRef, useState } from "react";
import { pond } from "protobuf-ts/pond";
const useStyles = makeStyles((_theme: Theme) => {
@@ -32,7 +32,7 @@ const useStyles = makeStyles((_theme: Theme) => {
interface AddDeviceTagProps {
device: Device;
- deviceTags: string[];
+ deviceTags: pond.TagSettings[];
addTagToDevice: (tag: Tag) => void;
}
@@ -60,7 +60,7 @@ function AddDeviceTag(props: AddDeviceTagProps) {
}, [])
const tagItems = tags
- .filter(tag => !deviceTags.some(key => key === tag.settings.key))
+ .filter(tag => !deviceTags.some(tagSettings => tagSettings.key === tag.settings.key))
.filter(tag => filterByTag(searchValue, tag))
.sort((a, b) => (a.name().toLowerCase() > b.name().toLowerCase() ? 1 : -1))
.map((tag, index, array) => (
@@ -102,7 +102,10 @@ function AddDeviceTag(props: AddDeviceTagProps) {
- setCreateNewOpen(false)} />
+ {
+ setCreateNewOpen(false)
+ loadTags()
+ }} />
);
}
@@ -127,7 +130,6 @@ function DeviceTag(props: DeviceTagProps) {
interface DeviceTagsProps {
device: Device;
disableAdd?: boolean;
- tags: pond.Tag[];
}
export default function DeviceTags(props: DeviceTagsProps) {
@@ -138,8 +140,8 @@ export default function DeviceTags(props: DeviceTagsProps) {
// const [loading, setLoading] = useState(false)
const deviceAPI = useDeviceAPI();
const { error } = useSnackbar();
- const [deviceTags, setDeviceTags] = useState(device.status.tagKeys);
- // const previousDeviceRef = useRef(device);
+ const [deviceTags, setDeviceTags] = useState(device.status.tags);
+ const previousDeviceRef = useRef(device);
const loadTags = () => {
// setLoading(true)
@@ -155,36 +157,35 @@ export default function DeviceTags(props: DeviceTagsProps) {
}
useEffect(() => {
- let newTags: string[] = []
- props.tags.forEach(tag => {
- if (tag.settings) newTags.push(tag.settings?.key)
- })
- setDeviceTags(newTags)
- }, [props.tags])
+ if (previousDeviceRef.current !== device) {
+ setDeviceTags(device.status.tags);
+ previousDeviceRef.current = device;
+ }
+ }, [device]);
useEffect(() => {
loadTags()
}, [])
const addTag = (tag: Tag) => {
- if (!deviceTags.some(dt => dt === tag.key())) {
+ if (!deviceTags.some(dt => dt.key === tag.settings.key)) {
deviceAPI
- .tag(device.id(), tag.key())
+ .tag(device.id(), tag.settings.key)
.then(() => {
- setDeviceTags([...deviceTags, tag.key()]);
+ setDeviceTags([...deviceTags, tag.settings]);
})
- .catch(() => error("Failed to tag device as " + tag.name()));
+ .catch(() => error("Failed to tag device as " + tag.name));
}
};
const removeTagFromDevice = (tag: Tag) => {
- if (deviceTags.some(dt => dt === tag.key())) {
+ if (deviceTags.some(dt => dt.key === tag.settings.key)) {
deviceAPI
.untag(device.id(), tag.key())
.then(() => {
- setDeviceTags(deviceTags.filter(t => tag.key() !== t));
+ setDeviceTags(deviceTags.filter(t => tag.key() !== t.key));
})
- .catch(() => error("Failed to remove tag " + tag.name() + " from device"));
+ .catch(() => error("Failed to remove tag " + tag.name + " from device"));
}
};
@@ -194,14 +195,11 @@ export default function DeviceTags(props: DeviceTagsProps) {
return (
- {deviceTags.map(key => {
- let tag = tags.find(t => t.settings.key === key);
- if (!tag) {
- return null;
- }
+ {deviceTags?.map(tagSettings => {
+ let pondTag = pond.Tag.create({ settings: tagSettings })
return (
-
-
+
+
);
})}
diff --git a/src/pages/Device.tsx b/src/pages/Device.tsx
index 9e13e4c..d04f440 100644
--- a/src/pages/Device.tsx
+++ b/src/pages/Device.tsx
@@ -1,4 +1,4 @@
-import { Button, Checkbox, Divider, FormControlLabel, List, ListItem, Typography } from "@mui/material";
+import { Button, Divider, List, ListItem, Typography } from "@mui/material";
import Grid from '@mui/material/Grid2';
import { Component, Device, Interaction, User } from "models";
import { getContextKeys, getContextTypes } from "pbHelpers/Context";
@@ -33,7 +33,7 @@ export default function DevicePage() {
const [loading, setLoading] = useState(false)
const [permissions, setPermissions] = useState([])
const [preferences, setPreferences] = useState(pond.DevicePreferences.create())
- const [tags, setTags] = useState([]);
+ // const [tags, setTags] = useState([]);
const [interactions, setInteractions] = useState([]);
const [prefsMap, setPrefsMap] = useState