mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Index Management] Fix bug when editing a template with no mappings (#78653)
This commit is contained in:
parent
488344a642
commit
0b3c39e64f
3 changed files with 56 additions and 2 deletions
|
@ -98,6 +98,60 @@ describe('<TemplateEdit />', () => {
|
|||
|
||||
expect(find('fieldsListItem').length).toBe(1);
|
||||
});
|
||||
|
||||
it('allows you to save an unmodified template', async () => {
|
||||
const { actions } = testBed;
|
||||
// Logistics
|
||||
await actions.completeStepOne();
|
||||
// Component templates
|
||||
await actions.completeStepTwo();
|
||||
// Index settings
|
||||
await actions.completeStepThree();
|
||||
// Mappings
|
||||
await actions.completeStepFour();
|
||||
// Aliases
|
||||
await actions.completeStepFive();
|
||||
|
||||
// Submit the form
|
||||
await act(async () => {
|
||||
actions.clickNextButton();
|
||||
});
|
||||
|
||||
const latestRequest = server.requests[server.requests.length - 1];
|
||||
const { version } = templateToEdit;
|
||||
|
||||
const expected = {
|
||||
name: 'index_template_without_mappings',
|
||||
indexPatterns: ['indexPattern1'],
|
||||
version,
|
||||
_kbnMeta: {
|
||||
type: 'default',
|
||||
isLegacy: templateToEdit._kbnMeta.isLegacy,
|
||||
hasDatastream: false,
|
||||
},
|
||||
};
|
||||
|
||||
expect(JSON.parse(JSON.parse(latestRequest.requestBody).body)).toEqual(expected);
|
||||
});
|
||||
|
||||
it('allows you to view the "Request" tab of an unmodified template', async () => {
|
||||
const { actions, exists } = testBed;
|
||||
|
||||
// Logistics
|
||||
await actions.completeStepOne();
|
||||
// Component templates
|
||||
await actions.completeStepTwo();
|
||||
// Index settings
|
||||
await actions.completeStepThree();
|
||||
// Mappings
|
||||
await actions.completeStepFour();
|
||||
// Aliases
|
||||
await actions.completeStepFive();
|
||||
|
||||
await actions.review.selectTab('request');
|
||||
|
||||
expect(exists('requestTab')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with mappings', () => {
|
||||
|
|
|
@ -278,7 +278,7 @@ export const StepReview: React.FunctionComponent<Props> = React.memo(
|
|||
);
|
||||
|
||||
const RequestTab = () => {
|
||||
const includeTypeName = doMappingsHaveType(template!.template.mappings);
|
||||
const includeTypeName = doMappingsHaveType(template!.template?.mappings);
|
||||
const esApiEndpoint = isLegacy ? '_template' : '_index_template';
|
||||
const endpoint = `PUT ${esApiEndpoint}/${name || '<templateName>'}${
|
||||
includeTypeName ? '?include_type_name' : ''
|
||||
|
|
|
@ -284,7 +284,7 @@ export async function saveTemplate(template: TemplateDeserialized, isClone?: boo
|
|||
}
|
||||
|
||||
export async function updateTemplate(template: TemplateDeserialized) {
|
||||
const includeTypeName = doMappingsHaveType(template.template.mappings);
|
||||
const includeTypeName = doMappingsHaveType(template.template?.mappings);
|
||||
const { name } = template;
|
||||
const result = await sendRequest({
|
||||
path: `${API_BASE_PATH}/index_templates/${encodeURIComponent(name)}`,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue