Skip to content

Commit

Permalink
Add logic to collect VisLayers in line chart render flow (#3131)
Browse files Browse the repository at this point in the history
* Collect VisLayers in VisualizeEmbeddable render flow

Signed-off-by: Tyler Ohlsen <[email protected]>

* Refactor types; address comments

Signed-off-by: Tyler Ohlsen <[email protected]>

* Simplify fetchVisLayers() and pipeline helper fns

Signed-off-by: Tyler Ohlsen <[email protected]>

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

Signed-off-by: Josh Romero <[email protected]>

---------

Signed-off-by: Tyler Ohlsen <[email protected]>
Signed-off-by: Josh Romero <[email protected]>
Co-authored-by: Josh Romero <[email protected]>
  • Loading branch information
ohltyler and joshuarrrr authored Mar 9, 2023
1 parent d63ef1f commit 236f49f
Show file tree
Hide file tree
Showing 20 changed files with 375 additions and 100 deletions.
60 changes: 0 additions & 60 deletions src/plugins/vis_augmenter/common/types.ts

This file was deleted.

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 '../../common';
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 };
}
6 changes: 5 additions & 1 deletion src/plugins/vis_augmenter/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ export {
SavedObjectOpenSearchDashboardsServicesWithAugmentVis,
} from './saved_augment_vis';

export { ISavedAugmentVis, VisLayerExpressionFn, AugmentVisSavedObject } 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';
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { VisLayerExpressionFn } from '../types';
import { VisLayerTypes } from '../../common';
import { VisLayerExpressionFn, VisLayerTypes } from '../types';
import {
createSavedAugmentVisLoader,
SavedObjectOpenSearchDashboardsServicesWithAugmentVis,
Expand All @@ -19,15 +18,23 @@ describe('SavedObjectLoaderAugmentVis', () => {
testArg: 'test-value',
},
} as VisLayerExpressionFn;
const validObj1 = generateAugmentVisSavedObject('valid-obj-id-1', fn);
const validObj2 = generateAugmentVisSavedObject('valid-obj-id-2', fn);
const invalidFnTypeObj = generateAugmentVisSavedObject('invalid-fn-obj-id-1', {
...fn,
// @ts-ignore
type: 'invalid-type',
});
// @ts-ignore
const missingFnObj = generateAugmentVisSavedObject('missing-fn-obj-id-1', {});
const validObj1 = generateAugmentVisSavedObject('valid-obj-id-1', fn, 'test-vis-id');
const validObj2 = generateAugmentVisSavedObject('valid-obj-id-2', fn, 'test-vis-id');
const invalidFnTypeObj = generateAugmentVisSavedObject(
'invalid-fn-obj-id-1',
{
...fn,
// @ts-ignore
type: 'invalid-type',
},
'test-vis-id'
);

const missingFnObj = generateAugmentVisSavedObject(
'missing-fn-obj-id-1',
{} as VisLayerExpressionFn,
'test-vis-id'
);

it('find returns single saved obj', async () => {
const loader = createSavedAugmentVisLoader({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
SavedObjectOpenSearchDashboardsServices,
} from '../../../saved_objects/public';
import { createSavedAugmentVisClass } from './_saved_augment_vis';
import { VisLayerTypes } from '../../common';
import { VisLayerTypes } from '../types';

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface SavedObjectOpenSearchDashboardsServicesWithAugmentVis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { extractReferences, injectReferences } from './saved_augment_vis_references';
import {
extractReferences,
injectReferences,
VIS_REFERENCE_NAME,
} from './saved_augment_vis_references';
import { AugmentVisSavedObject } from '../types';
import { VIS_REFERENCE_NAME } from './saved_augment_vis_references';

describe('extractReferences()', () => {
test('extracts nothing if visId is null', () => {
Expand Down
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 {}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ import { VisLayerExpressionFn, ISavedAugmentVis } from '../../types';
import { VIS_REFERENCE_NAME } from '../saved_augment_vis_references';

const pluginResourceId = 'test-plugin-resource-id';
const visId = 'test-vis-id';
const title = 'test-title';
const version = 1;

export const generateAugmentVisSavedObject = (idArg: string, exprFnArg: VisLayerExpressionFn) => {
export const generateAugmentVisSavedObject = (
idArg: string,
exprFnArg: VisLayerExpressionFn,
visIdArg: string
) => {
return {
id: idArg,
title,
pluginResourceId,
visLayerExpressionFn: exprFnArg,
VIS_REFERENCE_NAME,
visId,
visId: visIdArg,
version,
} as ISavedAugmentVis;
};
Expand Down
51 changes: 36 additions & 15 deletions src/plugins/vis_augmenter/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,45 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { SavedObject } from '../../saved_objects/public';
import { VisLayerTypes } from '../common';
export enum VisLayerTypes {
PointInTimeEvents = 'PointInTimeEvents',
}

export interface ISavedAugmentVis {
id?: string;
description?: string;
pluginResourceId: string;
visName?: string;
visId?: string;
visLayerExpressionFn: VisLayerExpressionFn;
version?: number;
export type PluginResourceType = string;

export interface PluginResource {
type: PluginResourceType;
id: string;
name: string;
urlPath: string;
}

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

export type VisLayers = VisLayer[];

export interface EventMetadata {
pluginResourceId: string;
tooltip?: string;
}

export interface PointInTimeEvent {
timestamp: number;
metadata: EventMetadata;
}

export interface AugmentVisSavedObject extends SavedObject, ISavedAugmentVis {}
export interface PointInTimeEventsVisLayer extends VisLayer {
events: PointInTimeEvent[];
}

export const isPointInTimeEventsVisLayer = (obj: any) => {
return obj?.type === VisLayerTypes.PointInTimeEvents;
};

export const isValidVisLayer = (obj: any) => {
return obj?.type in VisLayerTypes;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
* SPDX-License-Identifier: Apache-2.0
*/

export * from './types';
export * from './utils';
Loading

0 comments on commit 236f49f

Please sign in to comment.