Skip to content

Commit

Permalink
Move ui/indices into es_ui_shared plugin. (#60186)
Browse files Browse the repository at this point in the history
* Convert js files to ts.
* Add indices namespace.
  • Loading branch information
cjcenizal authored Mar 18, 2020
1 parent 24534e8 commit 9aad898
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 42 deletions.
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/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
Expand Up @@ -26,14 +26,14 @@ import {

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { CronEditor } from '../../../../../../../../../src/plugins/es_ui_shared/public/components/cron_editor';
import { INDEX_ILLEGAL_CHARACTERS_VISIBLE } from '../../../../legacy_imports';
import { indexPatterns } from '../../../../../../../../../src/plugins/data/public';

import { indices } from '../../../../shared_imports';
import { getLogisticalDetailsUrl, getCronUrl } from '../../../services';
import { StepError } from './components';

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

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

export class StepLogistics extends Component {
static propTypes = {
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 { findIllegalCharactersInIndexName } from '../../../../legacy_imports';
import { indices } from '../../../../shared_imports';

export function validateRollupIndex(rollupIndex, indexPattern) {
if (!rollupIndex || !rollupIndex.trim()) {
Expand All @@ -27,7 +27,7 @@ export function validateRollupIndex(rollupIndex, indexPattern) {
];
}

const illegalCharacters = findIllegalCharactersInIndexName(rollupIndex);
const illegalCharacters = indices.findIllegalCharactersInIndexName(rollupIndex);

if (illegalCharacters.length) {
return [
Expand Down
3 changes: 0 additions & 3 deletions x-pack/legacy/plugins/rollup/public/legacy_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@
* you may not use this file except in compliance with the Elastic License.
*/

// @ts-ignore
export { findIllegalCharactersInIndexName, INDEX_ILLEGAL_CHARACTERS_VISIBLE } from 'ui/indices';

export { AggTypeFilters } from 'ui/agg_types';
export { AggTypeFieldFilters } from 'ui/agg_types';
7 changes: 7 additions & 0 deletions x-pack/legacy/plugins/rollup/public/shared_imports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* 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.
*/

export { indices } from '../../../../../src/plugins/es_ui_shared/public';

0 comments on commit 9aad898

Please sign in to comment.