Skip to content

Commit c0b8771

Browse files
committed
Refactor types; address comments
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
1 parent 1687089 commit c0b8771

File tree

8 files changed

+53
-46
lines changed

8 files changed

+53
-46
lines changed

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 '../';
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

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

21-
export {
22-
ISavedAugmentVis,
23-
VisLayerExpressionFn,
24-
AugmentVisSavedObject,
25-
VisLayerFunctionDefinition,
26-
VisLayer,
27-
VisLayers,
28-
} from './types';
21+
export { VisLayer, VisLayers, VisLayerTypes } from './types';
2922

3023
export * from './expressions';
3124
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';
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/types.ts

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

6-
import { SavedObject } from '../../saved_objects/public';
7-
import { ExpressionFunctionDefinition } from '../../expressions';
8-
96
export enum VisLayerTypes {
107
PointInTimeEvents = 'PointInTimeEvents',
118
}
@@ -48,34 +45,3 @@ export const isPointInTimeEventsVisLayer = (obj: any) => {
4845
export const isValidVisLayer = (obj: any) => {
4946
return obj?.type in VisLayerTypes;
5047
};
51-
52-
export interface ISavedAugmentVis {
53-
id?: string;
54-
title: string;
55-
description?: string;
56-
pluginResourceId: string;
57-
visName?: string;
58-
visId?: string;
59-
visLayerExpressionFn: VisLayerExpressionFn;
60-
version?: number;
61-
}
62-
63-
export interface VisLayerExpressionFn {
64-
type: keyof typeof VisLayerTypes;
65-
name: string;
66-
// plugin expression fns can freely set custom arguments
67-
args: { [key: string]: any };
68-
}
69-
70-
export interface AugmentVisSavedObject extends SavedObject, ISavedAugmentVis {}
71-
72-
export interface VisLayerResponseValue {
73-
visLayers: object;
74-
}
75-
76-
export type VisLayerFunctionDefinition = ExpressionFunctionDefinition<
77-
string,
78-
VisLayerResponseValue,
79-
any,
80-
Promise<VisLayerResponseValue>
81-
>;

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

+12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ export const isEligibleForVisLayers = (vis: Vis): boolean => {
1919
return vis.params.type === 'line';
2020
};
2121

22+
/**
23+
* Using a SavedAugmentVisLoader, fetch all saved objects that are of 'augment-vis' type
24+
* and filter out to return the ones associated to the particular vis via
25+
* matching vis ID.
26+
*/
2227
export const getAugmentVisSavedObjs = async (
2328
visId: string | undefined,
2429
loader: SavedAugmentVisLoader | undefined
@@ -32,6 +37,13 @@ export const getAugmentVisSavedObjs = async (
3237
}
3338
};
3439

40+
/**
41+
* Given an array of augment-vis saved objects that contain expression function details,
42+
* construct a pipeline that will execute each of these expression functions.
43+
* Note that the order does not matter; each expression function should be taking
44+
* in the current output and appending its results to it, such that the end result
45+
* contains the results from each expression function that was ran.
46+
*/
3547
export const buildPipelineFromAugmentVisSavedObjs = (objs: ISavedAugmentVis[]): string => {
3648
const visLayerExpressionFns = [] as Array<
3749
ExpressionAstFunctionBuilder<VisLayerFunctionDefinition>

src/plugins/visualizations/public/embeddable/visualize_embeddable.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ export class VisualizeEmbeddable
417417
timefilter: this.timefilter,
418418
timeRange: this.timeRange,
419419
abortSignal: this.abortController!.signal,
420-
visLayers: !isEmpty(exprVisLayers) ? exprVisLayers.layers : ([] as VisLayers),
420+
visLayers: isEmpty(exprVisLayers) ? ([] as VisLayers) : exprVisLayers.layers,
421421
});
422422

423423
if (this.handler && !abortController.signal.aborted) {

0 commit comments

Comments
 (0)