Skip to content

Commit

Permalink
System index templates can't be edited (#55229)
Browse files Browse the repository at this point in the history
* Removed period validation

* Add back period validation

* Fix EsLint

* Undo Snapshot changes from Index Management bug

* Undo Capitalization

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
jkelastic and elasticmachine authored Jan 30, 2020
1 parent 8a4d680 commit b7bcff7
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from '../../../../../../../../../src/plugins/es_ui_shared/static/forms/components';
import { documentationService } from '../../../services/documentation';
import { StepProps } from '../types';
import { schemas } from '../template_form_schemas';
import { schemas, nameConfig, nameConfigWithoutValidations } from '../template_form_schemas';

// Create or Form components with partial props that are common to all instances
const UseField = getUseField({ component: Field });
Expand Down Expand Up @@ -131,6 +131,7 @@ export const StepLogistics: React.FunctionComponent<StepProps> = ({
['data-test-subj']: name.testSubject,
euiFieldProps: { disabled: isEditing },
}}
config={isEditing ? nameConfigWithoutValidations : nameConfig}
/>
</FormRow>
{/* Index patterns */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
FormSchema,
FIELD_TYPES,
VALIDATION_TYPES,
FieldConfig,
} from '../../../../../../../../src/plugins/es_ui_shared/static/forms/hook_form_lib';

import {
Expand All @@ -34,70 +35,71 @@ const {
const { toInt } = fieldFormatters;
const indexPatternInvalidCharacters = INVALID_INDEX_PATTERN_CHARS.join(' ');

export const schemas: Record<string, FormSchema> = {
logistics: {
name: {
type: FIELD_TYPES.TEXT,
label: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.fieldNameLabel', {
defaultMessage: 'Name',
export const nameConfig: FieldConfig = {
type: FIELD_TYPES.TEXT,
label: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.fieldNameLabel', {
defaultMessage: 'Name',
}),
validations: [
{
validator: emptyField(
i18n.translate('xpack.idxMgmt.templateValidation.templateNameRequiredError', {
defaultMessage: 'A template name is required.',
})
),
},
{
validator: containsCharsField({
chars: ' ',
message: i18n.translate('xpack.idxMgmt.templateValidation.templateNameSpacesError', {
defaultMessage: 'Spaces are not allowed in a template name.',
}),
}),
validations: [
{
validator: emptyField(
i18n.translate('xpack.idxMgmt.templateValidation.templateNameRequiredError', {
defaultMessage: 'A template name is required.',
})
),
},
{
validator: containsCharsField({
chars: ' ',
message: i18n.translate('xpack.idxMgmt.templateValidation.templateNameSpacesError', {
defaultMessage: 'Spaces are not allowed in a template name.',
}),
}),
},
{
validator: startsWithField({
char: '_',
message: i18n.translate(
'xpack.idxMgmt.templateValidation.templateNameUnderscoreError',
{
defaultMessage: 'A template name must not start with an underscore.',
}
),
}),
},
{
validator: startsWithField({
char: '.',
message: i18n.translate('xpack.idxMgmt.templateValidation.templateNamePeriodError', {
defaultMessage: 'A template name must not start with a period.',
}),
}),
},
{
validator: containsCharsField({
chars: INVALID_TEMPLATE_NAME_CHARS,
message: ({ charsFound }) =>
i18n.translate(
'xpack.idxMgmt.templateValidation.templateNameInvalidaCharacterError',
{
defaultMessage: 'A template name must not contain the character "{invalidChar}"',
values: { invalidChar: charsFound[0] },
}
),
},
{
validator: startsWithField({
char: '_',
message: i18n.translate('xpack.idxMgmt.templateValidation.templateNameUnderscoreError', {
defaultMessage: 'A template name must not start with an underscore.',
}),
}),
},
{
validator: startsWithField({
char: '.',
message: i18n.translate('xpack.idxMgmt.templateValidation.templateNamePeriodError', {
defaultMessage: 'A template name must not start with a period.',
}),
}),
},
{
validator: containsCharsField({
chars: INVALID_TEMPLATE_NAME_CHARS,
message: ({ charsFound }) =>
i18n.translate('xpack.idxMgmt.templateValidation.templateNameInvalidaCharacterError', {
defaultMessage: 'A template name must not contain the character "{invalidChar}"',
values: { invalidChar: charsFound[0] },
}),
},
{
validator: lowerCaseStringField(
i18n.translate('xpack.idxMgmt.templateValidation.templateNameLowerCaseRequiredError', {
defaultMessage: 'The template name must be in lowercase.',
})
),
},
],
}),
},
{
validator: lowerCaseStringField(
i18n.translate('xpack.idxMgmt.templateValidation.templateNameLowerCaseRequiredError', {
defaultMessage: 'The template name must be in lowercase.',
})
),
},
],
};

export const nameConfigWithoutValidations: FieldConfig = {
...nameConfig,
validations: [],
};

export const schemas: Record<string, FormSchema> = {
logistics: {
name: nameConfig,
indexPatterns: {
type: FIELD_TYPES.COMBO_BOX,
defaultValue: [],
Expand Down

0 comments on commit b7bcff7

Please sign in to comment.