Skip to content

Commit

Permalink
fix index pattern w/o timefield filter application (elastic#54757)
Browse files Browse the repository at this point in the history
* fix index pattern w/o timefield filter application

* add null check

* Hide timefilter in editor only if timeFieldName is explicitly

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
Liza Katz and elasticmachine authored Jan 14, 2020
1 parent 9b57897 commit d7b4809
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,17 @@ export class DashboardAppController {
$scope.indexPatterns,
(p: IndexPattern) => p.id === indexPatternId
);
if (indexPattern && indexPattern.timeFieldName) {
const { timeRangeFilter, restOfFilters } = extractTimeFilter(
indexPattern.timeFieldName,
filters
);
queryFilter.addFilters(restOfFilters);
if (timeRangeFilter) changeTimeFilter(timefilter, timeRangeFilter);
if (indexPattern) {
if (indexPattern.timeFieldName) {
const { timeRangeFilter, restOfFilters } = extractTimeFilter(
indexPattern.timeFieldName,
filters
);
queryFilter.addFilters(restOfFilters);
if (timeRangeFilter) changeTimeFilter(timefilter, timeRangeFilter);
} else {
queryFilter.addFilters(filters);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,11 @@ function VisEditor(
};

$scope.showQueryBarTimePicker = () => {
return vis.type.options.showTimePicker;
// tsvb loads without an indexPattern initially (TODO investigate).
// hide timefilter only if timeFieldName is explicitly undefined.
let hasTimeField = true;
if ($scope.indexPattern) hasTimeField = !!$scope.indexPattern.timeFieldName;
return vis.type.options.showTimePicker && hasTimeField;
};

$scope.timeRange = timefilter.getTime();
Expand Down
81 changes: 81 additions & 0 deletions test/functional/apps/visualize/_data_table_notimeindex_filters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import expect from '@kbn/expect';

export default function({ getService, getPageObjects }) {
const log = getService('log');
const filterBar = getService('filterBar');
const renderable = getService('renderable');
const dashboardAddPanel = getService('dashboardAddPanel');
const PageObjects = getPageObjects(['common', 'visualize', 'header', 'dashboard', 'timePicker']);

describe('data table with index without time filter filters', function indexPatternCreation() {
const vizName1 = 'Visualization DataTable w/o time filter';

before(async function() {
log.debug('navigateToApp visualize');
await PageObjects.visualize.navigateToNewVisualization();
log.debug('clickDataTable');
await PageObjects.visualize.clickDataTable();
log.debug('clickNewSearch');
await PageObjects.visualize.clickNewSearch(
PageObjects.visualize.index.LOGSTASH_NON_TIME_BASED
);
log.debug('Bucket = Split Rows');
await PageObjects.visualize.clickBucket('Split rows');
log.debug('Aggregation = Histogram');
await PageObjects.visualize.selectAggregation('Histogram');
log.debug('Field = bytes');
await PageObjects.visualize.selectField('bytes');
log.debug('Interval = 2000');
await PageObjects.visualize.setNumericInterval('2000');
await PageObjects.visualize.clickGo();
});

it('should be able to save and load', async function() {
await PageObjects.visualize.saveVisualizationExpectSuccessAndBreadcrumb(vizName1);

await PageObjects.visualize.loadSavedVisualization(vizName1);
await PageObjects.visualize.waitForVisualization();
});

it('timefilter should be disabled', async () => {
const isOff = await PageObjects.timePicker.isOff();
expect(isOff).to.be.eql(true);
});

// test to cover bug #54548 - add this visualization to a dashboard and filter
it('should add to dashboard and allow filtering', async function() {
await PageObjects.common.navigateToApp('dashboard');
await PageObjects.dashboard.clickNewDashboard();
await dashboardAddPanel.addVisualization(vizName1);

// hover and click on cell to filter
await PageObjects.visualize.filterOnTableCell(1, 2);

await PageObjects.header.waitUntilLoadingHasFinished();
await renderable.waitForRender();
const filterCount = await filterBar.getFilterCount();
expect(filterCount).to.be(1);

await filterBar.removeAllFilters();
});
});
}
1 change: 1 addition & 0 deletions test/functional/apps/visualize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default function({ getService, loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./_area_chart'));
loadTestFile(require.resolve('./_data_table'));
loadTestFile(require.resolve('./_data_table_nontimeindex'));
loadTestFile(require.resolve('./_data_table_notimeindex_filters.js'));
});

describe('', function() {
Expand Down
5 changes: 5 additions & 0 deletions test/functional/page_objects/time_picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ export function TimePickerPageProvider({ getService, getPageObjects }) {
await PageObjects.header.awaitGlobalLoadingIndicatorHidden();
}

async isOff() {
const element = await find.byClassName('euiDatePickerRange--readOnly');
return !!element;
}

async isQuickSelectMenuOpen() {
return await testSubjects.exists('superDatePickerQuickMenu');
}
Expand Down

0 comments on commit d7b4809

Please sign in to comment.