Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(abap-inq): updates abap inquirer options and conditions #2571

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cuddly-icons-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sap-ux/abap-deploy-config-inquirer': minor
---

updates options and conditions for prompts
11 changes: 10 additions & 1 deletion packages/abap-deploy-config-inquirer/src/prompts/conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
PackageInputChoices,
TargetSystemType,
TransportChoices,
type UI5AbapRepoPromptOptions,
type AbapDeployConfigAnswersInternal,
type AbapDeployConfigPromptOptions,
type BackendTarget,
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -232,6 +238,9 @@ function defaultOrShowTransportQuestion(): boolean {
* @returns boolean
*/
export function showTransportInputChoice(): boolean {
if (PromptState.transportAnswers.transportRequired === false) {
return false;
}
return defaultOrShowTransportQuestion();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { InputQuestion, Question } from 'inquirer';
*/
function getUi5AbapRepoPrompt(options: AbapDeployConfigPromptOptions): Question<AbapDeployConfigAnswersInternal> {
return {
when: (): boolean => showUi5AppDeployConfigQuestion(),
when: (): boolean => showUi5AppDeployConfigQuestion(options.ui5AbapRepo),
type: 'input',
name: promptNames.ui5AbapRepo,
message: (): string => {
Expand Down Expand Up @@ -44,7 +44,7 @@ function getUi5AbapRepoPrompt(options: AbapDeployConfigPromptOptions): Question<
*/
function getDescriptionPrompt(options: AbapDeployConfigPromptOptions): Question<AbapDeployConfigAnswersInternal> {
return {
when: (): boolean => showUi5AppDeployConfigQuestion(),
when: (): boolean => showUi5AppDeployConfigQuestion(options.ui5AbapRepo),
type: 'input',
name: promptNames.description,
message: t('prompts.config.app.description.message'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions packages/abap-deploy-config-inquirer/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Loading