diff --git a/apps/hpc-ftsadmin/src/app/components/flow-form.tsx b/apps/hpc-ftsadmin/src/app/components/flow-form.tsx index d164f598b..ab45e0758 100644 --- a/apps/hpc-ftsadmin/src/app/components/flow-form.tsx +++ b/apps/hpc-ftsadmin/src/app/components/flow-form.tsx @@ -1797,6 +1797,51 @@ export const FlowForm = (props: Props) => { ); } }; + + const fetchAssociatedGlobalCluster = async ( + objectType: string, + governingEntity: AutoCompleteSelectionType[] | null, + setFieldValue: FormikHelpers['setFieldValue'], + values: FormValues + ) => { + if ( + (values.sourcePlans.length === 0 && + objectType === 'sourceGoverningEntities') || + (values.destinationPlans.length === 0 && + objectType === 'destinationGoverningEntities') + ) { + return; + } + const governingEntityId = Number( + governingEntity && governingEntity[0]?.value + ); + + if (isNaN(governingEntityId)) { + throw new Error(`Invalid governing entity value: ${governingEntityId}`); + } + try { + const fetchedGlobalCluster = + await env.model.governingEntities.getGoverningEntities({ + id: governingEntityId, + }); + if (fetchedGlobalCluster) { + setObjectsWithArray( + fetchedGlobalCluster, + [ + objectType === 'sourceGoverningEntities' + ? 'sourceGlobalClusters' + : 'destinationGlobalClusters', + ], + ['globalClusters'], + setFieldValue, + values + ); + } + } catch (error) { + console.error('Error fetching governing entity:', error); + } + }; + const fetchAssociatedGoverningEntity = async ( objectType: string, globalCluster: AutoCompleteSelectionType[] | null, @@ -1855,26 +1900,24 @@ export const FlowForm = (props: Props) => { function (governingEntity) { return ( governingEntity.globalClusterIds.indexOf( - globalCluster[globalCluster.length - 1].value.toString() + globalCluster[globalCluster.length - 1].value ) > -1 ); } ); if (governingEntities.length) { - governingEntities.forEach(function (governingEntity) { - setObjectsWithArray( - { governingEntities: governingEntity }, - [ - objectType === 'sourceGlobalClusters' - ? 'sourceGoverningEntities' - : 'destinationGoverningEntities', - ], - ['governingEntities'], - setFieldValue, - values - ); - }); + setObjectsWithArray( + { governingEntities }, + [ + objectType === 'sourceGlobalClusters' + ? 'sourceGoverningEntities' + : 'destinationGoverningEntities', + ], + ['governingEntities'], + setFieldValue, + values + ); } } }; @@ -2059,7 +2102,6 @@ export const FlowForm = (props: Props) => { updateUploadedFile[index] = responseData; return updateUploadedFile; }); - console.log(uploadedFileArray, 'uploadedFileArray'); } else { console.error('No file selected for upload.'); } @@ -2134,6 +2176,8 @@ export const FlowForm = (props: Props) => { sourceOrganizations: fetchOrganizationDetails, sourceGlobalClusters: fetchAssociatedGoverningEntity, destinationGlobalClusters: fetchAssociatedGoverningEntity, + sourceGoverningEntities: fetchAssociatedGlobalCluster, + destinationGoverningEntities: fetchAssociatedGlobalCluster, sourceUsageYears: fetchKeywords, destinationUsageYears: fetchKeywords, }; @@ -2934,6 +2978,14 @@ export const FlowForm = (props: Props) => { optionsData={sourceGoverningEntities} // fnPromise={environment.model.governingEntities.getAllPlanGoverningEntities} isMulti + onChange={(event, value) => { + updateFlowObjects( + event, + value, + setFieldValue, + values + ); + }} behavior={FORM_SETTINGS.governingEntity.behavior} isAutocompleteAPI={false} entryInfo={inputEntries.sourceGoverningEntities} @@ -3054,6 +3106,14 @@ export const FlowForm = (props: Props) => { label={st.t(lang, (s) => s.flowForm.fieldCluster)} name="destinationGoverningEntities" optionsData={destinationGoverningEntities} + onChange={(event, value) => { + updateFlowObjects( + event, + value, + setFieldValue, + values + ); + }} isMulti behavior={FORM_SETTINGS.governingEntity.behavior} isAutocompleteAPI={false} diff --git a/libs/hpc-data/src/lib/governing-entity.ts b/libs/hpc-data/src/lib/governing-entity.ts index 2a87a8954..495394f49 100644 --- a/libs/hpc-data/src/lib/governing-entity.ts +++ b/libs/hpc-data/src/lib/governing-entity.ts @@ -24,7 +24,7 @@ export const GOVERNING_ENTITY_DETAIL = t.type({ entityPrototypeId: t.number, entityType: t.string, governingEntityVersion: GoverningEntityVersion, - globalClusterIds: t.array(t.string), + globalClusterIds: t.array(t.union([t.string, t.number])), latestTaggedVersion: t.boolean, latestVersion: t.boolean, planId: t.number, @@ -49,4 +49,7 @@ export interface Model { getAllPlanGoverningEntities( params: GetGoverningEntityParams ): Promise; + getGoverningEntities( + params: GetGoverningEntityParams + ): Promise; } diff --git a/libs/hpc-dummy/src/lib/dummy.ts b/libs/hpc-dummy/src/lib/dummy.ts index 3ea977c00..86a2a5c11 100644 --- a/libs/hpc-dummy/src/lib/dummy.ts +++ b/libs/hpc-dummy/src/lib/dummy.ts @@ -1046,6 +1046,12 @@ export class Dummy { throw new errors.NotFoundError(); } ), + getGoverningEntities: dummyEndpoint( + 'governingEntities.getGoverningEntities', + async (params: governingEntities.GetGoverningEntityParams) => { + throw new errors.NotFoundError(); + } + ), }, locations: { getAutocompleteLocations: dummyEndpoint( diff --git a/libs/hpc-live/src/lib/model.ts b/libs/hpc-live/src/lib/model.ts index 06d0879af..7717c8e8c 100644 --- a/libs/hpc-live/src/lib/model.ts +++ b/libs/hpc-live/src/lib/model.ts @@ -800,10 +800,16 @@ export class LiveModel implements Model { pathname: `/v1/governingEntity`, queryParams: { excludeAttachments: 'true', - planId: id.toString(), + planId: id.id.toString(), }, resultType: governingEntities.GET_GOVERNING_ENTITIES_RESULT, }), + getGoverningEntities: (id) => + this.call({ + method: 'GET', + pathname: `/v1/governingEntity/${id.id.toString()}`, + resultType: governingEntities.GET_GOVERNING_ENTITIES_RESULT, + }), }; } get locations(): locations.Model {