From 4ca61d0c3d595c58b46de69a3c3ec4dc8a5946e3 Mon Sep 17 00:00:00 2001 From: Jason Venable Date: Thu, 17 Oct 2024 20:18:19 -0400 Subject: [PATCH] feat(settings): control switching to Output panel when Push-or-deploy-on-save is enabled --- .../salesforcedx-vscode-core/package.json | 5 +++++ .../salesforcedx-vscode-core/package.nls.json | 1 + .../src/commands/deploySourcePath.ts | 13 +++++++++--- .../src/commands/projectDeployStart.ts | 21 ++++++++++++++++--- .../salesforcedx-vscode-core/src/constants.ts | 2 ++ .../src/settings/pushOrDeployOnSave.ts | 9 ++++++-- .../src/settings/salesforceCoreSettings.ts | 5 +++++ .../jest/settings/pushOrDeployOnSave.test.ts | 15 ++++++++++++- 8 files changed, 62 insertions(+), 9 deletions(-) diff --git a/packages/salesforcedx-vscode-core/package.json b/packages/salesforcedx-vscode-core/package.json index 67daab5b771..5ece71f7102 100644 --- a/packages/salesforcedx-vscode-core/package.json +++ b/packages/salesforcedx-vscode-core/package.json @@ -957,6 +957,11 @@ "default": false, "description": "%prefer_deploy_on_save_enabled_description%" }, + "salesforcedx-vscode-core.push-or-deploy-on-save.showOutputPanel": { + "type": "boolean", + "default": false, + "description": "%push_or_deploy_on_save_show_output_panel%" + }, "salesforcedx-vscode-core.detectConflictsAtSync": { "type": "boolean", "default": false, diff --git a/packages/salesforcedx-vscode-core/package.nls.json b/packages/salesforcedx-vscode-core/package.nls.json index 07f8cb656d5..8863b0b6baf 100644 --- a/packages/salesforcedx-vscode-core/package.nls.json +++ b/packages/salesforcedx-vscode-core/package.nls.json @@ -56,6 +56,7 @@ "project_retrieve_start_default_org_text": "SFDX: Pull Source from Default Org", "project_retrieve_start_ignore_conflicts_default_org_text": "SFDX: Pull Source from Default Org and Ignore Conflicts", "push_or_deploy_on_save_enabled_description": "Specifies whether or not to automatically push (for source-tracked orgs) or deploy (for non-source-tracked orgs) when a local source file is saved.", + "push_or_deploy_on_save_show_output_panel": "Specifies whether to switch to the Output panel when a local source file is saved.", "refresh_components_text": "SFDX: Refresh Components", "refresh_types_text": "SFDX: Refresh Types", "rename_lightning_component_text": "SFDX: Rename Component", diff --git a/packages/salesforcedx-vscode-core/src/commands/deploySourcePath.ts b/packages/salesforcedx-vscode-core/src/commands/deploySourcePath.ts index 3a06513c1c8..1ed609c77a4 100644 --- a/packages/salesforcedx-vscode-core/src/commands/deploySourcePath.ts +++ b/packages/salesforcedx-vscode-core/src/commands/deploySourcePath.ts @@ -11,6 +11,7 @@ import { channelService } from '../channels'; import { getConflictMessagesFor } from '../conflict/messages'; import { nls } from '../messages'; import { notificationService } from '../notifications'; +import { salesforceCoreSettings } from '../settings'; import { telemetryService } from '../telemetry'; import { DeployExecutor } from './baseDeployRetrieve'; import { SourcePathChecker } from './retrieveSourcePath'; @@ -19,8 +20,9 @@ import { CompositePostconditionChecker } from './util/compositePostconditionChec import { TimestampConflictChecker } from './util/timestampConflictChecker'; export class LibraryDeploySourcePathExecutor extends DeployExecutor { - constructor() { + constructor(showChannelOutput: boolean = true) { super(nls.localize('deploy_this_source_text'), 'deploy_with_sourcepath'); + this.showChannelOutput = showChannelOutput; } public async getComponents( @@ -36,7 +38,8 @@ export class LibraryDeploySourcePathExecutor extends DeployExecutor { export const deploySourcePaths = async ( sourceUri: vscode.Uri | vscode.Uri[] | undefined, - uris: vscode.Uri[] | undefined + uris: vscode.Uri[] | undefined, + isDeployOnSave?: boolean | undefined ) => { if (!sourceUri) { // When the source is deployed via the command palette, both sourceUri and uris are @@ -70,10 +73,14 @@ export const deploySourcePaths = async ( const messages = getConflictMessagesFor('deploy_with_sourcepath'); if (messages) { + const showOutputPanel = !( + isDeployOnSave && !salesforceCoreSettings.getDeployOnSaveShowOutputPanel() + ); + const commandlet = new SfCommandlet( new SfWorkspaceChecker(), new LibraryPathsGatherer(uris), - new LibraryDeploySourcePathExecutor(), + new LibraryDeploySourcePathExecutor(showOutputPanel), new CompositePostconditionChecker( new SourcePathChecker(), new TimestampConflictChecker(false, messages) diff --git a/packages/salesforcedx-vscode-core/src/commands/projectDeployStart.ts b/packages/salesforcedx-vscode-core/src/commands/projectDeployStart.ts index 1fd864e6403..351b7adfb00 100644 --- a/packages/salesforcedx-vscode-core/src/commands/projectDeployStart.ts +++ b/packages/salesforcedx-vscode-core/src/commands/projectDeployStart.ts @@ -24,6 +24,7 @@ import { PersistentStorageService } from '../conflict'; import { PROJECT_DEPLOY_START_LOG_NAME } from '../constants'; import { handlePushDiagnosticErrors } from '../diagnostics'; import { nls } from '../messages'; +import { salesforceCoreSettings } from '../settings'; import { telemetryService } from '../telemetry'; import { DeployRetrieveExecutor } from './baseDeployRetrieve'; import { @@ -53,10 +54,12 @@ export class ProjectDeployStartExecutor extends SfCommandletExecutor<{}> { private flag: string | undefined; public constructor( flag?: string, - public params: CommandParams = pushCommand + public params: CommandParams = pushCommand, + showChannelOutput: boolean = true ) { super(); this.flag = flag; + this.showChannelOutput = showChannelOutput; } protected getDeployType() { @@ -263,9 +266,21 @@ export class ProjectDeployStartExecutor extends SfCommandletExecutor<{}> { const workspaceChecker = new SfWorkspaceChecker(); const parameterGatherer = new EmptyParametersGatherer(); -export async function projectDeployStart(this: FlagParameter) { +export async function projectDeployStart( + this: FlagParameter, + isDeployOnSave: boolean +) { + const showOutputPanel = !( + isDeployOnSave && !salesforceCoreSettings.getDeployOnSaveShowOutputPanel() + ); + const { flag } = this || {}; - const executor = new ProjectDeployStartExecutor(flag, pushCommand); + const executor = new ProjectDeployStartExecutor( + flag, + pushCommand, + showOutputPanel + ); + const commandlet = new SfCommandlet( workspaceChecker, parameterGatherer, diff --git a/packages/salesforcedx-vscode-core/src/constants.ts b/packages/salesforcedx-vscode-core/src/constants.ts index 09d22522ba6..40dfe130cc2 100644 --- a/packages/salesforcedx-vscode-core/src/constants.ts +++ b/packages/salesforcedx-vscode-core/src/constants.ts @@ -41,6 +41,8 @@ export const PREFER_DEPLOY_ON_SAVE_ENABLED = 'push-or-deploy-on-save.preferDeployOnSave'; export const PUSH_OR_DEPLOY_ON_SAVE_IGNORE_CONFLICTS = 'push-or-deploy-on-save.ignoreConflictsOnPush'; +export const DEPLOY_ON_SAVE_SHOW_OUTPUT_PANEL = + 'push-or-deploy-on-save.showOutputPanel'; export const RETRIEVE_TEST_CODE_COVERAGE = 'retrieve-test-code-coverage'; export const SHOW_CLI_SUCCESS_INFO_MSG = 'show-cli-success-msg'; export const TELEMETRY_ENABLED = 'telemetry.enabled'; diff --git a/packages/salesforcedx-vscode-core/src/settings/pushOrDeployOnSave.ts b/packages/salesforcedx-vscode-core/src/settings/pushOrDeployOnSave.ts index 2a12063752e..b9bdaaefab3 100644 --- a/packages/salesforcedx-vscode-core/src/settings/pushOrDeployOnSave.ts +++ b/packages/salesforcedx-vscode-core/src/settings/pushOrDeployOnSave.ts @@ -67,7 +67,12 @@ export class DeployQueue { } private async executeDeployCommand(toDeploy: vscode.Uri[]) { - vscode.commands.executeCommand('sf.deploy.multiple.source.paths', toDeploy); + await vscode.commands.executeCommand( + 'sf.deploy.multiple.source.paths', + toDeploy, + null, + true + ); } private async executePushCommand() { @@ -76,7 +81,7 @@ export class DeployQueue { ? '.ignore.conflicts' : ''; const command = `sf.project.deploy.start${ignoreConflictsCommand}`; - vscode.commands.executeCommand(command); + vscode.commands.executeCommand(command, true); } private async doDeploy(): Promise { diff --git a/packages/salesforcedx-vscode-core/src/settings/salesforceCoreSettings.ts b/packages/salesforcedx-vscode-core/src/settings/salesforceCoreSettings.ts index 5b4fc87d620..9927338e8e8 100644 --- a/packages/salesforcedx-vscode-core/src/settings/salesforceCoreSettings.ts +++ b/packages/salesforcedx-vscode-core/src/settings/salesforceCoreSettings.ts @@ -19,6 +19,7 @@ import { PREFER_DEPLOY_ON_SAVE_ENABLED, PUSH_OR_DEPLOY_ON_SAVE_ENABLED, PUSH_OR_DEPLOY_ON_SAVE_IGNORE_CONFLICTS, + DEPLOY_ON_SAVE_SHOW_OUTPUT_PANEL, RETRIEVE_TEST_CODE_COVERAGE, SHOW_CLI_SUCCESS_INFO_MSG, TELEMETRY_ENABLED @@ -76,6 +77,10 @@ export class SalesforceCoreSettings { return this.getConfigValue(PREFER_DEPLOY_ON_SAVE_ENABLED, false); } + public getDeployOnSaveShowOutputPanel(): boolean { + return this.getConfigValue(DEPLOY_ON_SAVE_SHOW_OUTPUT_PANEL, false); + } + public getEnableSourceTrackingForDeployAndRetrieve(): boolean { return this.getConfigValue( ENABLE_SOURCE_TRACKING_FOR_DEPLOY_RETRIEVE, diff --git a/packages/salesforcedx-vscode-core/test/jest/settings/pushOrDeployOnSave.test.ts b/packages/salesforcedx-vscode-core/test/jest/settings/pushOrDeployOnSave.test.ts index 703776a146c..a14a00f5343 100644 --- a/packages/salesforcedx-vscode-core/test/jest/settings/pushOrDeployOnSave.test.ts +++ b/packages/salesforcedx-vscode-core/test/jest/settings/pushOrDeployOnSave.test.ts @@ -15,6 +15,7 @@ describe('DeployQueue', () => { let getWorkspaceOrgTypeMock: jest.SpyInstance; let executeDeployCommandSpy: jest.SpyInstance; let executePushCommandSpy: jest.SpyInstance; + let vscodeExecuteCommandSpy: jest.SpyInstance; beforeEach(() => { getPushOrDeployOnSaveEnabledMock = jest.spyOn( @@ -37,10 +38,12 @@ describe('DeployQueue', () => { (DeployQueue as any).prototype, 'executePushCommand' ); + vscodeExecuteCommandSpy = jest.spyOn(vscode.commands, 'executeCommand'); }); afterEach(() => { DeployQueue.reset(); + jest.restoreAllMocks(); }); it('should execute a push command when org type is source-tracked, "Push or deploy on save" is enabled, and "Prefer deploy on save" is disabled', async () => { @@ -53,6 +56,10 @@ describe('DeployQueue', () => { expect(getPreferDeployOnSaveEnabledMock).toHaveBeenCalled(); expect(executePushCommandSpy).toHaveBeenCalled(); expect(executeDeployCommandSpy).not.toHaveBeenCalled(); + expect(vscodeExecuteCommandSpy).toHaveBeenCalledWith( + 'sf.project.deploy.start.ignore.conflicts', + true + ); }); it('should execute a deploy command when "Push or deploy on save" and "Prefer deploy on save" are enabled', async () => { @@ -62,8 +69,14 @@ describe('DeployQueue', () => { await DeployQueue.get().enqueue(vscode.Uri.file('/sample')); expect(getPreferDeployOnSaveEnabledMock).toHaveBeenCalled(); - expect(executeDeployCommandSpy).toHaveBeenCalled(); expect(executePushCommandSpy).not.toHaveBeenCalled(); + expect(executeDeployCommandSpy).toHaveBeenCalled(); + expect(vscodeExecuteCommandSpy).toHaveBeenCalledWith( + 'sf.deploy.multiple.source.paths', + [undefined], + null, + true + ); }); }); });