Skip to content

Commit 56fa86e

Browse files
committed
Fix for concurrency allocation editing across multiple projects
1 parent ef5d30e commit 56fa86e

File tree

1 file changed

+14
-7
lines changed
  • apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.concurrency

1 file changed

+14
-7
lines changed

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.concurrency/route.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ function initialAllocation(environments: ConcurrencyResult["environments"]) {
270270
);
271271
}
272272

273+
function allocationTotal(environments: ConcurrencyResult["environments"]) {
274+
const allocation = initialAllocation(environments);
275+
return Array.from(allocation.values()).reduce((e, acc) => e + acc, 0);
276+
}
277+
273278
function Upgradable({
274279
extraConcurrency,
275280
extraAllocatedConcurrency,
@@ -294,9 +299,11 @@ function Upgradable({
294299

295300
const [allocation, setAllocation] = useState(initialAllocation(environments));
296301

297-
const allocated = Array.from(allocation.values()).reduce((e, acc) => e + acc, 0);
298-
const unallocated = extraConcurrency - allocated;
299-
const allocationModified = allocated !== extraAllocatedConcurrency;
302+
const allocatedInProject = Array.from(allocation.values()).reduce((e, acc) => e + acc, 0);
303+
const initialAllocationInProject = allocationTotal(environments);
304+
const unallocated = extraConcurrency - allocatedInProject;
305+
const changeInAllocation = allocatedInProject - initialAllocationInProject;
306+
const allocationModified = changeInAllocation !== 0;
300307

301308
return (
302309
<div className="flex flex-col gap-3">
@@ -336,10 +343,10 @@ function Upgradable({
336343
<span className="text-text-dimmed line-through">
337344
{extraAllocatedConcurrency}
338345
</span>{" "}
339-
{allocated}
346+
{extraAllocatedConcurrency + changeInAllocation}
340347
</>
341348
) : (
342-
allocated
349+
extraAllocatedConcurrency
343350
)}
344351
</TableCell>
345352
</TableRow>
@@ -360,10 +367,10 @@ function Upgradable({
360367
<span className="text-text-dimmed line-through">
361368
{extraUnallocatedConcurrency}
362369
</span>{" "}
363-
{unallocated}
370+
{extraUnallocatedConcurrency - changeInAllocation}
364371
</>
365372
) : (
366-
unallocated
373+
extraUnallocatedConcurrency
367374
)}
368375
</TableCell>
369376
</TableRow>

0 commit comments

Comments
 (0)