Skip to content

Commit a88daa6

Browse files
committed
ui: Add all vendor entries to the menu.
1 parent c6492e1 commit a88daa6

File tree

2 files changed

+135
-5
lines changed

2 files changed

+135
-5
lines changed

interface/ui/src/components/Menu.tsx

Lines changed: 118 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ import { Link, useLocation, useNavigate } from "react-router-dom";
44
import type { MenuProps } from "antd";
55
import { Menu, Select, Button } from "antd";
66

7-
import { Vendor, ListVendorsResponse } from "@api/grpc-web/api_pb";
7+
import { Vendor, ListVendorsResponse, ListDevicesRequest, ListDevicesResponse, Device, ListProfilesRequest, ListProfilesResponse, Profile, ListCodecsRequest, ListCodecsResponse, Codec } from "@api/grpc-web/api_pb";
88
import DeviceProfileStore from "../stores/DeviceProfileStore";
99

1010

1111
function SideMenu() {
1212
const [vendor, setVendor] = useState<string | undefined>(undefined);
1313
const [vendors, setVendors] = useState<Vendor[]>([]);
1414
const [selectedKey, setSelectedKey] = useState<string>("");
15+
const [devices, setDevices] = useState<Device[]>([]);
16+
const [profiles, setProfiles] = useState<Profile[]>([]);
17+
const [codecs, setCodecs] = useState<Codec[]>([]);
1518

1619
const navigate = useNavigate();
1720
const location = useLocation();
@@ -40,6 +43,47 @@ function SideMenu() {
4043
};
4144
}, []);
4245

46+
useEffect(() => {
47+
if (vendor == undefined) {
48+
return;
49+
}
50+
51+
const loadDevices = () => {
52+
const req = new ListDevicesRequest();
53+
req.setVendorDir(vendor);
54+
DeviceProfileStore.listDevices(req, (resp: ListDevicesResponse) => {
55+
setDevices(resp.getResultList());
56+
});
57+
};
58+
59+
const loadProfiles = () => {
60+
const req = new ListProfilesRequest();
61+
req.setVendorDir(vendor);
62+
DeviceProfileStore.listProfiles(req, (resp: ListProfilesResponse) => {
63+
setProfiles(resp.getResultList());
64+
});
65+
};
66+
67+
const loadCodecs = () => {
68+
const req = new ListCodecsRequest();
69+
req.setVendorDir(vendor);
70+
DeviceProfileStore.listCodecs(req, (resp: ListCodecsResponse) => {
71+
setCodecs(resp.getResultList());
72+
});
73+
};
74+
75+
DeviceProfileStore.on("change", loadDevices)
76+
DeviceProfileStore.on("change", loadProfiles);
77+
DeviceProfileStore.on("change", loadCodecs);
78+
loadDevices();
79+
loadProfiles();
80+
loadCodecs();
81+
82+
return () => {
83+
DeviceProfileStore.removeAllListeners("change");
84+
};
85+
}, [vendor]);
86+
4387
useEffect(() => {
4488
parseLocation();
4589
}, [location])
@@ -73,30 +117,99 @@ function SideMenu() {
73117

74118
setSelectedKey("");
75119

120+
if (path.includes("vendors") && path.endsWith("edit")) {
121+
setSelectedKey("vendor-edit");
122+
}
76123
if (path.includes("profiles")) {
77-
setSelectedKey("profiles");
124+
setSelectedKey("devices");
125+
126+
if (path.endsWith("create")) {
127+
setSelectedKey("profiles-create");
128+
} else if (path.endsWith(".toml")) {
129+
setSelectedKey("profiles-" + path.split("/").slice(-1));
130+
}
78131
}
79132
if (path.includes("codecs")) {
80133
setSelectedKey("codecs");
134+
135+
if (path.endsWith("create")) {
136+
setSelectedKey("codecs-create");
137+
} else if (path.endsWith(".js")) {
138+
setSelectedKey("codecs-" + path.split("/").slice(-1));
139+
}
81140
}
82141
if (path.includes("devices")) {
83142
setSelectedKey("devices");
143+
144+
if (path.endsWith("create")) {
145+
setSelectedKey("devices-create");
146+
} else if (path.endsWith(".toml")) {
147+
setSelectedKey("devices-" + path.split("/").slice(-1));
148+
}
84149
}
85150
}, [location.pathname]);
86151

87152
let items: MenuProps["items"] = [
88153
{
89-
key: "devices", label: <Link to={`/vendors/${vendor}/devices`}>Devices</ Link>
154+
key: "vendor",
155+
label: "Vendor",
156+
children: [
157+
{
158+
key: "vendor-edit",
159+
label: <Link to={`/vendors/${vendor}/edit`}>Update vendor</Link>,
160+
},
161+
],
162+
},
163+
{
164+
key: "devices",
165+
label: "Devices",
166+
children: [
167+
{
168+
key: "devices-create", label: <Link to={`/vendors/${vendor}/devices/create`}>Add device</Link>,
169+
},
170+
].concat(devices.map((v) => {
171+
return {
172+
key: "devices-" + v.getFile(),
173+
label: <Link to={`/vendors/${vendor}/devices/${v.getFile()}`}>{v.getFile()}</Link>,
174+
};
175+
})),
176+
},
177+
{
178+
key: "profiles",
179+
label: "Profiles",
180+
children: [
181+
{
182+
key: "profiles-create",
183+
label: <Link to={`/vendors/${vendor}/profiles/create`}>Add profile</Link>,
184+
},
185+
].concat(profiles.map((v) => {
186+
return {
187+
key: "profiles-" + v.getFile(),
188+
label: <Link to={`/vendors/${vendor}/profiles/${v.getFile()}`}>{v.getFile()}</Link>,
189+
};
190+
})),
191+
},
192+
{
193+
key: "codecs", label: "Codecs", children: [
194+
{
195+
key: "codecs-create",
196+
label: <Link to={`/vendors/${vendor}/codecs/create`}>Add codec</Link>,
197+
},
198+
].concat(codecs.map((v) => {
199+
return {
200+
key: "codecs-" + v.getFile(),
201+
label: <Link to={`/vendors/${vendor}/codecs/${v.getFile()}`}>{v.getFile()}</Link>,
202+
};
203+
}))
90204
},
91-
{ key: "profiles", label: <Link to={`/vendors/${vendor}/profiles`}>Profiles</Link> },
92-
{ key: "codecs", label: <Link to={`/vendors/${vendor}/codecs`}>Codecs</Link> },
93205
];
94206

95207
return (<div>
96208
<Select showSearch allowClear placeholder="Select vendor" options={vendorOptions} value={vendor} className="vendor-select" onSelect={onVendorSelect} onClear={onVendorClear} />
97209
{vendor ? <Menu
98210
items={items}
99211
selectedKeys={[selectedKey]}
212+
mode="inline"
100213
/> : <Link to="/vendors/add"><Button className="vendor-add" type="primary">Add vendor</Button></Link>}
101214
</div>);
102215
}

interface/ui/src/stores/DeviceProfileStore.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ class DeviceProfileStore extends EventEmitter {
163163
duration: 3,
164164
});
165165

166+
this.emit("change");
167+
166168
callbackFunc();
167169
});
168170
}
@@ -190,6 +192,8 @@ class DeviceProfileStore extends EventEmitter {
190192
duration: 3,
191193
});
192194

195+
this.emit("change");
196+
193197
callbackFunc();
194198
});
195199
}
@@ -206,6 +210,8 @@ class DeviceProfileStore extends EventEmitter {
206210
duration: 3,
207211
});
208212

213+
this.emit("change");
214+
209215
callbackFunc();
210216
});
211217
}
@@ -233,6 +239,8 @@ class DeviceProfileStore extends EventEmitter {
233239
duration: 3,
234240
});
235241

242+
this.emit("change");
243+
236244
callbackFunc();
237245
});
238246
}
@@ -260,6 +268,8 @@ class DeviceProfileStore extends EventEmitter {
260268
duration: 3,
261269
});
262270

271+
this.emit("change");
272+
263273
callbackFunc();
264274
});
265275
}
@@ -287,6 +297,8 @@ class DeviceProfileStore extends EventEmitter {
287297
duration: 3,
288298
});
289299

300+
this.emit("change");
301+
290302
callbackFunc();
291303
});
292304
}
@@ -303,6 +315,8 @@ class DeviceProfileStore extends EventEmitter {
303315
duration: 3,
304316
});
305317

318+
this.emit("change");
319+
306320
callbackFunc();
307321
});
308322
}
@@ -330,6 +344,7 @@ class DeviceProfileStore extends EventEmitter {
330344
duration: 3,
331345
});
332346

347+
this.emit("change");
333348

334349
callbackFunc();
335350
});
@@ -358,6 +373,8 @@ class DeviceProfileStore extends EventEmitter {
358373
duration: 3,
359374
});
360375

376+
this.emit("change");
377+
361378
callbackFunc();
362379
});
363380
}

0 commit comments

Comments
 (0)