diff --git a/.changeset/cuddly-icons-lie.md b/.changeset/cuddly-icons-lie.md new file mode 100644 index 0000000000..154e555507 --- /dev/null +++ b/.changeset/cuddly-icons-lie.md @@ -0,0 +1,5 @@ +--- +'@sap-ux/abap-deploy-config-inquirer': minor +--- + +updates options and conditions for prompts diff --git a/packages/abap-deploy-config-inquirer/src/prompts/conditions.ts b/packages/abap-deploy-config-inquirer/src/prompts/conditions.ts index acfa407989..9ab0a57cc4 100644 --- a/packages/abap-deploy-config-inquirer/src/prompts/conditions.ts +++ b/packages/abap-deploy-config-inquirer/src/prompts/conditions.ts @@ -10,6 +10,7 @@ import { PackageInputChoices, TargetSystemType, TransportChoices, + type UI5AbapRepoPromptOptions, type AbapDeployConfigAnswersInternal, type AbapDeployConfigPromptOptions, type BackendTarget, @@ -143,9 +144,14 @@ export function showPasswordQuestion(): boolean { /** * Determines if the UI5 app deploy config question should be shown (UI5 Abap Repo name & Description). * + * @param ui5AbapPromptOptions - UI5 Abap Repo prompt options * @returns boolean */ -export function showUi5AppDeployConfigQuestion(): boolean { +export function showUi5AppDeployConfigQuestion(ui5AbapPromptOptions?: UI5AbapRepoPromptOptions): boolean { + // if hideIfOnPremise option is true and the target system is on-premise, hide the prompt + if (!ui5AbapPromptOptions?.hide && ui5AbapPromptOptions?.hideIfOnPremise && !PromptState.abapDeployConfig?.scp) { + return false; + } return !PromptState.transportAnswers.transportConfigNeedsCreds; } @@ -232,6 +238,9 @@ function defaultOrShowTransportQuestion(): boolean { * @returns boolean */ export function showTransportInputChoice(): boolean { + if (PromptState.transportAnswers.transportRequired === false) { + return false; + } return defaultOrShowTransportQuestion(); } diff --git a/packages/abap-deploy-config-inquirer/src/prompts/questions/config/app.ts b/packages/abap-deploy-config-inquirer/src/prompts/questions/config/app.ts index 10d6843832..548c15bcd5 100644 --- a/packages/abap-deploy-config-inquirer/src/prompts/questions/config/app.ts +++ b/packages/abap-deploy-config-inquirer/src/prompts/questions/config/app.ts @@ -13,7 +13,7 @@ import type { InputQuestion, Question } from 'inquirer'; */ function getUi5AbapRepoPrompt(options: AbapDeployConfigPromptOptions): Question { return { - when: (): boolean => showUi5AppDeployConfigQuestion(), + when: (): boolean => showUi5AppDeployConfigQuestion(options.ui5AbapRepo), type: 'input', name: promptNames.ui5AbapRepo, message: (): string => { @@ -44,7 +44,7 @@ function getUi5AbapRepoPrompt(options: AbapDeployConfigPromptOptions): Question< */ function getDescriptionPrompt(options: AbapDeployConfigPromptOptions): Question { return { - when: (): boolean => showUi5AppDeployConfigQuestion(), + when: (): boolean => showUi5AppDeployConfigQuestion(options.ui5AbapRepo), type: 'input', name: promptNames.description, message: t('prompts.config.app.description.message'), diff --git a/packages/abap-deploy-config-inquirer/src/prompts/validators.ts b/packages/abap-deploy-config-inquirer/src/prompts/validators.ts index b21643bf31..059381cb87 100644 --- a/packages/abap-deploy-config-inquirer/src/prompts/validators.ts +++ b/packages/abap-deploy-config-inquirer/src/prompts/validators.ts @@ -8,6 +8,7 @@ import { isValidUrl, isAppNameValid } from '../validator-utils'; +import { DEFAULT_PACKAGE_ABAP } from '../constants'; import { getTransportListFromService } from '../service-provider-utils'; import { t } from '../i18n'; import { findBackendSystemByUrl, initTransportConfig, getPackageAnswer, queryPackages } from '../utils'; @@ -356,6 +357,10 @@ export async function validatePackage( if (!input?.trim()) { return t('warnings.providePackage'); } + if (input === DEFAULT_PACKAGE_ABAP) { + PromptState.transportAnswers.transportRequired = false; + return true; + } const systemConfig: SystemConfig = { url: PromptState.abapDeployConfig.url, client: PromptState.abapDeployConfig.client, diff --git a/packages/abap-deploy-config-inquirer/src/types.ts b/packages/abap-deploy-config-inquirer/src/types.ts index 91bedb525c..a1a26233c5 100644 --- a/packages/abap-deploy-config-inquirer/src/types.ts +++ b/packages/abap-deploy-config-inquirer/src/types.ts @@ -88,6 +88,10 @@ export type UI5AbapRepoPromptOptions = | { hide?: false; default?: string; + /** + * If set to true, the prompt will be hidden if the target system is on-premise. + */ + hideIfOnPremise?: boolean; } | { hide: true; diff --git a/packages/abap-deploy-config-inquirer/test/prompts/conditions.test.ts b/packages/abap-deploy-config-inquirer/test/prompts/conditions.test.ts index c193b7c164..61f2055d7d 100644 --- a/packages/abap-deploy-config-inquirer/test/prompts/conditions.test.ts +++ b/packages/abap-deploy-config-inquirer/test/prompts/conditions.test.ts @@ -193,6 +193,14 @@ describe('Test abap deploy config inquirer conditions', () => { expect(showUi5AppDeployConfigQuestion()).toBe(true); }); + test('should not show ui5 app deploy config questions', () => { + const promptOptions = { + hideIfOnPremise: true + }; + PromptState.abapDeployConfig.scp = false; + expect(showUi5AppDeployConfigQuestion(promptOptions)).toBe(false); + }); + test('should show package input choice question', () => { // cli PromptState.isYUI = false; diff --git a/packages/abap-deploy-config-inquirer/test/prompts/validators.test.ts b/packages/abap-deploy-config-inquirer/test/prompts/validators.test.ts index 4e6ceb3847..c3aadfde32 100644 --- a/packages/abap-deploy-config-inquirer/test/prompts/validators.test.ts +++ b/packages/abap-deploy-config-inquirer/test/prompts/validators.test.ts @@ -315,6 +315,12 @@ describe('Test validators', () => { const result = await validatePackage(' ', previousAnswers); expect(result).toBe(t('warnings.providePackage')); }); + + it('should return true for default package', async () => { + const result = await validatePackage('$TMP', previousAnswers); + expect(result).toBe(true); + expect(PromptState.transportAnswers.transportRequired).toBe(false); + }); }); describe('validateTransportChoiceInput', () => {