forked from github/plane
fix: handled attachment upload filename size error in the issue detail (#3485)
* fix: handled attachment upload filename size error in the issue detail * ui: profile detail sidebar border
This commit is contained in:
parent
212f2b54f8
commit
532da80375
@ -38,7 +38,6 @@ export const IssueAttachmentsDetail: FC<TIssueAttachmentsDetail> = (props) => {
|
|||||||
const attachment = attachmentId && getAttachmentById(attachmentId);
|
const attachment = attachmentId && getAttachmentById(attachmentId);
|
||||||
|
|
||||||
if (!attachment) return <></>;
|
if (!attachment) return <></>;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<IssueAttachmentDeleteModal
|
<IssueAttachmentDeleteModal
|
||||||
|
@ -5,6 +5,8 @@ import { useDropzone } from "react-dropzone";
|
|||||||
import { useApplication } from "hooks/store";
|
import { useApplication } from "hooks/store";
|
||||||
// constants
|
// constants
|
||||||
import { MAX_FILE_SIZE } from "constants/common";
|
import { MAX_FILE_SIZE } from "constants/common";
|
||||||
|
// helpers
|
||||||
|
import { generateFileName } from "helpers/attachment.helper";
|
||||||
// types
|
// types
|
||||||
import { TAttachmentOperations } from "./root";
|
import { TAttachmentOperations } from "./root";
|
||||||
|
|
||||||
@ -26,15 +28,17 @@ export const IssueAttachmentUpload: React.FC<Props> = observer((props) => {
|
|||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
const onDrop = useCallback((acceptedFiles: File[]) => {
|
const onDrop = useCallback((acceptedFiles: File[]) => {
|
||||||
if (!acceptedFiles[0] || !workspaceSlug) return;
|
const currentFile: File = acceptedFiles[0];
|
||||||
|
if (!currentFile || !workspaceSlug) return;
|
||||||
|
|
||||||
|
const uploadedFile: File = new File([currentFile], generateFileName(currentFile.name), { type: currentFile.type });
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("asset", acceptedFiles[0]);
|
formData.append("asset", uploadedFile);
|
||||||
formData.append(
|
formData.append(
|
||||||
"attributes",
|
"attributes",
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
name: acceptedFiles[0].name,
|
name: uploadedFile.name,
|
||||||
size: acceptedFiles[0].size,
|
size: uploadedFile.size,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
@ -60,7 +60,7 @@ export const ProfileSidebar = observer(() => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full flex-shrink-0 overflow-y-auto shadow-custom-shadow-sm md:h-full md:w-80">
|
<div className="w-full flex-shrink-0 overflow-y-auto shadow-custom-shadow-sm md:h-full md:w-80 border-l border-custom-border-100">
|
||||||
{userProjectsData ? (
|
{userProjectsData ? (
|
||||||
<>
|
<>
|
||||||
<div className="relative h-32">
|
<div className="relative h-32">
|
||||||
|
@ -1,3 +1,14 @@
|
|||||||
|
export const generateFileName = (fileName: string) => {
|
||||||
|
const date = new Date();
|
||||||
|
const timestamp = date.getTime();
|
||||||
|
|
||||||
|
const _fileName = getFileName(fileName);
|
||||||
|
const nameWithoutExtension = _fileName.length > 80 ? _fileName.substring(0, 80) : _fileName;
|
||||||
|
const extension = getFileExtension(fileName);
|
||||||
|
|
||||||
|
return `${nameWithoutExtension}-${timestamp}.${extension}`;
|
||||||
|
};
|
||||||
|
|
||||||
export const getFileExtension = (filename: string) => filename.slice(((filename.lastIndexOf(".") - 1) >>> 0) + 2);
|
export const getFileExtension = (filename: string) => filename.slice(((filename.lastIndexOf(".") - 1) >>> 0) + 2);
|
||||||
|
|
||||||
export const getFileName = (fileName: string) => {
|
export const getFileName = (fileName: string) => {
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
import { action, computed, makeObservable, observable, runInAction } from "mobx";
|
import { action, computed, makeObservable, observable, runInAction } from "mobx";
|
||||||
import set from "lodash/set";
|
import set from "lodash/set";
|
||||||
|
import update from "lodash/update";
|
||||||
|
import concat from "lodash/concat";
|
||||||
|
import uniq from "lodash/uniq";
|
||||||
|
import pull from "lodash/pull";
|
||||||
// services
|
// services
|
||||||
import { IssueAttachmentService } from "services/issue";
|
import { IssueAttachmentService } from "services/issue";
|
||||||
// types
|
// types
|
||||||
@ -83,10 +87,13 @@ export class IssueAttachmentStore implements IIssueAttachmentStore {
|
|||||||
try {
|
try {
|
||||||
const response = await this.issueAttachmentService.getIssueAttachment(workspaceSlug, projectId, issueId);
|
const response = await this.issueAttachmentService.getIssueAttachment(workspaceSlug, projectId, issueId);
|
||||||
|
|
||||||
runInAction(() => {
|
if (response && response.length > 0) {
|
||||||
this.attachments[issueId] = response.map((attachment) => attachment.id);
|
const _attachmentIds = response.map((attachment) => attachment.id);
|
||||||
response.forEach((attachment) => set(this.attachmentMap, attachment.id, attachment));
|
runInAction(() => {
|
||||||
});
|
update(this.attachments, [issueId], (attachmentIds = []) => uniq(concat(attachmentIds, _attachmentIds)));
|
||||||
|
response.forEach((attachment) => set(this.attachmentMap, attachment.id, attachment));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -98,10 +105,11 @@ export class IssueAttachmentStore implements IIssueAttachmentStore {
|
|||||||
try {
|
try {
|
||||||
const response = await this.issueAttachmentService.uploadIssueAttachment(workspaceSlug, projectId, issueId, data);
|
const response = await this.issueAttachmentService.uploadIssueAttachment(workspaceSlug, projectId, issueId, data);
|
||||||
|
|
||||||
runInAction(() => {
|
if (response && response.id)
|
||||||
this.attachments[issueId].push(response.id);
|
runInAction(() => {
|
||||||
set(this.attachmentMap, response.id, response);
|
update(this.attachments, [issueId], (attachmentIds = []) => uniq(concat(attachmentIds, [response.id])));
|
||||||
});
|
set(this.attachmentMap, response.id, response);
|
||||||
|
});
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -118,12 +126,13 @@ export class IssueAttachmentStore implements IIssueAttachmentStore {
|
|||||||
attachmentId
|
attachmentId
|
||||||
);
|
);
|
||||||
|
|
||||||
const reactionIndex = this.attachments[issueId].findIndex((_comment) => _comment === attachmentId);
|
runInAction(() => {
|
||||||
if (reactionIndex >= 0)
|
update(this.attachments, [issueId], (attachmentIds = []) => {
|
||||||
runInAction(() => {
|
if (attachmentIds.includes(attachmentId)) pull(attachmentIds, attachmentId);
|
||||||
this.attachments[issueId].splice(reactionIndex, 1);
|
return attachmentIds;
|
||||||
delete this.attachmentMap[attachmentId];
|
|
||||||
});
|
});
|
||||||
|
delete this.attachmentMap[attachmentId];
|
||||||
|
});
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user