|
21 | 21 | let requests = $state([]); |
22 | 22 | let loading = $state(true); |
23 | 23 | let acting = $state(false); |
24 | | - let comment = $state(''); |
| 24 | + let commentsByRequest = $state({}); |
25 | 25 | let expandedRequests = $state(new Set()); |
26 | 26 | let lastInitialRequests = null; |
27 | 27 |
|
28 | 28 | function applyRequests(nextRequests) { |
29 | 29 | requests = nextRequests || []; |
| 30 | + commentsByRequest = Object.fromEntries( |
| 31 | + requests.map((request) => [request.id, commentsByRequest[request.id] ?? '']) |
| 32 | + ); |
30 | 33 | const next = new Set(expandedRequests); |
31 | 34 | for (const request of requests) if (request.status === 'pending') next.add(request.id); |
32 | 35 | expandedRequests = next; |
|
107 | 110 | } |
108 | 111 | acting = true; |
109 | 112 | 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] = ''; |
112 | 115 | successToast(`Decision recorded: ${decision}`); |
113 | 116 | await load(); |
114 | 117 | ondecisionMade?.(requests); |
|
130 | 133 | if (!ok) return; |
131 | 134 | acting = true; |
132 | 135 | 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] = ''; |
135 | 138 | successToast('Approval cancelled and item returned to previous status'); |
136 | 139 | await load(); |
137 | 140 | ondecisionMade?.(requests); |
|
272 | 275 | Reject |
273 | 276 | </Button> |
274 | 277 | <Button variant="default" icon={MessageSquare} |
275 | | - disabled={acting || comment.trim() === ''} |
| 278 | + disabled={acting || commentsByRequest[req.id].trim() === ''} |
276 | 279 | onclick={() => decide(req, 'comment')} |
277 | 280 | dataTestid="approval-decision-comment-submit"> |
278 | 281 | Comment |
|
283 | 286 | style="border-color: var(--ds-border); background: var(--ds-surface);" |
284 | 287 | rows="2" |
285 | 288 | placeholder="Optional comment…" |
286 | | - bind:value={comment} |
| 289 | + bind:value={commentsByRequest[req.id]} |
287 | 290 | data-testid="approval-decision-comment" |
288 | 291 | ></textarea> |
289 | 292 | </div> |
|
0 commit comments