Skip to content

Commit

Permalink
Fix EsLint
Browse files Browse the repository at this point in the history
  • Loading branch information
jkelastic committed Jan 23, 2020
1 parent c5a4d31 commit ad204c5
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 67 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
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ export const PolicyStepSettings: React.FunctionComponent<StepProps> = ({
// State for using selectable indices list or custom patterns
// Users with more than 100 indices will probably want to use an index pattern to select
// them instead, so we'll default to showing them the index pattern input.
const [selectIndicesMode, setSelectIndicesMode] = useState<'list' | 'custom'>(
const [selectIndicesMode, setSelectIndicesMode] = useState<'custom' | 'list'>(
typeof config.indices === 'string' ||
(Array.isArray(config.indices) && config.indices.length > 100)
? 'custom'
: 'list'
? 'list'
: 'custom'
);

// State for custom patterns
Expand Down Expand Up @@ -171,7 +171,7 @@ export const PolicyStepSettings: React.FunctionComponent<StepProps> = ({
>
<FormattedMessage
id="xpack.snapshotRestore.policyForm.stepSettings.indicesToggleCustomLink"
defaultMessage="Use index patterns"
defaultMessage="Use custom patterns"
/>
</EuiLink>
</EuiFlexItem>
Expand All @@ -181,7 +181,7 @@ export const PolicyStepSettings: React.FunctionComponent<StepProps> = ({
<EuiFlexItem grow={false}>
<FormattedMessage
id="xpack.snapshotRestore.policyForm.stepSettings.indicesPatternLabel"
defaultMessage="Index patterns"
defaultMessage="Custom patterns"
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
Expand Down

0 comments on commit ad204c5

Please sign in to comment.