|
|
|
|
@ -1,9 +1,10 @@
@@ -1,9 +1,10 @@
|
|
|
|
|
import React, { useState, useEffect } from "react"; |
|
|
|
|
import { useMutation } from "@apollo/react-hooks"; |
|
|
|
|
import { driversToInterfaces } from "../../utils/indi"; |
|
|
|
|
import React, { useState, useEffect, Fragment } from "react"; |
|
|
|
|
import { useMutation, useApolloClient } from "@apollo/react-hooks"; |
|
|
|
|
import { msgToColor } from "../../utils/indi"; |
|
|
|
|
import Property from "./property"; |
|
|
|
|
import gql from "graphql-tag"; |
|
|
|
|
import { Box, Button, Tabs, Tab } from "grommet"; |
|
|
|
|
import { Box, Button, Tabs, Tab, Text, Layer } from "grommet"; |
|
|
|
|
import { Close, Trash } from "grommet-icons"; |
|
|
|
|
|
|
|
|
|
const CONNECT_DEVICE = gql` |
|
|
|
|
mutation connectDevice($id: String!) { |
|
|
|
|
@ -13,7 +14,14 @@ const CONNECT_DEVICE = gql`
@@ -13,7 +14,14 @@ const CONNECT_DEVICE = gql`
|
|
|
|
|
} |
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const Device = ({ device }) => { |
|
|
|
|
const MSGS_FRAGMENT = gql` |
|
|
|
|
fragment DeviceMsgs on Device { |
|
|
|
|
messages |
|
|
|
|
} |
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const Device = ({ device, messages, onMessagesClosed }) => { |
|
|
|
|
const client = useApolloClient(); |
|
|
|
|
const [connect] = useMutation(CONNECT_DEVICE, { |
|
|
|
|
variables: { id: device.id }, |
|
|
|
|
}); |
|
|
|
|
@ -40,12 +48,16 @@ const Device = ({ device }) => {
@@ -40,12 +48,16 @@ const Device = ({ device }) => {
|
|
|
|
|
}} |
|
|
|
|
/> |
|
|
|
|
)} |
|
|
|
|
<Tabs justify="start" activeIndex={currentTab} onActive={(nextTab) => { |
|
|
|
|
<Tabs |
|
|
|
|
justify="start" |
|
|
|
|
activeIndex={currentTab} |
|
|
|
|
onActive={(nextTab) => { |
|
|
|
|
setCurrentTab(nextTab); |
|
|
|
|
const newValue = { ...selectedTabs }; |
|
|
|
|
newValue[device.id] = nextTab; |
|
|
|
|
setSelectedTabs(newValue) |
|
|
|
|
}}> |
|
|
|
|
setSelectedTabs(newValue); |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
{groups.map((g) => ( |
|
|
|
|
<Tab title={g} key={g}> |
|
|
|
|
<Box pad="small"> |
|
|
|
|
@ -57,6 +69,32 @@ const Device = ({ device }) => {
@@ -57,6 +69,32 @@ const Device = ({ device }) => {
|
|
|
|
|
</Tab> |
|
|
|
|
))} |
|
|
|
|
</Tabs> |
|
|
|
|
|
|
|
|
|
{messages ? ( |
|
|
|
|
<Layer position="right" full="vertical" modal={false}> |
|
|
|
|
<Box direction="row"> |
|
|
|
|
<Button icon={<Close />} onClick={() => onMessagesClosed()} /> |
|
|
|
|
<Button |
|
|
|
|
icon={<Trash />} |
|
|
|
|
onClick={() => { |
|
|
|
|
client.writeFragment({ |
|
|
|
|
id: client.cache.config.dataIdFromObject(device), |
|
|
|
|
fragment: MSGS_FRAGMENT, |
|
|
|
|
data: { |
|
|
|
|
__typename: "Device", |
|
|
|
|
messages: [], |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
}} |
|
|
|
|
/> |
|
|
|
|
</Box> |
|
|
|
|
<Box width="medium" pad="small"> |
|
|
|
|
{device.messages.map((msg) => ( |
|
|
|
|
<Text color={msgToColor(msg)}>{msg}</Text> |
|
|
|
|
))} |
|
|
|
|
</Box> |
|
|
|
|
</Layer> |
|
|
|
|
) : null} |
|
|
|
|
</Box> |
|
|
|
|
); |
|
|
|
|
}; |
|
|
|
|
|