fix: default new task inspection object
This commit is contained in:
@@ -240,6 +240,19 @@ export default function TaskManager({
|
||||
const activeInspectionObject = inspectionObjects.find(
|
||||
object => object.id === activeTask?.inspectionObjectId
|
||||
);
|
||||
|
||||
// 打开新建任务表单时默认选择首个可用检测对象;若列表异步刷新,
|
||||
// 则仅在当前选择失效时回退到第一项,避免覆盖用户的手动选择。
|
||||
useEffect(() => {
|
||||
if (!adding) return;
|
||||
setNewTaskInspectionObjectId(currentId => {
|
||||
if (inspectionObjects.some(object => object.id === currentId)) {
|
||||
return currentId;
|
||||
}
|
||||
return inspectionObjects[0]?.id ?? null;
|
||||
});
|
||||
}, [adding, inspectionObjects]);
|
||||
|
||||
const createTask = trpc.inspectionTask.create.useMutation({
|
||||
onSuccess: result => {
|
||||
pendingDefaultSelection.current = {
|
||||
@@ -692,6 +705,7 @@ export default function TaskManager({
|
||||
<button
|
||||
className="industrial-btn flex shrink-0 items-center gap-0.5 whitespace-nowrap px-2 py-0.5 text-[10px]"
|
||||
onClick={() => {
|
||||
setNewTaskInspectionObjectId(inspectionObjects[0]?.id ?? null);
|
||||
setAdding(true);
|
||||
onStartCreate?.();
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user