From f8c34521228460ffa72912012585acdbb6e40286 Mon Sep 17 00:00:00 2001 From: Alexander Bolotskov Date: Wed, 25 Dec 2019 01:06:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20adds=20a=20feature=20to?= =?UTF-8?q?=20search=20for=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Works same as the scopes searching - just start typing --- lib/questions/scope.js | 3 +-- lib/questions/type.js | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/questions/scope.js b/lib/questions/scope.js index 23f1a306..69a66a8c 100644 --- a/lib/questions/scope.js +++ b/lib/questions/scope.js @@ -1,5 +1,5 @@ /** - * Searches for the scopes starting with the given substring. + * Searches for the scopes containing the given substring. * * @param {string} substring Substring to search with. * @param {string[]} scopes Scopes list. @@ -26,7 +26,6 @@ exports.createQuestion = (state) => { } const question = { - choices: scopes, message: 'Select the scope this component affects:', name: 'scope', source: (_answers, input) => findScope(input, scopes), diff --git a/lib/questions/type.js b/lib/questions/type.js index 891c0c0c..12296755 100644 --- a/lib/questions/type.js +++ b/lib/questions/type.js @@ -10,13 +10,30 @@ const typeToListItem = ({types, disableEmoji}, type) => { }; }; +/** + * Searches for the type that includes the given substring. + * + * @param {string} substring Substring to search with. + * @param {string[]} config The whole config. + */ +const findType = function (substring, config) { + const input = (substring || '').toLowerCase(); + let foundTypes = config.list; + + if (input !== '') { + foundTypes = config.list.filter((type) => type.toLowerCase().includes(input)); + } + + return Promise.resolve(foundTypes.map((type) => typeToListItem(config, type))) +}; + exports.createQuestion = (state) => { const {config} = state; const question = { - choices: config.list.map((type) => typeToListItem(config, type)), message: 'Select the type of change that you\'re committing:', name: 'type', - type: 'list' + source: (_answers, input) => findType(input, config), + type: 'autocomplete' }; return question;