Skip to content

Commit

Permalink
fix PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp committed Dec 17, 2019
1 parent 1fcf01e commit 8c3324f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { get, map } from 'lodash';
import { schema } from '@kbn/config-schema';
import { APICaller, IRouter, KibanaRequest } from 'kibana/server';

import { IFieldType, indexPatternsUtils, esFilters } from '../index';
import { IFieldType, indexPatterns, esFilters } from '../index';

export function registerValueSuggestionsRoute(
router: IRouter,
Expand Down Expand Up @@ -57,12 +57,12 @@ export function registerValueSuggestionsRoute(
terminate_after: await uiSettings.get<number>('kibana.autocompleteTerminateAfter'),
};

const indexPattern = await indexPatternsUtils.findIndexPatternById(
const indexPattern = await indexPatterns.findIndexPatternById(
context.core.savedObjects.client,
index
);

const field = indexPatternsUtils.getFieldByName(fieldName, indexPattern);
const field = indexPattern && indexPatterns.getFieldByName(fieldName, indexPattern);
const body = await getBody(autocompleteSearchOptions, field || fieldName, query, boolFilter);

try {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export {
IndexPatternsFetcher,
FieldDescriptor,
shouldReadFieldFromDocValues,
indexPatternsUtils,
indexPatterns,
} from './index_patterns';
export * from './search';
export {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data/server/index_patterns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
import * as indexPatternsUtils from './utils';
import * as indexPatterns from './utils';

export { IndexPatternsFetcher, FieldDescriptor, shouldReadFieldFromDocValues } from './fetcher';
export { IndexPatternsService } from './index_patterns_service';
export { indexPatternsUtils };
export { indexPatterns };
12 changes: 4 additions & 8 deletions src/plugins/data/server/index_patterns/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@ import { IIndexPattern, IFieldType } from '../../common';

export const getFieldByName = (
fieldName: string,
indexPattern?: IIndexPattern
indexPattern: IIndexPattern
): IFieldType | undefined => {
if (indexPattern) {
const fields: IFieldType[] = indexPattern && JSON.parse(indexPattern.attributes.fields);
const field = fields && fields.find(f => f.name === fieldName);
const fields: IFieldType[] = indexPattern && JSON.parse(indexPattern.attributes.fields);
const field = fields && fields.find(f => f.name === fieldName);

if (field) {
return field;
}
}
return field;
};

export const findIndexPatternById = async (
Expand Down

0 comments on commit 8c3324f

Please sign in to comment.