Fixed switch update according to switch rule
This commit is contained in:
@@ -14,14 +14,6 @@ import {
|
|||||||
} from "grommet";
|
} from "grommet";
|
||||||
import { Close, Trash } from "grommet-icons";
|
import { Close, Trash } from "grommet-icons";
|
||||||
|
|
||||||
const CONNECT_DEVICE = gql`
|
|
||||||
mutation connectDevice($id: String!) {
|
|
||||||
connectDevice(id: $id) {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const MSGS_FRAGMENT = gql`
|
const MSGS_FRAGMENT = gql`
|
||||||
fragment DeviceMsgs on Device {
|
fragment DeviceMsgs on Device {
|
||||||
messages
|
messages
|
||||||
@@ -30,9 +22,6 @@ const MSGS_FRAGMENT = gql`
|
|||||||
|
|
||||||
const Device = ({ device, messages, onMessagesClosed }) => {
|
const Device = ({ device, messages, onMessagesClosed }) => {
|
||||||
const client = useApolloClient();
|
const client = useApolloClient();
|
||||||
const [connect] = useMutation(CONNECT_DEVICE, {
|
|
||||||
variables: { id: device.id },
|
|
||||||
});
|
|
||||||
const [groups, setGroups] = useState([]);
|
const [groups, setGroups] = useState([]);
|
||||||
const [selectedTabs, setSelectedTabs] = useState({});
|
const [selectedTabs, setSelectedTabs] = useState({});
|
||||||
const [currentTab, setCurrentTab] = useState(0);
|
const [currentTab, setCurrentTab] = useState(0);
|
||||||
@@ -49,14 +38,6 @@ const Device = ({ device, messages, onMessagesClosed }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
{!device.connected && (
|
|
||||||
<Button
|
|
||||||
label="Connect"
|
|
||||||
onClick={() => {
|
|
||||||
connect();
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<Tabs
|
<Tabs
|
||||||
justify="start"
|
justify="start"
|
||||||
activeIndex={currentTab}
|
activeIndex={currentTab}
|
||||||
|
|||||||
@@ -20,13 +20,20 @@ const SwitchVector = ({ vector }) => {
|
|||||||
key={v.name}
|
key={v.name}
|
||||||
label={v.label}
|
label={v.label}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
if (vector.rule === 0 && v.switch === true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const newValues = vector.values.map((val) => {
|
const newValues = vector.values.map((val) => {
|
||||||
if (v.name === val.name) {
|
if (v.name === val.name) {
|
||||||
return { name: val.name, value: true };
|
if (vector.rule === 0) {
|
||||||
|
|
||||||
|
}
|
||||||
|
return { name: val.name, value: vector.rule === 0 ? true : !val.switch};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
name: val.name,
|
name: val.name,
|
||||||
value: vector.rule === 0 ? false : val.switch,
|
value: vector.rule === 0 || vector.rule === 1 ? false : val.switch,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user