Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into actions_connector…
Browse files Browse the repository at this point in the history
…_ui_embedding

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
  • Loading branch information
YulNaumenko committed Mar 5, 2020
2 parents a303775 + 4883d4b commit 2c1145e
Show file tree
Hide file tree
Showing 372 changed files with 7,626 additions and 9,514 deletions.
7 changes: 1 addition & 6 deletions examples/search_explorer/public/es_strategy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ import {
import { DoSearch } from './do_search';
import { GuideSection } from './guide_section';

// @ts-ignore
import serverPlugin from '!!raw-loader!./../../../src/plugins/data/server/search/es_search/es_search_service';
// @ts-ignore
import serverStrategy from '!!raw-loader!./../../../src/plugins/data/server/search/es_search/es_search_strategy';

Expand Down Expand Up @@ -127,10 +125,7 @@ export class EsSearchTest extends React.Component<Props, State> {
},
{
title: 'Server',
code: [
{ description: 'es_search_service.ts', snippet: serverPlugin },
{ description: 'es_search_strategy.ts', snippet: serverStrategy },
],
code: [{ description: 'es_search_strategy.ts', snippet: serverStrategy }],
},
]}
demo={this.renderDemo()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h1 class="euiScreenReaderOnly">{{screenTitle}}</h1>

<main class="container-fluid">
<div class="row">
<div class="col-md-2 sidebar-container collapsible-sidebar" id="discover-sidebar">
<div class="col-md-2 sidebar-container collapsible-sidebar" id="discover-sidebar" data-test-subj="discover-sidebar">
<div class="dscFieldChooser">
<disc-field-chooser
columns="state.columns"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ import React from 'react';
import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers';
import { IndexPatternCreationConfig } from '../../../../../../../../management/public';
import { IFieldType } from '../../../../../../../../../../plugins/data/public';
import { dataPluginMock } from '../../../../../../../../../../plugins/data/public/mocks';

import { StepTimeField } from '../step_time_field';

jest.mock('./components/header', () => ({ Header: 'Header' }));
jest.mock('./components/time_field', () => ({ TimeField: 'TimeField' }));
jest.mock('./components/advanced_options', () => ({ AdvancedOptions: 'AdvancedOptions' }));
jest.mock('./components/action_buttons', () => ({ ActionButtons: 'ActionButtons' }));
jest.mock('./../../lib/extract_time_fields', () => ({
extractTimeFields: (fields: IFieldType) => fields,
jest.mock('./../../lib', () => ({
extractTimeFields: require.requireActual('./../../lib').extractTimeFields,
ensureMinimumTime: async (fields: IFieldType) => Promise.resolve(fields),
}));
jest.mock('ui/chrome', () => ({
addBasePath: () => {},
Expand All @@ -42,7 +42,19 @@ const mockIndexPatternCreationType = new IndexPatternCreationConfig({
});

const noop = () => {};
const indexPatternsService = dataPluginMock.createStartContract().indexPatterns;
const fields = [
{
name: '@timestamp',
type: 'date',
},
];
const indexPatternsService = {
make: () => ({
fieldsFetcher: {
fetchForWildcard: jest.fn().mockReturnValue(Promise.resolve(fields)),
},
}),
} as any;

describe('StepTimeField', () => {
it('should render normally', () => {
Expand Down Expand Up @@ -292,4 +304,30 @@ describe('StepTimeField', () => {
error: 'foobar',
});
});

it('should call createIndexPattern with undefined time field when no time filter chosen', async () => {
const createIndexPattern = jest.fn();

const component = shallowWithI18nProvider(
<StepTimeField
indexPattern="ki*"
indexPatternsService={indexPatternsService}
goToPreviousStep={noop}
createIndexPattern={createIndexPattern}
indexPatternCreationType={mockIndexPatternCreationType}
/>
);

await (component.instance() as StepTimeField).fetchTimeFields();

expect((component.state() as any).timeFields).toHaveLength(3);

(component.instance() as StepTimeField).onTimeFieldChanged(({
target: { value: undefined },
} as unknown) as React.ChangeEvent<HTMLSelectElement>);

await (component.instance() as StepTimeField).createIndexPattern();

expect(createIndexPattern).toHaveBeenCalledWith(undefined, '');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interface StepTimeFieldProps {
indexPattern: string;
indexPatternsService: DataPublicPluginStart['indexPatterns'];
goToPreviousStep: () => void;
createIndexPattern: (selectedTimeField: string, indexPatternId: string) => void;
createIndexPattern: (selectedTimeField: string | undefined, indexPatternId: string) => void;
indexPatternCreationType: IndexPatternCreationConfig;
}

Expand Down Expand Up @@ -143,7 +143,7 @@ export class StepTimeField extends Component<StepTimeFieldProps, StepTimeFieldSt
const { selectedTimeField, indexPatternId } = this.state;
this.setState({ isCreating: true });
try {
await createIndexPattern(selectedTimeField || '', indexPatternId);
await createIndexPattern(selectedTimeField, indexPatternId);
} catch (error) {
if (!this.mounted) return;
this.setState({
Expand Down
42 changes: 0 additions & 42 deletions src/plugins/data/server/search/es_search/es_search_service.test.ts

This file was deleted.

42 changes: 0 additions & 42 deletions src/plugins/data/server/search/es_search/es_search_service.ts

This file was deleted.

7 changes: 1 addition & 6 deletions src/plugins/data/server/search/es_search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
* under the License.
*/

import { PluginInitializerContext } from '../../../../../core/server';
import { EsSearchService } from './es_search_service';
export { esSearchStrategyProvider } from './es_search_strategy';

export { ES_SEARCH_STRATEGY, IEsSearchRequest, IEsSearchResponse } from '../../../common/search';

export function esSearchService(initializerContext: PluginInitializerContext) {
return new EsSearchService(initializerContext);
}
13 changes: 1 addition & 12 deletions src/plugins/data/server/search/i_search_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@
* under the License.
*/

import { IContextProvider, APICaller } from 'kibana/server';
import { IContextProvider } from 'kibana/server';
import { ISearchContext } from './i_search_context';
import { IResponseTypesMap, IRequestTypesMap } from './i_search';
import { TRegisterSearchStrategyProvider, TSearchStrategyProvider } from './i_search_strategy';
import { TStrategyTypes } from './strategy_types';
import { DEFAULT_SEARCH_STRATEGY } from '../../common/search';

/**
* The setup contract exposed by the Search plugin exposes the search strategy extension
Expand All @@ -40,12 +37,4 @@ export interface ISearchSetup {
* strategies.
*/
registerSearchStrategyProvider: TRegisterSearchStrategyProvider;

__LEGACY: {
search: <T extends TStrategyTypes = typeof DEFAULT_SEARCH_STRATEGY>(
caller: APICaller,
request: IRequestTypesMap[T],
strategyName?: T
) => Promise<IResponseTypesMap[T]>;
};
}
9 changes: 0 additions & 9 deletions src/plugins/data/server/search/search_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ describe('Search service', () => {
const setup = plugin.setup(mockCoreSetup);
expect(setup).toHaveProperty('registerSearchStrategyContext');
expect(setup).toHaveProperty('registerSearchStrategyProvider');
expect(setup).toHaveProperty('__LEGACY');
});
});

describe('__LEGACY', () => {
it('calls searchAPI.search', async () => {
const setup = plugin.setup(mockCoreSetup);
setup.__LEGACY.search(jest.fn(), {}, 'foo');
expect(mockSearchApi.search).toBeCalled();
});
});
});
20 changes: 6 additions & 14 deletions src/plugins/data/server/search/search_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
TRegisterSearchStrategyProvider,
} from './i_search_strategy';
import { IRouteHandlerSearchContext } from './i_route_handler_search_context';
import { esSearchService } from './es_search';
import { ES_SEARCH_STRATEGY, esSearchStrategyProvider } from './es_search';

declare module 'kibana/server' {
interface RequestHandlerContext {
Expand Down Expand Up @@ -71,15 +71,6 @@ export class SearchService implements Plugin<ISearchSetup, void> {
const api: ISearchSetup = {
registerSearchStrategyContext: this.contextContainer!.registerContext,
registerSearchStrategyProvider,
__LEGACY: {
search: (caller, request, strategyName) => {
const searchAPI = createApi({
caller,
searchStrategies: this.searchStrategies,
});
return searchAPI.search(request, {}, strategyName);
},
},
};

api.registerSearchStrategyContext(this.initializerContext.opaqueId, 'core', () => core);
Expand All @@ -89,10 +80,11 @@ export class SearchService implements Plugin<ISearchSetup, void> {
() => this.initializerContext.config.legacy.globalConfig$
);

// ES search capabilities are written in a way that it could easily be a separate plugin,
// however these two plugins are tightly coupled due to the default search strategy using
// es search types.
esSearchService(this.initializerContext).setup(core, { search: api });
api.registerSearchStrategyProvider(
this.initializerContext.opaqueId,
ES_SEARCH_STRATEGY,
esSearchStrategyProvider
);

return api;
}
Expand Down
25 changes: 13 additions & 12 deletions src/plugins/es_ui_shared/public/request/np_ready_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export interface SendRequestConfig {
body?: any;
}

export interface SendRequestResponse<D = any> {
export interface SendRequestResponse<D = any, E = Error> {
data: D | null;
error: Error | null;
error: E | null;
}

export interface UseRequestConfig extends SendRequestConfig {
Expand All @@ -39,20 +39,21 @@ export interface UseRequestConfig extends SendRequestConfig {
deserializer?: (data: any) => any;
}

export interface UseRequestResponse<D = any> {
export interface UseRequestResponse<D = any, E = Error> {
isInitialRequest: boolean;
isLoading: boolean;
error: Error | null;
error: E | null;
data: D | null;
sendRequest: (...args: any[]) => Promise<SendRequestResponse<D>>;
sendRequest: (...args: any[]) => Promise<SendRequestResponse<D, E>>;
}

export const sendRequest = async <D = any>(
export const sendRequest = async <D = any, E = Error>(
httpClient: HttpSetup,
{ path, method, body, query }: SendRequestConfig
): Promise<SendRequestResponse<D>> => {
): Promise<SendRequestResponse<D, E>> => {
try {
const response = await httpClient[method](path, { body, query });
const stringifiedBody = typeof body === 'string' ? body : JSON.stringify(body);
const response = await httpClient[method](path, { body: stringifiedBody, query });

return {
data: response.data ? response.data : response,
Expand All @@ -66,7 +67,7 @@ export const sendRequest = async <D = any>(
}
};

export const useRequest = <D = any>(
export const useRequest = <D = any, E = Error>(
httpClient: HttpSetup,
{
path,
Expand All @@ -77,8 +78,8 @@ export const useRequest = <D = any>(
initialData,
deserializer = (data: any): any => data,
}: UseRequestConfig
): UseRequestResponse<D> => {
const sendRequestRef = useRef<() => Promise<SendRequestResponse<D>>>();
): UseRequestResponse<D, E> => {
const sendRequestRef = useRef<() => Promise<SendRequestResponse<D, E>>>();
// Main states for tracking request status and data
const [error, setError] = useState<null | any>(null);
const [isLoading, setIsLoading] = useState<boolean>(true);
Expand Down Expand Up @@ -122,7 +123,7 @@ export const useRequest = <D = any>(
body,
};

const response = await sendRequest(httpClient, requestBody);
const response = await sendRequest<D, E>(httpClient, requestBody);
const { data: serializedResponseData, error: responseError } = response;

// If an outdated request has resolved, DON'T update state, but DO allow the processData handler
Expand Down
Loading

0 comments on commit 2c1145e

Please sign in to comment.