-
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.
Redo imports; move everything from common to public
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
- Loading branch information
Showing
17 changed files
with
259 additions
and
229 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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
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
File renamed without changes.
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 |
---|---|---|
|
@@ -3,4 +3,4 @@ | |
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export * from './types'; | ||
export * from './utils'; |
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,80 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { Vis } from '../../../visualizations/public'; | ||
import { buildPipelineFromAugmentVisSavedObjs, isEligibleForVisLayers } from './utils'; | ||
import { VisLayerTypes, ISavedAugmentVis } from '../types'; | ||
|
||
describe('utils', () => { | ||
// TODO: redo / update this test suite when eligibility is finalized. | ||
// Tracked in https://github.com/opensearch-project/OpenSearch-Dashboards/issues/3268 | ||
describe('isEligibleForVisLayers', () => { | ||
it('vis is ineligible with invalid type', async () => { | ||
const vis = ({ | ||
params: { | ||
type: 'not-line', | ||
}, | ||
} as unknown) as Vis; | ||
expect(isEligibleForVisLayers(vis)).toEqual(false); | ||
}); | ||
it('vis is eligible with valid type', async () => { | ||
const vis = ({ | ||
params: { | ||
type: 'line', | ||
}, | ||
} as unknown) as Vis; | ||
expect(isEligibleForVisLayers(vis)).toEqual(true); | ||
}); | ||
}); | ||
|
||
describe('getAugmentVisSavedObjs', () => { | ||
// TODO: add tests after saved obj PR tests are added; can use | ||
// them for instantiating mock saved obj loader | ||
}); | ||
|
||
describe('buildPipelineFromAugmentVisSavedObjs', () => { | ||
const obj1 = { | ||
title: 'obj1', | ||
pluginResourceId: 'obj-1-resource-id', | ||
visLayerExpressionFn: { | ||
type: VisLayerTypes.PointInTimeEvents, | ||
name: 'fn-1', | ||
args: { | ||
arg1: 'value-1', | ||
}, | ||
}, | ||
} as ISavedAugmentVis; | ||
const obj2 = { | ||
title: 'obj2', | ||
pluginResourceId: 'obj-2-resource-id', | ||
visLayerExpressionFn: { | ||
type: VisLayerTypes.PointInTimeEvents, | ||
name: 'fn-2', | ||
args: { | ||
arg2: 'value-2', | ||
}, | ||
}, | ||
} as ISavedAugmentVis; | ||
it('catches error with empty array', async () => { | ||
try { | ||
buildPipelineFromAugmentVisSavedObjs([]); | ||
} catch (e: any) { | ||
expect( | ||
e.message.includes( | ||
'Expression function from augment-vis saved objects could not be generated' | ||
) | ||
); | ||
} | ||
}); | ||
it('builds with one saved obj', async () => { | ||
const str = buildPipelineFromAugmentVisSavedObjs([obj1]); | ||
expect(str).toEqual('fn-1 arg1="value-1"'); | ||
}); | ||
it('builds with multiple saved objs', async () => { | ||
const str = buildPipelineFromAugmentVisSavedObjs([obj1, obj2]); | ||
expect(str).toEqual(`fn-1 arg1="value-1"\n| fn-2 arg2="value-2"`); | ||
}); | ||
}); | ||
}); |
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,55 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { get } from 'lodash'; | ||
import { Vis } from '../../../visualizations/public'; | ||
import { | ||
formatExpression, | ||
buildExpressionFunction, | ||
buildExpression, | ||
ExpressionAstFunctionBuilder, | ||
} from '../../../../plugins/expressions/public'; | ||
import { ISavedAugmentVis, SavedAugmentVisLoader, VisLayerFunctionDefinition } from '../'; | ||
|
||
// TODO: provide a deeper eligibility check. | ||
// Tracked in https://github.com/opensearch-project/OpenSearch-Dashboards/issues/3268 | ||
export const isEligibleForVisLayers = (vis: Vis): boolean => { | ||
return vis.params.type === 'line'; | ||
}; | ||
|
||
export const getAugmentVisSavedObjs = async ( | ||
visId: string | undefined, | ||
loader: SavedAugmentVisLoader | undefined | ||
): Promise<ISavedAugmentVis[]> => { | ||
try { | ||
const resp = await loader?.findAll(); | ||
const allSavedObjects = (get(resp, 'hits', []) as any[]) as ISavedAugmentVis[]; | ||
return allSavedObjects.filter((hit: ISavedAugmentVis) => hit.visId === visId); | ||
} catch (e) { | ||
// console.error('Unable to search for augment-vis saved objects: ', e); | ||
return [] as ISavedAugmentVis[]; | ||
} | ||
}; | ||
|
||
export const buildPipelineFromAugmentVisSavedObjs = (objs: ISavedAugmentVis[]): string => { | ||
const visLayerExpressionFns = [] as Array< | ||
ExpressionAstFunctionBuilder<VisLayerFunctionDefinition> | ||
>; | ||
|
||
try { | ||
objs.forEach((obj: ISavedAugmentVis) => { | ||
visLayerExpressionFns.push( | ||
buildExpressionFunction<VisLayerFunctionDefinition>( | ||
obj.visLayerExpressionFn.name, | ||
obj.visLayerExpressionFn.args | ||
) | ||
); | ||
}); | ||
const ast = buildExpression(visLayerExpressionFns).toAst(); | ||
return formatExpression(ast); | ||
} catch (e) { | ||
throw new Error('Expression function from augment-vis saved objects could not be generated'); | ||
} | ||
}; |
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
Oops, something went wrong.