From a105b7059095c4e959024df47523c8ee022e3caf Mon Sep 17 00:00:00 2001 From: Catherine Liu Date: Thu, 12 Sep 2019 11:30:15 -0700 Subject: [PATCH] [Canvas] Adds support for uppercase cluster names in esdocs and other datasource bug fixes (#44311) (#45035) * Sets index argument value as default index when index is not provided * Checks if default index exists before retrieving the index pattern saved object * Removed toLowerCase on index names * Removed lower casing of index names --- .../canvas_plugin_src/functions/server/esdocs.ts | 4 ++-- .../components/es_index_select/es_index_select.js | 2 +- .../public/expression_types/datasources/esdocs.js | 8 ++++++-- .../plugins/canvas/public/lib/es_service.js | 15 ++++++++++----- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/x-pack/legacy/plugins/canvas/canvas_plugin_src/functions/server/esdocs.ts b/x-pack/legacy/plugins/canvas/canvas_plugin_src/functions/server/esdocs.ts index fb118c841fffa..3dcc6807724b4 100644 --- a/x-pack/legacy/plugins/canvas/canvas_plugin_src/functions/server/esdocs.ts +++ b/x-pack/legacy/plugins/canvas/canvas_plugin_src/functions/server/esdocs.ts @@ -81,7 +81,7 @@ export function esdocs(): ExpressionFunction<'esdocs', Filter, Arguments, any> { }); if (index) { - query.from(index.toLowerCase()); + query.from(index); } if (fields) { @@ -92,7 +92,7 @@ export function esdocs(): ExpressionFunction<'esdocs', Filter, Arguments, any> { if (sort) { const [sortField, sortOrder] = sort.split(',').map(str => str.trim()); if (sortField) { - query.order(`"${sortField}"`, sortOrder.toLowerCase() === 'asc'); + query.order(`"${sortField}"`, sortOrder === 'asc'); } } diff --git a/x-pack/legacy/plugins/canvas/public/components/es_index_select/es_index_select.js b/x-pack/legacy/plugins/canvas/public/components/es_index_select/es_index_select.js index eff835e84e411..edc4506f20bda 100644 --- a/x-pack/legacy/plugins/canvas/public/components/es_index_select/es_index_select.js +++ b/x-pack/legacy/plugins/canvas/public/components/es_index_select/es_index_select.js @@ -18,7 +18,7 @@ export const ESIndexSelect = ({ value, loading, indices, onChange, onFocus, onBl return ( onChange(get(index, 'label', defaultIndex).toLowerCase())} + onChange={([index]) => onChange(get(index, 'label', defaultIndex))} onSearchChange={searchValue => { // resets input when user starts typing if (searchValue) { diff --git a/x-pack/legacy/plugins/canvas/public/expression_types/datasources/esdocs.js b/x-pack/legacy/plugins/canvas/public/expression_types/datasources/esdocs.js index ead7f58a851ba..ced1c51496d46 100644 --- a/x-pack/legacy/plugins/canvas/public/expression_types/datasources/esdocs.js +++ b/x-pack/legacy/plugins/canvas/public/expression_types/datasources/esdocs.js @@ -35,7 +35,7 @@ const EsdocsDatasource = ({ args, updateArgs, defaultIndex }) => { }; const getIndex = () => { - return getSimpleArg('index', args)[0] || defaultIndex; + return getSimpleArg('index', args)[0] || ''; }; const getQuery = () => { @@ -58,7 +58,11 @@ const EsdocsDatasource = ({ args, updateArgs, defaultIndex }) => { const fields = getFields(); const [sortField, sortOrder] = getSortBy(); - const index = getIndex().toLowerCase(); + const index = getIndex(); + + if (!index && defaultIndex) { + setArg('index', defaultIndex); + } const sortOptions = [{ value: 'asc', text: 'Ascending' }, { value: 'desc', text: 'Descending' }]; diff --git a/x-pack/legacy/plugins/canvas/public/lib/es_service.js b/x-pack/legacy/plugins/canvas/public/lib/es_service.js index d94ef0d518a06..6a6f4073b065a 100644 --- a/x-pack/legacy/plugins/canvas/public/lib/es_service.js +++ b/x-pack/legacy/plugins/canvas/public/lib/es_service.js @@ -42,8 +42,13 @@ export const getIndices = () => }) .catch(err => notify.error(err, { title: `Couldn't fetch Elasticsearch indices` })); -export const getDefaultIndex = () => - savedObjectsClient - .get('index-pattern', AdvancedSettings.get('defaultIndex')) - .then(defaultIndex => defaultIndex.attributes.title) - .catch(err => notify.error(err, { title: `Couldn't fetch default index` })); +export const getDefaultIndex = () => { + const defaultIndexId = AdvancedSettings.get('defaultIndex'); + + return defaultIndexId + ? savedObjectsClient + .get('index-pattern', defaultIndexId) + .then(defaultIndex => defaultIndex.attributes.title) + .catch(err => notify.error(err, { title: `Couldn't fetch default index` })) + : Promise.resolve(''); +};