Skip to content

Commit 85670f8

Browse files
Copilotalexr00
andcommitted
Refactor to reduce code duplication in AssignUnassignEventView
Extract joinedAssignees and joinedUnassignees into variables to avoid repeating the joinWithAnd expressions and improve maintainability. Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent e3e5e05 commit 85670f8

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

webviews/components/timeline.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,8 @@ const AssignUnassignEventView = ({ event }: { event: AssignEvent | UnassignEvent
456456
const { actor } = event;
457457
const assignees = (event as AssignEvent).assignees || [];
458458
const unassignees = (event as UnassignEvent).unassignees || [];
459+
const joinedAssignees = joinWithAnd(assignees.map(a => <AuthorLink key={`${a.id}a`} for={a} />));
460+
const joinedUnassignees = joinWithAnd(unassignees.map(a => <AuthorLink key={`${a.id}u`} for={a} />));
459461

460462
// Check if actor is assigning/unassigning themselves
461463
const isSelfAssign = assignees.length === 1 && assignees[0].login === actor.login;
@@ -464,13 +466,13 @@ const AssignUnassignEventView = ({ event }: { event: AssignEvent | UnassignEvent
464466
let message: JSX.Element;
465467
if (assignees.length > 0 && unassignees.length > 0) {
466468
// Handle mixed case with potential self-assignment
467-
const assignMessage = isSelfAssign ? <>assigned themselves</> : <>assigned {joinWithAnd(assignees.map(a => <AuthorLink key={`${a.id}a`} for={a} />))}</>;
468-
const unassignMessage = isSelfUnassign ? <>removed their assignment</> : <>unassigned {joinWithAnd(unassignees.map(a => <AuthorLink key={`${a.id}u`} for={a} />))}</>;
469+
const assignMessage = isSelfAssign ? <>assigned themselves</> : <>assigned {joinedAssignees}</>;
470+
const unassignMessage = isSelfUnassign ? <>removed their assignment</> : <>unassigned {joinedUnassignees}</>;
469471
message = <>{assignMessage} and {unassignMessage}</>;
470472
} else if (assignees.length > 0) {
471-
message = isSelfAssign ? <>assigned themselves</> : <>assigned {joinWithAnd(assignees.map(a => <AuthorLink key={`${a.id}a`} for={a} />))}</>;
473+
message = isSelfAssign ? <>assigned themselves</> : <>assigned {joinedAssignees}</>;
472474
} else {
473-
message = isSelfUnassign ? <>removed their assignment</> : <>unassigned {joinWithAnd(unassignees.map(a => <AuthorLink key={`${a.id}u`} for={a} />))}</>;
475+
message = isSelfUnassign ? <>removed their assignment</> : <>unassigned {joinedUnassignees}</>;
474476
}
475477

476478
return (

0 commit comments

Comments
 (0)