Skip to content

Commit

Permalink
fix scripted fields
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkime committed Apr 24, 2020
1 parent d2ef538 commit 142169a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
4 changes: 1 addition & 3 deletions src/legacy/ui/public/field_editor/field_editor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ jest.mock('@elastic/eui', () => ({
}));

jest.mock('ui/scripting_languages', () => ({
GetEnabledScriptingLanguagesProvider: jest
.fn()
.mockImplementation(() => () => ['painless', 'testlang']),
getEnabledScriptingLanguages: () => ['painless', 'testlang'],
getSupportedScriptingLanguages: () => ['painless'],
getDeprecatedScriptingLanguages: () => ['testlang'],
}));
Expand Down
5 changes: 2 additions & 3 deletions src/legacy/ui/public/field_editor/field_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { intersection, union, get } from 'lodash';
import { HttpStart } from 'src/core/public';

import {
GetEnabledScriptingLanguagesProvider,
getEnabledScriptingLanguages,
getDeprecatedScriptingLanguages,
getSupportedScriptingLanguages,
} from 'ui/scripting_languages';
Expand Down Expand Up @@ -183,8 +183,7 @@ export class FieldEditor extends PureComponent<FieldEdiorProps, FieldEditorState
const { field } = this.state;
const { indexPattern } = this.props;

const getEnabledScriptingLanguages = GetEnabledScriptingLanguagesProvider(getHttpStart());
const enabledLangs = await getEnabledScriptingLanguages();
const enabledLangs = await getEnabledScriptingLanguages(await getHttpStart());
const scriptingLangs = intersection(
enabledLangs,
union(this.supportedLangs, this.deprecatedLangs)
Expand Down
25 changes: 9 additions & 16 deletions src/legacy/ui/public/scripting_languages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import { i18n } from '@kbn/i18n';
import { HttpStart } from 'src/core/public';
import chrome from '../chrome';
import { toastNotifications } from '../notify';

export function getSupportedScriptingLanguages(): string[] {
Expand All @@ -30,18 +29,12 @@ export function getDeprecatedScriptingLanguages(): string[] {
return [];
}

export function GetEnabledScriptingLanguagesProvider($http: HttpStart) {
return () => {
return $http
.get(chrome.addBasePath('/api/kibana/scripts/languages'))
.then((res: any) => res.data)
.catch(() => {
toastNotifications.addDanger(
i18n.translate('common.ui.scriptingLanguages.errorFetchingToastDescription', {
defaultMessage: 'Error getting available scripting languages from Elasticsearch',
})
);
return [];
});
};
}
export const getEnabledScriptingLanguages = (http: HttpStart) =>
http.get('/api/kibana/scripts/languages').catch(() => {
toastNotifications.addDanger(
i18n.translate('common.ui.scriptingLanguages.errorFetchingToastDescription', {
defaultMessage: 'Error getting available scripting languages from Elasticsearch',
})
);
return [];
});

0 comments on commit 142169a

Please sign in to comment.