Skip to content

Commit

Permalink
Merge branch 'master' into fix35379
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine committed Dec 26, 2019
2 parents 1ad99e3 + 6669111 commit ba61f32
Show file tree
Hide file tree
Showing 141 changed files with 1,319 additions and 811 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"@elastic/charts": "^14.0.0",
"@elastic/datemath": "5.0.2",
"@elastic/ems-client": "1.0.5",
"@elastic/eui": "17.1.2",
"@elastic/eui": "17.3.1",
"@elastic/filesaver": "1.1.2",
"@elastic/good": "8.1.1-kibana2",
"@elastic/numeral": "2.3.3",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
import { UiSettingsPlugin } from './plugin';

export const plugin = () => new UiSettingsPlugin();
import Fs from 'fs';
import { promisify } from 'util';

export const readFile = promisify(Fs.readFile);
export const writeFile = promisify(Fs.writeFile);
19 changes: 5 additions & 14 deletions src/core/server/uuid/resolve_uuid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,22 @@
* under the License.
*/

import { promises } from 'fs';
import { join } from 'path';
import { readFile, writeFile } from './fs';
import { resolveInstanceUuid } from './resolve_uuid';
import { configServiceMock } from '../config/config_service.mock';
import { loggingServiceMock } from '../logging/logging_service.mock';
import { BehaviorSubject } from 'rxjs';
import { Logger } from '../logging';

const { readFile, writeFile } = promises;

jest.mock('uuid', () => ({
v4: () => 'NEW_UUID',
}));

jest.mock('fs', () => {
const actual = jest.requireActual('fs');
return {
...actual,
promises: {
...actual.promises,
readFile: jest.fn(() => Promise.resolve('')),
writeFile: jest.fn(() => Promise.resolve('')),
},
};
});
jest.mock('./fs', () => ({
readFile: jest.fn(() => Promise.resolve('')),
writeFile: jest.fn(() => Promise.resolve('')),
}));

const DEFAULT_FILE_UUID = 'FILE_UUID';
const DEFAULT_CONFIG_UUID = 'CONFIG_UUID';
Expand Down
4 changes: 1 addition & 3 deletions src/core/server/uuid/resolve_uuid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@
*/

import uuid from 'uuid';
import { promises } from 'fs';
import { join } from 'path';
import { take } from 'rxjs/operators';
import { readFile, writeFile } from './fs';
import { IConfigService } from '../config';
import { PathConfigType, config as pathConfigDef } from '../path';
import { HttpConfigType, config as httpConfigDef } from '../http';
import { Logger } from '../logging';

const { readFile, writeFile } = promises;

const FILE_ENCODING = 'utf8';
const FILE_NAME = 'uuid';

Expand Down
13 changes: 11 additions & 2 deletions src/legacy/core_plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ import { CoreSetup, CoreStart, Plugin } from 'kibana/public';
import { SearchService, SearchStart } from './search';
import { DataPublicPluginStart } from '../../../../plugins/data/public';

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { setFieldFormats } from '../../../../plugins/data/public/services';
import {
setFieldFormats,
setNotifications,
setIndexPatterns,
setQueryService,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../plugins/data/public/services';

export interface DataPluginStartDependencies {
data: DataPublicPluginStart;
Expand Down Expand Up @@ -57,6 +62,10 @@ export class DataPlugin implements Plugin<void, DataStart, {}, DataPluginStartDe
public start(core: CoreStart, { data }: DataPluginStartDependencies): DataStart {
// This is required for when Angular code uses Field and FieldList.
setFieldFormats(data.fieldFormats);
setQueryService(data.query);
setIndexPatterns(data.indexPatterns);
setFieldFormats(data.fieldFormats);
setNotifications(core.notifications);

return {
search: this.search.start(core),
Expand Down
32 changes: 15 additions & 17 deletions src/legacy/core_plugins/data/public/search/expressions/esaggs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,34 @@ import { get, has } from 'lodash';
import { i18n } from '@kbn/i18n';
import { AggConfigs } from 'ui/agg_types/agg_configs';
import { createFormat } from 'ui/visualize/loader/pipeline_helpers/utilities';
import chrome from 'ui/chrome';
import { Query, TimeRange, esFilters } from 'src/plugins/data/public';
import {
KibanaContext,
KibanaDatatable,
ExpressionFunction,
KibanaDatatableColumn,
} from 'src/plugins/expressions/public';
import { npStart } from 'ui/new_platform';
import {
Query,
TimeRange,
esFilters,
getTime,
FilterManager,
} from '../../../../../../plugins/data/public';
import {
SearchSource,
ISearchSource,
getRequestInspectorStats,
getResponseInspectorStats,
} from '../../../../../ui/public/courier';
// @ts-ignore
import {
FilterBarQueryFilterProvider,
QueryFilter,
} from '../../../../../ui/public/filter_manager/query_filter';

import { buildTabularInspectorData } from '../../../../../ui/public/inspector/build_tabular_inspector_data';
import { calculateObjectHash } from '../../../../visualizations/public';
import { getTime } from '../../../../../ui/public/timefilter';
// @ts-ignore
import { tabifyAggResponse } from '../../../../../ui/public/agg_response/tabify/tabify';
import { PersistedState } from '../../../../../ui/public/persisted_state';
import { Adapters } from '../../../../../../plugins/inspector/public';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getQueryService, getIndexPatterns } from '../../../../../../plugins/data/public/services';

export interface RequestHandlerParams {
searchSource: ISearchSource;
Expand All @@ -57,7 +57,7 @@ export interface RequestHandlerParams {
query?: Query;
filters?: esFilters.Filter[];
forceFetch: boolean;
queryFilter: QueryFilter;
filterManager: FilterManager;
uiState?: PersistedState;
partialRows?: boolean;
inspectorAdapters: Adapters;
Expand Down Expand Up @@ -90,7 +90,7 @@ const handleCourierRequest = async ({
partialRows,
metricsAtAllLevels,
inspectorAdapters,
queryFilter,
filterManager,
abortSignal,
}: RequestHandlerParams) => {
// Create a new search source that inherits the original search source
Expand Down Expand Up @@ -216,7 +216,7 @@ const handleCourierRequest = async ({
}

inspectorAdapters.data.setTabularLoader(
() => buildTabularInspectorData((searchSource as any).tabifiedResponse, queryFilter),
() => buildTabularInspectorData((searchSource as any).tabifiedResponse, filterManager),
{ returnsFormattedValues: true }
);

Expand Down Expand Up @@ -259,10 +259,8 @@ export const esaggs = (): ExpressionFunction<typeof name, Context, Arguments, Re
},
},
async fn(context, args, { inspectorAdapters, abortSignal }) {
const $injector = await chrome.dangerouslyGetActiveInjector();
const Private: Function = $injector.get('Private');
const { indexPatterns } = npStart.plugins.data;
const queryFilter = Private(FilterBarQueryFilterProvider);
const indexPatterns = getIndexPatterns();
const { filterManager } = getQueryService();

const aggConfigsState = JSON.parse(args.aggConfigs);
const indexPattern = await indexPatterns.get(args.index);
Expand All @@ -283,7 +281,7 @@ export const esaggs = (): ExpressionFunction<typeof name, Context, Arguments, Re
metricsAtAllLevels: args.metricsAtAllLevels,
partialRows: args.partialRows,
inspectorAdapters,
queryFilter,
filterManager,
abortSignal: (abortSignal as unknown) as AbortSignal,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { setOverlays } from '../../../../../../../plugins/data/public/services';
import { OverlayStart } from 'kibana/public';

export const openModal = jest.fn();

jest.doMock('ui/new_platform', () => {
return {
npStart: {
core: {
overlays: {
openModal,
},
},
},
};
});
setOverlays(({
openModal,
} as unknown) as OverlayStart);
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* under the License.
*/
import React from 'react';
// @ts-ignore
import { npStart } from 'ui/new_platform';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiButton, EuiTextAlign } from '@elastic/eui';

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getOverlays } from '../../../../../../../plugins/data/public/services';
import { toMountPoint } from '../../../../../../../plugins/kibana_react/public';
import { ShardFailureModal } from './shard_failure_modal';
import { ResponseWithShardFailure, Request } from './shard_failure_types';
Expand All @@ -34,7 +34,7 @@ interface Props {

export function ShardFailureOpenModalButton({ request, response, title }: Props) {
function onClick() {
const modal = npStart.core.overlays.openModal(
const modal = getOverlays().openModal(
toMountPoint(
<ShardFailureModal
request={request}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@
*/

import { handleResponse } from './handle_response';
import { toastNotifications } from 'ui/notify/toasts';

jest.mock('ui/notify/toasts', () => {
return {
toastNotifications: {
addWarning: jest.fn(),
},
};
});
// Temporary disable eslint, will be removed after moving to new platform folder
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { notificationServiceMock } from '../../../../../../core/public/notifications/notifications_service.mock';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { setNotifications } from '../../../../../../plugins/data/public/services';

jest.mock('@kbn/i18n', () => {
return {
Expand All @@ -37,8 +34,11 @@ jest.mock('@kbn/i18n', () => {
});

describe('handleResponse', () => {
const notifications = notificationServiceMock.createStartContract();

beforeEach(() => {
(toastNotifications.addWarning as jest.Mock).mockReset();
setNotifications(notifications);
(notifications.toasts.addWarning as jest.Mock).mockReset();
});

test('should notify if timed out', () => {
Expand All @@ -48,8 +48,8 @@ describe('handleResponse', () => {
};
const result = handleResponse(request, response);
expect(result).toBe(response);
expect(toastNotifications.addWarning).toBeCalled();
expect((toastNotifications.addWarning as jest.Mock).mock.calls[0][0].title).toMatch(
expect(notifications.toasts.addWarning).toBeCalled();
expect((notifications.toasts.addWarning as jest.Mock).mock.calls[0][0].title).toMatch(
'request timed out'
);
});
Expand All @@ -63,8 +63,8 @@ describe('handleResponse', () => {
};
const result = handleResponse(request, response);
expect(result).toBe(response);
expect(toastNotifications.addWarning).toBeCalled();
expect((toastNotifications.addWarning as jest.Mock).mock.calls[0][0].title).toMatch(
expect(notifications.toasts.addWarning).toBeCalled();
expect((notifications.toasts.addWarning as jest.Mock).mock.calls[0][0].title).toMatch(
'shards failed'
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@
import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiSpacer } from '@elastic/eui';
import { toastNotifications } from 'ui/notify/toasts';
import { ShardFailureOpenModalButton } from './components/shard_failure_open_modal_button';
import { Request, ResponseWithShardFailure } from './components/shard_failure_types';
import { SearchRequest, SearchResponse } from '../types';
import { toMountPoint } from '../../../../../../plugins/kibana_react/public';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getNotifications } from '../../../../../../plugins/data/public/services';

export function handleResponse(request: SearchRequest, response: SearchResponse) {
if (response.timed_out) {
toastNotifications.addWarning({
getNotifications().toasts.addWarning({
title: i18n.translate('data.search.searchSource.fetch.requestTimedOutNotificationMessage', {
defaultMessage: 'Data might be incomplete because your request timed out',
}),
Expand Down Expand Up @@ -62,7 +63,7 @@ export function handleResponse(request: SearchRequest, response: SearchResponse)
</>
);

toastNotifications.addWarning({ title, text });
getNotifications().toasts.addWarning({ title, text });
}

return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@
import _ from 'lodash';
import { npSetup } from 'ui/new_platform';
import chrome from 'ui/chrome';
import { fieldWildcardFilter } from 'ui/field_wildcard';
import { normalizeSortRequest } from './normalize_sort_request';
import { fetchSoon } from '../fetch';
import { fieldWildcardFilter } from '../../../../../../plugins/kibana_utils/public';
import { getHighlightRequest, esFilters, esQuery } from '../../../../../../plugins/data/public';
import { RequestFailure } from '../fetch/errors';
import { filterDocvalueFields } from './filter_docvalue_fields';
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ba61f32

Please sign in to comment.