[Index Management] Fix bug when editing a template with no mappings (#78653)

This commit is contained in:
Alison Goryachev 2020-09-29 09:19:31 -04:00 committed by GitHub
parent 488344a642
commit 0b3c39e64f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 2 deletions

View file

@ -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', () => {

View file

@ -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' : ''

View file

@ -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)}`,