Skip to content

Commit

Permalink
[Canvas] Adds support for uppercase cluster names in esdocs and other…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
cqliu1 authored Sep 12, 2019
1 parent 583b568 commit a105b70
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function esdocs(): ExpressionFunction<'esdocs', Filter, Arguments, any> {
});

if (index) {
query.from(index.toLowerCase());
query.from(index);
}

if (fields) {
Expand All @@ -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');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const ESIndexSelect = ({ value, loading, indices, onChange, onFocus, onBl
return (
<EuiComboBox
selectedOptions={selectedOption}
onChange={([index]) => onChange(get(index, 'label', defaultIndex).toLowerCase())}
onChange={([index]) => onChange(get(index, 'label', defaultIndex))}
onSearchChange={searchValue => {
// resets input when user starts typing
if (searchValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const EsdocsDatasource = ({ args, updateArgs, defaultIndex }) => {
};

const getIndex = () => {
return getSimpleArg('index', args)[0] || defaultIndex;
return getSimpleArg('index', args)[0] || '';
};

const getQuery = () => {
Expand All @@ -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' }];

Expand Down
15 changes: 10 additions & 5 deletions x-pack/legacy/plugins/canvas/public/lib/es_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
};

0 comments on commit a105b70

Please sign in to comment.