Skip to content

Commit

Permalink
Update VisLayer data models (#3374)
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <[email protected]>
  • Loading branch information
ohltyler authored Feb 4, 2023
1 parent 2b82edd commit a990ab9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 40 deletions.
51 changes: 17 additions & 34 deletions src/plugins/vis_augmenter/common/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,39 @@

import { VisLayerTypes, VisLayer, isPointInTimeEventsVisLayer, isValidVisLayer } from './types';

const generateVisLayer = (type: any): VisLayer => {
return {
type,
originPlugin: 'test-plugin',
pluginResource: {
type: 'test-resource-type',
id: 'test-resource-id',
name: 'test-resource-name',
urlPath: 'test-resource-url-path',
},
};
};

describe('isPointInTimeEventsVisLayer()', function () {
it('should return false if type does not match', function () {
const visLayer = ({
type: 'incorrect-type',
name: 'visLayerName',
field1: 'value1',
field2: 'value2',
} as unknown) as VisLayer;
const visLayer = generateVisLayer('unknown-vis-layer-type');
expect(isPointInTimeEventsVisLayer(visLayer)).toBe(false);
});

it('should return true if type matches', function () {
const visLayer = {
type: VisLayerTypes.PointInTimeEvents,
name: 'testName',
events: [
{
timestamp: 123,
resourceId: 'testId',
resourceName: 'testName',
},
],
} as VisLayer;
const visLayer = generateVisLayer(VisLayerTypes.PointInTimeEvents);
expect(isPointInTimeEventsVisLayer(visLayer)).toBe(true);
});
});

describe('isValidVisLayer()', function () {
it('should return false if no valid type', function () {
const visLayer = ({
type: 'incorrect-type',
name: 'visLayerName',
field1: 'value1',
field2: 'value2',
} as unknown) as VisLayer;
const visLayer = generateVisLayer('unknown-vis-layer-type');
expect(isValidVisLayer(visLayer)).toBe(false);
});

it('should return true if type matches', function () {
const visLayer = {
type: VisLayerTypes.PointInTimeEvents,
name: 'testName',
events: [
{
timestamp: 123,
resourceId: 'testId',
resourceName: 'testName',
},
],
} as VisLayer;
const visLayer = generateVisLayer(VisLayerTypes.PointInTimeEvents);
expect(isValidVisLayer(visLayer)).toBe(true);
});
});
18 changes: 12 additions & 6 deletions src/plugins/vis_augmenter/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,25 @@ export enum VisLayerTypes {
PointInTimeEvents = 'PointInTimeEvents',
}

export type PluginResourceType = string;

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

export interface VisLayer {
type: keyof typeof VisLayerTypes;
name: string;
originPlugin: string;
pluginResource: PluginResource;
}

export type VisLayers = VisLayer[];

// resourceId & resourceName are required so that the
// events flyout can partition data based on these attributes
// (e.g., partitioning anomalies based on the detector they came from)
export interface EventMetadata {
resourceId: string;
resourceName: string;
pluginResourceId: string;
tooltip?: string;
}

Expand Down

0 comments on commit a990ab9

Please sign in to comment.