-
Notifications
You must be signed in to change notification settings - Fork 892
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add interfaces for layering data on Visualizations (#3108)
* Add vis layer interfaces Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
- Loading branch information
Showing
7 changed files
with
165 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { VisLayerTypes, VisLayer, isPointInTimeEventsVisLayer, isValidVisLayer } from './types'; | ||
|
||
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; | ||
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; | ||
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; | ||
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; | ||
expect(isValidVisLayer(visLayer)).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { ExpressionFunctionDefinition } from '../../expressions'; | ||
|
||
export enum VisLayerTypes { | ||
PointInTimeEvents = 'PointInTimeEvents', | ||
} | ||
|
||
export interface VisLayer { | ||
type: keyof typeof VisLayerTypes; | ||
name: string; | ||
} | ||
|
||
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; | ||
tooltip?: string; | ||
} | ||
|
||
export interface PointInTimeEvent { | ||
timestamp: number; | ||
metadata: EventMetadata; | ||
} | ||
|
||
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; | ||
}; | ||
|
||
export interface VisLayerResponseValue { | ||
visLayers: object; | ||
} | ||
|
||
export type VisLayerFunctionDefinition = ExpressionFunctionDefinition< | ||
string, | ||
VisLayerResponseValue, | ||
any, | ||
Promise<VisLayerResponseValue> | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export * from './vis_layers'; |
33 changes: 33 additions & 0 deletions
33
src/plugins/vis_augmenter/public/expressions/vis_layers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { ExpressionTypeDefinition } from '../../../expressions'; | ||
import { VisLayers } from '../../common'; | ||
|
||
const name = 'vis_layers'; | ||
|
||
export interface ExprVisLayers { | ||
type: typeof name; | ||
layers: VisLayers; | ||
} | ||
|
||
// Setting default empty arrays for null & undefined edge cases | ||
export const visLayers: ExpressionTypeDefinition<typeof name, ExprVisLayers> = { | ||
name, | ||
from: { | ||
null: () => { | ||
return { | ||
type: name, | ||
layers: [] as VisLayers, | ||
} as ExprVisLayers; | ||
}, | ||
undefined: () => { | ||
return { | ||
type: name, | ||
layers: [] as VisLayers, | ||
} as ExprVisLayers; | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters