Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const IssueDetailWidgetCollapsibles: FC<Props> = observer((props) => {
const {
issue: { getIssueById },
subIssues: { subIssuesByIssueId },
attachment: { getAttachmentsUploadStatusByIssueId },
attachment: { getAttachmentsCountByIssueId, getAttachmentsUploadStatusByIssueId },
relation: { getRelationCountByIssueId },
} = useIssueDetail();

Expand All @@ -41,8 +41,8 @@ export const IssueDetailWidgetCollapsibles: FC<Props> = observer((props) => {
const shouldRenderRelations = issueRelationsCount > 0;
const shouldRenderLinks = !!issue?.link_count && issue?.link_count > 0;
const attachmentUploads = getAttachmentsUploadStatusByIssueId(issueId);
const shouldRenderAttachments =
(!!issue?.attachment_count && issue?.attachment_count > 0) || (!!attachmentUploads && attachmentUploads.length > 0);
const attachmentsCount = getAttachmentsCountByIssueId(issueId);
const shouldRenderAttachments = attachmentsCount > 0 || (!!attachmentUploads && attachmentUploads.length > 0);

return (
<div className="flex flex-col">
Expand Down
13 changes: 10 additions & 3 deletions web/core/store/issue/issue-details/attachment.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface IIssueAttachmentStore extends IIssueAttachmentStoreActions {
getAttachmentsUploadStatusByIssueId: (issueId: string) => TAttachmentUploadStatus[] | undefined;
getAttachmentsByIssueId: (issueId: string) => string[] | undefined;
getAttachmentById: (attachmentId: string) => TIssueAttachment | undefined;
getAttachmentsCountByIssueId: (issueId: string) => number;
}

export class IssueAttachmentStore implements IIssueAttachmentStore {
Expand Down Expand Up @@ -109,6 +110,11 @@ export class IssueAttachmentStore implements IIssueAttachmentStore {
return this.attachmentMap[attachmentId] ?? undefined;
};

getAttachmentsCountByIssueId = (issueId: string) => {
const attachments = this.getAttachmentsByIssueId(issueId);
return attachments?.length ?? 0;
};

// actions
addAttachments = (issueId: string, attachments: TIssueAttachment[]) => {
if (attachments && attachments.length > 0) {
Expand Down Expand Up @@ -155,12 +161,14 @@ export class IssueAttachmentStore implements IIssueAttachmentStore {
this.debouncedUpdateProgress(issueId, tempId, progressPercentage);
}
);
const issueAttachmentsCount = this.getAttachmentsByIssueId(issueId)?.length ?? 0;

if (response && response.id) {
runInAction(() => {
update(this.attachments, [issueId], (attachmentIds = []) => uniq(concat(attachmentIds, [response.id])));
set(this.attachmentMap, response.id, response);
this.rootIssueStore.issues.updateIssue(issueId, {
attachment_count: this.getAttachmentsCountByIssueId(issueId),
});
});
}

Expand All @@ -182,7 +190,6 @@ export class IssueAttachmentStore implements IIssueAttachmentStore {
issueId,
attachmentId
);
const issueAttachmentsCount = this.getAttachmentsByIssueId(issueId)?.length ?? 1;

runInAction(() => {
update(this.attachments, [issueId], (attachmentIds = []) => {
Expand All @@ -191,7 +198,7 @@ export class IssueAttachmentStore implements IIssueAttachmentStore {
});
delete this.attachmentMap[attachmentId];
this.rootIssueStore.issues.updateIssue(issueId, {
attachment_count: issueAttachmentsCount - 1, // decrement attachment count
attachment_count: this.getAttachmentsCountByIssueId(issueId),
});
});

Expand Down