fix: work item attachment count mutation (#6670)
This commit is contained in:
parent
aa0b2c0be4
commit
fde8630c5b
2 changed files with 13 additions and 6 deletions
|
|
@ -26,7 +26,7 @@ export const IssueDetailWidgetCollapsibles: FC<Props> = observer((props) => {
|
||||||
const {
|
const {
|
||||||
issue: { getIssueById },
|
issue: { getIssueById },
|
||||||
subIssues: { subIssuesByIssueId },
|
subIssues: { subIssuesByIssueId },
|
||||||
attachment: { getAttachmentsUploadStatusByIssueId },
|
attachment: { getAttachmentsCountByIssueId, getAttachmentsUploadStatusByIssueId },
|
||||||
relation: { getRelationCountByIssueId },
|
relation: { getRelationCountByIssueId },
|
||||||
} = useIssueDetail();
|
} = useIssueDetail();
|
||||||
|
|
||||||
|
|
@ -41,8 +41,8 @@ export const IssueDetailWidgetCollapsibles: FC<Props> = observer((props) => {
|
||||||
const shouldRenderRelations = issueRelationsCount > 0;
|
const shouldRenderRelations = issueRelationsCount > 0;
|
||||||
const shouldRenderLinks = !!issue?.link_count && issue?.link_count > 0;
|
const shouldRenderLinks = !!issue?.link_count && issue?.link_count > 0;
|
||||||
const attachmentUploads = getAttachmentsUploadStatusByIssueId(issueId);
|
const attachmentUploads = getAttachmentsUploadStatusByIssueId(issueId);
|
||||||
const shouldRenderAttachments =
|
const attachmentsCount = getAttachmentsCountByIssueId(issueId);
|
||||||
(!!issue?.attachment_count && issue?.attachment_count > 0) || (!!attachmentUploads && attachmentUploads.length > 0);
|
const shouldRenderAttachments = attachmentsCount > 0 || (!!attachmentUploads && attachmentUploads.length > 0);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ export interface IIssueAttachmentStore extends IIssueAttachmentStoreActions {
|
||||||
getAttachmentsUploadStatusByIssueId: (issueId: string) => TAttachmentUploadStatus[] | undefined;
|
getAttachmentsUploadStatusByIssueId: (issueId: string) => TAttachmentUploadStatus[] | undefined;
|
||||||
getAttachmentsByIssueId: (issueId: string) => string[] | undefined;
|
getAttachmentsByIssueId: (issueId: string) => string[] | undefined;
|
||||||
getAttachmentById: (attachmentId: string) => TIssueAttachment | undefined;
|
getAttachmentById: (attachmentId: string) => TIssueAttachment | undefined;
|
||||||
|
getAttachmentsCountByIssueId: (issueId: string) => number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class IssueAttachmentStore implements IIssueAttachmentStore {
|
export class IssueAttachmentStore implements IIssueAttachmentStore {
|
||||||
|
|
@ -109,6 +110,11 @@ export class IssueAttachmentStore implements IIssueAttachmentStore {
|
||||||
return this.attachmentMap[attachmentId] ?? undefined;
|
return this.attachmentMap[attachmentId] ?? undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
getAttachmentsCountByIssueId = (issueId: string) => {
|
||||||
|
const attachments = this.getAttachmentsByIssueId(issueId);
|
||||||
|
return attachments?.length ?? 0;
|
||||||
|
};
|
||||||
|
|
||||||
// actions
|
// actions
|
||||||
addAttachments = (issueId: string, attachments: TIssueAttachment[]) => {
|
addAttachments = (issueId: string, attachments: TIssueAttachment[]) => {
|
||||||
if (attachments && attachments.length > 0) {
|
if (attachments && attachments.length > 0) {
|
||||||
|
|
@ -155,12 +161,14 @@ export class IssueAttachmentStore implements IIssueAttachmentStore {
|
||||||
this.debouncedUpdateProgress(issueId, tempId, progressPercentage);
|
this.debouncedUpdateProgress(issueId, tempId, progressPercentage);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const issueAttachmentsCount = this.getAttachmentsByIssueId(issueId)?.length ?? 0;
|
|
||||||
|
|
||||||
if (response && response.id) {
|
if (response && response.id) {
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
update(this.attachments, [issueId], (attachmentIds = []) => uniq(concat(attachmentIds, [response.id])));
|
update(this.attachments, [issueId], (attachmentIds = []) => uniq(concat(attachmentIds, [response.id])));
|
||||||
set(this.attachmentMap, response.id, response);
|
set(this.attachmentMap, response.id, response);
|
||||||
|
this.rootIssueStore.issues.updateIssue(issueId, {
|
||||||
|
attachment_count: this.getAttachmentsCountByIssueId(issueId),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -182,7 +190,6 @@ export class IssueAttachmentStore implements IIssueAttachmentStore {
|
||||||
issueId,
|
issueId,
|
||||||
attachmentId
|
attachmentId
|
||||||
);
|
);
|
||||||
const issueAttachmentsCount = this.getAttachmentsByIssueId(issueId)?.length ?? 1;
|
|
||||||
|
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
update(this.attachments, [issueId], (attachmentIds = []) => {
|
update(this.attachments, [issueId], (attachmentIds = []) => {
|
||||||
|
|
@ -191,7 +198,7 @@ export class IssueAttachmentStore implements IIssueAttachmentStore {
|
||||||
});
|
});
|
||||||
delete this.attachmentMap[attachmentId];
|
delete this.attachmentMap[attachmentId];
|
||||||
this.rootIssueStore.issues.updateIssue(issueId, {
|
this.rootIssueStore.issues.updateIssue(issueId, {
|
||||||
attachment_count: issueAttachmentsCount - 1, // decrement attachment count
|
attachment_count: this.getAttachmentsCountByIssueId(issueId),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue