fix(label): contextMenu
This commit is contained in:
@@ -52,7 +52,7 @@ import { renderGroupPath } from "../useRenderGroupPath"
|
|||||||
import useRenderTag from "../useRenderTag"
|
import useRenderTag from "../useRenderTag"
|
||||||
import { useRightToolsStore } from "../useRightToolsStore"
|
import { useRightToolsStore } from "../useRightToolsStore"
|
||||||
import { useTopToolsStore } from "../useTopToolsStore"
|
import { useTopToolsStore } from "../useTopToolsStore"
|
||||||
import { checkCommentsIsSame } from "../util"
|
import { buildSubAttributeFormValues, checkCommentsIsSame } from "../util"
|
||||||
import { safeClone } from "../utils/clone"
|
import { safeClone } from "../utils/clone"
|
||||||
import { labelTypeMap } from "../utils/constants"
|
import { labelTypeMap } from "../utils/constants"
|
||||||
import { adjustPoints } from "../utils/paperjs"
|
import { adjustPoints } from "../utils/paperjs"
|
||||||
@@ -3315,50 +3315,26 @@ const PaperContainer = (
|
|||||||
.get(activeImage)
|
.get(activeImage)
|
||||||
?.get(operationId)
|
?.get(operationId)
|
||||||
?.find((item) => item[0] === id)
|
?.find((item) => item[0] === id)
|
||||||
|
const operationSchema = getOperationSchema(operationId)
|
||||||
form.setFieldValue("id", id.toString())
|
|
||||||
form.setFieldValue("operation", operationId)
|
|
||||||
if (currentPath?.[2].sub_attributes) {
|
|
||||||
let operationSchema = getOperationSchema(operationId)
|
|
||||||
let obj: {
|
|
||||||
[key: string]: string | string[]
|
|
||||||
} = {}
|
|
||||||
Object.entries(currentPath?.[2].sub_attributes).map(([key, value]) => {
|
|
||||||
let select_mode = operationSchema?.sub_attributes_describe?.find(
|
|
||||||
(item) => item.chinese_name === key
|
|
||||||
)?.select_mode
|
|
||||||
switch (select_mode) {
|
|
||||||
case 2:
|
|
||||||
obj[key] = Array.isArray(value)
|
|
||||||
? value
|
|
||||||
: (value as string)
|
|
||||||
.split(",")
|
|
||||||
.map((item) => item.trim())
|
|
||||||
.filter(Boolean)
|
|
||||||
return
|
|
||||||
default:
|
|
||||||
obj[key] = value as string
|
|
||||||
return
|
|
||||||
}
|
|
||||||
})
|
|
||||||
form.setFieldValue("sub_attributes", obj)
|
|
||||||
}
|
|
||||||
if (currentPath?.[2].comment) {
|
|
||||||
const nowComment =
|
const nowComment =
|
||||||
currentPath?.[2].comment[currentPath?.[2].comment.length - 1]
|
currentPath?.[2].comment?.[currentPath?.[2].comment.length - 1]
|
||||||
form.setFieldValue(
|
|
||||||
"check_box_comments",
|
form.setValues({
|
||||||
|
id: id.toString(),
|
||||||
|
operation: operationId,
|
||||||
|
sub_attributes: buildSubAttributeFormValues(
|
||||||
|
operationSchema,
|
||||||
|
currentPath?.[2].sub_attributes || {}
|
||||||
|
),
|
||||||
|
check_box_comments:
|
||||||
nowComment && nowComment.check_box_comments.length
|
nowComment && nowComment.check_box_comments.length
|
||||||
? nowComment.check_box_comments
|
? nowComment.check_box_comments
|
||||||
: []
|
: [],
|
||||||
)
|
text_comments:
|
||||||
form.setFieldValue(
|
|
||||||
"text_comments",
|
|
||||||
nowComment && nowComment.text_comments.length
|
nowComment && nowComment.text_comments.length
|
||||||
? nowComment.text_comments[0]
|
? nowComment.text_comments[0]
|
||||||
: ""
|
: "",
|
||||||
)
|
})
|
||||||
}
|
|
||||||
// 可选的ids
|
// 可选的ids
|
||||||
let images = Array.from(labelState.keys()).filter(
|
let images = Array.from(labelState.keys()).filter(
|
||||||
(key) => key !== activeImage
|
(key) => key !== activeImage
|
||||||
@@ -3580,11 +3556,10 @@ const PaperContainer = (
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
// newOperation的subAttributes
|
// newOperation的subAttributes
|
||||||
let subAttr = Object.assign(
|
let subAttr = safeClone(
|
||||||
{},
|
|
||||||
useTopToolsStore.getState().subAttributes[
|
useTopToolsStore.getState().subAttributes[
|
||||||
operationSchema?.label_class ?? ""
|
operationSchema?.label_class ?? ""
|
||||||
]
|
] || {}
|
||||||
)
|
)
|
||||||
// 修改labeldata
|
// 修改labeldata
|
||||||
setOperation(activeImage, newOperation, [
|
setOperation(activeImage, newOperation, [
|
||||||
@@ -3612,16 +3587,21 @@ const PaperContainer = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const handleChangeContextMenuSubAttr = useCallback(
|
const handleChangeContextMenuSubAttr = useCallback(
|
||||||
(key: string, value: string) => {
|
(key: string, value: string | string[]) => {
|
||||||
|
const currentSubAttributes = safeClone(
|
||||||
|
(pathItem?.[2]?.sub_attributes ||
|
||||||
|
newDetail.sub_attributes ||
|
||||||
|
{}) as Record<string, any>
|
||||||
|
)
|
||||||
|
currentSubAttributes[key] = Array.isArray(value) ? value.join(",") : value
|
||||||
|
|
||||||
setOperation(activeImage, operationId, [
|
setOperation(activeImage, operationId, [
|
||||||
id,
|
id,
|
||||||
pathItem?.[1] || [],
|
pathItem?.[1] || [],
|
||||||
{
|
{
|
||||||
...newDetail,
|
...newDetail,
|
||||||
...(pathItem?.[2] || {}),
|
...(pathItem?.[2] || {}),
|
||||||
sub_attributes: Object.assign(newDetail.sub_attributes || {}, {
|
sub_attributes: currentSubAttributes,
|
||||||
[key]: value,
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
pathItem?.[3] || [],
|
pathItem?.[3] || [],
|
||||||
])
|
])
|
||||||
@@ -3892,7 +3872,7 @@ const PaperContainer = (
|
|||||||
)
|
)
|
||||||
handleChangeContextMenuSubAttr(
|
handleChangeContextMenuSubAttr(
|
||||||
item.chinese_name,
|
item.chinese_name,
|
||||||
value.toString()
|
value
|
||||||
)
|
)
|
||||||
}}>
|
}}>
|
||||||
<Stack gap={6} mt={6}>
|
<Stack gap={6} mt={6}>
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ import {
|
|||||||
NODE_SIZE_MIN,
|
NODE_SIZE_MIN,
|
||||||
useTopToolsStore,
|
useTopToolsStore,
|
||||||
} from "../useTopToolsStore"
|
} from "../useTopToolsStore"
|
||||||
import { getSubAttrStatus } from "../util"
|
import { buildSubAttributeFormValues, getSubAttrStatus } from "../util"
|
||||||
import { safeClone } from "../utils/clone"
|
import { safeClone } from "../utils/clone"
|
||||||
import { labelTypeMap, TaskStatusEnum } from "../utils/constants"
|
import { labelTypeMap, TaskStatusEnum } from "../utils/constants"
|
||||||
import { adjustAllPoints } from "../utils/paperjs"
|
import { adjustAllPoints } from "../utils/paperjs"
|
||||||
@@ -1488,36 +1488,10 @@ const TopTools = (
|
|||||||
operationId: string,
|
operationId: string,
|
||||||
values: Record<string, string | string[] | undefined> = {}
|
values: Record<string, string | string[] | undefined> = {}
|
||||||
) => {
|
) => {
|
||||||
const schema = getOperationSchema(operationId)
|
return buildSubAttributeFormValues(
|
||||||
if (!schema?.sub_attributes_describe?.length) return {}
|
getOperationSchema(operationId),
|
||||||
|
values
|
||||||
const nextValues: Record<string, string | string[]> = {}
|
|
||||||
|
|
||||||
schema.sub_attributes_describe.forEach((item) => {
|
|
||||||
const currentValue = values[item.chinese_name]
|
|
||||||
if (
|
|
||||||
currentValue === undefined ||
|
|
||||||
currentValue === null ||
|
|
||||||
currentValue === ""
|
|
||||||
)
|
)
|
||||||
return
|
|
||||||
|
|
||||||
if (item.select_mode === 2) {
|
|
||||||
nextValues[item.chinese_name] = Array.isArray(currentValue)
|
|
||||||
? currentValue
|
|
||||||
: currentValue
|
|
||||||
.split(",")
|
|
||||||
.map((value) => value.trim())
|
|
||||||
.filter(Boolean)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
nextValues[item.chinese_name] = Array.isArray(currentValue)
|
|
||||||
? currentValue[0] || ""
|
|
||||||
: currentValue
|
|
||||||
})
|
|
||||||
|
|
||||||
return nextValues
|
|
||||||
},
|
},
|
||||||
[getOperationSchema]
|
[getOperationSchema]
|
||||||
)
|
)
|
||||||
@@ -1627,6 +1601,10 @@ const TopTools = (
|
|||||||
size="xs"
|
size="xs"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
form.reset()
|
form.reset()
|
||||||
|
form.setFieldValue(
|
||||||
|
"sub_attributes",
|
||||||
|
getPresetFormValues(activeOperation, {})
|
||||||
|
)
|
||||||
if (operationSchema?.label_class)
|
if (operationSchema?.label_class)
|
||||||
setsubAttributes(operationSchema.label_class, {})
|
setsubAttributes(operationSchema.label_class, {})
|
||||||
}}>
|
}}>
|
||||||
|
|||||||
@@ -86,6 +86,45 @@ export const getSubAttrStatus = (
|
|||||||
return bool
|
return bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const buildSubAttributeFormValues = (
|
||||||
|
operationSchema: Project.LabelSchemaList | null,
|
||||||
|
detail: Record<string, any> = {}
|
||||||
|
) => {
|
||||||
|
const nextValues: Record<string, string | string[]> = {}
|
||||||
|
if (!operationSchema?.sub_attributes_describe?.length) return nextValues
|
||||||
|
|
||||||
|
operationSchema.sub_attributes_describe.forEach((item) => {
|
||||||
|
nextValues[item.chinese_name] = item.select_mode === 2 ? [] : ""
|
||||||
|
|
||||||
|
const currentValue = detail?.[item.chinese_name]
|
||||||
|
if (
|
||||||
|
currentValue === undefined ||
|
||||||
|
currentValue === null ||
|
||||||
|
currentValue === "" ||
|
||||||
|
(Array.isArray(currentValue) && currentValue.length === 0)
|
||||||
|
) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.select_mode === 2) {
|
||||||
|
nextValues[item.chinese_name] = Array.isArray(currentValue)
|
||||||
|
? currentValue
|
||||||
|
: currentValue
|
||||||
|
.toString()
|
||||||
|
.split(",")
|
||||||
|
.map((value: string) => value.trim())
|
||||||
|
.filter(Boolean)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
nextValues[item.chinese_name] = Array.isArray(currentValue)
|
||||||
|
? currentValue[0] || ""
|
||||||
|
: currentValue.toString()
|
||||||
|
})
|
||||||
|
|
||||||
|
return nextValues
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
export const checkCommentsIsSame: (
|
export const checkCommentsIsSame: (
|
||||||
a: any[] | null,
|
a: any[] | null,
|
||||||
|
|||||||
Reference in New Issue
Block a user