Skip to content

Commit

Permalink
refactor: Initialize organization details in OrgHandlerUtils
Browse files Browse the repository at this point in the history
This commit refactors the `initializeOrgDetails` function in `OrgHandlerUtils.ts` to improve the initialization of organization details. It now retrieves stored organization details from the global state and returns them if available. If not, it uses the PAC wrapper to fetch the organization details and stores them in the global state for future use. This change enhances the efficiency and reliability of the organization details initialization process.
  • Loading branch information
amitjoshi committed Sep 4, 2024
1 parent 2b78c94 commit 5cbd1fa
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/common/utilities/OrgHandlerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,32 @@ export async function initializeOrgDetails(
extensionContext: ExtensionContext,
pacWrapper?: PacWrapper
): Promise<IOrgDetails> {
const orgDetails: IOrgDetails = { orgID: '', orgUrl: '', environmentID: '' };

if (isOrgDetailsInitialized) {
return { orgID: '', orgUrl: '', environmentID: '' };
return orgDetails;
}

const orgDetails: IOrgDetails | undefined = extensionContext.globalState.get(ORG_DETAILS_KEY);
if (orgDetails && orgDetails.orgID && orgDetails.orgUrl && orgDetails.environmentID) {
return orgDetails;
// Get stored organization details from global state
const storedOrgDetails: IOrgDetails | undefined = extensionContext.globalState.get(ORG_DETAILS_KEY);
if (storedOrgDetails && storedOrgDetails.orgID && storedOrgDetails.orgUrl && storedOrgDetails.environmentID) {
return storedOrgDetails;
}

if (pacWrapper) {
try {
return await fetchOrgDetailsFromPac(pacWrapper, extensionContext);
const fetchedOrgDetails = await fetchOrgDetailsFromPac(pacWrapper, extensionContext);
orgDetails.orgID = fetchedOrgDetails.orgID;
orgDetails.orgUrl = fetchedOrgDetails.orgUrl;
orgDetails.environmentID = fetchedOrgDetails.environmentID;
} catch (error) {
await createAuthProfileExp(pacWrapper);
return await fetchOrgDetailsFromPac(pacWrapper, extensionContext);
const fetchedOrgDetails = await fetchOrgDetailsFromPac(pacWrapper, extensionContext);
orgDetails.orgID = fetchedOrgDetails.orgID;
orgDetails.orgUrl = fetchedOrgDetails.orgUrl;
orgDetails.environmentID = fetchedOrgDetails.environmentID;
}
}

return { orgID: '', orgUrl: '', environmentID: '' };
return orgDetails;
}

0 comments on commit 5cbd1fa

Please sign in to comment.