Skip to content

Commit

Permalink
Fix FieldClusters autofill
Browse files Browse the repository at this point in the history
  • Loading branch information
Onitoxan committed Nov 22, 2024
1 parent ea062bd commit cf48d6d
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions apps/hpc-ftsadmin/src/app/utils/fn-autofills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,14 +399,19 @@ export const autofillFieldClusters = async ({
(fieldCluster) => typeof fieldCluster !== 'string'
) as FormObjectValue[];

const globalClusters = await Promise.all(
fieldClusters.map(async (fC) => {
const gE = await env.model.governingEntities.getGoverningEntity({
id: valueToInteger(fC.value),
});
return gE.globalClusters;
// Here we make sure to just take the newly added value
// in case the user removed some of the previously
// auto filled values
const lastFieldClusterAdded = fieldClusters.at(-1);
if (!lastFieldClusterAdded) {
return;
}

const globalClusters = await env.model.governingEntities
.getGoverningEntity({
id: valueToInteger(lastFieldClusterAdded.value),
})
).then((gCs) => gCs.flat());
.then((gE) => gE.globalClusters);

helperSetFieldValue(
fieldName,
Expand Down

0 comments on commit cf48d6d

Please sign in to comment.