Repository navigation
Ezra/309 unapprove distributions #312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
69d6a0a
ac36cf3
7462a26
587b6bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -317,6 +317,11 @@ export default class AllocationService { | |
| "Cannot transfer items from an approved distribution. Approved distributions are locked." | ||
| ); | ||
| } | ||
| if (allocation.signOffId !== null) { | ||
| throw new ArgumentError( | ||
| "Cannot transfer items that have been signed off." | ||
| ); | ||
| } | ||
|
Comment on lines
+320
to
+324
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new guard correctly prevents transferring signed-off allocations out of a distribution. However, After unapproving such a distribution:
To avoid this stuck state, // In distributionService.ts -> updateDistribution, before db.distribution.update()
if (data.pending === true && currentDistribution.pending === false) {
const signedOffCount = await db.allocation.count({
where: { distributionId, signOffId: { not: null } },
});
if (signedOffCount > 0) {
throw new ArgumentError(
"Cannot unapprove a distribution that has signed-off allocations."
);
}
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. commited these changes as well
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @greptile review
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perfect! The fix is implemented correctly in The implementation:
Combined with the transfer guard in One minor style note: line 672 has inconsistent spacing in The PR is solid! |
||
| } | ||
|
|
||
| if (update.distributionId) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
await promiserejects (e.g. the server returns an error), the lines after it —setIsDropdownOpen(false)andfetchTableData()— will never run. The dropdown will stay open even after the error toast is shown. The same pattern exists inapproveDistribution. Using atry/finallyblock ensures cleanup always happens:The same fix should be applied to
approveDistribution(lines 157–175).Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commited these changes for both approval and unapproval
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@greptile review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix looks good! Both
approveDistributionandunapproveDistributionnow properly use try/finally blocks. The dropdown will close even if the API call fails, which resolves the issue.The implementation is correct -
fetchTableData()stays inside the try block so it only runs on success, which is the right behavior.