[Lens] Add IgnoreGlobalFilters feature to query annotations (#140325)

*  Add ignore global filters feature

*  Fix tests

* 🔧 Remove unused translations

* ♻️ Make it simpler

*  Fix test

* 🔧 slighlty increase bundle limit size

* ♻️ Refactor to only include the feature with no UI

* 🔧 Added migration

* 🏷️ Fix type issues

*  Fix more tests

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Marco Liberati 2022-09-19 13:22:30 +02:00 committed by GitHub
parent 189196181c
commit 1d0504f1f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 79 additions and 17 deletions

View file

@ -31,7 +31,7 @@ pageLoadAssetSize:
embeddableEnhanced: 22107
enterpriseSearch: 35741
esUiShared: 326654
eventAnnotation: 19334
eventAnnotation: 19500
expressionError: 22127
expressionGauge: 25000
expressionHeatmap: 27505

View file

@ -49,6 +49,7 @@ interface QueryGroup {
timeField: string;
dataView: DataView;
allFields?: string[];
ignoreGlobalFilters: boolean;
}
export function getTimeZone(uiSettings: IUiSettingsClient) {
@ -112,18 +113,20 @@ export const requestEventAnnotations = (
dataView,
aggConfigs,
timeFields,
ignoreGlobalFilters,
}: {
dataView: DataView;
aggConfigs: AggConfigs;
timeFields: string[];
ignoreGlobalFilters: boolean;
}) =>
lastValueFrom(
handleRequest({
aggs: aggConfigs,
indexPattern: dataView,
timeFields,
filters: input?.filters,
query: input?.query as any,
filters: ignoreGlobalFilters ? undefined : input?.filters,
query: ignoreGlobalFilters ? undefined : (input?.query as any),
timeRange: input?.timeRange,
abortSignal,
inspectorAdapters,
@ -182,7 +185,7 @@ const convertManualToDatatableRows = (
return datatableRows;
};
const prepareEsaggsForQueryGroups = async (
const prepareEsaggsForQueryGroups = (
queryGroups: QueryGroup[],
interval: string,
aggs: AggsStart
@ -267,7 +270,12 @@ const prepareEsaggsForQueryGroups = async (
aggregations?.map((agg) => agg.value) ?? []
);
return {
esaggsParams: { dataView: group.dataView, aggConfigs, timeFields: [group.timeField] },
esaggsParams: {
dataView: group.dataView,
aggConfigs,
timeFields: [group.timeField],
ignoreGlobalFilters: Boolean(group.ignoreGlobalFilters),
},
fieldsColIdMap:
group.allFields?.reduce<Record<string, string>>(
(acc, fieldName, i) => ({
@ -306,7 +314,7 @@ function regroupForRequestOptimization(
(dataView.timeFieldName ||
dataView.fields.find((field) => field.type === 'date' && field.displayName)?.name);
const key = `${g.dataView.value.id}-${timeField}`;
const key = `${g.dataView.value.id}-${timeField}-${Boolean(current.ignoreGlobalFilters)}`;
const subGroup = acc[key] as QueryGroup;
if (subGroup) {
let allFields = [...(subGroup.allFields || []), ...(current.extraFields || [])];
@ -334,6 +342,7 @@ function regroupForRequestOptimization(
timeField: timeField!,
allFields,
annotations: [current],
ignoreGlobalFilters: Boolean(current.ignoreGlobalFilters),
},
};
}

View file

@ -103,6 +103,13 @@ export const queryPointEventAnnotation: ExpressionFunctionDefinition<
defaultMessage: `Switch to hide annotation`,
}),
},
ignoreGlobalFilters: {
types: ['boolean'],
help: i18n.translate('eventAnnotation.queryAnnotation.args.ignoreGlobalFilters', {
defaultMessage: `Switch to ignore global filters for the annotation`,
}),
default: true,
},
},
fn: function fn(input: unknown, args: QueryPointEventAnnotationArgs) {
return {

View file

@ -15,6 +15,7 @@ export type QueryPointEventAnnotationArgs = {
timeField?: string;
extraFields?: string[];
textField?: string;
ignoreGlobalFilters?: boolean;
} & PointStyleProps;
export type QueryPointEventAnnotationOutput = QueryPointEventAnnotationArgs & {

View file

@ -72,6 +72,7 @@ export type QueryPointEventAnnotationConfig = {
timeField?: string;
textField?: string;
extraFields?: string[];
ignoreGlobalFilters?: boolean;
key: {
type: 'point_in_time';
};

View file

@ -157,6 +157,7 @@ describe('Event Annotation Service', () => {
icon: ['triangle'],
textVisibility: [false],
textField: [],
ignoreGlobalFilters: [false],
filter: [
{
chain: [
@ -264,6 +265,7 @@ describe('Event Annotation Service', () => {
icon: ['triangle'],
textVisibility: [false],
textField: [],
ignoreGlobalFilters: [false],
filter: [
{
chain: [
@ -326,6 +328,7 @@ describe('Event Annotation Service', () => {
icon: ['triangle'],
textVisibility: [textVisibility],
textField: expected ? [expected] : [],
ignoreGlobalFilters: [false],
filter: [
{
chain: [

View file

@ -91,6 +91,7 @@ export function getEventAnnotationService(): EventAnnotationServiceType {
textField,
filter,
extraFields,
ignoreGlobalFilters,
} = annotation;
expressions.push({
type: 'expression' as const,
@ -110,6 +111,7 @@ export function getEventAnnotationService(): EventAnnotationServiceType {
textField: textVisibility && textField ? [textField] : [],
filter: filter ? [queryToAst(filter)] : [],
extraFields: extraFields || [],
ignoreGlobalFilters: [Boolean(ignoreGlobalFilters)],
},
},
],

View file

@ -560,6 +560,7 @@ describe('#toExpression', () => {
layerType: layerTypes.ANNOTATIONS,
annotations: [],
indexPatternId: 'my-indexPattern',
ignoreGlobalFilters: true,
},
],
},

View file

@ -190,6 +190,7 @@ export const buildExpression = (
annotations: layer.annotations.map((c) => ({
...c,
label: uniqueLabels[c.id],
ignoreGlobalFilters: layer.ignoreGlobalFilters,
})),
};
});

View file

@ -119,6 +119,7 @@ export interface XYAnnotationLayerConfig {
hide?: boolean;
indexPatternId: string;
simpleView?: boolean;
ignoreGlobalFilters: boolean;
}
export type XYLayerConfig =

View file

@ -464,6 +464,7 @@ describe('xy_visualization', () => {
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation],
ignoreGlobalFilters: true,
},
],
},
@ -475,6 +476,7 @@ describe('xy_visualization', () => {
layerId: 'annotation',
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
ignoreGlobalFilters: true,
annotations: [
exampleAnnotation,
{
@ -502,6 +504,7 @@ describe('xy_visualization', () => {
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation2],
ignoreGlobalFilters: true,
},
],
},
@ -525,6 +528,7 @@ describe('xy_visualization', () => {
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation2, { ...exampleAnnotation2, id: 'newColId' }],
ignoreGlobalFilters: true,
});
});
it('should reorder a dimension to a annotation layer', () => {
@ -539,6 +543,7 @@ describe('xy_visualization', () => {
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation, exampleAnnotation2],
ignoreGlobalFilters: true,
},
],
},
@ -563,6 +568,7 @@ describe('xy_visualization', () => {
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation2, exampleAnnotation],
ignoreGlobalFilters: true,
});
});
@ -578,12 +584,14 @@ describe('xy_visualization', () => {
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation],
ignoreGlobalFilters: true,
},
{
layerId: 'second',
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation2],
ignoreGlobalFilters: true,
},
],
},
@ -609,12 +617,14 @@ describe('xy_visualization', () => {
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation],
ignoreGlobalFilters: true,
},
{
layerId: 'second',
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [{ ...exampleAnnotation, id: 'an2' }],
ignoreGlobalFilters: true,
},
]);
});
@ -630,12 +640,14 @@ describe('xy_visualization', () => {
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation],
ignoreGlobalFilters: true,
},
{
layerId: 'second',
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation2],
ignoreGlobalFilters: true,
},
],
},
@ -661,12 +673,14 @@ describe('xy_visualization', () => {
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation2],
ignoreGlobalFilters: true,
},
{
layerId: 'second',
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation],
ignoreGlobalFilters: true,
},
]);
});
@ -682,12 +696,14 @@ describe('xy_visualization', () => {
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation],
ignoreGlobalFilters: true,
},
{
layerId: 'second',
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation2],
ignoreGlobalFilters: true,
},
],
},
@ -713,12 +729,14 @@ describe('xy_visualization', () => {
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [],
ignoreGlobalFilters: true,
},
{
layerId: 'second',
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation],
ignoreGlobalFilters: true,
},
]);
});
@ -734,12 +752,14 @@ describe('xy_visualization', () => {
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation],
ignoreGlobalFilters: true,
},
{
layerId: 'second',
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [],
ignoreGlobalFilters: true,
},
],
},
@ -765,12 +785,14 @@ describe('xy_visualization', () => {
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [],
ignoreGlobalFilters: true,
},
{
layerId: 'second',
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation],
ignoreGlobalFilters: true,
},
]);
});
@ -851,6 +873,7 @@ describe('xy_visualization', () => {
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation, { ...exampleAnnotation, id: 'an2' }],
ignoreGlobalFilters: true,
},
],
},
@ -870,6 +893,7 @@ describe('xy_visualization', () => {
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation],
ignoreGlobalFilters: true,
},
]);
});
@ -1590,6 +1614,7 @@ describe('xy_visualization', () => {
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation],
ignoreGlobalFilters: true,
},
],
};
@ -2407,6 +2432,7 @@ describe('xy_visualization', () => {
layerId: 'annotation',
layerType: layerTypes.ANNOTATIONS,
annotations: [exampleAnnotation2],
ignoreGlobalFilters: true,
},
],
},
@ -2427,6 +2453,7 @@ describe('xy_visualization', () => {
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation2],
ignoreGlobalFilters: true,
},
],
});
@ -2444,6 +2471,7 @@ describe('xy_visualization', () => {
layerId: 'annotation',
layerType: layerTypes.ANNOTATIONS,
annotations: [exampleAnnotation2],
ignoreGlobalFilters: true,
},
],
},
@ -2464,6 +2492,7 @@ describe('xy_visualization', () => {
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation2],
ignoreGlobalFilters: true,
},
],
});

View file

@ -286,6 +286,7 @@ const newLayerFn = {
layerType: layerTypes.ANNOTATIONS,
annotations: [],
indexPatternId,
ignoreGlobalFilters: true,
}),
};

View file

@ -55,6 +55,7 @@ describe('AnnotationsPanel', () => {
layerId: 'annotation',
indexPatternId: 'indexPattern1',
annotations: [customLineStaticAnnotation],
ignoreGlobalFilters: true,
},
],
};
@ -129,6 +130,7 @@ describe('AnnotationsPanel', () => {
layerId: 'annotation',
layerType: 'annotations',
indexPatternId: 'indexPattern1',
ignoreGlobalFilters: true,
};
const component = mount(
<AnnotationsPanel
@ -207,6 +209,7 @@ describe('AnnotationsPanel', () => {
indexPatternId: 'indexPattern1',
layerId: 'annotation',
layerType: 'annotations',
ignoreGlobalFilters: true,
},
],
});
@ -231,6 +234,7 @@ describe('AnnotationsPanel', () => {
indexPatternId: 'indexPattern1',
layerId: 'annotation',
layerType: 'annotations',
ignoreGlobalFilters: true,
},
],
});
@ -260,6 +264,7 @@ describe('AnnotationsPanel', () => {
layerId: 'annotation',
layerType: 'annotations',
indexPatternId: indexPattern.id,
ignoreGlobalFilters: true,
};
const frameMock = createMockFramePublicAPI({
datasourceLayers: {},

View file

@ -550,6 +550,7 @@ describe('xy_suggestions', () => {
layerId: 'second',
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
ignoreGlobalFilters: true,
annotations: [
{
id: '1',

View file

@ -27,7 +27,7 @@ import {
commonUpdateVisLayerType,
getLensCustomVisualizationMigrations,
getLensFilterMigrations,
commonExplicitAnnotationType,
commonEnrichAnnotationLayer,
getLensDataViewMigrations,
commonMigrateMetricIds,
commonMigratePartitionChartGroups,
@ -141,7 +141,7 @@ export const makeLensEmbeddableFactory =
};
let migratedLensState = commonMigrateMetricIds(lensState.attributes);
migratedLensState = commonExplicitAnnotationType(
migratedLensState = commonEnrichAnnotationLayer(
migratedLensState as LensDocShape850<XYVisState850>
);
migratedLensState = commonMigratePartitionChartGroups(

View file

@ -423,7 +423,7 @@ export const commonFixValueLabelsInXY = (
};
};
export const commonExplicitAnnotationType = (
export const commonEnrichAnnotationLayer = (
attributes: LensDocShape850<XYVisStatePre850>
): LensDocShape850<VisState850> => {
// Skip the migration heavy part if not XY or it does not contain annotations
@ -449,6 +449,7 @@ export const commonExplicitAnnotationType = (
return {
...l,
annotations: l.annotations.map((a) => ({ ...a, type: 'manual' })),
ignoreGlobalFilters: true,
};
}),
},

View file

@ -2294,7 +2294,7 @@ describe('Lens migrations', () => {
});
});
describe('8.5.0 Add Annotation event type and dataView references', () => {
describe('8.5.0 Add Annotation event type and ignore filters flag', () => {
const context = { log: { warn: () => {} } } as unknown as SavedObjectMigrationContext;
const example = {
type: 'lens',
@ -2328,6 +2328,7 @@ describe('Lens migrations', () => {
expect(annotationLayer).toEqual({
layerType: 'annotations',
annotations: [{ id: 'annotation-id', type: 'manual' }],
ignoreGlobalFilters: true,
});
});
});

View file

@ -55,7 +55,7 @@ import {
commonFixValueLabelsInXY,
commonLockOldMetricVisSettings,
commonPreserveOldLegendSizeDefault,
commonExplicitAnnotationType,
commonEnrichAnnotationLayer,
getLensDataViewMigrations,
commonMigrateMetricIds,
commonMigratePartitionChartGroups,
@ -520,12 +520,12 @@ const preserveOldLegendSizeDefault: SavedObjectMigrationFn<LensDocShape810, Lens
doc
) => ({ ...doc, attributes: commonPreserveOldLegendSizeDefault(doc.attributes) });
const addEventAnnotationType: SavedObjectMigrationFn<
const enrichAnnotationLayers: SavedObjectMigrationFn<
LensDocShape850<XYVisStatePre850>,
LensDocShape850<VisState850>
> = (doc) => {
const newDoc = cloneDeep(doc);
return { ...newDoc, attributes: commonExplicitAnnotationType(newDoc.attributes) };
return { ...newDoc, attributes: commonEnrichAnnotationLayer(newDoc.attributes) };
};
const migrateMetricIds: SavedObjectMigrationFn<LensDocShape850, LensDocShape850> = (doc) => ({
@ -565,7 +565,7 @@ const lensMigrations: SavedObjectMigrationMap = {
enhanceTableRowHeight
),
'8.3.0': flow(lockOldMetricVisSettings, preserveOldLegendSizeDefault, fixValueLabelsInXY),
'8.5.0': flow(migrateMetricIds, addEventAnnotationType, migratePartitionChartGroups),
'8.5.0': flow(migrateMetricIds, enrichAnnotationLayers, migratePartitionChartGroups),
};
export const getAllMigrations = (

View file

@ -294,6 +294,7 @@ export interface XYVisState850 {
layerId: string;
layerType: Extract<LayerType, 'annotations'>;
annotations: Array<{ id: string; type: 'manual' | 'query' }>;
ignoreGlobalFilters: boolean;
}
>;
}

View file

@ -17798,7 +17798,6 @@
"xpack.lens.xyChart.addLayerTooltip": "Utilisez plusieurs calques pour combiner les types de visualisation ou pour visualiser différentes vues de données.",
"xpack.lens.xyChart.addReferenceLineLayerLabel": "Lignes de référence",
"xpack.lens.xyChart.addReferenceLineLayerLabelDisabledHelp": "Ajouter des données pour activer le calque de référence",
"xpack.lens.xyChart.annotation.name": "Masquer lannotation",
"xpack.lens.xyChart.annotationDate": "Date de lannotation",
"xpack.lens.xyChart.annotationDate.from": "De",
"xpack.lens.xyChart.annotationDate.to": "À",

View file

@ -17781,7 +17781,6 @@
"xpack.lens.xyChart.addLayerTooltip": "複数のレイヤーを使用すると、ビジュアライゼーションタイプを組み合わせたり、別のデータビューを可視化したりすることができます。",
"xpack.lens.xyChart.addReferenceLineLayerLabel": "基準線",
"xpack.lens.xyChart.addReferenceLineLayerLabelDisabledHelp": "一部のデータを追加して、基準レイヤーを有効にする",
"xpack.lens.xyChart.annotation.name": "注釈を非表示",
"xpack.lens.xyChart.annotationDate": "注釈日",
"xpack.lens.xyChart.annotationDate.from": "開始:",
"xpack.lens.xyChart.annotationDate.to": "終了:",

View file

@ -17803,7 +17803,6 @@
"xpack.lens.xyChart.addLayerTooltip": "使用多个图层以组合可视化类型或可视化不同的数据视图。",
"xpack.lens.xyChart.addReferenceLineLayerLabel": "参考线",
"xpack.lens.xyChart.addReferenceLineLayerLabelDisabledHelp": "添加一些数据以启用参考图层",
"xpack.lens.xyChart.annotation.name": "隐藏标注",
"xpack.lens.xyChart.annotationDate": "标注日期",
"xpack.lens.xyChart.annotationDate.from": "自",
"xpack.lens.xyChart.annotationDate.to": "至",