MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / DeviceProfileSelect

Function DeviceProfileSelect

ui/src/components/DeviceProfileSelect.tsx:42–265  ·  view source on GitHub ↗
(props: IProps)

Source from the content-addressed store, hash-verified

40}
41
42function DeviceProfileSelect(props: IProps) {
43 const form = Form.useFormInstance();
44 const [dpOptions, setDpOptions] = useState<CascaderOption[]>([
45 { label: "Tenant", value: "tenant", isLeaf: false, type: "init" },
46 { label: "Vendor", value: "vendor", isLeaf: false, type: "init" },
47 ]);
48
49 useEffect(() => {
50 if (props.value && props.value !== "") {
51 // Get device-profile
52 const req = new GetDeviceProfileRequest();
53 req.setId(props.value);
54 DeviceProfileStore.get(req, (resp: GetDeviceProfileResponse) => {
55 const dp = resp.getDeviceProfile();
56 if (dp === undefined) {
57 return;
58 }
59
60 if (dp.getDeviceId() !== "") {
61 // Get device-profile device
62 const req = new GetDeviceProfileDeviceRequest();
63 req.setId(dp.getDeviceId());
64 DeviceProfileStore.getDevice(req, (resp: GetDeviceProfileDeviceResponse) => {
65 const dev = resp.getDevice();
66 if (dev === undefined) {
67 return;
68 }
69
70 // Get all device-profile devices for this tenant
71 const req = new ListDeviceProfileDevicesRequest();
72 req.setVendorId(dev.getVendorId());
73 req.setLimit(9999);
74 DeviceProfileStore.listDevices(req, (resp: ListDeviceProfileDevicesResponse) => {
75 const devices = resp.getResultList();
76
77 // Get all device-profile vendors
78 const req = new ListDeviceProfileVendorsRequest();
79 req.setLimit(9999);
80 DeviceProfileStore.listVendors(req, (resp: ListDeviceProfileVendorsResponse) => {
81 const vendors = resp.getResultList();
82
83 // Get all device-profiles (for the device)
84 const req = new ListDeviceProfilesRequest();
85 req.setDeviceId(dp.getDeviceId());
86 req.setLimit(9999);
87 req.setGlobalOnly(true);
88
89 DeviceProfileStore.list(req, (resp: ListDeviceProfilesResponse) => {
90 const profiles = resp.getResultList();
91
92 dpOptions[1].children = vendors.map(v => {
93 if (v.getId() === dev.getVendorId()) {
94 return {
95 type: "vendor",
96 label: v.getName(),
97 value: v.getId(),
98 isLeaf: false,
99 children: devices.map(d => {

Callers

nothing calls this directly

Calls 3

getEnumNameFunction · 0.90
getMethod · 0.45
listMethod · 0.45

Tested by

no test coverage detected