Skip to content

Commit

Permalink
chore(platform): update the model when modelList loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
xiejay97 committed Mar 6, 2023
1 parent adb5f33 commit 2350eb0
Showing 1 changed file with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,25 @@ function DeviceModal(props: AppDeviceModalProps, ref: React.ForwardedRef<OpenSet
setVisible(true);
setDevice(device);

form.reset(device ? { name: device.name, model: device.model } : undefined);
form.reset(device ? { name: device.name } : undefined);
updateForm();

if (isUndefined(modelList)) {
modelApi.list().subscribe({
next: (res) => {
setModelList(
res.resources.map((model) => ({
label: model.name,
value: model.name,
disabled: model.disabled,
}))
);
},
});
}
setModelList(undefined);
modelApi.list().subscribe({
next: (res) => {
setModelList(
res.resources.map((model) => ({
label: model.name,
value: model.name,
disabled: model.disabled,
}))
);
if (device) {
form.patchValue({ model: device.model });
updateForm();
}
},
});
});

useImperativeHandle(ref, () => open, [open]);
Expand Down Expand Up @@ -88,13 +91,7 @@ function DeviceModal(props: AppDeviceModalProps, ref: React.ForwardedRef<OpenSet
</DForm.Item>
<DForm.Item dFormControls={{ model: 'Please select model!' }} dLabel="Model">
{({ model }) => (
<DSelect
dFormControl={modelList ? model : undefined}
dList={modelList ?? []}
dLoading={isUndefined(modelList)}
dPlaceholder="Model"
dClearable
/>
<DSelect dFormControl={model} dList={modelList ?? []} dLoading={isUndefined(modelList)} dPlaceholder="Model" dClearable />
)}
</DForm.Item>
</DForm.Group>
Expand Down

0 comments on commit 2350eb0

Please sign in to comment.