From dec20a8fb013851635748facc263552046d78f42 Mon Sep 17 00:00:00 2001 From: Alison Goryachev Date: Thu, 30 Jan 2020 15:01:40 -0500 Subject: [PATCH] [7.x] System index templates can't be edited (#55229) (#56417) --- .../template_form/steps/step_logistics.tsx | 3 +- .../template_form/template_form_schemas.tsx | 124 +++++++++--------- 2 files changed, 65 insertions(+), 62 deletions(-) diff --git a/x-pack/legacy/plugins/index_management/public/app/components/template_form/steps/step_logistics.tsx b/x-pack/legacy/plugins/index_management/public/app/components/template_form/steps/step_logistics.tsx index 290ade3504551..d2134837c15e5 100644 --- a/x-pack/legacy/plugins/index_management/public/app/components/template_form/steps/step_logistics.tsx +++ b/x-pack/legacy/plugins/index_management/public/app/components/template_form/steps/step_logistics.tsx @@ -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 }); @@ -131,6 +131,7 @@ export const StepLogistics: React.FunctionComponent = ({ ['data-test-subj']: name.testSubject, euiFieldProps: { disabled: isEditing }, }} + config={isEditing ? nameConfigWithoutValidations : nameConfig} /> {/* Index patterns */} diff --git a/x-pack/legacy/plugins/index_management/public/app/components/template_form/template_form_schemas.tsx b/x-pack/legacy/plugins/index_management/public/app/components/template_form/template_form_schemas.tsx index 5f3e28ddffb8e..ed2616cc64e38 100644 --- a/x-pack/legacy/plugins/index_management/public/app/components/template_form/template_form_schemas.tsx +++ b/x-pack/legacy/plugins/index_management/public/app/components/template_form/template_form_schemas.tsx @@ -12,6 +12,7 @@ import { FormSchema, FIELD_TYPES, VALIDATION_TYPES, + FieldConfig, } from '../../../../../../../../src/plugins/es_ui_shared/static/forms/hook_form_lib'; import { @@ -34,70 +35,71 @@ const { const { toInt } = fieldFormatters; const indexPatternInvalidCharacters = INVALID_INDEX_PATTERN_CHARS.join(' '); -export const schemas: Record = { - 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 = { + logistics: { + name: nameConfig, indexPatterns: { type: FIELD_TYPES.COMBO_BOX, defaultValue: [],