Skip to content

Commit bfdb06e

Browse files
committed
fix(add-search-doc): Ask for state machine then label
Makes more sense that way around
1 parent 3afb68a commit bfdb06e

5 files changed

Lines changed: 27 additions & 12 deletions

File tree

lib/actions/add-search-doc/index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,21 @@ async function * gatherLaunch (stateMachines) {
121121
console.log(c.bold('Launches'))
122122

123123
while (true) {
124-
const title = await ask({
125-
message: 'Launch label (hit Enter to quit)'
126-
})
127-
if (!title) {
128-
return
129-
}
130-
131124
const stateMachine = await ask({
132125
type: 'autocomplete',
126+
allowNone: true,
133127
message: 'State machine to launch',
134128
choices: stateMachines
135129
})
136130

131+
if (!stateMachine) {
132+
return
133+
}
134+
135+
const title = await ask({
136+
message: 'Launch label'
137+
})
138+
137139
yield {
138140
title,
139141
stateMachine

lib/actions/util/ask.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const { prompt } = require('enquirer')
22

33
async function ask (question) {
4+
const None = '--NONE--'
5+
46
if (!question.type) {
57
question.type = 'input'
68
}
@@ -10,8 +12,19 @@ async function ask (question) {
1012
if (question.multiple && !question.hint) {
1113
question.hint = '(Use <space> to select, <return> to submit)'
1214
}
13-
const selection = await prompt(question)
14-
return selection[question.name]
15+
if (question.type === 'autocomplete' && question.allowNone) {
16+
question.choices = [
17+
{
18+
name: 'None',
19+
hint: `(select to exit)`,
20+
value: None
21+
},
22+
...question.choices
23+
]
24+
}
25+
26+
const selection = (await prompt(question))[question.name]
27+
return (selection !== None) ? selection : null
1528
} // ask
1629

1730
module.exports = ask

test/add-search-doc-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ describe('tymly add-search-doc', () => {
3434
// '', // addition fields -> select none of them
3535
helpers.down, // categories - select pizza
3636
helpers.down + helpers.down + ' ' + helpers.down + ' ', // roles - select chef and customer
37+
helpers.down + helpers.down, // select view state machine
3738
'View',
38-
helpers.down, // select view state machine
3939
'',
4040
'yes-boys' // accept default filename
4141
],

test/fixtures/add-search-doc/expected/multiple-everything/search-docs/yes-boys.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"domain": "'search'::text",
77
"docType": "'wmfs_pizza'::text",
88
"title": "label::text",
9-
"description": "code::text || ' ' || label::text",
9+
"description": "concat(code::text, ' ', label::text)",
1010
"additionalTerms": "NULL::text[]",
1111
"category": "'pizza'::text",
1212
"eventTimestamp": "NULL::timestamp with time zone",

test/fixtures/add-search-doc/expected/path-to-external-model/search-docs/drinks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"domain": "'search'::text",
77
"docType": "'wmfs_drinks'::text",
88
"title": "label::text",
9-
"description": "code::text || ' ' || label::text",
9+
"description": "concat(code::text, ' ', label::text)",
1010
"additionalTerms": "NULL::text[]",
1111
"category": "'pizza'::text",
1212
"eventTimestamp": "NULL::timestamp with time zone",

0 commit comments

Comments
 (0)