Skip to content

Commit

Permalink
[Lens] Add feature to ignore global filters at layer level (#159248)
Browse files Browse the repository at this point in the history
## Summary

Fixes #143493

* Add the switch control in Layer Settings
  * [x] Make sure it does not duplicate on Annotation Layer Settings 
  * [x] Data Layers
  * [x] Reference line layers
  * [x] Extended dataView picker to support multiple icons
    * [x] Added unit tests 
  * [x] Functional tests

<img width="351" alt="Screenshot 2023-06-07 at 15 28 19"
src="https://github.com/elastic/kibana/assets/924948/00dc5523-0bec-4e9c-b1d0-4d36804b29f9">
<img width="340" alt="Screenshot 2023-06-07 at 15 31 31"
src="https://github.com/elastic/kibana/assets/924948/d36ca147-5d8c-4123-9be3-2932844cbd15">
<img width="331" alt="Screenshot 2023-06-07 at 15 28 25"
src="https://github.com/elastic/kibana/assets/924948/c7d4f166-b8ab-4439-a83c-debf82b913ad">
<img width="324" alt="Screenshot 2023-06-07 at 15 27 59"
src="https://github.com/elastic/kibana/assets/924948/3738a7e0-6e49-4e22-b857-965a953b4b84">
<img width="323" alt="Screenshot 2023-06-07 at 15 27 53"
src="https://github.com/elastic/kibana/assets/924948/5965bf1c-0e25-4c0e-b54f-fa315157fd44">


*  Create `IgnoreGlobalFilter` shared component folder
   * [x] Layer setting control component
   * [x] Info badge component
   
 * Extends `esaggs_fn` to support the flag
   * [x] Avoid to pass the filter to the handler if set
   * [x] Add unit tests

* Notification badges
* [x] Extends the badge component in Embeddable to support grouped
messages
    * [x] Added unit tests
  
<img width="750" alt="Screenshot 2023-06-07 at 15 31 39"
src="https://github.com/elastic/kibana/assets/924948/01bf8203-9133-4429-9b79-17ec67613c7e">
<img width="828" alt="Screenshot 2023-06-07 at 15 30 57"
src="https://github.com/elastic/kibana/assets/924948/9acb78f2-d061-4225-a4af-b3a66e7454fc">
<img width="756" alt="Screenshot 2023-06-07 at 15 27 43"
src="https://github.com/elastic/kibana/assets/924948/b9f79aed-7c02-4060-9c0f-61f438dc031d">


* Add support for Open in Lens
  * [x] Add unit tests for each converter
  * [x] Functional tests


### Checklist

Delete any items that are not applicable to this PR.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [x] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)

---------

Co-authored-by: Stratoula Kalafateli <[email protected]>
  • Loading branch information
dej611 and stratoula authored Jun 9, 2023
1 parent b6a2611 commit e325d41
Show file tree
Hide file tree
Showing 56 changed files with 1,266 additions and 263 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface Arguments {
timeFields?: string[];
probability?: number;
samplerSeed?: number;
ignoreGlobalFilters?: boolean;
}

export type EsaggsExpressionFunctionDefinition = ExpressionFunctionDefinition<
Expand Down Expand Up @@ -111,6 +112,12 @@ export const getEsaggsMeta: () => Omit<EsaggsExpressionFunctionDefinition, 'fn'>
'The seed to generate the random sampling of documents. Uses random sampler.',
}),
},
ignoreGlobalFilters: {
types: ['boolean'],
help: i18n.translate('data.search.functions.esaggs.ignoreGlobalFilters.help', {
defaultMessage: 'Whether to ignore or use global query and filters',
}),
},
},
});

Expand Down
24 changes: 24 additions & 0 deletions src/plugins/data/public/search/expressions/esaggs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,28 @@ describe('esaggs expression function - public', () => {
})
);
});

test('does not forward filters and query if ignoreGlobalFilters is enabled', async () => {
const input = {
type: 'kibana_context' as 'kibana_context',
filters: [{ $state: {}, meta: {}, query: {} }],
query: {
query: 'hiya',
language: 'painless',
},
timeRange: { from: 'a', to: 'b' },
} as KibanaContext;

await definition()
.fn(input, { ...args, ignoreGlobalFilters: true }, mockHandlers)
.toPromise();

expect(handleEsaggsRequest).toHaveBeenCalledWith(
expect.objectContaining({
filters: undefined,
query: undefined,
timeRange: input.timeRange,
})
);
});
});
4 changes: 2 additions & 2 deletions src/plugins/data/public/search/expressions/esaggs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ export function getFunctionDefinition({
return handleEsaggsRequest({
abortSignal,
aggs: aggConfigs,
filters: get(input, 'filters', undefined),
filters: args.ignoreGlobalFilters ? undefined : get(input, 'filters', undefined),
indexPattern,
inspectorAdapters,
query: get(input, 'query', undefined) as any,
query: args.ignoreGlobalFilters ? undefined : (get(input, 'query', undefined) as any),
searchSessionId: getSearchSessionId(),
searchSourceService: searchSource,
timeFields: args.timeFields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const convertToLens: ConvertGaugeVisToLensVisualization = async (vis, tim
layerId,
columns: columns.map(excludeMetaFromColumn),
columnOrder: [],
ignoreGlobalFilters: false,
},
],
configuration: getConfiguration(
Expand Down
1 change: 1 addition & 0 deletions src/plugins/vis_types/gauge/public/convert_to_lens/goal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const convertToLens: ConvertGoalVisToLensVisualization = async (vis, time
layerId,
columns: columns.map(excludeMetaFromColumn),
columnOrder: [],
ignoreGlobalFilters: false,
},
],
configuration: getConfiguration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export const convertToLens: ConvertHeatmapToLensVisualization = async (vis, time
layerId,
columns: layerConfig.columns.map(excludeMetaFromColumn),
columnOrder: [],
ignoreGlobalFilters: false,
},
],
configuration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const convertToLens: ConvertMetricVisToLensVisualization = async (vis, ti
layerId,
columns: layerConfig.columns.map(excludeMetaFromColumn),
columnOrder: [],
ignoreGlobalFilters: false,
},
],
configuration: getConfiguration(
Expand Down
1 change: 1 addition & 0 deletions src/plugins/vis_types/pie/public/convert_to_lens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const convertToLens: ConvertPieToLensVisualization = async (vis, timefilt
layerId,
columns: layerConfig.columns.map(excludeMetaFromColumn),
columnOrder: [],
ignoreGlobalFilters: false,
},
],
configuration: getConfiguration(layerId, vis, layerConfig),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export const convertToLens: ConvertTableToLensVisualization = async (vis, timefi
layerId,
columns: layerConfig.columns.map(excludeMetaFromColumn),
columnOrder: [],
ignoreGlobalFilters: false,
},
],
configuration: getConfiguration(layerId, vis.params, layerConfig),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function YesNo({
name,
value,
disabled,
'data-test-subj': dataTestSubj,
'data-test-subj': dataTestSubj = name,
onChange,
}: YesNoProps) {
const handleChange = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,60 @@ describe('convertToLens', () => {
expect(result).toBeDefined();
expect(result?.type).toBe('lnsMetric');
});

test('should carry the ignoreGlobalFilters flag if set on the panel', async () => {
mockGetMetricsColumns.mockReturnValue([metricColumn]);
mockGetSeriesAgg.mockReturnValue({ metrics: [metric] });
mockGetConfigurationForGauge.mockReturnValue({});

const result = await convertToLens(
{
params: createPanel({
series: [
createSeries({
metrics: [{ id: 'some-id', type: METRIC_TYPES.AVG, field: 'test-field' }],
hidden: false,
}),
createSeries({
metrics: [{ id: 'some-id', type: METRIC_TYPES.AVG, field: 'test-field' }],
hidden: false,
}),
],
ignore_global_filter: 1,
}),
} as Vis<Panel>,
undefined,
true
);
expect(result?.layers.every((l) => l.ignoreGlobalFilters)).toBe(true);
});

test('should carry the ignoreGlobalFilters flag if set on the series', async () => {
mockGetMetricsColumns.mockReturnValue([metricColumn]);
mockGetSeriesAgg.mockReturnValue({ metrics: [metric] });
mockGetConfigurationForGauge.mockReturnValue({});

const result = await convertToLens(
{
params: createPanel({
series: [
createSeries({
metrics: [{ id: 'some-id', type: METRIC_TYPES.AVG, field: 'test-field' }],
hidden: false,
ignore_global_filter: 1,
}),
createSeries({
metrics: [{ id: 'some-id', type: METRIC_TYPES.AVG, field: 'test-field' }],
hidden: false,
}),
],
ignore_global_filter: 0,
}),
} as Vis<Panel>,
undefined,
true
);

expect(result?.layers[0].ignoreGlobalFilters).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const convertToLens: ConvertTsvbToLensVisualization = async (

const extendedLayer: ExtendedLayer = {
indexPatternId,
ignoreGlobalFilters: Boolean(model.ignore_global_filter || series.ignore_global_filter),
layerId: uuidv4(),
columns: [...metricsColumns, ...(bucket ? [bucket] : [])],
columnOrder: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const createSeries = (partialSeries?: Partial<Series>): Series => ({
series_index_pattern: { id: 'test' },
series_max_bars: 0,
steps: 0,
ignore_global_filter: 0,
...partialSeries,
});

Expand All @@ -57,5 +58,6 @@ export const createPanel = (parialPanel?: Partial<Panel>): Panel => ({
show_grid: 0,
show_legend: 0,
type: PANEL_TYPES.TIMESERIES,
ignore_global_filter: 0,
...parialPanel,
});
Loading

0 comments on commit e325d41

Please sign in to comment.