From afce3bede7c948db02373e6d55ff227ad2220e58 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Fri, 16 Sep 2016 13:51:06 -0400 Subject: [PATCH 1/2] do not remove selection when clicking refreh fields --- .../management/sections/indices/_create.js | 22 ++++++++++++++++++- 1 file changed, 21 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 cb98e86824576..ff3a8d3baba2b 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) { + updateFieldListAndSeed(results, timeField); + } else { + updateFieldList(results); + } + }); }; $scope.createIndexPattern = function () { @@ -247,6 +254,19 @@ uiModules.get('apps/management') }, notify.fatal); } + function updateFieldListAndSeed(results, seedField) { + + updateFieldList(results); + + if (!results.dateFields.length) { + return; + } + + const matchingField = results.dateFields.find(field => field.name === seedField.name); + index.timeField = matchingField ? matchingField : results.dateFields[0]; + + } + function updateFieldList(results) { index.fetchFieldsError = results.fetchFieldsError; index.dateFields = results.dateFields; From 411957cd96d17ec9d00f7bef6391a37a56f13edb Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 20 Sep 2016 17:32:21 -0400 Subject: [PATCH 2/2] improve readability --- .../public/management/sections/indices/_create.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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 ff3a8d3baba2b..c0c00806f2bcb 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/_create.js +++ b/src/core_plugins/kibana/public/management/sections/indices/_create.js @@ -46,7 +46,7 @@ uiModules.get('apps/management') const timeField = index.timeField; fetchFieldList().then(function (results) { if (timeField) { - updateFieldListAndSeed(results, timeField); + updateFieldListAndSetTimeField(results, timeField.name); } else { updateFieldList(results); } @@ -254,17 +254,20 @@ uiModules.get('apps/management') }, notify.fatal); } - function updateFieldListAndSeed(results, seedField) { - + function updateFieldListAndSetTimeField(results, timeFieldName) { updateFieldList(results); if (!results.dateFields.length) { return; } - const matchingField = results.dateFields.find(field => field.name === seedField.name); - index.timeField = matchingField ? matchingField : results.dateFields[0]; + 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) {