Skip to content

Commit

Permalink
more accurate typings
Browse files Browse the repository at this point in the history
  • Loading branch information
drewdaemon committed Mar 10, 2023
1 parent 685645d commit b10e5a7
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 14 deletions.
2 changes: 2 additions & 0 deletions x-pack/plugins/lens/public/visualizations/xy/state_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ export function injectReferences(
if (isPersistedByValueAnnotationsLayer(persistedLayer)) {
injectedLayer = {
...persistedLayer,
hide: persistedLayer.hide,
simpleView: persistedLayer.simpleView,
indexPatternId:
// getIndexPatternIdFromInitialContext(persistedLayer, initialContext) || TODO - was this doing anything?
indexPatternIdFromReferences,
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/lens/public/visualizations/xy/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ export interface XYByValueAnnotationLayerConfig {

export type XYPersistedByValueAnnotationLayerConfig = Omit<
XYByValueAnnotationLayerConfig,
'indexPatternId'
> & { persistanceType?: 'byValue' }; // optional for backwards compatibility
'indexPatternId' | 'hide' | 'simpleView'
> & { persistanceType?: 'byValue'; hide?: boolean; simpleView?: boolean }; // props made optional for backwards compatibility since this is how the existing saved objects are

export type XYByReferenceAnnotationLayerConfig = XYByValueAnnotationLayerConfig & {
annotationGroupId: string;
Expand Down
61 changes: 49 additions & 12 deletions x-pack/plugins/lens/public/visualizations/xy/visualization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,8 @@ describe('xy_visualization', () => {
annotationGroupId: annotationGroupId1,
ignoreGlobalFilters: persistedAnnotationLayers[0].ignoreGlobalFilters,
annotations: persistedAnnotationLayers[0].annotations,
hide: persistedAnnotationLayers[0].hide,
simpleView: persistedAnnotationLayers[0].simpleView,
hide: Boolean(persistedAnnotationLayers[0].hide),
simpleView: Boolean(persistedAnnotationLayers[0].simpleView),
indexPatternId: dataViewId,
__lastSaved: libraryAnnotationGroups[annotationGroupId1],
},
Expand All @@ -481,8 +481,8 @@ describe('xy_visualization', () => {
annotationGroupId: annotationGroupId2,
ignoreGlobalFilters: persistedAnnotationLayers[1].ignoreGlobalFilters,
annotations: persistedAnnotationLayers[1].annotations,
hide: persistedAnnotationLayers[1].hide,
simpleView: persistedAnnotationLayers[1].simpleView,
hide: Boolean(persistedAnnotationLayers[1].hide),
simpleView: Boolean(persistedAnnotationLayers[1].simpleView),
indexPatternId: dataViewId,
__lastSaved: libraryAnnotationGroups[annotationGroupId2],
},
Expand Down Expand Up @@ -765,6 +765,8 @@ describe('xy_visualization', () => {
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation],
ignoreGlobalFilters: true,
hide: false,
simpleView: false,
},
],
},
Expand Down Expand Up @@ -1014,6 +1016,8 @@ describe('xy_visualization', () => {
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation2],
ignoreGlobalFilters: true,
hide: false,
simpleView: false,
},
],
},
Expand Down Expand Up @@ -1074,6 +1078,8 @@ describe('xy_visualization', () => {
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation],
ignoreGlobalFilters: true,
hide: false,
simpleView: false,
},
],
},
Expand Down Expand Up @@ -1134,6 +1140,8 @@ describe('xy_visualization', () => {
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation2],
ignoreGlobalFilters: true,
hide: false,
simpleView: false,
},
],
},
Expand Down Expand Up @@ -1175,6 +1183,8 @@ describe('xy_visualization', () => {
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation, exampleAnnotation2],
ignoreGlobalFilters: true,
hide: false,
simpleView: false,
},
],
},
Expand Down Expand Up @@ -1218,13 +1228,17 @@ describe('xy_visualization', () => {
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation],
ignoreGlobalFilters: true,
hide: false,
simpleView: false,
},
{
layerId: 'second',
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation2],
ignoreGlobalFilters: true,
hide: false,
simpleView: false,
},
],
},
Expand Down Expand Up @@ -1276,13 +1290,17 @@ describe('xy_visualization', () => {
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation],
ignoreGlobalFilters: true,
hide: false,
simpleView: false,
},
{
layerId: 'second',
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation2],
ignoreGlobalFilters: true,
hide: false,
simpleView: false,
},
],
},
Expand Down Expand Up @@ -1334,13 +1352,17 @@ describe('xy_visualization', () => {
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation],
ignoreGlobalFilters: true,
hide: false,
simpleView: false,
},
{
layerId: 'second',
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation2],
ignoreGlobalFilters: true,
hide: false,
simpleView: false,
},
],
},
Expand Down Expand Up @@ -1391,13 +1413,18 @@ describe('xy_visualization', () => {
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation],
ignoreGlobalFilters: true,
hide: false,
simpleView: false,
},

{
layerId: 'second',
layerType: layerTypes.ANNOTATIONS,
indexPatternId: 'indexPattern1',
annotations: [],
ignoreGlobalFilters: true,
hide: false,
simpleView: false,
},
],
},
Expand Down Expand Up @@ -1515,6 +1542,8 @@ describe('xy_visualization', () => {
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation, { ...exampleAnnotation, id: 'an2' }],
ignoreGlobalFilters: true,
hide: false,
simpleView: false,
},
],
},
Expand Down Expand Up @@ -2262,6 +2291,8 @@ describe('xy_visualization', () => {
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation],
ignoreGlobalFilters: true,
hide: false,
simpleView: false,
},
],
};
Expand Down Expand Up @@ -2897,6 +2928,8 @@ describe('xy_visualization', () => {
indexPatternId: 'indexPattern1',
annotations: [exampleAnnotation],
ignoreGlobalFilters: true,
hide: false,
simpleView: false,
},
],
};
Expand Down Expand Up @@ -3091,8 +3124,8 @@ describe('xy_visualization', () => {
layerType: 'annotations',
indexPatternId: 'some-id',
ignoreGlobalFilters: true,
simpleView: undefined,
hide: undefined,
simpleView: false,
hide: false,
annotations: [
{
label: 'Event',
Expand Down Expand Up @@ -3125,8 +3158,8 @@ describe('xy_visualization', () => {
layerType: 'annotations',
indexPatternId: 'some-id',
ignoreGlobalFilters: true,
simpleView: undefined,
hide: undefined,
simpleView: false,
hide: false,
annotations: [
{
label: 'Event',
Expand All @@ -3147,8 +3180,8 @@ describe('xy_visualization', () => {
layerType: 'annotations',
indexPatternId: 'some-id',
ignoreGlobalFilters: true,
simpleView: undefined,
hide: undefined,
simpleView: false,
hide: false,
annotations: [
{
label: 'Event',
Expand Down Expand Up @@ -3198,8 +3231,8 @@ describe('xy_visualization', () => {
},
} as PointInTimeEventAnnotationConfig,
],
hide: undefined,
simpleView: undefined,
hide: false,
simpleView: false,
};
state.layers = [layer];

Expand Down Expand Up @@ -3435,6 +3468,8 @@ describe('xy_visualization', () => {
annotations: [exampleAnnotation2],
ignoreGlobalFilters: true,
indexPatternId: 'myIndexPattern',
hide: false,
simpleView: false,
},
],
},
Expand Down Expand Up @@ -3467,6 +3502,8 @@ describe('xy_visualization', () => {
annotations: [exampleAnnotation2],
ignoreGlobalFilters: true,
indexPatternId: 'myIndexPattern',
hide: false,
simpleView: false,
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ const newLayerFn = {
annotations: [],
indexPatternId,
ignoreGlobalFilters: true,
hide: undefined,
simpleView: undefined,
}),
};

Expand Down

0 comments on commit b10e5a7

Please sign in to comment.