Skip to content

Commit b02ce5a

Browse files
committed
fix(approvals): isolate request comments (WI-967)
1 parent b303534 commit b02ce5a

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

frontend/src/lib/features/items/ApprovalsTimeline.svelte

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121
let requests = $state([]);
2222
let loading = $state(true);
2323
let acting = $state(false);
24-
let comment = $state('');
24+
let commentsByRequest = $state({});
2525
let expandedRequests = $state(new Set());
2626
let lastInitialRequests = null;
2727
2828
function applyRequests(nextRequests) {
2929
requests = nextRequests || [];
30+
commentsByRequest = Object.fromEntries(
31+
requests.map((request) => [request.id, commentsByRequest[request.id] ?? ''])
32+
);
3033
const next = new Set(expandedRequests);
3134
for (const request of requests) if (request.status === 'pending') next.add(request.id);
3235
expandedRequests = next;
@@ -107,8 +110,8 @@
107110
}
108111
acting = true;
109112
try {
110-
await api.approvals.decide(req.id, decision, comment);
111-
comment = '';
113+
await api.approvals.decide(req.id, decision, commentsByRequest[req.id] ?? '');
114+
commentsByRequest[req.id] = '';
112115
successToast(`Decision recorded: ${decision}`);
113116
await load();
114117
ondecisionMade?.(requests);
@@ -130,8 +133,8 @@
130133
if (!ok) return;
131134
acting = true;
132135
try {
133-
await api.approvals.cancel(req.id, comment);
134-
comment = '';
136+
await api.approvals.cancel(req.id, commentsByRequest[req.id] ?? '');
137+
commentsByRequest[req.id] = '';
135138
successToast('Approval cancelled and item returned to previous status');
136139
await load();
137140
ondecisionMade?.(requests);
@@ -272,7 +275,7 @@
272275
Reject
273276
</Button>
274277
<Button variant="default" icon={MessageSquare}
275-
disabled={acting || comment.trim() === ''}
278+
disabled={acting || commentsByRequest[req.id].trim() === ''}
276279
onclick={() => decide(req, 'comment')}
277280
dataTestid="approval-decision-comment-submit">
278281
Comment
@@ -283,7 +286,7 @@
283286
style="border-color: var(--ds-border); background: var(--ds-surface);"
284287
rows="2"
285288
placeholder="Optional comment…"
286-
bind:value={comment}
289+
bind:value={commentsByRequest[req.id]}
287290
data-testid="approval-decision-comment"
288291
></textarea>
289292
</div>

0 commit comments

Comments
 (0)