Skip to content

Commit

Permalink
[Exploratory View] add a global filter to exploratory view when there…
Browse files Browse the repository at this point in the history
… is only one series (#122301) (#122799)

* add a global filter to exploratory view when there is only one series

* adjust types

* addjust sample lens attributes

* fix breakdown column order

* update tests

Co-authored-by: Kibana Machine <[email protected]>
Co-authored-by: shahzad31 <[email protected]>
(cherry picked from commit 1d27050)

Co-authored-by: Dominique Clarke <[email protected]>
  • Loading branch information
kibanamachine and dominiqueclarke authored Jan 12, 2022
1 parent 3051b81 commit 9e5b5ee
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ describe('Lens Attribute', () => {
});
});

it('should not use global filters when there is more than one series', function () {
const multiSeriesLensAttr = new LensAttributes([layerConfig, layerConfig]).getJSON();
expect(multiSeriesLensAttr.state.query.query).toEqual('transaction.duration.us < 60000000');
});

describe('Layer breakdowns', function () {
it('should return breakdown column', function () {
const layerConfig1: LayerConfig = {
Expand Down Expand Up @@ -517,8 +522,8 @@ describe('Lens Attribute', () => {

expect(lnsAttr.layers.layer0).toEqual({
columnOrder: [
'x-axis-column-layer0',
'breakdown-column-layer0',
'x-axis-column-layer0',
'y-axis-column-layer0',
'y-axis-column-layer0X0',
'y-axis-column-layer0X1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export class LensAttributes {
visualization: XYState;
layerConfigs: LayerConfig[];
isMultiSeries: boolean;
globalFilter?: { query: string; language: string };

constructor(layerConfigs: LayerConfig[]) {
this.layers = {};
Expand All @@ -119,10 +120,27 @@ export class LensAttributes {

this.layerConfigs = layerConfigs;
this.isMultiSeries = layerConfigs.length > 1;
this.globalFilter = this.getGlobalFilter(this.isMultiSeries);
this.layers = this.getLayers();
this.visualization = this.getXyState();
}

getGlobalFilter(isMultiSeries: boolean) {
if (isMultiSeries) {
return undefined;
}
const defaultLayerFilter = this.layerConfigs[0].seriesConfig.query
? ` and ${this.layerConfigs[0].seriesConfig.query.query}`
: '';
return {
query: `${this.getLayerFilters(
this.layerConfigs[0],
this.layerConfigs.length
)}${defaultLayerFilter}`,
language: 'kuery',
};
}

getBreakdownColumn({
sourceField,
layerId,
Expand Down Expand Up @@ -676,10 +694,10 @@ export class LensAttributes {

layers[layerId] = {
columnOrder: [
`x-axis-column-${layerId}`,
...(breakdown && sourceField !== USE_BREAK_DOWN_COLUMN && breakdown !== PERCENTILE
? [`breakdown-column-${layerId}`]
: []),
`x-axis-column-${layerId}`,
`y-axis-column-${layerId}`,
...Object.keys(this.getChildYAxises(layerConfig, layerId, columnFilter)),
],
Expand Down Expand Up @@ -770,7 +788,7 @@ export class LensAttributes {
new Set([...this.layerConfigs.map(({ indexPattern }) => indexPattern.id)])
);

const query = this.layerConfigs[0].seriesConfig.query;
const query = this.globalFilter || this.layerConfigs[0].seriesConfig.query;

return {
title: 'Prefilled from exploratory view app',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ export const sampleAttribute = {
filters: [],
query: {
language: 'kuery',
query: 'transaction.duration.us < 60000000',
query:
'transaction.type: page-load and processor.event: transaction and transaction.type : * and transaction.duration.us < 60000000',
},
visualization: {
axisTitlesVisibilitySettings: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ export const sampleAttributeCoreWebVital = {
filters: [],
query: {
language: 'kuery',
query: 'transaction.type: "page-load"',
query:
'transaction.type: page-load and processor.event: transaction and transaction.type: "page-load"',
},
visualization: {
axisTitlesVisibilitySettings: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const sampleAttributeKpi = {
filters: [],
query: {
language: 'kuery',
query: '',
query: 'transaction.type: page-load and processor.event: transaction',
},
visualization: {
axisTitlesVisibilitySettings: {
Expand Down

0 comments on commit 9e5b5ee

Please sign in to comment.