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

Function loadDeviceProfileData

ui/src/components/DeviceProfileSelect.tsx:166–248  ·  view source on GitHub ↗
(selectedOptions: CascaderOption[])

Source from the content-addressed store, hash-verified

164 }, [props.name, props.value, props.tenant, form]);
165
166 const loadDeviceProfileData = (selectedOptions: CascaderOption[]) => {
167 if (selectedOptions.length === 0) {
168 return;
169 }
170
171 const targetOption = selectedOptions[selectedOptions.length - 1];
172
173 if (targetOption.type === "init" && targetOption.value === "vendor") {
174 const req = new ListDeviceProfileVendorsRequest();
175 req.setLimit(9999);
176
177 DeviceProfileStore.listVendors(req, (resp: ListDeviceProfileVendorsResponse) => {
178 targetOption.children = resp.getResultList().map(v => {
179 return {
180 type: "vendor",
181 label: v.getName(),
182 value: v.getId(),
183 isLeaf: false,
184 };
185 });
186
187 setDpOptions([...dpOptions]);
188 });
189 } else if (targetOption.type === "init" && targetOption.value === "tenant") {
190 const req = new ListDeviceProfilesRequest();
191 req.setTenantId(props.tenant.getId());
192 req.setTenantOnly(true);
193 req.setLimit(9999);
194
195 DeviceProfileStore.list(req, (resp: ListDeviceProfilesResponse) => {
196 targetOption.children = resp.getResultList().map(v => {
197 return {
198 type: "profile",
199 label: v.getName(),
200 value: v.getId(),
201 isLeaf: true,
202 };
203 });
204
205 setDpOptions([...dpOptions]);
206 });
207 } else if (targetOption.type === "vendor") {
208 const req = new ListDeviceProfileDevicesRequest();
209 req.setLimit(9999);
210 if (typeof targetOption.value === "string") {
211 req.setVendorId(targetOption.value);
212 }
213
214 DeviceProfileStore.listDevices(req, (resp: ListDeviceProfileDevicesResponse) => {
215 targetOption.children = resp.getResultList().map(v => {
216 return {
217 type: "device",
218 label: v.getName(),
219 value: v.getId(),
220 isLeaf: false,
221 };
222 });
223

Callers

nothing calls this directly

Calls 2

getEnumNameFunction · 0.90
listMethod · 0.45

Tested by

no test coverage detected