Skip to content

Commit

Permalink
[Index Management] Fix schema for index templates (#203552)
Browse files Browse the repository at this point in the history
Fixes #203553

## Summary

This PR fixes the template schema so that the server allows creating a
template with undefined index mode. The issue is that when we exposed
the index mode info in #197874, we
assumed that, by default, the index mode is `standard` so `indexMode`
was added as a required field. However, in
#199521, we added the index mode
field only if data streams toggle is enabled, so the `indexMode` is
`undefined`.

The PR also fixes a smaller issuer where Index mode is displayed even
when it is undefined (when data streams are disabled):
**Before:**
<img width="905" alt="Screenshot 2024-12-10 at 19 01 09"
src="https://github.com/user-attachments/assets/e22cab14-eade-4591-8da8-f9aec5ad6c43">

**Now:**
<img width="905" alt="Screenshot 2024-12-10 at 18 19 29"
src="https://github.com/user-attachments/assets/e7768cdc-9610-4a25-b403-0320b7137db5">


**How to test:**
1. Go to Index Management -> Index templates and start creating an index
template.
2. Specify the name and the index pattern and disable the "Data streams"
toggle.
3. Go to Review step and verify that index mode is not displayed in the
summary and that creating the index template is successful.
  • Loading branch information
ElenaStoeva authored Dec 11, 2024
1 parent 42594eb commit bdc8032
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/index_management/common/types/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface TemplateDeserialized {
priority?: number; // Composable template only
allowAutoCreate: string;
order?: number; // Legacy template only
indexMode: IndexMode;
indexMode?: IndexMode;
ilmPolicy?: {
name: string;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,19 @@ export const StepReview: React.FunctionComponent<Props> = React.memo(
</EuiDescriptionListDescription>

{/* Index mode */}
<EuiDescriptionListTitle data-test-subj="indexModeTitle">
<FormattedMessage
id="xpack.idxMgmt.templateForm.stepReview.summaryTab.indexModeLabel"
defaultMessage="Index mode"
/>
</EuiDescriptionListTitle>
<EuiDescriptionListDescription data-test-subj="indexModeValue">
{indexModeLabels[indexMode]}
</EuiDescriptionListDescription>
{indexMode && (
<>
<EuiDescriptionListTitle data-test-subj="indexModeTitle">
<FormattedMessage
id="xpack.idxMgmt.templateForm.stepReview.summaryTab.indexModeLabel"
defaultMessage="Index mode"
/>
</EuiDescriptionListTitle>
<EuiDescriptionListDescription data-test-subj="indexModeValue">
{indexModeLabels[indexMode]}
</EuiDescriptionListDescription>
</>
)}

{/* Mappings */}
<EuiDescriptionListTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,19 @@ export const TabSummary: React.FunctionComponent<Props> = ({ templateDetails })
)}

{/* Index mode */}
<EuiDescriptionListTitle>
<FormattedMessage
id="xpack.idxMgmt.templateDetails.stepReview.summaryTab.indexModeLabel"
defaultMessage="Index mode"
/>
</EuiDescriptionListTitle>
<EuiDescriptionListDescription>
{indexModeLabels[indexMode]}
</EuiDescriptionListDescription>
{indexMode && (
<>
<EuiDescriptionListTitle>
<FormattedMessage
id="xpack.idxMgmt.templateDetails.stepReview.summaryTab.indexModeLabel"
defaultMessage="Index mode"
/>
</EuiDescriptionListTitle>
<EuiDescriptionListDescription>
{indexModeLabels[indexMode]}
</EuiDescriptionListDescription>
</>
)}

{/* Allow auto create */}
{isLegacy !== true &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const templateSchema = schema.object({
version: schema.maybe(schema.number()),
order: schema.maybe(schema.number()),
priority: schema.maybe(schema.number()),
indexMode: schema.string(),
indexMode: schema.maybe(schema.string()),
// Not present for legacy templates
allowAutoCreate: schema.maybe(schema.string()),
template: schema.maybe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export function templatesHelpers(getService: FtrProviderContext['getService']) {
name,
indexPatterns,
version: 1,
indexMode: 'standard',
template: { ...getTemplateMock(isMappingsSourceFieldEnabled) },
_kbnMeta: {
isLegacy,
Expand Down

0 comments on commit bdc8032

Please sign in to comment.