From a2c5bf82732f10263ceed9eedd4efe3fe5cdfb9b Mon Sep 17 00:00:00 2001 From: Matthew Kime Date: Tue, 7 Feb 2023 21:05:59 -0600 Subject: [PATCH] [data view mgmt] fix field refresh when index pattern is changed. (#150403) Data view management now updates the field list of an edited data view upon save. Closes: https://github.com/elastic/kibana/issues/150248 --- .../edit_index_pattern/edit_index_pattern.tsx | 5 ++- .../table/__snapshots__/table.test.tsx.snap | 16 +++++++--- .../components/table/table.tsx | 2 +- .../_index_pattern_create_delete.ts | 31 +++++++++++++++++++ 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/plugins/data_view_management/public/components/edit_index_pattern/edit_index_pattern.tsx b/src/plugins/data_view_management/public/components/edit_index_pattern/edit_index_pattern.tsx index 811222ef71e88..de421c0b8945e 100644 --- a/src/plugins/data_view_management/public/components/edit_index_pattern/edit_index_pattern.tsx +++ b/src/plugins/data_view_management/public/components/edit_index_pattern/edit_index_pattern.tsx @@ -128,7 +128,10 @@ export const EditIndexPattern = withRouter( const isRollup = new URLSearchParams(useLocation().search).get('type') === 'rollup'; const displayIndexPatternEditor = showEditDialog ? ( setShowEditDialog(false)} + onSave={() => { + setFields(indexPattern.getNonScriptedFields()); + setShowEditDialog(false); + }} onCancel={() => setShowEditDialog(false)} defaultTypeIsRollup={isRollup} editData={indexPattern} diff --git a/src/plugins/data_view_management/public/components/edit_index_pattern/indexed_fields_table/components/table/__snapshots__/table.test.tsx.snap b/src/plugins/data_view_management/public/components/edit_index_pattern/indexed_fields_table/components/table/__snapshots__/table.test.tsx.snap index ac6ab1172a535..65c124c6676fa 100644 --- a/src/plugins/data_view_management/public/components/edit_index_pattern/indexed_fields_table/components/table/__snapshots__/table.test.tsx.snap +++ b/src/plugins/data_view_management/public/components/edit_index_pattern/indexed_fields_table/components/table/__snapshots__/table.test.tsx.snap @@ -82,13 +82,17 @@ exports[`Table render conflict summary modal 1`] = ` `; exports[`Table render name 1`] = ` - + customer `; exports[`Table render name 2`] = ` - + customer   @@ -126,7 +130,9 @@ exports[`Table should render mixed, non-conflicting type 1`] = ` `; exports[`Table should render normal field name 1`] = ` - + Elastic `; @@ -324,7 +330,9 @@ exports[`Table should render the boolean template (true) 1`] = ` `; exports[`Table should render timestamp field name 1`] = ` - + timestamp   diff --git a/src/plugins/data_view_management/public/components/edit_index_pattern/indexed_fields_table/components/table/table.tsx b/src/plugins/data_view_management/public/components/edit_index_pattern/indexed_fields_table/components/table/table.tsx index a7b6cf621bb64..b7ed701b31c68 100644 --- a/src/plugins/data_view_management/public/components/edit_index_pattern/indexed_fields_table/components/table/table.tsx +++ b/src/plugins/data_view_management/public/components/edit_index_pattern/indexed_fields_table/components/table/table.tsx @@ -220,7 +220,7 @@ const getItems = (conflictDescriptions: IndexedFieldItem['conflictDescriptions'] }; export const renderFieldName = (field: IndexedFieldItem, timeFieldName?: string) => ( - + {field.name} {field.info && field.info.length ? ( diff --git a/test/functional/apps/management/_index_pattern_create_delete.ts b/test/functional/apps/management/_index_pattern_create_delete.ts index 8447610d60aa8..f89013eac43fa 100644 --- a/test/functional/apps/management/_index_pattern_create_delete.ts +++ b/test/functional/apps/management/_index_pattern_create_delete.ts @@ -22,11 +22,20 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { describe('creating and deleting default index', function describeIndexTests() { before(async function () { await esArchiver.emptyKibanaIndex(); + await esArchiver.loadIfNeeded( + 'test/functional/fixtures/es_archiver/kibana_sample_data_flights_index_pattern' + ); await kibanaServer.uiSettings.replace({}); await PageObjects.settings.navigateTo(); await PageObjects.settings.clickKibanaIndexPatterns(); }); + after(async function () { + await esArchiver.unload( + 'test/functional/fixtures/es_archiver/kibana_sample_data_flights_index_pattern' + ); + }); + describe('can open and close editor', function () { it('without creating index pattern', async function () { await PageObjects.settings.clickKibanaIndexPatterns(); @@ -157,6 +166,28 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { }); }); + describe('index pattern edit', function () { + it('should update field list', async function () { + await PageObjects.settings.editIndexPattern( + 'kibana_sample_data_flights', + 'timestamp', + undefined, + true + ); + + await retry.try(async () => { + // verify initial field list + expect(await testSubjects.exists('field-name-AvgTicketPrice')).to.be(true); + }); + + await PageObjects.settings.editIndexPattern('logstash-*', '@timestamp', undefined, true); + await retry.try(async () => { + // verify updated field list + expect(await testSubjects.exists('field-name-agent')).to.be(true); + }); + }); + }); + describe('index pattern deletion', function indexDelete() { before(function () { const expectedAlertText = 'Delete data view';