Add button to delete draft reviews

This commit is contained in:
Thomas Scholtes
2025-07-17 11:35:13 +02:00
committed by Rūdolfs Ošiņš
parent 595382b240
commit ea395ee884
4 changed files with 67 additions and 32 deletions
+1 -1
View File
@@ -163,7 +163,7 @@
{/if}
{#if deleteComment}
<div class="icon-button">
<Icon name="cross" onclick={deleteComment} />
<Icon name="trash" onclick={deleteComment} />
</div>
{/if}
{#if reactions && reactOnComment}
+10
View File
@@ -82,6 +82,7 @@
| "stop"
| "sun"
| "thumb-up"
| "trash"
| "unresolve"
| "user"
| "warning";
@@ -1398,6 +1399,15 @@
<path d="M7 6H8V7H7L7 6Z" />
<path d="M7 10L8 10V11L7 11L7 10Z" />
<path d="M7 12L8 12L8 13H7L7 12Z" />
{:else if name === "trash"}
<path d="M6.5 2L9.5 2V3L6.5 3V2Z" />
<path d="M3.5 5H4.5L4.5 13H3.5L3.5 5Z" />
<path d="M4.5 13L11.5 13V14L4.5 14V13Z" />
<path d="M11.5 5L12.5 5L12.5 13H11.5L11.5 5Z" />
<path d="M2.5 3L13.5 3V4L2.5 4L2.5 3Z" />
<path d="M9.5 5H10.5L10.5 12L9.5 12V5Z" />
<path d="M7.5 5L8.5 5V12H7.5L7.5 5Z" />
<path d="M5.5 5H6.5L6.5 12H5.5L5.5 5Z" />
{:else if name === "unresolve"}
<path d="M7 11.5V12.5H6V11.5H7Z" />
<path d="M8 10.5V11.5L7 11.5L7 10.5H8Z" />
+40 -26
View File
@@ -363,32 +363,46 @@
{/if}
</span>
{#if "draft" in review}
<div style:margin-inline-start="auto">
<Button
styleHeight="2.5rem"
variant="secondary"
title={canPublish
? undefined
: "Add a summary or select a verdict to publish the review"}
disabled={!canPublish || publishingInProgress}
onclick={async () => {
publishingInProgress = true;
try {
await draftReviewStorage.publish(review.id);
await push({
resource: "repo.patch",
rid: repo.rid,
patch: patchId,
reviewId: undefined,
status: undefined,
});
} finally {
publishingInProgress = false;
}
}}>
<Icon name="checkout" />Publish
</Button>
</div>
<div style:margin-inline-start="auto"></div>
<NakedButton
styleHeight="2.5rem"
variant="ghost"
onclick={() => {
draftReviewStorage.delete(review.id);
void push({
resource: "repo.patch",
rid: repo.rid,
patch: patchId,
reviewId: undefined,
status: undefined,
});
}}>
<Icon name="trash" />Delete
</NakedButton>
<Button
styleHeight="2.5rem"
variant="secondary"
title={canPublish
? undefined
: "Add a summary or select a verdict to publish the review"}
disabled={!canPublish || publishingInProgress}
onclick={async () => {
publishingInProgress = true;
try {
await draftReviewStorage.publish(review.id);
await push({
resource: "repo.patch",
rid: repo.rid,
patch: patchId,
reviewId: undefined,
status: undefined,
});
} finally {
publishingInProgress = false;
}
}}>
<Icon name="checkout" />Publish
</Button>
{/if}
</div>
+16 -5
View File
@@ -115,6 +115,15 @@ export const draftReviewStorage = {
});
},
delete(id: string): DraftReviewStored | undefined {
const review = storage.value[id];
storage.update(reviews => {
delete reviews[id];
return reviews;
});
return review;
},
deleteComment(id: string, commentId: string) {
updateStoredDraftReview(id, review => {
const index = review.comments.findIndex(
@@ -170,11 +179,13 @@ export const draftReviewStorage = {
},
async publish(id: string) {
const draftReviewStored = storage.value[id];
storage.update(reviews => {
delete reviews[id];
return reviews;
});
const draftReviewStored = draftReviewStorage.delete(id);
if (!draftReviewStored) {
throw new Error(
`Failed to publish draft review: Review ${id} does not exist`,
);
}
await invoke<Patch>("create_patch_review", {
args: {
rid: draftReviewStored.rid,