From 428b378c61fcf8f1d6af0abbb76c262b4255a0ab Mon Sep 17 00:00:00 2001 From: soridalac Date: Tue, 17 Dec 2024 10:21:21 -0800 Subject: [PATCH] fix: mso --- src/commands/org/create/sandbox.ts | 76 +++++++++++++++--------------- src/shared/sandboxCommandBase.ts | 73 ++++++++++++++++++++++------ 2 files changed, 97 insertions(+), 52 deletions(-) diff --git a/src/commands/org/create/sandbox.ts b/src/commands/org/create/sandbox.ts index 217a7e25..dad5d0de 100644 --- a/src/commands/org/create/sandbox.ts +++ b/src/commands/org/create/sandbox.ts @@ -6,7 +6,6 @@ */ import { Duration } from '@salesforce/kit'; -import { MultiStageOutput } from '@oclif/multi-stage-output'; import { Flags } from '@salesforce/sf-plugins-core'; import { Lifecycle, Messages, SandboxEvents, SandboxRequest, SfError } from '@salesforce/core'; import { Interfaces } from '@oclif/core'; @@ -192,51 +191,52 @@ export default class CreateSandbox extends SandboxCommandBase({ - stages: this.flags.async - ? ['Prepare request', 'Send request', 'Done'] - : ['Prepare request', 'Send request', 'Waiting for org to respond', 'Done'], - title: this.flags.async ? 'Create Sandbox (async)' : 'Create Sandbox', - jsonEnabled: false, - postStagesBlock: [ - { - label: 'Sandbox ID', - get: (data) => data?.id, - type: 'dynamic-key-value', - bold: true, - }, - { - label: 'Status', - get: (data) => data?.status, - type: 'dynamic-key-value', - bold: true, - }, - ], + this.registerLifecycleListeners(lifecycle, { + isAsync: this.flags.async, + setDefault: this.flags['set-default'], + alias: this.flags.alias, + prodOrg: this.prodOrg, + tracksSource: this.flags['no-track-source'] === true ? false : undefined, }); - - mso.goto('Prepare request', { status: 'Pending' }); + // const mso = new MultiStageOutput<{ status: string; id: string }>({ + // stages: this.flags.async + // ? ['Prepare request', 'Send request', 'Done'] + // : ['Prepare request', 'Send request', 'Waiting for org to respond', 'Done'], + // title: this.flags.async ? 'Create Sandbox (async)' : 'Create Sandbox', + // jsonEnabled: false, + // postStagesBlock: [ + // { + // label: 'Sandbox ID', + // get: (data) => data?.id, + // type: 'dynamic-key-value', + // bold: true, + // }, + // { + // label: 'Status', + // get: (data) => data?.status, + // type: 'dynamic-key-value', + // bold: true, + // }, + // ], + // }); + + // this.mso.goto('Prepare request', { status: 'Pending' }); if (!this.flags.async) { - mso.skipTo('Sandbox Create', { status: 'Pending' }); + this.spinner.start('Sandbox Create'); + // this.mso.skipTo('Sandbox Create', { status: 'Pending' }); } this.debug('Calling create with SandboxRequest: %s ', sandboxReq); try { - mso.goto('Send request', { status: 'In Progress' }); + // this.mso.goto('Send request', { status: 'In Progress' }); const sandboxProcessObject = await this.prodOrg.createSandbox(sandboxReq, { wait: this.flags.wait, interval: this.flags['poll-interval'], @@ -244,21 +244,21 @@ export default class CreateSandbox extends SandboxCommandBase extends SfCommand { : this.constructor.name === 'CreateSandbox' ? 'Create' : 'Create/Refresh'; + this.sandboxProgress = new SandboxProgress({ action: this.action }); } protected async getSandboxRequestConfig(): Promise { @@ -89,6 +96,34 @@ export abstract class SandboxCommandBase extends SfCommand { lifecycle: Lifecycle, options: { isAsync: boolean; alias?: string; setDefault?: boolean; prodOrg?: Org; tracksSource?: boolean } ): void { + const mso = new MultiStageOutput({ + stages: ['Creating new sandbox', 'Authenticating'], + title: 'Create Sandbox', + jsonEnabled: false, + postStagesBlock: [ + { + label: 'Sandbox ID', + get: (data): string | undefined => data?.id, + type: 'dynamic-key-value', + bold: true, + }, + { + label: 'Status', + get: (data): string | undefined => data?.status, + type: 'dynamic-key-value', + bold: true, + }, + { + label: 'Copy Progress', + get: (data): string | undefined => { + if (data?.sandboxStatus.sandboxProcessObj.CopyProgress) + return `${data?.sandboxStatus.sandboxProcessObj.CopyProgress}`; + }, + type: 'dynamic-key-value', + bold: true, + }, + ], + }); lifecycle.on('POLLING_TIME_OUT', async () => { this.pollingTimeOut = true; this.warn('Sandbox creation process time out.'); @@ -97,6 +132,7 @@ export abstract class SandboxCommandBase extends SfCommand { const sandboxId = this.latestSandboxProgressObj.Id; if (sandboxId) { this.info(`Sandbox ID: ${sandboxId}`); + mso.updateData({ status: this.latestSandboxProgressObj.Status }); } } return Promise.resolve(this.updateSandboxRequestData()); @@ -114,7 +150,7 @@ export abstract class SandboxCommandBase extends SfCommand { this.latestSandboxProgressObj = results ?? this.latestSandboxProgressObj; this.updateSandboxRequestData(); if (!options.isAsync) { - this.spinner.stop(); + // this.spinner.stop(); } // things that require data on latestSandboxProgressObj if (this.latestSandboxProgressObj) { @@ -124,7 +160,7 @@ export abstract class SandboxCommandBase extends SfCommand { }); const currentStage = progress.status; this.sandboxProgress.markPreviousStagesAsCompleted(currentStage); - this.updateStage(currentStage, 'inProgress'); + // this.updateStage(currentStage, 'inProgress'); this.updateProgress( { sandboxProcessObj: this.latestSandboxProgressObj, sandboxRes: undefined }, options.isAsync @@ -140,15 +176,15 @@ export abstract class SandboxCommandBase extends SfCommand { lifecycle.on(SandboxEvents.EVENT_STATUS, async (results: StatusEvent) => { this.latestSandboxProgressObj = results.sandboxProcessObj; const sandboxId = this.latestSandboxProgressObj?.Id; - + // results.sandboxProcessObj.Status; if (sandboxId) { this.info(`Sandbox ID: ${sandboxId}`); } this.updateSandboxRequestData(); - const progress = this.sandboxProgress.getSandboxProgress(results); - const currentStage = progress.status; - this.updateStage(currentStage, 'inProgress'); + // const progress = this.sandboxProgress.getSandboxProgress(results); + // const currentStage = progress.status; + // this.updateStage(currentStage, 'inProgress'); return Promise.resolve(this.updateProgress(results, options.isAsync)); }); @@ -231,16 +267,25 @@ export abstract class SandboxCommandBase extends SfCommand { sandboxProcessObj: event.sandboxProcessObj, }; if (!isAsync) { - this.spinner.status = this.sandboxProgress.formatProgressStatus(); + // this.spinner.status = this.sandboxProgress.formatProgressStatus(); } - } - protected updateStage(stage: string | undefined, state: State): void { - if (stage) { - this.sandboxProgress.transitionStages(stage, state); - } + // Dynamically update MultiStageOutput status + // const currentStage = this.sandboxProgress.getSandboxProgress(event)?.status; + // this.mso.updateStage(currentStage, 'inProgress'); + + // if (event.sandboxProcessObj) { + // this.mso.updateProgress(event.sandboxProcessObj, true); + // } } + // protected updateStage(stage: string | undefined, state: State): void { + // if (stage) { + // this.sandboxProgress.transitionStages(stage, state); + // this.mso.updateData(stage, state); + // } + // } + protected updateSandboxRequestData(): void { if (this.sandboxRequestData && this.latestSandboxProgressObj) { this.sandboxRequestData.sandboxProcessObject = this.latestSandboxProgressObj;