Skip to content

Commit

Permalink
Merge branch 'master' into fix-sample-resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Mar 18, 2020
2 parents b2f022a + 9aad898 commit c429b6f
Show file tree
Hide file tree
Showing 122 changed files with 3,992 additions and 613 deletions.
18 changes: 11 additions & 7 deletions src/legacy/ui/public/new_platform/new_platform.karma_mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import sinon from 'sinon';
import { getFieldFormatsRegistry } from '../../../../test_utils/public/stub_field_formats';
import { METRIC_TYPE } from '@kbn/analytics';
import {
setFieldFormats,
setIndexPatterns,
setQueryService,
setUiSettings,
setInjectedMetadata,
setFieldFormats,
setSearchService,
setHttp,
setNotifications,
setOverlays,
setQueryService,
setSearchService,
setUiSettings,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../plugins/data/public/services';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
Expand Down Expand Up @@ -477,11 +479,13 @@ export function __start__(coreStart) {

// Services that need to be set in the legacy platform since the legacy data plugin
// which previously provided them has been removed.
setHttp(npStart.core.http);
setNotifications(npStart.core.notifications);
setOverlays(npStart.core.overlays);
setUiSettings(npStart.core.uiSettings);
setQueryService(npStart.plugins.data.query);
setIndexPatterns(npStart.plugins.data.indexPatterns);
setFieldFormats(npStart.plugins.data.fieldFormats);
setIndexPatterns(npStart.plugins.data.indexPatterns);
setQueryService(npStart.plugins.data.query);
setSearchService(npStart.plugins.data.search);
setAggs(npStart.plugins.data.search.aggs);
setOverlays(npStart.core.overlays);
}
34 changes: 33 additions & 1 deletion src/legacy/ui/public/new_platform/new_platform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@
jest.mock('history');

import { setRootControllerMock, historyMock } from './new_platform.test.mocks';
import { legacyAppRegister, __reset__, __setup__ } from './new_platform';
import {
legacyAppRegister,
__reset__,
__setup__,
__start__,
PluginsSetup,
PluginsStart,
} from './new_platform';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import * as dataServices from '../../../../plugins/data/public/services';
import { LegacyCoreSetup, LegacyCoreStart } from '../../../../core/public';
import { coreMock } from '../../../../core/public/mocks';
import { npSetup, npStart } from './__mocks__';

describe('ui/new_platform', () => {
describe('legacyAppRegister', () => {
Expand Down Expand Up @@ -108,4 +119,25 @@ describe('ui/new_platform', () => {
expect(unmountMock).toHaveBeenCalled();
});
});

describe('service getters', () => {
const services: Record<string, Function> = dataServices;
const getters = Object.keys(services).filter(k => k.substring(0, 3) === 'get');

getters.forEach(g => {
it(`sets a value for ${g}`, () => {
__reset__();
__setup__(
(coreMock.createSetup() as unknown) as LegacyCoreSetup,
(npSetup.plugins as unknown) as PluginsSetup
);
__start__(
(coreMock.createStart() as unknown) as LegacyCoreStart,
(npStart.plugins as unknown) as PluginsStart
);

expect(services[g]()).toBeDefined();
});
});
});
});
18 changes: 11 additions & 7 deletions src/legacy/ui/public/new_platform/new_platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ import {
} from '../../../../core/public';
import { Plugin as DataPlugin } from '../../../../plugins/data/public';
import {
setFieldFormats,
setIndexPatterns,
setQueryService,
setUiSettings,
setInjectedMetadata,
setFieldFormats,
setSearchService,
setHttp,
setNotifications,
setOverlays,
setQueryService,
setSearchService,
setUiSettings,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../plugins/data/public/services';
import { Plugin as ExpressionsPlugin } from '../../../../plugins/expressions/public';
Expand Down Expand Up @@ -141,12 +143,14 @@ export function __start__(coreStart: LegacyCoreStart, plugins: PluginsStart) {

// Services that need to be set in the legacy platform since the legacy data plugin
// which previously provided them has been removed.
setHttp(npStart.core.http);
setNotifications(npStart.core.notifications);
setOverlays(npStart.core.overlays);
setUiSettings(npStart.core.uiSettings);
setQueryService(npStart.plugins.data.query);
setIndexPatterns(npStart.plugins.data.indexPatterns);
setFieldFormats(npStart.plugins.data.fieldFormats);
setIndexPatterns(npStart.plugins.data.indexPatterns);
setQueryService(npStart.plugins.data.query);
setSearchService(npStart.plugins.data.search);
setOverlays(npStart.core.overlays);
}

/** Flag used to ensure `legacyAppRegister` is only called once. */
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
- `filter`
- `index_patterns`
- `query`
- `search`
- `search`
2 changes: 2 additions & 0 deletions src/plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { createIndexPatternSelect } from './ui/index_pattern_select';
import { IndexPatternsService } from './index_patterns';
import {
setFieldFormats,
setHttp,
setIndexPatterns,
setInjectedMetadata,
setNotifications,
Expand Down Expand Up @@ -128,6 +129,7 @@ export class DataPublicPlugin implements Plugin<DataPublicPluginSetup, DataPubli

public start(core: CoreStart, { uiActions }: DataStartDependencies): DataPublicPluginStart {
const { uiSettings, http, notifications, savedObjects, overlays } = core;
setHttp(http);
setNotifications(notifications);
setOverlays(overlays);
setUiSettings(uiSettings);
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/es_ui_shared/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ export {
sendRequest,
useRequest,
} from './request/np_ready_request';

export { indices } from './indices';
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { indexPatterns } from '../../../../../plugins/data/public';
import { indexPatterns } from '../../../../data/public';

export const INDEX_ILLEGAL_CHARACTERS_VISIBLE = [...indexPatterns.ILLEGAL_CHARACTERS_VISIBLE, '*'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@
* under the License.
*/

export { INDEX_ILLEGAL_CHARACTERS_VISIBLE } from './constants';
import { INDEX_ILLEGAL_CHARACTERS_VISIBLE } from './constants';

export {
import {
indexNameBeginsWithPeriod,
findIllegalCharactersInIndexName,
indexNameContainsSpaces,
} from './validate';

export const indices = {
INDEX_ILLEGAL_CHARACTERS_VISIBLE,
indexNameBeginsWithPeriod,
findIllegalCharactersInIndexName,
indexNameContainsSpaces,
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,29 @@

import { INDEX_ILLEGAL_CHARACTERS_VISIBLE } from '../constants';

// Names beginning with periods are reserved for system indices.
export function indexNameBeginsWithPeriod(indexName = '') {
// Names beginning with periods are reserved for hidden indices.
export function indexNameBeginsWithPeriod(indexName?: string): boolean {
if (indexName === undefined) {
return false;
}
return indexName[0] === '.';
}

export function findIllegalCharactersInIndexName(indexName) {
const illegalCharacters = INDEX_ILLEGAL_CHARACTERS_VISIBLE.reduce((chars, char) => {
if (indexName.includes(char)) {
chars.push(char);
}
export function findIllegalCharactersInIndexName(indexName: string): string[] {
const illegalCharacters = INDEX_ILLEGAL_CHARACTERS_VISIBLE.reduce(
(chars: string[], char: string): string[] => {
if (indexName.includes(char)) {
chars.push(char);
}

return chars;
}, []);
return chars;
},
[]
);

return illegalCharacters;
}

export function indexNameContainsSpaces(indexName) {
export function indexNameContainsSpaces(indexName: string): boolean {
return indexName.includes(' ');
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@
* under the License.
*/

// Note: we can't import from "ui/indices" as the TS Type definition don't exist
// import { INDEX_ILLEGAL_CHARACTERS_VISIBLE } from 'ui/indices';
import { indices } from '../../../../public';
import { ValidationFunc } from '../../hook_form_lib';
import { startsWith, containsChars } from '../../../validators/string';
import { ERROR_CODE } from './types';

const INDEX_ILLEGAL_CHARACTERS = ['\\', '/', '?', '"', '<', '>', '|', '*'];

export const indexNameField = (i18n: any) => (
...args: Parameters<ValidationFunc>
): ReturnType<ValidationFunc<any, ERROR_CODE>> => {
Expand All @@ -51,7 +48,9 @@ export const indexNameField = (i18n: any) => (
};
}

const { charsFound, doesContain } = containsChars(INDEX_ILLEGAL_CHARACTERS)(value as string);
const { charsFound, doesContain } = containsChars(indices.INDEX_ILLEGAL_CHARACTERS_VISIBLE)(
value as string
);
if (doesContain) {
return {
message: i18n.translate('esUi.forms.fieldValidation.indexNameInvalidCharactersError', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import {
EuiTitle,
} from '@elastic/eui';

import { INDEX_ILLEGAL_CHARACTERS_VISIBLE } from 'ui/indices';
import { indices } from '../../../../../../../src/plugins/es_ui_shared/public';
import { indexPatterns } from '../../../../../../../src/plugins/data/public';

import routing from '../services/routing';
import { extractQueryParams } from '../services/query_params';
Expand All @@ -44,10 +45,9 @@ import {
} from '../services/auto_follow_pattern_validators';

import { AutoFollowPatternRequestFlyout } from './auto_follow_pattern_request_flyout';
import { indexPatterns } from '../../../../../../../src/plugins/data/public';

const indexPatternIllegalCharacters = indexPatterns.ILLEGAL_CHARACTERS_VISIBLE.join(' ');
const indexNameIllegalCharacters = INDEX_ILLEGAL_CHARACTERS_VISIBLE.join(' ');
const indexNameIllegalCharacters = indices.INDEX_ILLEGAL_CHARACTERS_VISIBLE.join(' ');

const getEmptyAutoFollowPattern = (remoteClusterName = '') => ({
name: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import PropTypes from 'prop-types';
import { debounce } from 'lodash';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { INDEX_ILLEGAL_CHARACTERS_VISIBLE } from 'ui/indices';
import { fatalError } from 'ui/notify';

import {
Expand All @@ -30,6 +29,7 @@ import {
EuiTitle,
} from '@elastic/eui';

import { indices } from '../../../../../../../../src/plugins/es_ui_shared/public';
import { indexNameValidator, leaderIndexValidator } from '../../services/input_validation';
import routing from '../../services/routing';
import { loadIndices } from '../../services/api';
Expand All @@ -47,7 +47,7 @@ import { RemoteClustersFormField } from '../remote_clusters_form_field';

import { FollowerIndexRequestFlyout } from './follower_index_request_flyout';

const indexNameIllegalCharacters = INDEX_ILLEGAL_CHARACTERS_VISIBLE.join(' ');
const indexNameIllegalCharacters = indices.INDEX_ILLEGAL_CHARACTERS_VISIBLE.join(' ');

const fieldToValidatorMap = advancedSettingsFields.reduce(
(map, advancedSetting) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import { updateFields, updateFormErrors } from './follower_index_form';

jest.mock('ui/new_platform');
jest.mock('ui/indices', () => ({
INDEX_ILLEGAL_CHARACTERS_VISIBLE: [],
}));

describe('<FollowerIndexForm /> state transitions', () => {
it('updateFormErrors() should merge errors with existing fieldsErrors', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import React from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';

import {
import { indices } from '../../../../../../../src/plugins/es_ui_shared/public';
import { indexPatterns } from '../../../../../../../src/plugins/data/public';

const {
indexNameBeginsWithPeriod,
findIllegalCharactersInIndexName,
indexNameContainsSpaces,
} from 'ui/indices';

import { indexPatterns } from '../../../../../../../src/plugins/data/public';
} = indices;

export const validateName = (name = '') => {
let errorMsg = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { INDEX_ILLEGAL_CHARACTERS_VISIBLE } from 'ui/indices';
import { indices } from '../../../../../../../src/plugins/es_ui_shared/public';

const isEmpty = value => {
return !value || !value.trim().length;
Expand All @@ -19,7 +19,7 @@ const beginsWithPeriod = value => {
};

const findIllegalCharacters = value => {
return INDEX_ILLEGAL_CHARACTERS_VISIBLE.reduce((chars, char) => {
return indices.INDEX_ILLEGAL_CHARACTERS_VISIBLE.reduce((chars, char) => {
if (value.includes(char)) {
chars.push(char);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
/* eslint-disable @typescript-eslint/consistent-type-definitions */

// Global map state passed to every layer.
export type MapFilters = {
buffer: unknown;
extent: unknown;
filters: unknown[];
query: unknown;
refreshTimerLastTriggeredAt: string;
timeFilters: unknown;
zoom: number;
};

export type VectorLayerRequestMeta = MapFilters & {
applyGlobalQuery: boolean;
fieldNames: string[];
geogridPrecision: number;
sourceQuery: unknown;
sourceMeta: unknown;
};

export type ESSearchSourceResponseMeta = {
areResultsTrimmed?: boolean;
sourceType?: string;

// top hits meta
areEntitiesTrimmed?: boolean;
entityCount?: number;
totalEntities?: number;
};

// Partial because objects are justified downstream in constructors
export type DataMeta = Partial<VectorLayerRequestMeta> & Partial<ESSearchSourceResponseMeta>;

export type DataRequestDescriptor = {
dataId: string;
dataMetaAtStart?: DataMeta;
dataRequestToken?: symbol;
data?: object;
dataMeta?: DataMeta;
};
Loading

0 comments on commit c429b6f

Please sign in to comment.