Skip to content

Commit

Permalink
Field Cluster Issue
Browse files Browse the repository at this point in the history
  • Loading branch information
seniorITdev committed Jun 27, 2024
1 parent 9d738c2 commit 37d65e4
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 17 deletions.
90 changes: 75 additions & 15 deletions apps/hpc-ftsadmin/src/app/components/flow-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,51 @@ export const FlowForm = (props: Props) => {
);
}
};

const fetchAssociatedGlobalCluster = async (
objectType: string,
governingEntity: AutoCompleteSelectionType[] | null,
setFieldValue: FormikHelpers<FormValues>['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,
Expand Down Expand Up @@ -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
);
}
}
};
Expand Down Expand Up @@ -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.');
}
Expand Down Expand Up @@ -2134,6 +2176,8 @@ export const FlowForm = (props: Props) => {
sourceOrganizations: fetchOrganizationDetails,
sourceGlobalClusters: fetchAssociatedGoverningEntity,
destinationGlobalClusters: fetchAssociatedGoverningEntity,
sourceGoverningEntities: fetchAssociatedGlobalCluster,
destinationGoverningEntities: fetchAssociatedGlobalCluster,
sourceUsageYears: fetchKeywords,
destinationUsageYears: fetchKeywords,
};
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down
5 changes: 4 additions & 1 deletion libs/hpc-data/src/lib/governing-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -49,4 +49,7 @@ export interface Model {
getAllPlanGoverningEntities(
params: GetGoverningEntityParams
): Promise<GetGoverningEntityResult>;
getGoverningEntities(
params: GetGoverningEntityParams
): Promise<GetGoverningEntityResult>;
}
6 changes: 6 additions & 0 deletions libs/hpc-dummy/src/lib/dummy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 7 additions & 1 deletion libs/hpc-live/src/lib/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 37d65e4

Please sign in to comment.