Skip to content

Commit

Permalink
refactor: Remove unused parameter in initializeOrgDetails function
Browse files Browse the repository at this point in the history
  • Loading branch information
amitjoshi committed Sep 10, 2024
1 parent 6a389f6 commit 332f12c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export class PowerPagesChatParticipant {

private async initializeOrgDetails(): Promise<void> {
try {
const { orgID, orgUrl, environmentID } = await initializeOrgDetails(this.isOrgDetailsInitialized, this.extensionContext, this._pacWrapper);
const { orgID, orgUrl, environmentID } = await initializeOrgDetails(this.isOrgDetailsInitialized, this._pacWrapper);

if (!orgID) {
return;
Expand All @@ -242,7 +242,7 @@ export class PowerPagesChatParticipant {
}

private async handleOrgChangeSuccess(orgDetails: ActiveOrgOutput): Promise<void> {
const { orgID, orgUrl, environmentID } = handleOrgChangeSuccess(orgDetails, this.extensionContext);
const { orgID, orgUrl, environmentID } = handleOrgChangeSuccess(orgDetails);
this.orgID = orgID;
this.orgUrl = orgUrl;
this.environmentID = environmentID;
Expand Down
19 changes: 4 additions & 15 deletions src/common/utilities/OrgHandlerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

import { ExtensionContext } from 'vscode';
import { ActiveOrgOutput } from '../../client/pac/PacTypes';
import { PacWrapper } from '../../client/pac/PacWrapper';
import { IOrgDetails } from '../chat-participants/powerpages/PowerPagesChatParticipantTypes';
Expand All @@ -15,26 +14,22 @@ export const ORG_DETAILS_KEY = 'orgDetails';

export function handleOrgChangeSuccess(
orgDetails: ActiveOrgOutput,
extensionContext: ExtensionContext
): IOrgDetails {
const { OrgId: orgID, OrgUrl: orgUrl, EnvironmentId: environmentID } = orgDetails;

extensionContext.globalState.update(ORG_DETAILS_KEY, { orgID, orgUrl, environmentID });

return { orgID, orgUrl, environmentID };
}

async function fetchOrgDetailsFromPac(pacWrapper: PacWrapper, extensionContext: ExtensionContext): Promise<IOrgDetails> {
async function fetchOrgDetailsFromPac(pacWrapper: PacWrapper): Promise<IOrgDetails> {
const pacActiveOrg = await pacWrapper.activeOrg();
if (pacActiveOrg && pacActiveOrg.Status === SUCCESS) {
return handleOrgChangeSuccess(pacActiveOrg.Results, extensionContext);
return handleOrgChangeSuccess(pacActiveOrg.Results);
}
throw new Error(ERROR_CONSTANTS.PAC_AUTH_FAILED);
}

export async function initializeOrgDetails(
isOrgDetailsInitialized: boolean,
extensionContext: ExtensionContext,
pacWrapper?: PacWrapper
): Promise<IOrgDetails> {
const orgDetails: IOrgDetails = { orgID: '', orgUrl: '', environmentID: '' };
Expand All @@ -43,21 +38,15 @@ export async function initializeOrgDetails(
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 {
const fetchedOrgDetails = await fetchOrgDetailsFromPac(pacWrapper, extensionContext);
const fetchedOrgDetails = await fetchOrgDetailsFromPac(pacWrapper);
orgDetails.orgID = fetchedOrgDetails.orgID;
orgDetails.orgUrl = fetchedOrgDetails.orgUrl;
orgDetails.environmentID = fetchedOrgDetails.environmentID;
} catch (error) {
await createAuthProfileExp(pacWrapper);
const fetchedOrgDetails = await fetchOrgDetailsFromPac(pacWrapper, extensionContext);
const fetchedOrgDetails = await fetchOrgDetailsFromPac(pacWrapper);
orgDetails.orgID = fetchedOrgDetails.orgID;
orgDetails.orgUrl = fetchedOrgDetails.orgUrl;
orgDetails.environmentID = fetchedOrgDetails.environmentID;
Expand Down

0 comments on commit 332f12c

Please sign in to comment.