From db3874c405b8623cca5a92e07d7d8a11aaf83bde Mon Sep 17 00:00:00 2001 From: Elastic Jasper Date: Tue, 20 Sep 2016 19:03:48 -0400 Subject: [PATCH] Backport PR #8312 --------- **Commit 1:** do not remove selection when clicking refreh fields * Original sha: afce3bede7c948db02373e6d55ff227ad2220e58 * Authored by Thomas Neirynck on 2016-09-16T17:51:06Z **Commit 2:** improve readability * Original sha: 411957cd96d17ec9d00f7bef6391a37a56f13edb * Authored by Thomas Neirynck on 2016-09-20T21:32:21Z --- .../management/sections/indices/_create.js | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/core_plugins/kibana/public/management/sections/indices/_create.js b/src/core_plugins/kibana/public/management/sections/indices/_create.js index cb98e8682457..c0c00806f2bc 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/_create.js +++ b/src/core_plugins/kibana/public/management/sections/indices/_create.js @@ -43,7 +43,14 @@ uiModules.get('apps/management') }; $scope.refreshFieldList = function () { - fetchFieldList().then(updateFieldList); + const timeField = index.timeField; + fetchFieldList().then(function (results) { + if (timeField) { + updateFieldListAndSetTimeField(results, timeField.name); + } else { + updateFieldList(results); + } + }); }; $scope.createIndexPattern = function () { @@ -247,6 +254,22 @@ uiModules.get('apps/management') }, notify.fatal); } + function updateFieldListAndSetTimeField(results, timeFieldName) { + updateFieldList(results); + + if (!results.dateFields.length) { + return; + } + + const matchingTimeField = results.dateFields.find(field => field.name === timeFieldName); + const defaultTimeField = results.dateFields[0]; + + //assign the field from the results-list + //angular recreates a new timefield instance, each time the list is refreshed. + //This ensures the selected field matches one of the instances in the list. + index.timeField = matchingTimeField ? matchingTimeField : defaultTimeField; + } + function updateFieldList(results) { index.fetchFieldsError = results.fetchFieldsError; index.dateFields = results.dateFields;