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

fix(core): use multiselect prompts for array properties #13270

Merged
merged 1 commit into from Nov 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 41 additions & 2 deletions packages/nx/src/utils/params.spec.ts
Expand Up @@ -1460,7 +1460,7 @@ describe('params', () => {
]);
});

it('should use an multiselect prompt for x-prompts with items', () => {
it('should use a multiselect prompt for x-prompts with items', () => {
const prompts = getPromptsForSchema(
{},
{
Expand Down Expand Up @@ -1492,7 +1492,46 @@ describe('params', () => {
]);
});

it('should use an multiselect prompt for x-prompts with items', () => {
it('should use a multiselect prompt for array properties', () => {
const prompts = getPromptsForSchema(
{},
{
properties: {
pets: {
type: 'array',
'x-prompt': {
type: 'list',
message: 'What kind of pets do you have?',
items: [
{ label: 'Cat', value: 'cat' },
{ label: 'Dog', value: 'dog' },
{ label: 'Fish', value: 'fish' },
],
},
},
},
},
{
version: 2,
projects: {},
}
);

expect(prompts).toEqual([
{
type: 'multiselect',
name: 'pets',
message: 'What kind of pets do you have?',
choices: [
{ message: 'Cat', name: 'cat' },
{ message: 'Dog', name: 'dog' },
{ message: 'Fish', name: 'fish' },
],
},
]);
});

it('should use a multiselect prompt for x-prompts with items', () => {
const prompts = getPromptsForSchema(
{},
{
Expand Down
7 changes: 4 additions & 3 deletions packages/nx/src/utils/params.ts
Expand Up @@ -770,9 +770,10 @@ export function getPromptsForSchema(
question.type = 'confirm';
} else if (v['x-prompt'].items) {
question.message = v['x-prompt'].message;
question.type = v['x-prompt'].multiselect
? 'multiselect'
: 'autocomplete';
question.type =
v['x-prompt'].multiselect || v.type === 'array'
? 'multiselect'
: 'autocomplete';
question.choices =
v['x-prompt'].items &&
v['x-prompt'].items.map((item) => {
Expand Down