Skip to content

Commit

Permalink
Move ui/courier into data shim plugin (elastic#52359) (elastic#53743)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeelmers authored Dec 23, 2019
1 parent 052e347 commit 4d6eeff
Show file tree
Hide file tree
Showing 84 changed files with 1,035 additions and 712 deletions.
9 changes: 8 additions & 1 deletion src/legacy/core_plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,16 @@ export function plugin() {
export { DataStart };

export { Field, FieldType, IFieldList, IndexPattern } from './index_patterns';
export { SavedQuery, SavedQueryTimeFilter } from '../../../../plugins/data/public';
export { EsQuerySortValue, FetchOptions, ISearchSource, SortDirection } from './search/types';
export { SearchSourceFields } from './search/types';
export {
SavedQueryAttributes,
SavedQuery,
SavedQueryTimeFilter,
} from '../../../../plugins/data/public';

/** @public static code */
export * from '../common';
export { FilterStateManager } from './filter/filter_manager';
export { getFromSavedObject, getRoutes, flattenHitWrapper } from './index_patterns';
export { getRequestInspectorStats, getResponseInspectorStats } from './search';
17 changes: 13 additions & 4 deletions src/legacy/core_plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

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
Expand All @@ -32,8 +33,9 @@ export interface DataPluginStartDependencies {
*
* @public
*/
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface DataStart {}
export interface DataStart {
search: SearchStart;
}

/**
* Data Plugin - public
Expand All @@ -48,13 +50,20 @@ export interface DataStart {}
*/

export class DataPlugin implements Plugin<void, DataStart, {}, DataPluginStartDependencies> {
private readonly search = new SearchService();

public setup(core: CoreSetup) {}

public start(core: CoreStart, { data }: DataPluginStartDependencies): DataStart {
// This is required for when Angular code uses Field and FieldList.
setFieldFormats(data.fieldFormats);
return {};

return {
search: this.search.start(core),
};
}

public stop() {}
public stop() {
this.search.stop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
import { npStart } from 'ui/new_platform';
import {
SearchSource,
SearchSourceContract,
ISearchSource,
getRequestInspectorStats,
getResponseInspectorStats,
} from '../../../../../ui/public/courier';
Expand All @@ -51,7 +51,7 @@ import { PersistedState } from '../../../../../ui/public/persisted_state';
import { Adapters } from '../../../../../../plugins/inspector/public';

export interface RequestHandlerParams {
searchSource: SearchSourceContract;
searchSource: ISearchSource;
aggs: AggConfigs;
timeRange?: TimeRange;
query?: Query;
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 @@ -19,7 +19,7 @@
import React from 'react';
import { EuiCodeBlock, EuiDescriptionList, EuiSpacer } from '@elastic/eui';
import { ShardFailure } from './shard_failure_types';
import { getFlattenedObject } from '../../../../../../legacy/utils/get_flattened_object';
import { getFlattenedObject } from '../../../../../../../legacy/utils/get_flattened_object';
import { ShardFailureDescriptionHeader } from './shard_failure_description_header';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function getFailureSummaryText(failure: ShardFailure, failureDetails?: st
const displayDetails =
typeof failureDetails === 'string' ? failureDetails : getFailureSummaryDetailsText(failure);

return i18n.translate('common.ui.courier.fetch.shardsFailedModal.failureHeader', {
return i18n.translate('data.search.searchSource.fetch.shardsFailedModal.failureHeader', {
defaultMessage: '{failureName} at {failureDetails}',
values: { failureName, failureDetails: displayDetails },
description: 'Summary of shard failures, e.g. "IllegalArgumentException at shard 0 node xyz"',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,18 @@ export function ShardFailureModal({ request, response, title, onClose }: Props)
const tabs = [
{
id: 'table',
name: i18n.translate('common.ui.courier.fetch.shardsFailedModal.tabHeaderShardFailures', {
defaultMessage: 'Shard failures',
description: 'Name of the tab displaying shard failures',
}),
name: i18n.translate(
'data.search.searchSource.fetch.shardsFailedModal.tabHeaderShardFailures',
{
defaultMessage: 'Shard failures',
description: 'Name of the tab displaying shard failures',
}
),
content: <ShardFailureTable failures={failures} />,
},
{
id: 'json-request',
name: i18n.translate('common.ui.courier.fetch.shardsFailedModal.tabHeaderRequest', {
name: i18n.translate('data.search.searchSource.fetch.shardsFailedModal.tabHeaderRequest', {
defaultMessage: 'Request',
description: 'Name of the tab displaying the JSON request',
}),
Expand All @@ -79,7 +82,7 @@ export function ShardFailureModal({ request, response, title, onClose }: Props)
},
{
id: 'json-response',
name: i18n.translate('common.ui.courier.fetch.shardsFailedModal.tabHeaderResponse', {
name: i18n.translate('data.search.searchSource.fetch.shardsFailedModal.tabHeaderResponse', {
defaultMessage: 'Response',
description: 'Name of the tab displaying the JSON response',
}),
Expand All @@ -104,15 +107,15 @@ export function ShardFailureModal({ request, response, title, onClose }: Props)
{copy => (
<EuiButtonEmpty onClick={copy}>
<FormattedMessage
id="common.ui.courier.fetch.shardsFailedModal.copyToClipboard"
id="data.search.searchSource.fetch.shardsFailedModal.copyToClipboard"
defaultMessage="Copy response to clipboard"
/>
</EuiButtonEmpty>
)}
</EuiCopy>
<EuiButton onClick={() => onClose()} fill data-test-sub="closeShardFailureModal">
<FormattedMessage
id="common.ui.courier.fetch.shardsFailedModal.close"
id="data.search.searchSource.fetch.shardsFailedModal.close"
defaultMessage="Close"
description="Closing the Modal"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { npStart } from 'ui/new_platform';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiButton, EuiTextAlign } from '@elastic/eui';

import { toMountPoint } from '../../../../../../plugins/kibana_react/public';
import { toMountPoint } from '../../../../../../../plugins/kibana_react/public';
import { ShardFailureModal } from './shard_failure_modal';
import { ResponseWithShardFailure, Request } from './shard_failure_types';

Expand Down Expand Up @@ -57,7 +57,7 @@ export function ShardFailureOpenModalButton({ request, response, title }: Props)
data-test-subj="openShardFailureModalBtn"
>
<FormattedMessage
id="common.ui.courier.fetch.shardsFailedModal.showDetails"
id="data.search.searchSource.fetch.shardsFailedModal.showDetails"
defaultMessage="Show details"
description="Open the modal to show details"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function ShardFailureTable({ failures }: { failures: ShardFailure[] }) {
render: (item: ListItem) => {
const failureSummeryText = getFailureSummaryText(item);
const collapseLabel = i18n.translate(
'common.ui.courier.fetch.shardsFailedModal.tableRowCollapse',
'data.search.searchSource.fetch.shardsFailedModal.tableRowCollapse',
{
defaultMessage: 'Collapse {rowDescription}',
description: 'Collapse a row of a table with failures',
Expand All @@ -53,7 +53,7 @@ export function ShardFailureTable({ failures }: { failures: ShardFailure[] }) {
);

const expandLabel = i18n.translate(
'common.ui.courier.fetch.shardsFailedModal.tableRowExpand',
'data.search.searchSource.fetch.shardsFailedModal.tableRowExpand',
{
defaultMessage: 'Expand {rowDescription}',
description: 'Expand a row of a table with failures',
Expand Down Expand Up @@ -81,7 +81,7 @@ export function ShardFailureTable({ failures }: { failures: ShardFailure[] }) {
},
{
field: 'shard',
name: i18n.translate('common.ui.courier.fetch.shardsFailedModal.tableColShard', {
name: i18n.translate('data.search.searchSource.fetch.shardsFailedModal.tableColShard', {
defaultMessage: 'Shard',
}),
sortable: true,
Expand All @@ -90,23 +90,23 @@ export function ShardFailureTable({ failures }: { failures: ShardFailure[] }) {
},
{
field: 'index',
name: i18n.translate('common.ui.courier.fetch.shardsFailedModal.tableColIndex', {
name: i18n.translate('data.search.searchSource.fetch.shardsFailedModal.tableColIndex', {
defaultMessage: 'Index',
}),
sortable: true,
truncateText: true,
},
{
field: 'node',
name: i18n.translate('common.ui.courier.fetch.shardsFailedModal.tableColNode', {
name: i18n.translate('data.search.searchSource.fetch.shardsFailedModal.tableColNode', {
defaultMessage: 'Node',
}),
sortable: true,
truncateText: true,
},
{
field: 'reason.type',
name: i18n.translate('common.ui.courier.fetch.shardsFailedModal.tableColReason', {
name: i18n.translate('data.search.searchSource.fetch.shardsFailedModal.tableColReason', {
defaultMessage: 'Reason',
}),
truncateText: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
* under the License.
*/

import { SearchError } from '../../courier';
import { KbnError } from '../../../../../plugins/kibana_utils/public';
import { SearchError } from '../search_strategy';
import { KbnError } from '../../../../../../plugins/kibana_utils/public';
import { SearchResponse } from '../types';

/**
* Request Failure - When an entire multi request fails
* @param {Error} err - the Error that came back
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { fetchSoon } from './fetch_soon';
import { callClient } from './call_client';
import { IUiSettingsClient } from '../../../../../core/public';
import { IUiSettingsClient } from '../../../../../../core/public';
import { FetchHandlers, FetchOptions } from './types';
import { SearchRequest, SearchResponse } from '../types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { getMSearchParams, getSearchParams } from './get_search_params';
import { IUiSettingsClient } from '../../../../../core/public';
import { IUiSettingsClient } from '../../../../../../core/public';

function getConfigStub(config: any = {}) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { IUiSettingsClient } from '../../../../../core/public';
import { IUiSettingsClient } from '../../../../../../core/public';

const sessionId = Date.now();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/

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

jest.mock('../../notify/toasts', () => {
jest.mock('ui/notify/toasts', () => {
return {
toastNotifications: {
addWarning: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,31 @@
import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiSpacer } from '@elastic/eui';
import { toastNotifications } from '../../notify/toasts';
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';
import { toMountPoint } from '../../../../../../plugins/kibana_react/public';

export function handleResponse(request: SearchRequest, response: SearchResponse) {
if (response.timed_out) {
toastNotifications.addWarning({
title: i18n.translate('common.ui.courier.fetch.requestTimedOutNotificationMessage', {
title: i18n.translate('data.search.searchSource.fetch.requestTimedOutNotificationMessage', {
defaultMessage: 'Data might be incomplete because your request timed out',
}),
});
}

if (response._shards && response._shards.failed) {
const title = i18n.translate('common.ui.courier.fetch.shardsFailedNotificationMessage', {
const title = i18n.translate('data.search.searchSource.fetch.shardsFailedNotificationMessage', {
defaultMessage: '{shardsFailed} of {shardsTotal} shards failed',
values: {
shardsFailed: response._shards.failed,
shardsTotal: response._shards.total,
},
});
const description = i18n.translate(
'common.ui.courier.fetch.shardsFailedNotificationDescription',
'data.search.searchSource.fetch.shardsFailedNotificationDescription',
{
defaultMessage: 'The data you are seeing might be incomplete or wrong.',
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { IUiSettingsClient } from '../../../../../core/public';
import { IUiSettingsClient } from '../../../../../../core/public';
import { SearchRequest, SearchResponse } from '../types';

export interface ApiCaller {
Expand Down
4 changes: 4 additions & 0 deletions src/legacy/core_plugins/data/public/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

export { SearchService, SearchSetup, SearchStart } from './search_service';

export { getRequestInspectorStats, getResponseInspectorStats } from './utils';
51 changes: 51 additions & 0 deletions src/legacy/core_plugins/data/public/search/search_service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { Plugin, CoreSetup, CoreStart } from '../../../../../core/public';
import { SearchSource } from './search_source';
import { defaultSearchStrategy } from './search_strategy';
import { SearchStrategyProvider } from './search_strategy/types';

export interface SearchSetup {} // eslint-disable-line @typescript-eslint/no-empty-interface

export interface SearchStart {
defaultSearchStrategy: SearchStrategyProvider;
SearchSource: typeof SearchSource;
}

/**
* The contract provided here is a new platform shim for ui/courier.
*
* Once it has been refactored to work with new platform services,
* it will move into the existing search service in src/plugins/data/public/search
*/
export class SearchService implements Plugin<SearchSetup, SearchStart> {
public setup(core: CoreSetup): SearchSetup {
return {};
}

public start(core: CoreStart): SearchStart {
return {
defaultSearchStrategy,
SearchSource,
};
}

public stop() {}
}
Loading

0 comments on commit 4d6eeff

Please sign in to comment.