From a88daa6142b1662be81607324cdb1210b22f7324 Mon Sep 17 00:00:00 2001 From: Orne Brocaar Date: Thu, 21 Nov 2024 15:22:22 +0000 Subject: [PATCH] ui: Add all vendor entries to the menu. --- interface/ui/src/components/Menu.tsx | 123 +++++++++++++++++- interface/ui/src/stores/DeviceProfileStore.ts | 17 +++ 2 files changed, 135 insertions(+), 5 deletions(-) diff --git a/interface/ui/src/components/Menu.tsx b/interface/ui/src/components/Menu.tsx index e6e1d62..c96a040 100644 --- a/interface/ui/src/components/Menu.tsx +++ b/interface/ui/src/components/Menu.tsx @@ -4,7 +4,7 @@ import { Link, useLocation, useNavigate } from "react-router-dom"; import type { MenuProps } from "antd"; import { Menu, Select, Button } from "antd"; -import { Vendor, ListVendorsResponse } from "@api/grpc-web/api_pb"; +import { Vendor, ListVendorsResponse, ListDevicesRequest, ListDevicesResponse, Device, ListProfilesRequest, ListProfilesResponse, Profile, ListCodecsRequest, ListCodecsResponse, Codec } from "@api/grpc-web/api_pb"; import DeviceProfileStore from "../stores/DeviceProfileStore"; @@ -12,6 +12,9 @@ function SideMenu() { const [vendor, setVendor] = useState(undefined); const [vendors, setVendors] = useState([]); const [selectedKey, setSelectedKey] = useState(""); + const [devices, setDevices] = useState([]); + const [profiles, setProfiles] = useState([]); + const [codecs, setCodecs] = useState([]); const navigate = useNavigate(); const location = useLocation(); @@ -40,6 +43,47 @@ function SideMenu() { }; }, []); + useEffect(() => { + if (vendor == undefined) { + return; + } + + const loadDevices = () => { + const req = new ListDevicesRequest(); + req.setVendorDir(vendor); + DeviceProfileStore.listDevices(req, (resp: ListDevicesResponse) => { + setDevices(resp.getResultList()); + }); + }; + + const loadProfiles = () => { + const req = new ListProfilesRequest(); + req.setVendorDir(vendor); + DeviceProfileStore.listProfiles(req, (resp: ListProfilesResponse) => { + setProfiles(resp.getResultList()); + }); + }; + + const loadCodecs = () => { + const req = new ListCodecsRequest(); + req.setVendorDir(vendor); + DeviceProfileStore.listCodecs(req, (resp: ListCodecsResponse) => { + setCodecs(resp.getResultList()); + }); + }; + + DeviceProfileStore.on("change", loadDevices) + DeviceProfileStore.on("change", loadProfiles); + DeviceProfileStore.on("change", loadCodecs); + loadDevices(); + loadProfiles(); + loadCodecs(); + + return () => { + DeviceProfileStore.removeAllListeners("change"); + }; + }, [vendor]); + useEffect(() => { parseLocation(); }, [location]) @@ -73,23 +117,91 @@ function SideMenu() { setSelectedKey(""); + if (path.includes("vendors") && path.endsWith("edit")) { + setSelectedKey("vendor-edit"); + } if (path.includes("profiles")) { - setSelectedKey("profiles"); + setSelectedKey("devices"); + + if (path.endsWith("create")) { + setSelectedKey("profiles-create"); + } else if (path.endsWith(".toml")) { + setSelectedKey("profiles-" + path.split("/").slice(-1)); + } } if (path.includes("codecs")) { setSelectedKey("codecs"); + + if (path.endsWith("create")) { + setSelectedKey("codecs-create"); + } else if (path.endsWith(".js")) { + setSelectedKey("codecs-" + path.split("/").slice(-1)); + } } if (path.includes("devices")) { setSelectedKey("devices"); + + if (path.endsWith("create")) { + setSelectedKey("devices-create"); + } else if (path.endsWith(".toml")) { + setSelectedKey("devices-" + path.split("/").slice(-1)); + } } }, [location.pathname]); let items: MenuProps["items"] = [ { - key: "devices", label: Devices + key: "vendor", + label: "Vendor", + children: [ + { + key: "vendor-edit", + label: Update vendor, + }, + ], + }, + { + key: "devices", + label: "Devices", + children: [ + { + key: "devices-create", label: Add device, + }, + ].concat(devices.map((v) => { + return { + key: "devices-" + v.getFile(), + label: {v.getFile()}, + }; + })), + }, + { + key: "profiles", + label: "Profiles", + children: [ + { + key: "profiles-create", + label: Add profile, + }, + ].concat(profiles.map((v) => { + return { + key: "profiles-" + v.getFile(), + label: {v.getFile()}, + }; + })), + }, + { + key: "codecs", label: "Codecs", children: [ + { + key: "codecs-create", + label: Add codec, + }, + ].concat(codecs.map((v) => { + return { + key: "codecs-" + v.getFile(), + label: {v.getFile()}, + }; + })) }, - { key: "profiles", label: Profiles }, - { key: "codecs", label: Codecs }, ]; return (
@@ -97,6 +209,7 @@ function SideMenu() { {vendor ? : }
); } diff --git a/interface/ui/src/stores/DeviceProfileStore.ts b/interface/ui/src/stores/DeviceProfileStore.ts index 9d8ba37..81eba43 100644 --- a/interface/ui/src/stores/DeviceProfileStore.ts +++ b/interface/ui/src/stores/DeviceProfileStore.ts @@ -163,6 +163,8 @@ class DeviceProfileStore extends EventEmitter { duration: 3, }); + this.emit("change"); + callbackFunc(); }); } @@ -190,6 +192,8 @@ class DeviceProfileStore extends EventEmitter { duration: 3, }); + this.emit("change"); + callbackFunc(); }); } @@ -206,6 +210,8 @@ class DeviceProfileStore extends EventEmitter { duration: 3, }); + this.emit("change"); + callbackFunc(); }); } @@ -233,6 +239,8 @@ class DeviceProfileStore extends EventEmitter { duration: 3, }); + this.emit("change"); + callbackFunc(); }); } @@ -260,6 +268,8 @@ class DeviceProfileStore extends EventEmitter { duration: 3, }); + this.emit("change"); + callbackFunc(); }); } @@ -287,6 +297,8 @@ class DeviceProfileStore extends EventEmitter { duration: 3, }); + this.emit("change"); + callbackFunc(); }); } @@ -303,6 +315,8 @@ class DeviceProfileStore extends EventEmitter { duration: 3, }); + this.emit("change"); + callbackFunc(); }); } @@ -330,6 +344,7 @@ class DeviceProfileStore extends EventEmitter { duration: 3, }); + this.emit("change"); callbackFunc(); }); @@ -358,6 +373,8 @@ class DeviceProfileStore extends EventEmitter { duration: 3, }); + this.emit("change"); + callbackFunc(); }); }