Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move ui/indices into es_ui_shared plugin. #60186

Merged
merged 6 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`
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 @@ -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,12 @@
* 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';
// @ts-ignore
import { INDEX_ILLEGAL_CHARACTERS_VISIBLE } from '../../../../indices';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebelga AFAICT this file isn't consumed anywhere, so I wasn't sure how to test this. I don't want to spend time writing a test for it. I'm inclined to leave it with the expectation that a problem will be surfaced and fixed if/when we consume this file. What are your thoughts?

Copy link
Contributor

@sebelga sebelga Mar 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, although I think it would have been nice to make use of this single validator in our apps instead of re-writing it multiple times as I've seen. Maybe as a second pass 😊

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 +49,9 @@ export const indexNameField = (i18n: any) => (
};
}

const { charsFound, doesContain } = containsChars(INDEX_ILLEGAL_CHARACTERS)(value as string);
const { charsFound, doesContain } = containsChars(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 { INDEX_ILLEGAL_CHARACTERS_VISIBLE } 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,7 +45,6 @@ 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(' ');
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 { INDEX_ILLEGAL_CHARACTERS_VISIBLE } from '../../../../../../../../src/plugins/es_ui_shared/public';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to namespace our export.

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

const { INDEX_ILLEGAL_CHARACTERS_VISIBLE } = indices;

This will avoid naming collisions and better organization of all our exports.

import { indexNameValidator, leaderIndexValidator } from '../../services/input_validation';
import routing from '../../services/routing';
import { loadIndices } from '../../services/api';
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 @@ -12,8 +12,7 @@ import {
indexNameBeginsWithPeriod,
findIllegalCharactersInIndexName,
indexNameContainsSpaces,
} from 'ui/indices';

} from '../../../../../../../src/plugins/es_ui_shared/public';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, it would be better to namespace under indices

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

export const validateName = (name = '') => {
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 { INDEX_ILLEGAL_CHARACTERS_VISIBLE } from '../../../../../../../src/plugins/es_ui_shared/public';

const isEmpty = value => {
return !value || !value.trim().length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ 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 { INDEX_ILLEGAL_CHARACTERS_VISIBLE } 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(' ');

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 { findIllegalCharactersInIndexName } from '../../../../shared_imports';

export function validateRollupIndex(rollupIndex, indexPattern) {
if (!rollupIndex || !rollupIndex.trim()) {
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';
10 changes: 10 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,10 @@
/*
* 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 {
findIllegalCharactersInIndexName,
INDEX_ILLEGAL_CHARACTERS_VISIBLE,
} from '../../../../../src/plugins/es_ui_shared/public';