Skip to content

Commit

Permalink
fix(core): use multiselect prompts for array properties (#13270)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Nov 19, 2022
1 parent 55c20b8 commit 3af70fc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
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

1 comment on commit 3af70fc

@vercel
Copy link

@vercel vercel bot commented on 3af70fc Nov 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx.dev
nx-dev-git-master-nrwl.vercel.app

Please sign in to comment.