Skip to content

Commit

Permalink
Add data stream field in logistics step
Browse files Browse the repository at this point in the history
  • Loading branch information
sebelga committed Jul 8, 2020
1 parent 913cfeb commit a4bf5e4
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@ import {
const hasEntries = (data: object = {}) => Object.entries(data).length > 0;

export function serializeTemplate(templateDeserialized: TemplateDeserialized): TemplateSerialized {
const { version, priority, indexPatterns, template, composedOf, _meta } = templateDeserialized;
const {
version,
priority,
indexPatterns,
template,
composedOf,
dataStream,
_meta,
} = templateDeserialized;

return {
version,
priority,
template,
index_patterns: indexPatterns,
data_stream: dataStream,
composed_of: composedOf,
_meta,
};
Expand Down
10 changes: 5 additions & 5 deletions x-pack/plugins/index_management/common/types/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ export interface TemplateDeserialized {
aliases?: Aliases;
mappings?: Mappings;
};
composedOf?: string[]; // Used on composable index template
composedOf?: string[]; // Composable template only
version?: number;
priority?: number;
order?: number; // Used on legacy index template
priority?: number; // Composable template only
order?: number; // Legacy template only
ilmPolicy?: {
name: string;
};
_meta?: { [key: string]: any };
dataStream?: { timestamp_field: string };
_meta?: { [key: string]: any }; // Composable template only
dataStream?: { timestamp_field: string }; // Composable template only
_kbnMeta: {
isManaged: boolean;
isCloudManaged: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/
import React, { useEffect } from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiTitle, EuiButtonEmpty, EuiSpacer } from '@elastic/eui';
import {
EuiFlexGroup,
EuiFlexItem,
EuiTitle,
EuiButtonEmpty,
EuiSpacer,
EuiLink,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';

Expand All @@ -25,56 +32,82 @@ import { schemas, nameConfig, nameConfigWithoutValidations } from '../template_f
const UseField = getUseField({ component: Field });
const FormRow = getFormRow({ titleTag: 'h3' });

const fieldsMeta = {
name: {
title: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.nameTitle', {
defaultMessage: 'Name',
}),
description: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.nameDescription', {
defaultMessage: 'A unique identifier for this template.',
}),
testSubject: 'nameField',
},
indexPatterns: {
title: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.indexPatternsTitle', {
defaultMessage: 'Index patterns',
}),
description: i18n.translate(
'xpack.idxMgmt.templateForm.stepLogistics.indexPatternsDescription',
{
defaultMessage: 'The index patterns to apply to the template.',
}
),
testSubject: 'indexPatternsField',
},
order: {
title: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.orderTitle', {
defaultMessage: 'Merge order',
}),
description: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.orderDescription', {
defaultMessage: 'The merge order when multiple templates match an index.',
}),
testSubject: 'orderField',
},
priority: {
title: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.priorityTitle', {
defaultMessage: 'Priority',
}),
description: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.priorityDescription', {
defaultMessage: 'Only the highest priority template will be applied.',
}),
testSubject: 'priorityField',
},
version: {
title: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.versionTitle', {
defaultMessage: 'Version',
}),
description: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.versionDescription', {
defaultMessage: 'A number that identifies the template to external management systems.',
}),
testSubject: 'versionField',
},
};
function getFieldsMeta(esDocsBase: string) {
return {
name: {
title: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.nameTitle', {
defaultMessage: 'Name',
}),
description: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.nameDescription', {
defaultMessage: 'A unique identifier for this template.',
}),
testSubject: 'nameField',
},
indexPatterns: {
title: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.indexPatternsTitle', {
defaultMessage: 'Index patterns',
}),
description: i18n.translate(
'xpack.idxMgmt.templateForm.stepLogistics.indexPatternsDescription',
{
defaultMessage: 'The index patterns to apply to the template.',
}
),
testSubject: 'indexPatternsField',
},
dataStream: {
title: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.dataStreamTitle', {
defaultMessage: 'Data stream',
}),
description: (
<FormattedMessage
id="xpack.idxMgmt.templateForm.stepLogistics.dataStreamDescription"
defaultMessage="Wheter indices that match the index patterns should automatically create a data stream. {docsLink}"
values={{
docsLink: (
<>
<br />
<EuiLink href={`${esDocsBase}/data-streams.html`} target="_blank">
{i18n.translate('xpack.idxMgmt.mappingsEditor.dynamicMappingDocumentionLink', {
defaultMessage: 'Learn more about data streams.',
})}
</EuiLink>
</>
),
}}
/>
),
testSubject: 'dataStreamField',
},
order: {
title: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.orderTitle', {
defaultMessage: 'Merge order',
}),
description: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.orderDescription', {
defaultMessage: 'The merge order when multiple templates match an index.',
}),
testSubject: 'orderField',
},
priority: {
title: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.priorityTitle', {
defaultMessage: 'Priority',
}),
description: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.priorityDescription', {
defaultMessage: 'Only the highest priority template will be applied.',
}),
testSubject: 'priorityField',
},
version: {
title: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.versionTitle', {
defaultMessage: 'Version',
}),
description: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.versionDescription', {
defaultMessage: 'A number that identifies the template to external management systems.',
}),
testSubject: 'versionField',
},
};
}

interface LogisticsForm {
[key: string]: any;
Expand Down Expand Up @@ -144,7 +177,9 @@ export const StepLogistics: React.FunctionComponent<Props> = React.memo(
return subscription.unsubscribe;
}, [onChange]); // eslint-disable-line react-hooks/exhaustive-deps

const { name, indexPatterns, order, priority, version } = fieldsMeta;
const { name, indexPatterns, dataStream, order, priority, version } = getFieldsMeta(
documentationService.getEsDocsBase()
);

return (
<>
Expand Down Expand Up @@ -207,6 +242,16 @@ export const StepLogistics: React.FunctionComponent<Props> = React.memo(
/>
</FormRow>

{/* Create data stream */}
{isLegacy !== true && (
<FormRow title={dataStream.title} description={dataStream.description}>
<UseField
path="dataStream"
componentProps={{ 'data-test-subj': dataStream.testSubject }}
/>
</FormRow>
)}

{/* Order */}
{isLegacy && (
<FormRow title={order.title} description={order.description}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,32 @@ export const schemas: Record<string, FormSchema> = {
},
],
},
dataStream: {
type: FIELD_TYPES.TOGGLE,
label: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.datastreamLabel', {
defaultMessage: 'Create data stream',
}),
defaultValue: false,
serializer: (value) => {
if (value === true) {
return {
timestamp_field: '@timestamp',
};
}
},
deserializer: (value) => {
if (typeof value === 'boolean') {
return value;
}

/**
* For now, it is enough to have a "data_stream" declared on the index template
* to assume that the template creates a data stream. In the future, this condition
* might change
*/
return value !== undefined;
},
},
order: {
type: FIELD_TYPES.NUMBER,
label: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.fieldOrderLabel', {
Expand Down Expand Up @@ -193,7 +219,7 @@ export const schemas: Record<string, FormSchema> = {
label: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.addMetadataLabel', {
defaultMessage: 'Add metadata',
}),
} as FieldConfig,
},
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const templateSchema = schema.object({
})
),
composedOf: schema.maybe(schema.arrayOf(schema.string())),
dataStream: schema.maybe(schema.object({}, { unknowns: 'allow' })),
_meta: schema.maybe(schema.object({}, { unknowns: 'allow' })),
ilmPolicy: schema.maybe(
schema.object({
Expand Down

0 comments on commit a4bf5e4

Please sign in to comment.