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, Text, Layer } from "grommet"; import { Close, Trash } from "grommet-icons"; const CONNECT_DEVICE = gql` mutation connectDevice($id: String!) { connectDevice(id: $id) { id } } `; 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 }, }); const [groups, setGroups] = useState([]); const [selectedTabs, setSelectedTabs] = useState({}); const [currentTab, setCurrentTab] = useState(0); useEffect(() => { const groups = new Set(); device.properties.forEach((v) => { groups.add(v.vector.group); }); setGroups(Array.from(groups)); setCurrentTab(selectedTabs[device.id] || 0); }, [device]); return ( {!device.connected && (