From ad328c03f0c6162b4f803d1e44e9ce443aed6653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chalifour?= Date: Fri, 27 Jul 2018 14:21:49 +0200 Subject: [PATCH 1/7] feat(cli): Accept multiple attributes to display BREAKING CHANGE: The option `mainAttribute` has been renamed `attributesToDisplay` and now accepts multiple attributes. Closes #151 --- src/cli/__tests__/isQuestionAsked.test.js | 4 ++-- src/cli/index.js | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/cli/__tests__/isQuestionAsked.test.js b/src/cli/__tests__/isQuestionAsked.test.js index e7c002c52..9a1d45407 100644 --- a/src/cli/__tests__/isQuestionAsked.test.js +++ b/src/cli/__tests__/isQuestionAsked.test.js @@ -42,11 +42,11 @@ test('with valid template should not ask', () => { ).toBe(false); }); -test('with indexName should ask mainAttribute', () => { +test('with indexName should ask attributesToDisplay', () => { expect( isQuestionAsked({ question: { - name: 'mainAttribute', + name: 'attributesToDisplay', }, args: { indexName: 'INDEX_NAME' }, }) diff --git a/src/cli/index.js b/src/cli/index.js index 462826ea1..da6dae209 100755 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -33,8 +33,8 @@ program .option('--api-key ', 'The Algolia search API key') .option('--index-name ', 'The main index of your search') .option( - '--main-attribute ', - 'The main searchable attribute of your index' + '--attributes-to-display ', + 'The attributes of your index to display' ) .option( '--attributes-for-faceting ', @@ -75,6 +75,10 @@ if (!appPath) { const optionsFromArguments = getOptionsFromArguments(options.rawArgs); const appName = optionsFromArguments.name || path.basename(appPath); +const attributesToDisplay = (optionsFromArguments.attributesToDisplay || '') + .split(',') + .filter(Boolean) + .map(x => x.trim()); try { checkAppPath(appPath); @@ -177,10 +181,11 @@ const questions = [ message: 'Index name', }, { - type: 'list', - name: 'mainAttribute', + type: 'checkbox', + name: 'attributesToDisplay', message: 'Attribute to display', suffix: `\n ${chalk.gray('Used to generate the default result template')}`, + pageSize: 10, choices: async answers => [ { name: 'None', @@ -190,7 +195,9 @@ const questions = [ new inquirer.Separator('From your index'), ...(await getAttributesFromIndex(answers)), ], - when: ({ appId, apiKey, indexName }) => appId && apiKey && indexName, + filter: attributes => attributes.filter(Boolean), + when: ({ appId, apiKey, indexName }) => + !attributesToDisplay.length > 0 && appId && apiKey && indexName, }, ].filter(question => isQuestionAsked({ question, args: optionsFromArguments })); @@ -204,6 +211,7 @@ async function run() { options: { ...optionsFromArguments, name: appName, + attributesToDisplay, }, answers: await inquirer.prompt(questions), })), From df54031d87322bc061ecd090d269ada9c08df1b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chalifour?= Date: Fri, 27 Jul 2018 14:22:54 +0200 Subject: [PATCH 2/7] docs(readme): Document `attributesToDisplay` --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f810ec911..c7f4145af 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ $ create-instantsearch-app --help --app-id The application ID --api-key The Algolia search API key --index-name The main index of your search - --main-attribute The main searchable attribute of your index + --attributes-to-display The attributes of your index to display --attributes-for-faceting The attributes for faceting --template