Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backport] PR #8312 to 5.x - do not remove selection when clicking refresh fields #8393

Merged
merged 1 commit into from
Sep 21, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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;
Expand Down