From 975cb90bbd1f286c7cada731fb056a5bf55f247d Mon Sep 17 00:00:00 2001 From: tal-rofe Date: Sat, 15 Apr 2023 12:45:16 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=94=A5=20support=20fusejs=20on=20?= =?UTF-8?q?scopes=20list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit support fusejs on scopes list, only when scopes are provided with array --- src/utils/questions.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/utils/questions.ts b/src/utils/questions.ts index 19d5317d..e0a19d52 100644 --- a/src/utils/questions.ts +++ b/src/utils/questions.ts @@ -22,6 +22,14 @@ export const getQuestions = async (configuration: IConfiguration) => { keys: ['value', 'emoji', 'description'], }); + const scopesFuse = new fuse(configuration.scopes, { + shouldSort: true, + threshold: 0.4, + location: 0, + distance: 100, + minMatchCharLength: 1, + }); + const shouldValidateTicket = await shouldValidateTicketId(configuration.allowEmptyTicketIdForBranches); return [ @@ -37,14 +45,16 @@ export const getQuestions = async (configuration: IConfiguration) => { ), }, { - type: isScopesListsMode ? 'list' : 'input', + when: !configuration.skipScope, + type: isScopesListsMode ? 'autocomplete' : 'input', name: 'scope', message: configuration.scopeQuestion, - choices: isScopesListsMode ? configuration.scopes : null, - when: !configuration.skipScope, - validate: isScopesListsMode - ? null - : (input: string) => input.length > 0 || 'Scope must be provided', + source: (_: unknown, query: string) => + Promise.resolve( + query + ? scopesFuse.search(query).map((match) => ({ name: match.item, value: match.item })) + : configuration.scopes, + ), }, { type: 'input',