mirror of
https://github.com/inventree/InvenTree.git
synced 2026-06-12 03:28:37 +00:00
[feature] Rename attachments (#11920)
* Implementation * Update API and CHANGELOG * Annotate response type * Simplify attachment renaming - Use the existing API endpoint * Capture the actual saved path * Tweak attachment table fields * Use built-in validation * Update docs * Unit testing * Ignore some lines from coverage * Check if file exists before deleting
This commit is contained in:
@@ -232,12 +232,16 @@ export function AttachmentTable({
|
||||
hidden: true
|
||||
},
|
||||
attachment: {},
|
||||
filename: {},
|
||||
link: {},
|
||||
comment: {}
|
||||
};
|
||||
|
||||
if (attachmentType != 'link') {
|
||||
delete fields['link'];
|
||||
} else {
|
||||
delete fields['attachment'];
|
||||
delete fields['filename'];
|
||||
}
|
||||
|
||||
// Remove the 'attachment' field if we are editing an existing attachment, or uploading a link
|
||||
@@ -245,6 +249,11 @@ export function AttachmentTable({
|
||||
delete fields['attachment'];
|
||||
}
|
||||
|
||||
if (!selectedAttachment) {
|
||||
// Cannot edit the filename during creation
|
||||
delete fields['filename'];
|
||||
}
|
||||
|
||||
return fields;
|
||||
}, [model_type, model_id, attachmentType, selectedAttachment]);
|
||||
|
||||
@@ -329,6 +338,11 @@ export function AttachmentTable({
|
||||
RowEditAction({
|
||||
hidden: !user.hasChangePermission(model_type),
|
||||
onClick: () => {
|
||||
if (record.attachment) {
|
||||
setAttachmentType('attachment');
|
||||
} else {
|
||||
setAttachmentType('link');
|
||||
}
|
||||
setSelectedAttachment(record.pk);
|
||||
editAttachment.open();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user