refactor(components): extract shared entity utilities and simplify item components (F1.3, F1.4)
Extract 3 entity composables (useEntityCustomFields, useEntityDocuments, useEntityProductDisplay) and entityCustomFieldLogic utility shared across ComponentItem (1336→585 LOC) and PieceItem (1588→740 LOC). Improve type safety in edit/create pages with explicit casts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -503,7 +503,6 @@ import {
|
||||
import {
|
||||
historyActionLabel,
|
||||
formatHistoryDate,
|
||||
formatHistoryValue,
|
||||
historyDiffEntries as _historyDiffEntries,
|
||||
} from '~/shared/utils/historyDisplayUtils'
|
||||
|
||||
@@ -626,7 +625,7 @@ const refreshDocuments = async () => {
|
||||
try {
|
||||
const result = await loadDocumentsByPiece(piece.value.id, { updateStore: false })
|
||||
if (result.success) {
|
||||
pieceDocuments.value = result.data || []
|
||||
pieceDocuments.value = Array.isArray(result.data) ? result.data : result.data ? [result.data] : []
|
||||
}
|
||||
} finally {
|
||||
loadingDocuments.value = false
|
||||
@@ -776,9 +775,9 @@ const loadPieceTypeDetails = async (currentPiece: any) => {
|
||||
const type = await getModelType(typeId)
|
||||
if (type && typeof type === 'object') {
|
||||
pieceTypeDetails.value = type
|
||||
refreshCustomFieldInputs(type.structure ?? null, currentPiece?.customFieldValues ?? null)
|
||||
refreshCustomFieldInputs((type.structure as PieceModelStructure | null) ?? null, currentPiece?.customFieldValues ?? null)
|
||||
}
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
pieceTypeDetails.value = null
|
||||
}
|
||||
}
|
||||
@@ -898,8 +897,8 @@ const submitEdition = async () => {
|
||||
saving.value = true
|
||||
try {
|
||||
const result = await updatePiece(piece.value.id, payload)
|
||||
if (result.success) {
|
||||
const updatedPiece = result.data
|
||||
if (result.success && result.data) {
|
||||
const updatedPiece = result.data as Record<string, any>
|
||||
await _saveCustomFieldValues(
|
||||
'piece',
|
||||
updatedPiece.id,
|
||||
|
||||
@@ -543,22 +543,23 @@ const submitCreation = async () => {
|
||||
submitting.value = true
|
||||
try {
|
||||
const result = await createPiece(payload)
|
||||
if (result.success) {
|
||||
if (result.success && result.data) {
|
||||
const createdPiece = result.data as Record<string, any>
|
||||
await _saveCustomFieldValues(
|
||||
'piece',
|
||||
result.data.id,
|
||||
createdPiece.id,
|
||||
[
|
||||
result.data?.typePiece?.pieceCustomFields,
|
||||
result.data?.typeMachinePieceRequirement?.typePiece?.pieceCustomFields,
|
||||
createdPiece?.typePiece?.pieceCustomFields,
|
||||
createdPiece?.typeMachinePieceRequirement?.typePiece?.pieceCustomFields,
|
||||
],
|
||||
{ customFieldInputs, upsertCustomFieldValue, updateCustomFieldValue, toast },
|
||||
)
|
||||
if (selectedDocuments.value.length && result.data?.id) {
|
||||
if (selectedDocuments.value.length && createdPiece.id) {
|
||||
uploadingDocuments.value = true
|
||||
const uploadResult = await uploadDocuments(
|
||||
{
|
||||
files: selectedDocuments.value,
|
||||
context: { pieceId: result.data.id },
|
||||
context: { pieceId: createdPiece.id },
|
||||
},
|
||||
{ updateStore: false },
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user