Skip to content

Commit 236f49f

Browse files
ohltylerjoshuarrrr
andauthored
Add logic to collect VisLayers in line chart render flow (#3131)
* Collect VisLayers in VisualizeEmbeddable render flow Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com> * Refactor types; address comments Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com> * Simplify fetchVisLayers() and pipeline helper fns Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com> * Update src/plugins/visualizations/public/embeddable/visualize_embeddable.ts Signed-off-by: Josh Romero <rmerqg@amazon.com> --------- Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com> Signed-off-by: Josh Romero <rmerqg@amazon.com> Co-authored-by: Josh Romero <rmerqg@amazon.com>
1 parent d63ef1f commit 236f49f

20 files changed

+375
-100
lines changed

src/plugins/vis_augmenter/common/types.ts

-60
This file was deleted.

src/plugins/vis_augmenter/public/expressions/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
export * from './vis_layers';
6+
export * from './types';

src/plugins/vis_augmenter/public/expressions/vis_layers.ts src/plugins/vis_augmenter/public/expressions/types.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { ExpressionTypeDefinition } from '../../../expressions';
7-
import { VisLayers } from '../../common';
6+
import { ExpressionTypeDefinition, ExpressionFunctionDefinition } from '../../../expressions';
7+
import { VisLayers, VisLayerTypes } from '../';
88

99
const name = 'vis_layers';
1010

@@ -31,3 +31,17 @@ export const visLayers: ExpressionTypeDefinition<typeof name, ExprVisLayers> = {
3131
},
3232
},
3333
};
34+
35+
export type VisLayerFunctionDefinition = ExpressionFunctionDefinition<
36+
string,
37+
ExprVisLayers,
38+
any,
39+
Promise<ExprVisLayers>
40+
>;
41+
42+
export interface VisLayerExpressionFn {
43+
type: keyof typeof VisLayerTypes;
44+
name: string;
45+
// plugin expression fns can freely set custom arguments
46+
args: { [key: string]: any };
47+
}

src/plugins/vis_augmenter/public/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ export {
1818
SavedObjectOpenSearchDashboardsServicesWithAugmentVis,
1919
} from './saved_augment_vis';
2020

21-
export { ISavedAugmentVis, VisLayerExpressionFn, AugmentVisSavedObject } from './types';
21+
export { VisLayer, VisLayers, VisLayerTypes } from './types';
22+
23+
export * from './expressions';
24+
export * from './utils';
25+
export * from './saved_augment_vis';

src/plugins/vis_augmenter/public/saved_augment_vis/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55

66
export * from './saved_augment_vis';
77
export * from './utils';
8+
export * from './types';

src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.test.ts

+18-11
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { VisLayerExpressionFn } from '../types';
7-
import { VisLayerTypes } from '../../common';
6+
import { VisLayerExpressionFn, VisLayerTypes } from '../types';
87
import {
98
createSavedAugmentVisLoader,
109
SavedObjectOpenSearchDashboardsServicesWithAugmentVis,
@@ -19,15 +18,23 @@ describe('SavedObjectLoaderAugmentVis', () => {
1918
testArg: 'test-value',
2019
},
2120
} as VisLayerExpressionFn;
22-
const validObj1 = generateAugmentVisSavedObject('valid-obj-id-1', fn);
23-
const validObj2 = generateAugmentVisSavedObject('valid-obj-id-2', fn);
24-
const invalidFnTypeObj = generateAugmentVisSavedObject('invalid-fn-obj-id-1', {
25-
...fn,
26-
// @ts-ignore
27-
type: 'invalid-type',
28-
});
29-
// @ts-ignore
30-
const missingFnObj = generateAugmentVisSavedObject('missing-fn-obj-id-1', {});
21+
const validObj1 = generateAugmentVisSavedObject('valid-obj-id-1', fn, 'test-vis-id');
22+
const validObj2 = generateAugmentVisSavedObject('valid-obj-id-2', fn, 'test-vis-id');
23+
const invalidFnTypeObj = generateAugmentVisSavedObject(
24+
'invalid-fn-obj-id-1',
25+
{
26+
...fn,
27+
// @ts-ignore
28+
type: 'invalid-type',
29+
},
30+
'test-vis-id'
31+
);
32+
33+
const missingFnObj = generateAugmentVisSavedObject(
34+
'missing-fn-obj-id-1',
35+
{} as VisLayerExpressionFn,
36+
'test-vis-id'
37+
);
3138

3239
it('find returns single saved obj', async () => {
3340
const loader = createSavedAugmentVisLoader({

src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
SavedObjectOpenSearchDashboardsServices,
1010
} from '../../../saved_objects/public';
1111
import { createSavedAugmentVisClass } from './_saved_augment_vis';
12-
import { VisLayerTypes } from '../../common';
12+
import { VisLayerTypes } from '../types';
1313

1414
// eslint-disable-next-line @typescript-eslint/no-empty-interface
1515
export interface SavedObjectOpenSearchDashboardsServicesWithAugmentVis

src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis_references.test.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { extractReferences, injectReferences } from './saved_augment_vis_references';
6+
import {
7+
extractReferences,
8+
injectReferences,
9+
VIS_REFERENCE_NAME,
10+
} from './saved_augment_vis_references';
711
import { AugmentVisSavedObject } from '../types';
8-
import { VIS_REFERENCE_NAME } from './saved_augment_vis_references';
912

1013
describe('extractReferences()', () => {
1114
test('extracts nothing if visId is null', () => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { SavedObject } from '../../../saved_objects/public';
7+
import { VisLayerExpressionFn } from '../expressions';
8+
9+
export interface ISavedAugmentVis {
10+
id?: string;
11+
title: string;
12+
description?: string;
13+
pluginResourceId: string;
14+
visName?: string;
15+
visId?: string;
16+
visLayerExpressionFn: VisLayerExpressionFn;
17+
version?: number;
18+
}
19+
20+
export interface AugmentVisSavedObject extends SavedObject, ISavedAugmentVis {}

src/plugins/vis_augmenter/public/saved_augment_vis/utils/test_helpers.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@ import { VisLayerExpressionFn, ISavedAugmentVis } from '../../types';
88
import { VIS_REFERENCE_NAME } from '../saved_augment_vis_references';
99

1010
const pluginResourceId = 'test-plugin-resource-id';
11-
const visId = 'test-vis-id';
11+
const title = 'test-title';
1212
const version = 1;
1313

14-
export const generateAugmentVisSavedObject = (idArg: string, exprFnArg: VisLayerExpressionFn) => {
14+
export const generateAugmentVisSavedObject = (
15+
idArg: string,
16+
exprFnArg: VisLayerExpressionFn,
17+
visIdArg: string
18+
) => {
1519
return {
1620
id: idArg,
21+
title,
1722
pluginResourceId,
1823
visLayerExpressionFn: exprFnArg,
1924
VIS_REFERENCE_NAME,
20-
visId,
25+
visId: visIdArg,
2126
version,
2227
} as ISavedAugmentVis;
2328
};

src/plugins/vis_augmenter/public/types.ts

+36-15
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,45 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { SavedObject } from '../../saved_objects/public';
7-
import { VisLayerTypes } from '../common';
6+
export enum VisLayerTypes {
7+
PointInTimeEvents = 'PointInTimeEvents',
8+
}
89

9-
export interface ISavedAugmentVis {
10-
id?: string;
11-
description?: string;
12-
pluginResourceId: string;
13-
visName?: string;
14-
visId?: string;
15-
visLayerExpressionFn: VisLayerExpressionFn;
16-
version?: number;
10+
export type PluginResourceType = string;
11+
12+
export interface PluginResource {
13+
type: PluginResourceType;
14+
id: string;
15+
name: string;
16+
urlPath: string;
1717
}
1818

19-
export interface VisLayerExpressionFn {
19+
export interface VisLayer {
2020
type: keyof typeof VisLayerTypes;
21-
name: string;
22-
// plugin expression fns can freely set custom arguments
23-
args: { [key: string]: any };
21+
originPlugin: string;
22+
pluginResource: PluginResource;
23+
}
24+
25+
export type VisLayers = VisLayer[];
26+
27+
export interface EventMetadata {
28+
pluginResourceId: string;
29+
tooltip?: string;
30+
}
31+
32+
export interface PointInTimeEvent {
33+
timestamp: number;
34+
metadata: EventMetadata;
2435
}
2536

26-
export interface AugmentVisSavedObject extends SavedObject, ISavedAugmentVis {}
37+
export interface PointInTimeEventsVisLayer extends VisLayer {
38+
events: PointInTimeEvent[];
39+
}
40+
41+
export const isPointInTimeEventsVisLayer = (obj: any) => {
42+
return obj?.type === VisLayerTypes.PointInTimeEvents;
43+
};
44+
45+
export const isValidVisLayer = (obj: any) => {
46+
return obj?.type in VisLayerTypes;
47+
};

src/plugins/vis_augmenter/common/index.ts src/plugins/vis_augmenter/public/utils/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
export * from './types';
6+
export * from './utils';

0 commit comments

Comments
 (0)