Fix default time field selection (#11664)

* [indexPattern/create] fix test subject

* [indexPattern/create] only auto-select when there is more than one time field

* [indexPatterns/create] describe weird timeField auto-selection

* [indexPattern/create] update no-date-field text

* restore functional test changes in 02787e3df5
This commit is contained in:
Spencer 2017-05-09 16:05:19 -07:00 committed by GitHub
parent 01fcf6b927
commit 9f0caba9b6
4 changed files with 18 additions and 11 deletions

View file

@ -102,12 +102,11 @@
<div class="kuiVerticalRhythmSmall">
<select
class="kuiSelect kuiSelect--large kuiVerticalRhythmSmall"
data-test-subj="createIndexPatternTimeFieldSelect || !controller.indexHasDateFields"
ng-disabled="controller.fetchFieldsError"
data-test-subj="createIndexPatternTimeFieldSelect"
ng-disabled="controller.fetchFieldsError || controller.dateFields.length === 1"
ng-required="!controller.fetchFieldsError"
ng-options="field.name for field in controller.dateFields"
ng-model="controller.newIndexPattern.timeField"
auto-select-if-only-one="controller.dateFields"
></select>
<p

View file

@ -40,8 +40,8 @@ uiModules.get('apps/management')
this.fetchFieldsError = $translate.instant('KIBANA-LOADING');
const TIME_FILTER_FIELD_OPTIONS = {
NO_DATE_FIELD_SELECTED: {
name: $translate.instant('KIBANA-NO_DATE_FIELD_SELECTED')
NO_DATE_FIELD_DESIRED: {
name: $translate.instant('KIBANA-NO_DATE_FIELD_DESIRED')
},
NO_DATE_FIELDS_IN_INDICES: {
name: $translate.instant('KIBANA-NO_DATE_FIELDS_IN_INDICES')
@ -103,12 +103,20 @@ uiModules.get('apps/management')
this.dateFields = results.dateFields || [];
this.indexHasDateFields = this.dateFields.length > 0;
const moreThanOneDateField = this.dateFields.length > 1;
if (this.indexHasDateFields) {
this.dateFields.unshift(TIME_FILTER_FIELD_OPTIONS.NO_DATE_FIELD_SELECTED);
this.dateFields.unshift(TIME_FILTER_FIELD_OPTIONS.NO_DATE_FIELD_DESIRED);
} else {
this.dateFields.unshift(TIME_FILTER_FIELD_OPTIONS.NO_DATE_FIELDS_IN_INDICES);
}
this.newIndexPattern.timeField = this.dateFields[0];
if (!moreThanOneDateField) {
// At this point the `dateFields` array contains the date fields and the "no selection"
// option. When we have less than two date fields we choose the last option, which will
// be the "no date fields available" option if there are zero date fields, or the only
// date field if there is one.
this.newIndexPattern.timeField = this.dateFields[this.dateFields.length - 1];
}
};
const updateFieldListAndSetTimeField = (results, timeFieldName) => {
@ -204,7 +212,7 @@ uiModules.get('apps/management')
this.createIndexPattern = () => {
const id = this.newIndexPattern.name;
let timeFieldName;
if ((this.newIndexPattern.timeField !== TIME_FILTER_FIELD_OPTIONS.NO_DATE_FIELD_SELECTED)
if ((this.newIndexPattern.timeField !== TIME_FILTER_FIELD_OPTIONS.NO_DATE_FIELD_DESIRED)
&& (this.newIndexPattern.timeField !== TIME_FILTER_FIELD_OPTIONS.NO_DATE_FIELDS_IN_INDICES)) {
timeFieldName = this.newIndexPattern.timeField.name;
}

View file

@ -30,7 +30,7 @@
"KIBANA-NON_MATCHING_INDICES_AND_ALIASES": "Indices and aliases that were found, but did not match the pattern:",
"KIBANA-MORE": "more",
"KIBANA-TIME_FILTER_FIELD_NAME": "Time Filter field name",
"KIBANA-NO_DATE_FIELD_SELECTED": "None selected",
"KIBANA-NO_DATE_FIELD_DESIRED": "I don't want to use the Time Filter",
"KIBANA-NO_DATE_FIELDS_IN_INDICES": "None available",
"KIBANA-REFRESH_FIELDS": "refresh fields",
"KIBANA-INDICES_DONT_CONTAIN_TIME_FIELDS": "The indices which match this index pattern don't contain any time fields.",

View file

@ -41,10 +41,10 @@ export default function ({ getService, getPageObjects }) {
});
});
it('should enable creation', function () {
it('should not enable creation', function () {
return PageObjects.settings.getCreateIndexPatternButton().isEnabled()
.then(function (enabled) {
expect(enabled).to.be.ok();
expect(enabled).to.not.be.ok();
});
});
});