Skip to content

Commit

Permalink
Expose external services to helper fns (#4139)
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
  • Loading branch information
ohltyler authored May 30, 2023
1 parent ec4c1df commit 66070aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,27 @@
*/

import { get } from 'lodash';
import { getSavedAugmentVisLoader, getUISettings } from '../../services';
import { ISavedAugmentVis } from '../types';
import {
PLUGIN_AUGMENTATION_ENABLE_SETTING,
PLUGIN_AUGMENTATION_MAX_OBJECTS_SETTING,
} from '../../../common/constants';
import { SavedAugmentVisLoader } from '../saved_augment_vis';
import { getSavedAugmentVisLoader, getUISettings } from '../../services';
import { IUiSettingsClient } from '../../../../../core/public';

/**
* Create an augment vis saved object given an object that
* implements the ISavedAugmentVis interface
*/
export const createAugmentVisSavedObject = async (AugmentVis: ISavedAugmentVis): Promise<any> => {
const loader = getSavedAugmentVisLoader();
const config = getUISettings();

export const createAugmentVisSavedObject = async (
AugmentVis: ISavedAugmentVis,
savedObjLoader?: SavedAugmentVisLoader,
uiSettings?: IUiSettingsClient
): Promise<any> => {
// Using optional services provided, or the built-in services from this plugin
const loader = savedObjLoader !== undefined ? savedObjLoader : getSavedAugmentVisLoader();
const config = uiSettings !== undefined ? uiSettings : getUISettings();
const isAugmentationEnabled = config.get(PLUGIN_AUGMENTATION_ENABLE_SETTING);
if (!isAugmentationEnabled) {
throw new Error(
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/vis_augmenter/public/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from '../';
import { PLUGIN_AUGMENTATION_ENABLE_SETTING } from '../../common/constants';
import { getUISettings } from '../services';
import { IUiSettingsClient } from '../../../../core/public';

export const isEligibleForVisLayers = (vis: Vis): boolean => {
// Only support date histogram and ensure there is only 1 x-axis and it has to be on the bottom.
Expand Down Expand Up @@ -53,9 +54,11 @@ export const isEligibleForVisLayers = (vis: Vis): boolean => {
*/
export const getAugmentVisSavedObjs = async (
visId: string | undefined,
loader: SavedAugmentVisLoader | undefined
loader: SavedAugmentVisLoader | undefined,
uiSettings?: IUiSettingsClient | undefined
): Promise<ISavedAugmentVis[]> => {
const config = getUISettings();
// Using optional services provided, or the built-in services from this plugin
const config = uiSettings !== undefined ? uiSettings : getUISettings();
const isAugmentationEnabled = config.get(PLUGIN_AUGMENTATION_ENABLE_SETTING);
if (!isAugmentationEnabled) {
throw new Error(
Expand Down

0 comments on commit 66070aa

Please sign in to comment.