From 9231d3c6c75d894ebfe6331baf8da76ed73a3903 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Tue, 11 Feb 2025 11:34:08 +0100 Subject: [PATCH] Display all additions of labels or assignees Instead of relying on actions of previous labels or assignees, we should always display changes to labels and assignees which can also happen on creation of an issue or patch. Also makes use of the `pluralize` helper function instead of reimplementing it. --- src/components/IssueTimeline.svelte | 144 ++++++++++++++++------------ src/components/PatchTimeline.svelte | 96 ++++++++++++------- 2 files changed, 143 insertions(+), 97 deletions(-) diff --git a/src/components/IssueTimeline.svelte b/src/components/IssueTimeline.svelte index 5f545ebf7..f46939099 100644 --- a/src/components/IssueTimeline.svelte +++ b/src/components/IssueTimeline.svelte @@ -17,6 +17,7 @@ authorForNodeId, formatTimestamp, issueStatusColor, + pluralize, publicKeyFromDid, } from "@app/lib/utils"; import Icon from "./Icon.svelte"; @@ -126,72 +127,95 @@ - {:else if op.type === "label" && op.previous && op.previous.type === op.type} - {@const changed = itemDiff(op.previous?.labels ?? [], op.labels)} - {#if changed.added.length || changed.removed.length} -
-
- -
-
- - {#if changed.added.length} - added label{changed.added.length > 1 ? "s" : ""} - {#each changed.added as label} - {label} - {/each} + {:else if op.type === "label"} +
+
+ +
+
+ + {#if op.previous && op.previous.type === op.type} + {@const changed = itemDiff(op.previous?.labels ?? [], op.labels)} + {#if changed.added.length || changed.removed.length} + {#if changed.added.length} + added {pluralize("label", changed.removed.length)} + {#each changed.added as label} + {label} + {/each} + {/if} + {#if changed.removed.length} + removed {pluralize("label", changed.removed.length)} + {#each changed.removed as label} + {label} + {/each} + {/if} {/if} - {#if changed.removed.length} - removed label{changed.removed.length > 1 ? "s" : ""} - {#each changed.removed as label} - {label} - {/each} - {/if} -
- {formatTimestamp(op.timestamp)} -
+ {:else} + added {pluralize("label", op.labels.length)} + {#each op.labels as label} + {label} + {/each} + {/if} +
+ {formatTimestamp(op.timestamp)}
- {/if} - {:else if op.type === "assign" && op.previous && op.previous.type === op.type} - {@const changed = itemDiff(op.previous?.assignees ?? [], op.assignees)} - {#if changed.added.length || changed.removed.length} -
-
- -
-
- - {#if changed.added.length} - assigned - {#each changed.added as assignee} - {#await invoke( "alias", { nid: publicKeyFromDid(assignee) }, ) then alias} - - {/await} - {/each} +
+ {:else if op.type === "assign"} +
+
+ +
+
+ + {#if op.previous && op.previous.type === op.type} + {@const changed = itemDiff( + op.previous?.assignees ?? [], + op.assignees, + )} + {#if changed.added.length || changed.removed.length} + {#if changed.added.length} + assigned + {#each changed.added as assignee} + {#await invoke( "alias", { nid: publicKeyFromDid(assignee) }, ) then alias} + + {/await} + {/each} + {/if} + {#if changed.removed.length} + unassigned + {#each changed.removed as assignee} + {#await invoke( "alias", { nid: publicKeyFromDid(assignee) }, ) then alias} + + {/await} + {/each} + {/if} {/if} - {#if changed.removed.length} - unassigned - {#each changed.removed as assignee} - {#await invoke( "alias", { nid: publicKeyFromDid(assignee) }, ) then alias} - - {/await} - {/each} - {/if} -
- {formatTimestamp(op.timestamp)} -
+ {:else} + assigned + {#each op.assignees as assignee} + {#await invoke( "alias", { nid: publicKeyFromDid(assignee) }, ) then alias} + + {/await} + {/each} + {/if} +
+ {formatTimestamp(op.timestamp)}
- {/if} +
{:else if op.type === "edit"} {#if op.previous && op.previous.type === op.type}
diff --git a/src/components/PatchTimeline.svelte b/src/components/PatchTimeline.svelte index a90b4de37..b573e8095 100644 --- a/src/components/PatchTimeline.svelte +++ b/src/components/PatchTimeline.svelte @@ -17,6 +17,7 @@ authorForNodeId, formatTimestamp, patchStatusColor, + pluralize, publicKeyFromDid, } from "@app/lib/utils"; import Icon from "./Icon.svelte"; @@ -147,42 +148,52 @@
- {:else if op.type === "label" && op.previous && op.previous.type === op.type} - {@const changed = itemDiff(op.previous?.labels ?? [], op.labels)} - {#if changed.added.length || changed.removed.length} -
-
- -
-
- - {#if changed.added.length} - added label{changed.added.length > 1 ? "s" : ""} - {#each changed.added as label} - {label} - {/each} + {:else if op.type === "label"} +
+
+ +
+
+ + {#if op.previous && op.previous.type === op.type} + {@const changed = itemDiff(op.previous?.labels ?? [], op.labels)} + {#if changed.added.length || changed.removed.length} + {#if changed.added.length} + added {pluralize("label", changed.added.length)} + {#each changed.added as label} + {label} + {/each} + {/if} + {#if changed.removed.length} + removed {pluralize("label", changed.removed.length)} + {#each changed.removed as label} + {label} + {/each} + {/if} {/if} - {#if changed.removed.length} - removed label{changed.removed.length > 1 ? "s" : ""} - {#each changed.removed as label} - {label} - {/each} - {/if} -
- {formatTimestamp(op.timestamp)} -
+ {:else} + added {pluralize("label", op.labels.length)} + {#each op.labels as label} + {label} + {/each} + {/if} +
+ {formatTimestamp(op.timestamp)}
- {/if} - {:else if op.type === "assign" && op.previous && op.previous.type === op.type} - {@const changed = itemDiff(op.previous?.assignees ?? [], op.assignees)} - {#if changed.added.length || changed.removed.length} -
-
- -
-
- +
+ {:else if op.type === "assign"} +
+
+ +
+
+ + {#if op.previous && op.previous.type === op.type} + {@const changed = itemDiff( + op.previous?.assignees ?? [], + op.assignees, + )} {#if changed.added.length} assigned {#each changed.added as assignee} @@ -207,12 +218,23 @@ {/await} {/each} {/if} -
- {formatTimestamp(op.timestamp)} -
+ {:else} + assigned + {#each op.assignees as assignee} + {#await invoke( "alias", { nid: publicKeyFromDid(assignee) }, ) then alias} + + {/await} + {/each} + {/if} +
+ {formatTimestamp(op.timestamp)}
- {/if} +
{:else if op.type === "merge"}