Skip to content

Commit

Permalink
Refactor types; address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
  • Loading branch information
ohltyler committed Mar 7, 2023
1 parent 1687089 commit c0b8771
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/plugins/vis_augmenter/public/expressions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
* SPDX-License-Identifier: Apache-2.0
*/

export * from './vis_layers';
export * from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { ExpressionTypeDefinition } from '../../../expressions';
import { VisLayers } from '../';
import { ExpressionTypeDefinition, ExpressionFunctionDefinition } from '../../../expressions';
import { VisLayers, VisLayerTypes } from '../';

const name = 'vis_layers';

Expand All @@ -31,3 +31,17 @@ export const visLayers: ExpressionTypeDefinition<typeof name, ExprVisLayers> = {
},
},
};

export type VisLayerFunctionDefinition = ExpressionFunctionDefinition<
string,
ExprVisLayers,
any,
Promise<ExprVisLayers>
>;

export interface VisLayerExpressionFn {
type: keyof typeof VisLayerTypes;
name: string;
// plugin expression fns can freely set custom arguments
args: { [key: string]: any };
}
10 changes: 2 additions & 8 deletions src/plugins/vis_augmenter/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,8 @@ export {
SavedObjectOpenSearchDashboardsServicesWithAugmentVis,
} from './saved_augment_vis';

export {
ISavedAugmentVis,
VisLayerExpressionFn,
AugmentVisSavedObject,
VisLayerFunctionDefinition,
VisLayer,
VisLayers,
} from './types';
export { VisLayer, VisLayers, VisLayerTypes } from './types';

export * from './expressions';
export * from './utils';
export * from './saved_augment_vis';
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@

export * from './saved_augment_vis';
export * from './utils';
export * from './types';
20 changes: 20 additions & 0 deletions src/plugins/vis_augmenter/public/saved_augment_vis/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { SavedObject } from '../../../saved_objects/public';
import { VisLayerExpressionFn } from '../expressions';

export interface ISavedAugmentVis {
id?: string;
title: string;
description?: string;
pluginResourceId: string;
visName?: string;
visId?: string;
visLayerExpressionFn: VisLayerExpressionFn;
version?: number;
}

export interface AugmentVisSavedObject extends SavedObject, ISavedAugmentVis {}
34 changes: 0 additions & 34 deletions src/plugins/vis_augmenter/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { SavedObject } from '../../saved_objects/public';
import { ExpressionFunctionDefinition } from '../../expressions';

export enum VisLayerTypes {
PointInTimeEvents = 'PointInTimeEvents',
}
Expand Down Expand Up @@ -48,34 +45,3 @@ export const isPointInTimeEventsVisLayer = (obj: any) => {
export const isValidVisLayer = (obj: any) => {
return obj?.type in VisLayerTypes;
};

export interface ISavedAugmentVis {
id?: string;
title: string;
description?: string;
pluginResourceId: string;
visName?: string;
visId?: string;
visLayerExpressionFn: VisLayerExpressionFn;
version?: number;
}

export interface VisLayerExpressionFn {
type: keyof typeof VisLayerTypes;
name: string;
// plugin expression fns can freely set custom arguments
args: { [key: string]: any };
}

export interface AugmentVisSavedObject extends SavedObject, ISavedAugmentVis {}

export interface VisLayerResponseValue {
visLayers: object;
}

export type VisLayerFunctionDefinition = ExpressionFunctionDefinition<
string,
VisLayerResponseValue,
any,
Promise<VisLayerResponseValue>
>;
12 changes: 12 additions & 0 deletions src/plugins/vis_augmenter/public/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export const isEligibleForVisLayers = (vis: Vis): boolean => {
return vis.params.type === 'line';
};

/**
* Using a SavedAugmentVisLoader, fetch all saved objects that are of 'augment-vis' type
* and filter out to return the ones associated to the particular vis via
* matching vis ID.
*/
export const getAugmentVisSavedObjs = async (
visId: string | undefined,
loader: SavedAugmentVisLoader | undefined
Expand All @@ -32,6 +37,13 @@ export const getAugmentVisSavedObjs = async (
}
};

/**
* Given an array of augment-vis saved objects that contain expression function details,
* construct a pipeline that will execute each of these expression functions.
* Note that the order does not matter; each expression function should be taking
* in the current output and appending its results to it, such that the end result
* contains the results from each expression function that was ran.
*/
export const buildPipelineFromAugmentVisSavedObjs = (objs: ISavedAugmentVis[]): string => {
const visLayerExpressionFns = [] as Array<
ExpressionAstFunctionBuilder<VisLayerFunctionDefinition>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ export class VisualizeEmbeddable
timefilter: this.timefilter,
timeRange: this.timeRange,
abortSignal: this.abortController!.signal,
visLayers: !isEmpty(exprVisLayers) ? exprVisLayers.layers : ([] as VisLayers),
visLayers: isEmpty(exprVisLayers) ? ([] as VisLayers) : exprVisLayers.layers,
});

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

0 comments on commit c0b8771

Please sign in to comment.