Skip to content

Commit

Permalink
fix(core): use multiselect prompts for array properties
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Nov 18, 2022
1 parent 33154c3 commit b09782a
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

0 comments on commit b09782a

Please sign in to comment.