From d19a257078f55a7c71038a201e4f8764bed9c69e Mon Sep 17 00:00:00 2001 From: Ashish Agrawal Date: Mon, 1 May 2023 14:27:03 -0700 Subject: [PATCH 01/11] Add new advanced settings Signed-off-by: Ashish Agrawal --- .../server/collectors/management/schema.ts | 2 ++ src/plugins/telemetry/schema/oss_plugins.json | 6 ++++ src/plugins/vis_augmenter/server/plugin.ts | 29 +++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/src/plugins/opensearch_dashboards_usage_collection/server/collectors/management/schema.ts b/src/plugins/opensearch_dashboards_usage_collection/server/collectors/management/schema.ts index 8127664c02cd..45fbc7aaaa87 100644 --- a/src/plugins/opensearch_dashboards_usage_collection/server/collectors/management/schema.ts +++ b/src/plugins/opensearch_dashboards_usage_collection/server/collectors/management/schema.ts @@ -40,6 +40,8 @@ export const stackManagementSchema: MakeSchemaFrom = { 'visualization:regionmap:showWarnings': { type: 'boolean' }, 'visualization:dimmingOpacity': { type: 'float' }, 'visualization:tileMap:maxPrecision': { type: 'long' }, + 'visualization:enablePluginAugmentation': { type: 'boolean' }, + 'visualization:enablePluginAugmentation.maxPluginObjects': { type: 'number' }, 'securitySolution:ipReputationLinks': { type: 'text' }, 'csv:separator': { type: 'keyword' }, 'visualization:tileMap:WMSdefaults': { type: 'text' }, diff --git a/src/plugins/telemetry/schema/oss_plugins.json b/src/plugins/telemetry/schema/oss_plugins.json index b1e09dda9794..1e25048ed03d 100644 --- a/src/plugins/telemetry/schema/oss_plugins.json +++ b/src/plugins/telemetry/schema/oss_plugins.json @@ -1372,6 +1372,12 @@ "visualization:tileMap:maxPrecision": { "type": "long" }, + "visualization:enablePluginAugmentation": { + "type": "boolean" + }, + "visualization:enablePluginAugmentation.maxPluginObjects": { + "type": "number" + }, "securitySolution:ipReputationLinks": { "type": "text" }, diff --git a/src/plugins/vis_augmenter/server/plugin.ts b/src/plugins/vis_augmenter/server/plugin.ts index f30cf6c974fe..8371f2c68162 100644 --- a/src/plugins/vis_augmenter/server/plugin.ts +++ b/src/plugins/vis_augmenter/server/plugin.ts @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { i18n } from '@osd/i18n'; +import { schema } from '@osd/config-schema'; import { PluginInitializerContext, CoreSetup, @@ -30,6 +32,33 @@ export class VisAugmenterPlugin this.logger.debug('VisAugmenter: Setup'); core.savedObjects.registerType(augmentVisSavedObjectType); core.capabilities.registerProvider(capabilitiesProvider); + + core.uiSettings.register({ + ['visualization:enablePluginAugmentation']: { + name: i18n.translate('visualization.enablePluginAugmentationTitle', { + defaultMessage: 'Enable plugin augmentation', + }), + value: true, + description: i18n.translate('visualization.enablePluginAugmentationText', { + defaultMessage: 'Plugin functionality can be accessed from line chart visualizations', + }), + category: ['visualization'], + schema: schema.boolean(), + }, + ['visualization:enablePluginAugmentation.maxPluginObjects']: { + name: i18n.translate('visualization.enablePluginAugmentation.maxPluginObjectsTitle', { + defaultMessage: 'Max number of associated augmentations', + }), + value: 10, + description: i18n.translate('visualization.enablePluginAugmentation.maxPluginObjectsText', { + defaultMessage: + 'Associating more than 10 plugin resources per visualization can lead to performance ' + + 'issues and increase the cost of running clusters.', + }), + category: ['visualization'], + schema: schema.number({ min: 0 }), + }, + }); return {}; } From 282a7c6e5e1bb29db95347c6355661583e9d1000 Mon Sep 17 00:00:00 2001 From: Ashish Agrawal Date: Fri, 12 May 2023 11:19:15 -0700 Subject: [PATCH 02/11] Add yml setting and doing settings checks now Signed-off-by: Ashish Agrawal --- config/opensearch_dashboards.yml | 7 +- package.json | 2 +- src/plugins/vis_augmenter/config.ts | 12 ++ src/plugins/vis_augmenter/public/plugin.ts | 3 +- .../saved_augment_vis/saved_augment_vis.ts | 111 ++++++++++++------ .../public/saved_augment_vis/utils/helpers.ts | 36 +++++- src/plugins/vis_augmenter/public/services.ts | 9 +- .../vis_augmenter/public/utils/utils.ts | 15 ++- src/plugins/vis_augmenter/server/index.ts | 9 +- src/plugins/vis_augmenter/server/plugin.ts | 68 ++++++----- .../create_vis_embeddable_from_object.ts | 5 +- .../public/embeddable/visualize_embeddable.ts | 77 ++++++------ 12 files changed, 239 insertions(+), 115 deletions(-) create mode 100644 src/plugins/vis_augmenter/config.ts diff --git a/config/opensearch_dashboards.yml b/config/opensearch_dashboards.yml index 38377296bd20..b575aeb629ba 100644 --- a/config/opensearch_dashboards.yml +++ b/config/opensearch_dashboards.yml @@ -137,7 +137,7 @@ #i18n.locale: "en" # Set the allowlist to check input graphite Url. Allowlist is the default check list. -#vis_type_timeline.graphiteAllowedUrls: ['https://www.hostedgraphite.com/UID/ACCESS_KEY/graphite'] +vis_type_timeline.graphiteAllowedUrls: ['https://www.hostedgraphite.com/UID/ACCESS_KEY/graphite'] # Set the denylist to check input graphite Url. Denylist is an IP list. # Below is an example for reference @@ -239,4 +239,7 @@ #data_source.encryption.wrappingKey: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] # Set the value of this setting to false to hide the help menu link to the OpenSearch Dashboards user survey -# opensearchDashboards.survey.url: "https://survey.opensearch.org" \ No newline at end of file +# opensearchDashboards.survey.url: "https://survey.opensearch.org" + +# Set the value of this setting to false to disable plugin augmentation on Dashboard +# vis_augmenter.pluginAugmentationEnabled: false diff --git a/package.json b/package.json index b9eb244f7756..840ce88cb0b7 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "dashboarding" ], "private": true, - "version": "3.0.0", + "version": "2.7.0", "branch": "main", "types": "./opensearch_dashboards.d.ts", "tsdocMetadata": "./build/tsdoc-metadata.json", diff --git a/src/plugins/vis_augmenter/config.ts b/src/plugins/vis_augmenter/config.ts new file mode 100644 index 000000000000..12b9854f451a --- /dev/null +++ b/src/plugins/vis_augmenter/config.ts @@ -0,0 +1,12 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { schema, TypeOf } from '@osd/config-schema'; + +export const configSchema = schema.object({ + pluginAugmentationEnabled: schema.boolean({ defaultValue: true }), +}); + +export type VisAugmenterPluginConfigType = TypeOf; diff --git a/src/plugins/vis_augmenter/public/plugin.ts b/src/plugins/vis_augmenter/public/plugin.ts index 1c064a1cee10..3bfedc2e0cea 100644 --- a/src/plugins/vis_augmenter/public/plugin.ts +++ b/src/plugins/vis_augmenter/public/plugin.ts @@ -7,7 +7,7 @@ import { ExpressionsSetup } from '../../expressions/public'; import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from '../../../core/public'; import { DataPublicPluginSetup, DataPublicPluginStart } from '../../data/public'; import { visLayers } from './expressions'; -import { setSavedAugmentVisLoader } from './services'; +import { setSavedAugmentVisLoader, setUISettings } from './services'; import { createSavedAugmentVisLoader, SavedAugmentVisLoader } from './saved_augment_vis'; // eslint-disable-next-line @typescript-eslint/no-empty-interface @@ -40,6 +40,7 @@ export class VisAugmenterPlugin } public start(core: CoreStart, { data }: VisAugmenterStartDeps): VisAugmenterStart { + setUISettings(core.uiSettings); const savedAugmentVisLoader = createSavedAugmentVisLoader({ savedObjectsClient: core.savedObjects.client, indexPatterns: data.indexPatterns, diff --git a/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts b/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts index 910ef0b9ea75..8db352868779 100644 --- a/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts +++ b/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts @@ -4,59 +4,94 @@ */ import { get, isEmpty } from 'lodash'; +import { IUiSettingsClient, SavedObjectsClientContract } from 'opensearch-dashboards/public'; import { SavedObjectLoader, SavedObjectOpenSearchDashboardsServices, } from '../../../saved_objects/public'; import { createSavedAugmentVisClass } from './_saved_augment_vis'; import { VisLayerTypes } from '../types'; +import { getUISettings } from '../services'; // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface SavedObjectOpenSearchDashboardsServicesWithAugmentVis extends SavedObjectOpenSearchDashboardsServices {} export type SavedAugmentVisLoader = ReturnType; + +export class SavedObjectLoaderAugmentVis extends SavedObjectLoader { + private readonly config: IUiSettingsClient = getUISettings(); + constructor( + servicesWithAugmentVis: SavedObjectOpenSearchDashboardsServicesWithAugmentVis, + SavedObjectClass: any, + savedObjectsClientContract: SavedObjectsClientContract + ) { + super(SavedObjectClass, savedObjectsClientContract); + } + + mapHitSource = (source: Record, id: string) => { + source.id = id; + source.visId = get(source, 'visReference.id', ''); + + if (isEmpty(source.visReference)) { + source.error = 'visReference is missing in augment-vis saved object'; + return source; + } + if (isEmpty(source.visLayerExpressionFn)) { + source.error = 'visLayerExpressionFn is missing in augment-vis saved object'; + return source; + } + if (!(get(source, 'visLayerExpressionFn.type', '') in VisLayerTypes)) { + source.error = 'Unknown VisLayer expression function type'; + return source; + } + return source; + }; + + /** + * Updates hit.attributes to contain an id related to the referenced visualization + * (visId) and returns the updated attributes object. + * @param hit + * @returns {hit.attributes} The modified hit.attributes object, with an id and url field. + */ + mapSavedObjectApiHits(hit: { + references: any[]; + attributes: Record; + id: string; + }) { + // For now we are assuming only one vis reference per saved object. + // If we change to multiple, we will need to dynamically handle that + const visReference = hit.references[0]; + return this.mapHitSource({ ...hit.attributes, visReference }, hit.id); + } + + /** + * Retrieve a saved object by id or create new one. + * Returns a promise that completes when the object finishes + * initializing. Throws exception when the setting is set to false. + * @param opts + * @returns {Promise} + */ + get(opts?: Record | string) { + const isAugmentationEnabled = this.config.get('visualization:enablePluginAugmentation'); + + if (!isAugmentationEnabled) { + // eslint-disable-next-line no-throw-literal + throw 'Visualization augmentation is disabled, please enable visualization:enablePluginAugmentation.'; + } + + // can accept object as argument in accordance to SavedVis class + // see src/plugins/saved_objects/public/saved_object/saved_object_loader.ts + // @ts-ignore + const obj = new this.Class(opts); + return obj.init(); + } +} + export function createSavedAugmentVisLoader( services: SavedObjectOpenSearchDashboardsServicesWithAugmentVis ) { const { savedObjectsClient } = services; - class SavedObjectLoaderAugmentVis extends SavedObjectLoader { - mapHitSource = (source: Record, id: string) => { - source.id = id; - source.visId = get(source, 'visReference.id', ''); - - if (isEmpty(source.visReference)) { - source.error = 'visReference is missing in augment-vis saved object'; - return source; - } - if (isEmpty(source.visLayerExpressionFn)) { - source.error = 'visLayerExpressionFn is missing in augment-vis saved object'; - return source; - } - if (!(get(source, 'visLayerExpressionFn.type', '') in VisLayerTypes)) { - source.error = 'Unknown VisLayer expression function type'; - return source; - } - return source; - }; - - /** - * Updates hit.attributes to contain an id related to the referenced visualization - * (visId) and returns the updated attributes object. - * @param hit - * @returns {hit.attributes} The modified hit.attributes object, with an id and url field. - */ - mapSavedObjectApiHits(hit: { - references: any[]; - attributes: Record; - id: string; - }) { - // For now we are assuming only one vis reference per saved object. - // If we change to multiple, we will need to dynamically handle that - const visReference = hit.references[0]; - return this.mapHitSource({ ...hit.attributes, visReference }, hit.id); - } - } const SavedAugmentVis = createSavedAugmentVisClass(services); - return new SavedObjectLoaderAugmentVis(SavedAugmentVis, savedObjectsClient) as SavedObjectLoader; + return new SavedObjectLoaderAugmentVis(services, SavedAugmentVis, savedObjectsClient); } diff --git a/src/plugins/vis_augmenter/public/saved_augment_vis/utils/helpers.ts b/src/plugins/vis_augmenter/public/saved_augment_vis/utils/helpers.ts index c3a54a377317..7c8158b3c9f6 100644 --- a/src/plugins/vis_augmenter/public/saved_augment_vis/utils/helpers.ts +++ b/src/plugins/vis_augmenter/public/saved_augment_vis/utils/helpers.ts @@ -3,8 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { getSavedAugmentVisLoader } from '../../services'; -import { ISavedAugmentVis } from '../../types'; +import { get } from 'lodash'; +import { getSavedAugmentVisLoader, getUISettings } from '../../services'; +import { ISavedAugmentVis } from '../types'; /** * Create an augment vis saved object given an object that @@ -12,5 +13,36 @@ import { ISavedAugmentVis } from '../../types'; */ export const createAugmentVisSavedObject = async (AugmentVis: ISavedAugmentVis): Promise => { const loader = getSavedAugmentVisLoader(); + const config = getUISettings(); + + const isAugmentationEnabled = config.get('visualization:enablePluginAugmentation'); + if (!isAugmentationEnabled) { + // eslint-disable-next-line no-throw-literal + throw 'Visualization augmentation is disabled, please enable visualization:enablePluginAugmentation.'; + } + const maxAssociatedCount = config.get('visualization:enablePluginAugmentation.maxPluginObjects'); + + await loader.findAll().then(async (resp) => { + if (resp !== undefined) { + const savedAugmentObjects = get(resp, 'hits', []); + // gets all the saved object for this visualization + const savedObjectsForThisVisualization = savedAugmentObjects.filter( + (savedObj) => get(savedObj, 'visId', '') === AugmentVis.visId + ); + + if (maxAssociatedCount <= savedObjectsForThisVisualization.length) { + // eslint-disable-next-line no-throw-literal + throw ( + 'Cannot associate the plugin resource to the visualization due to the limit of the' + + 'max amount of associated plugin resources (' + + maxAssociatedCount + + ') with ' + + savedObjectsForThisVisualization.length + + ' associated to the visualization' + ); + } + } + }); + return await loader.get((AugmentVis as any) as Record); }; diff --git a/src/plugins/vis_augmenter/public/services.ts b/src/plugins/vis_augmenter/public/services.ts index 00fa45374980..085d4ac44f66 100644 --- a/src/plugins/vis_augmenter/public/services.ts +++ b/src/plugins/vis_augmenter/public/services.ts @@ -3,9 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { createGetterSetter } from '../../opensearch_dashboards_utils/common'; -import { SavedObjectLoader } from '../../saved_objects/public'; +import { createGetterSetter } from '../../opensearch_dashboards_utils/public'; +import { IUiSettingsClient } from '../../../core/public'; +import { SavedObjectLoaderAugmentVis } from './saved_augment_vis'; export const [getSavedAugmentVisLoader, setSavedAugmentVisLoader] = createGetterSetter< - SavedObjectLoader + SavedObjectLoaderAugmentVis >('savedAugmentVisLoader'); + +export const [getUISettings, setUISettings] = createGetterSetter('UISettings'); diff --git a/src/plugins/vis_augmenter/public/utils/utils.ts b/src/plugins/vis_augmenter/public/utils/utils.ts index 0ec4ad486383..faaa3e9193f7 100644 --- a/src/plugins/vis_augmenter/public/utils/utils.ts +++ b/src/plugins/vis_augmenter/public/utils/utils.ts @@ -18,6 +18,7 @@ import { VisLayer, isVisLayerWithError, } from '../'; +import { getUISettings } from '../services'; 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. @@ -38,7 +39,10 @@ export const isEligibleForVisLayers = (vis: Vis): boolean => { const hasOnlyLineSeries = vis.params.seriesParams.every((seriesParam: { type: string }) => seriesParam.type === 'line') && vis.params.type === 'line'; - return hasValidXaxis && hasCorrectAggregationCount && hasOnlyLineSeries; + // Checks if the augmentation setting is enabled + const config = getUISettings(); + const isAugmentationEnabled = config.get('visualization:enablePluginAugmentation'); + return isAugmentationEnabled && hasValidXaxis && hasCorrectAggregationCount && hasOnlyLineSeries; }; /** @@ -50,6 +54,15 @@ export const getAugmentVisSavedObjs = async ( visId: string | undefined, loader: SavedAugmentVisLoader | undefined ): Promise => { + if (visId === undefined || loader === undefined) { + return [] as ISavedAugmentVis[]; + } + const config = getUISettings(); + const isAugmentationEnabled = config.get('visualization:enablePluginAugmentation'); + if (!isAugmentationEnabled) { + // eslint-disable-next-line no-throw-literal + throw 'Visualization augmentation is disabled, please enable visualization:enablePluginAugmentation.'; + } try { const resp = await loader?.findAll(); const allSavedObjects = (get(resp, 'hits', []) as any[]) as ISavedAugmentVis[]; diff --git a/src/plugins/vis_augmenter/server/index.ts b/src/plugins/vis_augmenter/server/index.ts index cc6530649a8e..9fb8b7b695fa 100644 --- a/src/plugins/vis_augmenter/server/index.ts +++ b/src/plugins/vis_augmenter/server/index.ts @@ -3,9 +3,16 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { PluginInitializerContext } from '../../../core/server'; +import { PluginConfigDescriptor, PluginInitializerContext } from '../../../core/server'; import { VisAugmenterPlugin } from './plugin'; +import { configSchema, VisAugmenterPluginConfigType } from '../config'; +export const config: PluginConfigDescriptor = { + exposeToBrowser: { + pluginAugmentationEnabled: true, + }, + schema: configSchema, +}; export function plugin(initializerContext: PluginInitializerContext) { return new VisAugmenterPlugin(initializerContext); } diff --git a/src/plugins/vis_augmenter/server/plugin.ts b/src/plugins/vis_augmenter/server/plugin.ts index 8371f2c68162..a0932abf5d23 100644 --- a/src/plugins/vis_augmenter/server/plugin.ts +++ b/src/plugins/vis_augmenter/server/plugin.ts @@ -5,6 +5,8 @@ import { i18n } from '@osd/i18n'; import { schema } from '@osd/config-schema'; +import { Observable } from 'rxjs'; +import { first } from 'rxjs/operators'; import { PluginInitializerContext, CoreSetup, @@ -14,6 +16,7 @@ import { } from '../../../core/server'; import { augmentVisSavedObjectType } from './saved_objects'; import { capabilitiesProvider } from './capabilities_provider'; +import { VisAugmenterPluginConfigType } from '../config'; // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface VisAugmenterPluginSetup {} @@ -23,42 +26,53 @@ export interface VisAugmenterPluginStart {} export class VisAugmenterPlugin implements Plugin { private readonly logger: Logger; + private readonly config$: Observable; constructor(initializerContext: PluginInitializerContext) { this.logger = initializerContext.logger.get(); + this.config$ = initializerContext.config.create(); } - public setup(core: CoreSetup) { + public async setup(core: CoreSetup) { this.logger.debug('VisAugmenter: Setup'); core.savedObjects.registerType(augmentVisSavedObjectType); core.capabilities.registerProvider(capabilitiesProvider); - core.uiSettings.register({ - ['visualization:enablePluginAugmentation']: { - name: i18n.translate('visualization.enablePluginAugmentationTitle', { - defaultMessage: 'Enable plugin augmentation', - }), - value: true, - description: i18n.translate('visualization.enablePluginAugmentationText', { - defaultMessage: 'Plugin functionality can be accessed from line chart visualizations', - }), - category: ['visualization'], - schema: schema.boolean(), - }, - ['visualization:enablePluginAugmentation.maxPluginObjects']: { - name: i18n.translate('visualization.enablePluginAugmentation.maxPluginObjectsTitle', { - defaultMessage: 'Max number of associated augmentations', - }), - value: 10, - description: i18n.translate('visualization.enablePluginAugmentation.maxPluginObjectsText', { - defaultMessage: - 'Associating more than 10 plugin resources per visualization can lead to performance ' + - 'issues and increase the cost of running clusters.', - }), - category: ['visualization'], - schema: schema.number({ min: 0 }), - }, - }); + const config: VisAugmenterPluginConfigType = await this.config$.pipe(first()).toPromise(); + const isAugmentationEnabled = + config.pluginAugmentationEnabled === undefined ? true : config.pluginAugmentationEnabled; + + if (isAugmentationEnabled) { + core.uiSettings.register({ + ['visualization:enablePluginAugmentation']: { + name: i18n.translate('visualization.enablePluginAugmentationTitle', { + defaultMessage: 'Enable plugin augmentation', + }), + value: true, + description: i18n.translate('visualization.enablePluginAugmentationText', { + defaultMessage: 'Plugin functionality can be accessed from line chart visualizations', + }), + category: ['visualization'], + schema: schema.boolean(), + }, + ['visualization:enablePluginAugmentation.maxPluginObjects']: { + name: i18n.translate('visualization.enablePluginAugmentation.maxPluginObjectsTitle', { + defaultMessage: 'Max number of associated augmentations', + }), + value: 10, + description: i18n.translate( + 'visualization.enablePluginAugmentation.maxPluginObjectsText', + { + defaultMessage: + 'Associating more than 10 plugin resources per visualization can lead to performance ' + + 'issues and increase the cost of running clusters.', + } + ), + category: ['visualization'], + schema: schema.number({ min: 0 }), + }, + }); + } return {}; } diff --git a/src/plugins/visualizations/public/embeddable/create_vis_embeddable_from_object.ts b/src/plugins/visualizations/public/embeddable/create_vis_embeddable_from_object.ts index e09f789f9a68..8d045125d853 100644 --- a/src/plugins/visualizations/public/embeddable/create_vis_embeddable_from_object.ts +++ b/src/plugins/visualizations/public/embeddable/create_vis_embeddable_from_object.ts @@ -40,12 +40,13 @@ import { IContainer, ErrorEmbeddable } from '../../../embeddable/public'; import { DisabledLabEmbeddable } from './disabled_lab_embeddable'; import { getSavedVisualizationsLoader, - getSavedAugmentVisLoader, + // getSavedAugmentVisLoader, getUISettings, getHttp, getTimeFilter, getCapabilities, } from '../services'; +import { getSavedAugmentVisLoader } from '../../../vis_augmenter/public'; import { VisualizeEmbeddableFactoryDeps } from './visualize_embeddable_factory'; import { VISUALIZE_ENABLE_LABS_SETTING } from '../../common/constants'; import { SavedVisualizationsLoader } from '../saved_visualizations'; @@ -89,7 +90,7 @@ export const createVisEmbeddableFromObject = (deps: VisualizeEmbeddableFactoryDe const editable = getCapabilities().visualize.save as boolean; - const savedAugmentVisLoader = getSavedAugmentVisLoader(); + const savedAugmentVisLoader = await getSavedAugmentVisLoader(); return new VisualizeEmbeddable( getTimeFilter(), diff --git a/src/plugins/visualizations/public/embeddable/visualize_embeddable.ts b/src/plugins/visualizations/public/embeddable/visualize_embeddable.ts index c313fe5ae3b9..5ceda93f6bc4 100644 --- a/src/plugins/visualizations/public/embeddable/visualize_embeddable.ts +++ b/src/plugins/visualizations/public/embeddable/visualize_embeddable.ts @@ -495,44 +495,47 @@ export class VisualizeEmbeddable expressionParams: IExpressionLoaderParams, abortController: AbortController ): Promise => { - const augmentVisSavedObjs = await getAugmentVisSavedObjs( - this.vis.id, - this.savedAugmentVisLoader - ); - if ( - !isEmpty(augmentVisSavedObjs) && - !abortController.signal.aborted && - isEligibleForVisLayers(this.vis) - ) { - const visLayersPipeline = buildPipelineFromAugmentVisSavedObjs(augmentVisSavedObjs); - // The initial input for the pipeline will just be an empty arr of VisLayers. As plugin - // expression functions are ran, they will incrementally append their generated VisLayers to it. - const visLayersPipelineInput = { - type: 'vis_layers', - layers: [] as VisLayers, - }; - // We cannot use this.handler in this case, since it does not support the run() cmd - // we need here. So, we consume the expressions service to run this directly instead. - const exprVisLayers = (await getExpressions().run( - visLayersPipeline, - visLayersPipelineInput, - expressionParams as Record - )) as ExprVisLayers; - const visLayers = exprVisLayers.layers; - const err = getAnyErrors(visLayers, this.vis.title); - // This is only true when one or more VisLayers has an error - if (err !== undefined) { - const { toasts } = getNotifications(); - toasts.addError(err, { - title: i18n.translate('visualizations.renderVisTitle', { - defaultMessage: `Error loading data on the ${this.vis.title} chart`, - }), - toastMessage: ' ', - id: this.id, - }); + try { + const augmentVisSavedObjs = await getAugmentVisSavedObjs( + this.vis.id, + this.savedAugmentVisLoader + ); + if ( + !isEmpty(augmentVisSavedObjs) && + !abortController.signal.aborted && + isEligibleForVisLayers(this.vis) + ) { + const visLayersPipeline = buildPipelineFromAugmentVisSavedObjs(augmentVisSavedObjs); + // The initial input for the pipeline will just be an empty arr of VisLayers. As plugin + // expression functions are ran, they will incrementally append their generated VisLayers to it. + const visLayersPipelineInput = { + type: 'vis_layers', + layers: [] as VisLayers, + }; + // We cannot use this.handler in this case, since it does not support the run() cmd + // we need here. So, we consume the expressions service to run this directly instead. + const exprVisLayers = (await getExpressions().run( + visLayersPipeline, + visLayersPipelineInput, + expressionParams as Record + )) as ExprVisLayers; + const visLayers = exprVisLayers.layers; + const err = getAnyErrors(visLayers, this.vis.title); + // This is only true when one or more VisLayers has an error + if (err !== undefined) { + const { toasts } = getNotifications(); + toasts.addError(err, { + title: i18n.translate('visualizations.renderVisTitle', { + defaultMessage: `Error loading data on the ${this.vis.title} chart`, + }), + toastMessage: ' ', + id: this.id, + }); + } + return visLayers; } - - return visLayers; + } catch { + return [] as VisLayers; } return [] as VisLayers; }; From e179ef5ce07cb1331ee9b5164516d8f0370bd527 Mon Sep 17 00:00:00 2001 From: Ashish Agrawal Date: Fri, 12 May 2023 11:27:13 -0700 Subject: [PATCH 03/11] minor fixes Signed-off-by: Ashish Agrawal --- config/opensearch_dashboards.yml | 2 +- package.json | 2 +- .../public/saved_augment_vis/saved_augment_vis.ts | 11 ++--------- .../embeddable/create_vis_embeddable_from_object.ts | 1 - src/plugins/visualizations/public/services.ts | 5 ----- 5 files changed, 4 insertions(+), 17 deletions(-) diff --git a/config/opensearch_dashboards.yml b/config/opensearch_dashboards.yml index b575aeb629ba..f6f1486e5499 100644 --- a/config/opensearch_dashboards.yml +++ b/config/opensearch_dashboards.yml @@ -137,7 +137,7 @@ #i18n.locale: "en" # Set the allowlist to check input graphite Url. Allowlist is the default check list. -vis_type_timeline.graphiteAllowedUrls: ['https://www.hostedgraphite.com/UID/ACCESS_KEY/graphite'] +#vis_type_timeline.graphiteAllowedUrls: ['https://www.hostedgraphite.com/UID/ACCESS_KEY/graphite'] # Set the denylist to check input graphite Url. Denylist is an IP list. # Below is an example for reference diff --git a/package.json b/package.json index 840ce88cb0b7..b9eb244f7756 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "dashboarding" ], "private": true, - "version": "2.7.0", + "version": "3.0.0", "branch": "main", "types": "./opensearch_dashboards.d.ts", "tsdocMetadata": "./build/tsdoc-metadata.json", diff --git a/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts b/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts index 8db352868779..e4fb09ea5a5c 100644 --- a/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts +++ b/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts @@ -4,7 +4,7 @@ */ import { get, isEmpty } from 'lodash'; -import { IUiSettingsClient, SavedObjectsClientContract } from 'opensearch-dashboards/public'; +import { IUiSettingsClient } from 'opensearch-dashboards/public'; import { SavedObjectLoader, SavedObjectOpenSearchDashboardsServices, @@ -20,13 +20,6 @@ export type SavedAugmentVisLoader = ReturnType, id: string) => { source.id = id; @@ -93,5 +86,5 @@ export function createSavedAugmentVisLoader( const { savedObjectsClient } = services; const SavedAugmentVis = createSavedAugmentVisClass(services); - return new SavedObjectLoaderAugmentVis(services, SavedAugmentVis, savedObjectsClient); + return new SavedObjectLoaderAugmentVis(SavedAugmentVis, savedObjectsClient); } diff --git a/src/plugins/visualizations/public/embeddable/create_vis_embeddable_from_object.ts b/src/plugins/visualizations/public/embeddable/create_vis_embeddable_from_object.ts index 8d045125d853..d908b45fc70c 100644 --- a/src/plugins/visualizations/public/embeddable/create_vis_embeddable_from_object.ts +++ b/src/plugins/visualizations/public/embeddable/create_vis_embeddable_from_object.ts @@ -40,7 +40,6 @@ import { IContainer, ErrorEmbeddable } from '../../../embeddable/public'; import { DisabledLabEmbeddable } from './disabled_lab_embeddable'; import { getSavedVisualizationsLoader, - // getSavedAugmentVisLoader, getUISettings, getHttp, getTimeFilter, diff --git a/src/plugins/visualizations/public/services.ts b/src/plugins/visualizations/public/services.ts index 92c01703ca17..51527bb50662 100644 --- a/src/plugins/visualizations/public/services.ts +++ b/src/plugins/visualizations/public/services.ts @@ -53,7 +53,6 @@ import { UiActionsStart } from '../../ui_actions/public'; import { SavedVisualizationsLoader } from './saved_visualizations'; import { SavedObjectLoader } from '../../saved_objects/public'; import { EmbeddableStart } from '../../embeddable/public'; -import { SavedAugmentVisLoader } from '../../vis_augmenter/public'; export const [getUISettings, setUISettings] = createGetterSetter('UISettings'); @@ -109,10 +108,6 @@ export const [getSavedSearchLoader, setSavedSearchLoader] = createGetterSetter('SavedAugmentVisLoader'); - export const [getNotifications, setNotifications] = createGetterSetter( 'Notifications' ); From 42bd042b627196ef5f1e6cda8c1bf6181898a603 Mon Sep 17 00:00:00 2001 From: Ashish Agrawal Date: Fri, 12 May 2023 16:55:58 -0700 Subject: [PATCH 04/11] Cleanup plus tests Signed-off-by: Ashish Agrawal --- src/plugins/vis_augmenter/public/constants.ts | 3 + .../saved_augment_vis.test.ts | 61 +++++++++++++++++++ .../saved_augment_vis/saved_augment_vis.ts | 37 ++++++++--- .../public/saved_augment_vis/utils/helpers.ts | 25 ++++---- .../vis_augmenter/public/utils/utils.test.ts | 16 +++++ .../vis_augmenter/public/utils/utils.ts | 10 +-- src/plugins/vis_augmenter/server/constants.ts | 8 +++ src/plugins/vis_augmenter/server/plugin.ts | 8 ++- 8 files changed, 141 insertions(+), 27 deletions(-) create mode 100644 src/plugins/vis_augmenter/server/constants.ts diff --git a/src/plugins/vis_augmenter/public/constants.ts b/src/plugins/vis_augmenter/public/constants.ts index 99b75a8de7ea..3611ae027b31 100644 --- a/src/plugins/vis_augmenter/public/constants.ts +++ b/src/plugins/vis_augmenter/public/constants.ts @@ -11,3 +11,6 @@ export const EVENT_MARK_SIZE = 100; export const EVENT_MARK_SIZE_ENLARGED = 140; export const EVENT_MARK_SHAPE = 'triangle-up'; export const EVENT_TIMELINE_HEIGHT = 25; +export const PLUGIN_AUGMENTATION_ENABLE_SETTING = 'visualization:enablePluginAugmentation'; +export const PLUGIN_AUGMENTATION_MAX_OBJECTS_SETTING = + 'visualization:enablePluginAugmentation.maxPluginObjects'; diff --git a/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.test.ts b/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.test.ts index 51360f72c331..04d1945358b1 100644 --- a/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.test.ts +++ b/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.test.ts @@ -9,8 +9,18 @@ import { SavedObjectOpenSearchDashboardsServicesWithAugmentVis, } from './saved_augment_vis'; import { generateAugmentVisSavedObject, getMockAugmentVisSavedObjectClient } from './utils'; +import { uiSettingsServiceMock } from '../../../../core/public/mocks'; +import { setUISettings } from '../services'; +import { PLUGIN_AUGMENTATION_ENABLE_SETTING } from '../constants'; + +const uiSettingsMock = uiSettingsServiceMock.createStartContract(); +setUISettings(uiSettingsMock); describe('SavedObjectLoaderAugmentVis', () => { + uiSettingsMock.get.mockImplementation((key: string) => { + return key === PLUGIN_AUGMENTATION_ENABLE_SETTING; + }); + const fn = { type: VisLayerTypes.PointInTimeEvents, name: 'test-fn', @@ -105,4 +115,55 @@ describe('SavedObjectLoaderAugmentVis', () => { expect(resp.hits[0].id).toEqual('valid-obj-id-1'); expect(resp.hits[0].error).toEqual('visReference is missing in augment-vis saved object'); }); + + it('find returns exception due to setting being disabled', async () => { + uiSettingsMock.get.mockImplementation((key: string) => { + return key !== PLUGIN_AUGMENTATION_ENABLE_SETTING; + }); + const loader = createSavedAugmentVisLoader(({ + // config: uiSettingsMock, + savedObjectsClient: getMockAugmentVisSavedObjectClient([]), + } as unknown) as SavedObjectOpenSearchDashboardsServicesWithAugmentVis); + try { + await loader.find(); + } catch (e) { + expect(e.message).toBe( + 'Visualization augmentation is disabled, please enable visualization:enablePluginAugmentation.' + ); + } + }); + + it('findAll returns exception due to setting being disabled', async () => { + uiSettingsMock.get.mockImplementation((key: string) => { + return key !== PLUGIN_AUGMENTATION_ENABLE_SETTING; + }); + const loader = createSavedAugmentVisLoader(({ + // config: uiSettingsMock, + savedObjectsClient: getMockAugmentVisSavedObjectClient([]), + } as unknown) as SavedObjectOpenSearchDashboardsServicesWithAugmentVis); + try { + await loader.findAll(); + } catch (e) { + expect(e.message).toBe( + 'Visualization augmentation is disabled, please enable visualization:enablePluginAugmentation.' + ); + } + }); + + it('get returns exception due to setting being disabled', async () => { + uiSettingsMock.get.mockImplementation((key: string) => { + return key !== PLUGIN_AUGMENTATION_ENABLE_SETTING; + }); + const loader = createSavedAugmentVisLoader(({ + // config: uiSettingsMock, + savedObjectsClient: getMockAugmentVisSavedObjectClient([]), + } as unknown) as SavedObjectOpenSearchDashboardsServicesWithAugmentVis); + try { + await loader.get(); + } catch (e) { + expect(e.message).toBe( + 'Visualization augmentation is disabled, please enable visualization:enablePluginAugmentation.' + ); + } + }); }); diff --git a/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts b/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts index e4fb09ea5a5c..7ba0efa17a92 100644 --- a/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts +++ b/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts @@ -12,6 +12,7 @@ import { import { createSavedAugmentVisClass } from './_saved_augment_vis'; import { VisLayerTypes } from '../types'; import { getUISettings } from '../services'; +import { PLUGIN_AUGMENTATION_ENABLE_SETTING } from '../constants'; // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface SavedObjectOpenSearchDashboardsServicesWithAugmentVis @@ -65,18 +66,36 @@ export class SavedObjectLoaderAugmentVis extends SavedObjectLoader { * @returns {Promise} */ get(opts?: Record | string) { - const isAugmentationEnabled = this.config.get('visualization:enablePluginAugmentation'); + this.isAugmentationEnabled(); + return super.get(opts); + } + + /** + * TODO: Rather than use a hardcoded limit, implement pagination. See + * https://github.com/elastic/kibana/issues/8044 for reference. + * + * @param search + * @param size + * @param fields + * @returns {Promise} + */ + findAll(search: string = '', size: number = 100, fields?: string[]) { + this.isAugmentationEnabled(); + return super.findAll(search, size, fields); + } + + find(search: string = '', size: number = 100) { + this.isAugmentationEnabled(); + return super.find(search, size); + } + private isAugmentationEnabled() { + const isAugmentationEnabled = this.config.get(PLUGIN_AUGMENTATION_ENABLE_SETTING, true); if (!isAugmentationEnabled) { - // eslint-disable-next-line no-throw-literal - throw 'Visualization augmentation is disabled, please enable visualization:enablePluginAugmentation.'; + throw new Error( + 'Visualization augmentation is disabled, please enable visualization:enablePluginAugmentation.' + ); } - - // can accept object as argument in accordance to SavedVis class - // see src/plugins/saved_objects/public/saved_object/saved_object_loader.ts - // @ts-ignore - const obj = new this.Class(opts); - return obj.init(); } } diff --git a/src/plugins/vis_augmenter/public/saved_augment_vis/utils/helpers.ts b/src/plugins/vis_augmenter/public/saved_augment_vis/utils/helpers.ts index 7c8158b3c9f6..b64a7818a68e 100644 --- a/src/plugins/vis_augmenter/public/saved_augment_vis/utils/helpers.ts +++ b/src/plugins/vis_augmenter/public/saved_augment_vis/utils/helpers.ts @@ -6,6 +6,10 @@ import { get } from 'lodash'; import { getSavedAugmentVisLoader, getUISettings } from '../../services'; import { ISavedAugmentVis } from '../types'; +import { + PLUGIN_AUGMENTATION_ENABLE_SETTING, + PLUGIN_AUGMENTATION_MAX_OBJECTS_SETTING, +} from '../../constants'; /** * Create an augment vis saved object given an object that @@ -15,12 +19,13 @@ export const createAugmentVisSavedObject = async (AugmentVis: ISavedAugmentVis): const loader = getSavedAugmentVisLoader(); const config = getUISettings(); - const isAugmentationEnabled = config.get('visualization:enablePluginAugmentation'); + const isAugmentationEnabled = config.get(PLUGIN_AUGMENTATION_ENABLE_SETTING); if (!isAugmentationEnabled) { - // eslint-disable-next-line no-throw-literal - throw 'Visualization augmentation is disabled, please enable visualization:enablePluginAugmentation.'; + throw new Error( + 'Visualization augmentation is disabled, please enable visualization:enablePluginAugmentation.' + ); } - const maxAssociatedCount = config.get('visualization:enablePluginAugmentation.maxPluginObjects'); + const maxAssociatedCount = config.get(PLUGIN_AUGMENTATION_MAX_OBJECTS_SETTING); await loader.findAll().then(async (resp) => { if (resp !== undefined) { @@ -31,14 +36,10 @@ export const createAugmentVisSavedObject = async (AugmentVis: ISavedAugmentVis): ); if (maxAssociatedCount <= savedObjectsForThisVisualization.length) { - // eslint-disable-next-line no-throw-literal - throw ( - 'Cannot associate the plugin resource to the visualization due to the limit of the' + - 'max amount of associated plugin resources (' + - maxAssociatedCount + - ') with ' + - savedObjectsForThisVisualization.length + - ' associated to the visualization' + throw new Error( + `Cannot associate the plugin resource to the visualization due to the limit of the max + amount of associated plugin resources (${maxAssociatedCount}) with + ${savedObjectsForThisVisualization.length} associated to the visualization` ); } } diff --git a/src/plugins/vis_augmenter/public/utils/utils.test.ts b/src/plugins/vis_augmenter/public/utils/utils.test.ts index c37e87194c97..c202cea87244 100644 --- a/src/plugins/vis_augmenter/public/utils/utils.test.ts +++ b/src/plugins/vis_augmenter/public/utils/utils.test.ts @@ -17,11 +17,21 @@ import { generateVisLayer, VisLayerTypes, VisLayerExpressionFn, + PLUGIN_AUGMENTATION_ENABLE_SETTING, } from '../'; import { AggConfigs, AggTypesRegistryStart, IndexPattern } from '../../../data/common'; import { mockAggTypesRegistry } from '../../../data/common/search/aggs/test_helpers'; +import { uiSettingsServiceMock } from '../../../../core/public/mocks'; +import { setUISettings } from '../services'; describe('utils', () => { + const uiSettingsMock = uiSettingsServiceMock.createStartContract(); + setUISettings(uiSettingsMock); + beforeEach(() => { + uiSettingsMock.get.mockImplementation((key: string) => { + return key === PLUGIN_AUGMENTATION_ENABLE_SETTING; + }); + }); describe('isEligibleForVisLayers', () => { const validConfigStates = [ { @@ -279,6 +289,12 @@ describe('utils', () => { } as unknown) as Vis; expect(isEligibleForVisLayers(invalidVis)).toEqual(false); }); + it('vis is ineligible with valid type and disabled setting', async () => { + uiSettingsMock.get.mockImplementation((key: string) => { + return key !== PLUGIN_AUGMENTATION_ENABLE_SETTING; + }); + expect(isEligibleForVisLayers(validVis)).toEqual(false); + }); it('vis is eligible with valid type', async () => { expect(isEligibleForVisLayers(validVis)).toEqual(true); }); diff --git a/src/plugins/vis_augmenter/public/utils/utils.ts b/src/plugins/vis_augmenter/public/utils/utils.ts index faaa3e9193f7..38cf14449f6e 100644 --- a/src/plugins/vis_augmenter/public/utils/utils.ts +++ b/src/plugins/vis_augmenter/public/utils/utils.ts @@ -17,6 +17,7 @@ import { VisLayerFunctionDefinition, VisLayer, isVisLayerWithError, + PLUGIN_AUGMENTATION_ENABLE_SETTING, } from '../'; import { getUISettings } from '../services'; @@ -41,7 +42,7 @@ export const isEligibleForVisLayers = (vis: Vis): boolean => { vis.params.type === 'line'; // Checks if the augmentation setting is enabled const config = getUISettings(); - const isAugmentationEnabled = config.get('visualization:enablePluginAugmentation'); + const isAugmentationEnabled = config.get(PLUGIN_AUGMENTATION_ENABLE_SETTING); return isAugmentationEnabled && hasValidXaxis && hasCorrectAggregationCount && hasOnlyLineSeries; }; @@ -58,10 +59,11 @@ export const getAugmentVisSavedObjs = async ( return [] as ISavedAugmentVis[]; } const config = getUISettings(); - const isAugmentationEnabled = config.get('visualization:enablePluginAugmentation'); + const isAugmentationEnabled = config.get(PLUGIN_AUGMENTATION_ENABLE_SETTING); if (!isAugmentationEnabled) { - // eslint-disable-next-line no-throw-literal - throw 'Visualization augmentation is disabled, please enable visualization:enablePluginAugmentation.'; + throw new Error( + 'Visualization augmentation is disabled, please enable visualization:enablePluginAugmentation.' + ); } try { const resp = await loader?.findAll(); diff --git a/src/plugins/vis_augmenter/server/constants.ts b/src/plugins/vis_augmenter/server/constants.ts new file mode 100644 index 000000000000..fedf06ee1d5e --- /dev/null +++ b/src/plugins/vis_augmenter/server/constants.ts @@ -0,0 +1,8 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +export const PLUGIN_AUGMENTATION_ENABLE_SETTING = 'visualization:enablePluginAugmentation'; +export const PLUGIN_AUGMENTATION_MAX_OBJECTS_SETTING = + 'visualization:enablePluginAugmentation.maxPluginObjects'; diff --git a/src/plugins/vis_augmenter/server/plugin.ts b/src/plugins/vis_augmenter/server/plugin.ts index a0932abf5d23..d2e856739a58 100644 --- a/src/plugins/vis_augmenter/server/plugin.ts +++ b/src/plugins/vis_augmenter/server/plugin.ts @@ -17,6 +17,10 @@ import { import { augmentVisSavedObjectType } from './saved_objects'; import { capabilitiesProvider } from './capabilities_provider'; import { VisAugmenterPluginConfigType } from '../config'; +import { + PLUGIN_AUGMENTATION_ENABLE_SETTING, + PLUGIN_AUGMENTATION_MAX_OBJECTS_SETTING, +} from './constants'; // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface VisAugmenterPluginSetup {} @@ -44,7 +48,7 @@ export class VisAugmenterPlugin if (isAugmentationEnabled) { core.uiSettings.register({ - ['visualization:enablePluginAugmentation']: { + [PLUGIN_AUGMENTATION_ENABLE_SETTING]: { name: i18n.translate('visualization.enablePluginAugmentationTitle', { defaultMessage: 'Enable plugin augmentation', }), @@ -55,7 +59,7 @@ export class VisAugmenterPlugin category: ['visualization'], schema: schema.boolean(), }, - ['visualization:enablePluginAugmentation.maxPluginObjects']: { + [PLUGIN_AUGMENTATION_MAX_OBJECTS_SETTING]: { name: i18n.translate('visualization.enablePluginAugmentation.maxPluginObjectsTitle', { defaultMessage: 'Max number of associated augmentations', }), From fdaf81944ef292ab0d71848d807ba317efe72853 Mon Sep 17 00:00:00 2001 From: Ashish Agrawal Date: Fri, 12 May 2023 17:08:41 -0700 Subject: [PATCH 05/11] code cleanup and address comments Signed-off-by: Ashish Agrawal --- .../saved_augment_vis.test.ts | 3 - .../saved_augment_vis/saved_augment_vis.ts | 148 +++++++++--------- .../vis_augmenter/public/utils/utils.ts | 3 - src/plugins/vis_augmenter/server/plugin.ts | 3 + 4 files changed, 77 insertions(+), 80 deletions(-) diff --git a/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.test.ts b/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.test.ts index 04d1945358b1..29e68fc87644 100644 --- a/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.test.ts +++ b/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.test.ts @@ -121,7 +121,6 @@ describe('SavedObjectLoaderAugmentVis', () => { return key !== PLUGIN_AUGMENTATION_ENABLE_SETTING; }); const loader = createSavedAugmentVisLoader(({ - // config: uiSettingsMock, savedObjectsClient: getMockAugmentVisSavedObjectClient([]), } as unknown) as SavedObjectOpenSearchDashboardsServicesWithAugmentVis); try { @@ -138,7 +137,6 @@ describe('SavedObjectLoaderAugmentVis', () => { return key !== PLUGIN_AUGMENTATION_ENABLE_SETTING; }); const loader = createSavedAugmentVisLoader(({ - // config: uiSettingsMock, savedObjectsClient: getMockAugmentVisSavedObjectClient([]), } as unknown) as SavedObjectOpenSearchDashboardsServicesWithAugmentVis); try { @@ -155,7 +153,6 @@ describe('SavedObjectLoaderAugmentVis', () => { return key !== PLUGIN_AUGMENTATION_ENABLE_SETTING; }); const loader = createSavedAugmentVisLoader(({ - // config: uiSettingsMock, savedObjectsClient: getMockAugmentVisSavedObjectClient([]), } as unknown) as SavedObjectOpenSearchDashboardsServicesWithAugmentVis); try { diff --git a/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts b/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts index 7ba0efa17a92..5e46dab32dfa 100644 --- a/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts +++ b/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts @@ -19,90 +19,90 @@ export interface SavedObjectOpenSearchDashboardsServicesWithAugmentVis extends SavedObjectOpenSearchDashboardsServices {} export type SavedAugmentVisLoader = ReturnType; -export class SavedObjectLoaderAugmentVis extends SavedObjectLoader { - private readonly config: IUiSettingsClient = getUISettings(); +export function createSavedAugmentVisLoader( + services: SavedObjectOpenSearchDashboardsServicesWithAugmentVis +) { + const { savedObjectsClient } = services; - mapHitSource = (source: Record, id: string) => { - source.id = id; - source.visId = get(source, 'visReference.id', ''); + class SavedObjectLoaderAugmentVis extends SavedObjectLoader { + private readonly config: IUiSettingsClient = getUISettings(); - if (isEmpty(source.visReference)) { - source.error = 'visReference is missing in augment-vis saved object'; - return source; - } - if (isEmpty(source.visLayerExpressionFn)) { - source.error = 'visLayerExpressionFn is missing in augment-vis saved object'; - return source; - } - if (!(get(source, 'visLayerExpressionFn.type', '') in VisLayerTypes)) { - source.error = 'Unknown VisLayer expression function type'; + mapHitSource = (source: Record, id: string) => { + source.id = id; + source.visId = get(source, 'visReference.id', ''); + + if (isEmpty(source.visReference)) { + source.error = 'visReference is missing in augment-vis saved object'; + return source; + } + if (isEmpty(source.visLayerExpressionFn)) { + source.error = 'visLayerExpressionFn is missing in augment-vis saved object'; + return source; + } + if (!(get(source, 'visLayerExpressionFn.type', '') in VisLayerTypes)) { + source.error = 'Unknown VisLayer expression function type'; + return source; + } return source; - } - return source; - }; + }; - /** - * Updates hit.attributes to contain an id related to the referenced visualization - * (visId) and returns the updated attributes object. - * @param hit - * @returns {hit.attributes} The modified hit.attributes object, with an id and url field. - */ - mapSavedObjectApiHits(hit: { - references: any[]; - attributes: Record; - id: string; - }) { - // For now we are assuming only one vis reference per saved object. - // If we change to multiple, we will need to dynamically handle that - const visReference = hit.references[0]; - return this.mapHitSource({ ...hit.attributes, visReference }, hit.id); - } + /** + * Updates hit.attributes to contain an id related to the referenced visualization + * (visId) and returns the updated attributes object. + * @param hit + * @returns {hit.attributes} The modified hit.attributes object, with an id and url field. + */ + mapSavedObjectApiHits(hit: { + references: any[]; + attributes: Record; + id: string; + }) { + // For now we are assuming only one vis reference per saved object. + // If we change to multiple, we will need to dynamically handle that + const visReference = hit.references[0]; + return this.mapHitSource({ ...hit.attributes, visReference }, hit.id); + } - /** - * Retrieve a saved object by id or create new one. - * Returns a promise that completes when the object finishes - * initializing. Throws exception when the setting is set to false. - * @param opts - * @returns {Promise} - */ - get(opts?: Record | string) { - this.isAugmentationEnabled(); - return super.get(opts); - } + /** + * Retrieve a saved object by id or create new one. + * Returns a promise that completes when the object finishes + * initializing. Throws exception when the setting is set to false. + * @param opts + * @returns {Promise} + */ + get(opts?: Record | string) { + this.isAugmentationEnabled(); + return super.get(opts); + } - /** - * TODO: Rather than use a hardcoded limit, implement pagination. See - * https://github.com/elastic/kibana/issues/8044 for reference. - * - * @param search - * @param size - * @param fields - * @returns {Promise} - */ - findAll(search: string = '', size: number = 100, fields?: string[]) { - this.isAugmentationEnabled(); - return super.findAll(search, size, fields); - } + /** + * TODO: Rather than use a hardcoded limit, implement pagination. See + * https://github.com/elastic/kibana/issues/8044 for reference. + * + * @param search + * @param size + * @param fields + * @returns {Promise} + */ + findAll(search: string = '', size: number = 100, fields?: string[]) { + this.isAugmentationEnabled(); + return super.findAll(search, size, fields); + } - find(search: string = '', size: number = 100) { - this.isAugmentationEnabled(); - return super.find(search, size); - } + find(search: string = '', size: number = 100) { + this.isAugmentationEnabled(); + return super.find(search, size); + } - private isAugmentationEnabled() { - const isAugmentationEnabled = this.config.get(PLUGIN_AUGMENTATION_ENABLE_SETTING, true); - if (!isAugmentationEnabled) { - throw new Error( - 'Visualization augmentation is disabled, please enable visualization:enablePluginAugmentation.' - ); + private isAugmentationEnabled() { + const isAugmentationEnabled = this.config.get(PLUGIN_AUGMENTATION_ENABLE_SETTING, true); + if (!isAugmentationEnabled) { + throw new Error( + 'Visualization augmentation is disabled, please enable visualization:enablePluginAugmentation.' + ); + } } } -} - -export function createSavedAugmentVisLoader( - services: SavedObjectOpenSearchDashboardsServicesWithAugmentVis -) { - const { savedObjectsClient } = services; const SavedAugmentVis = createSavedAugmentVisClass(services); return new SavedObjectLoaderAugmentVis(SavedAugmentVis, savedObjectsClient); diff --git a/src/plugins/vis_augmenter/public/utils/utils.ts b/src/plugins/vis_augmenter/public/utils/utils.ts index 38cf14449f6e..40a85305bbe8 100644 --- a/src/plugins/vis_augmenter/public/utils/utils.ts +++ b/src/plugins/vis_augmenter/public/utils/utils.ts @@ -55,9 +55,6 @@ export const getAugmentVisSavedObjs = async ( visId: string | undefined, loader: SavedAugmentVisLoader | undefined ): Promise => { - if (visId === undefined || loader === undefined) { - return [] as ISavedAugmentVis[]; - } const config = getUISettings(); const isAugmentationEnabled = config.get(PLUGIN_AUGMENTATION_ENABLE_SETTING); if (!isAugmentationEnabled) { diff --git a/src/plugins/vis_augmenter/server/plugin.ts b/src/plugins/vis_augmenter/server/plugin.ts index d2e856739a58..46fa539eb485 100644 --- a/src/plugins/vis_augmenter/server/plugin.ts +++ b/src/plugins/vis_augmenter/server/plugin.ts @@ -46,6 +46,9 @@ export class VisAugmenterPlugin const isAugmentationEnabled = config.pluginAugmentationEnabled === undefined ? true : config.pluginAugmentationEnabled; + // Checks if the global yaml setting for enabling plugin augmentation is disabled. + // If it is disabled, remove the settings as we would not want to show these to the + // user due to it being disabled at the cluster level. if (isAugmentationEnabled) { core.uiSettings.register({ [PLUGIN_AUGMENTATION_ENABLE_SETTING]: { From 66f7f1f7e0761dc1e3c3f21dbbde26ec2fff5f2e Mon Sep 17 00:00:00 2001 From: Ashish Agrawal Date: Wed, 17 May 2023 08:55:41 -0700 Subject: [PATCH 06/11] fix comments Signed-off-by: Ashish Agrawal --- src/plugins/vis_augmenter/{server => common}/constants.ts | 0 src/plugins/vis_augmenter/public/constants.ts | 3 --- src/plugins/vis_augmenter/public/index.ts | 1 + .../public/saved_augment_vis/saved_augment_vis.test.ts | 2 +- .../public/saved_augment_vis/saved_augment_vis.ts | 2 +- .../vis_augmenter/public/saved_augment_vis/utils/helpers.ts | 2 +- src/plugins/vis_augmenter/public/utils/utils.test.ts | 2 +- src/plugins/vis_augmenter/public/utils/utils.ts | 2 +- src/plugins/vis_augmenter/server/plugin.ts | 2 +- .../public/embeddable/create_vis_embeddable_from_object.ts | 2 +- src/plugins/visualizations/public/services.ts | 3 +++ 11 files changed, 11 insertions(+), 10 deletions(-) rename src/plugins/vis_augmenter/{server => common}/constants.ts (100%) diff --git a/src/plugins/vis_augmenter/server/constants.ts b/src/plugins/vis_augmenter/common/constants.ts similarity index 100% rename from src/plugins/vis_augmenter/server/constants.ts rename to src/plugins/vis_augmenter/common/constants.ts diff --git a/src/plugins/vis_augmenter/public/constants.ts b/src/plugins/vis_augmenter/public/constants.ts index 3611ae027b31..99b75a8de7ea 100644 --- a/src/plugins/vis_augmenter/public/constants.ts +++ b/src/plugins/vis_augmenter/public/constants.ts @@ -11,6 +11,3 @@ export const EVENT_MARK_SIZE = 100; export const EVENT_MARK_SIZE_ENLARGED = 140; export const EVENT_MARK_SHAPE = 'triangle-up'; export const EVENT_TIMELINE_HEIGHT = 25; -export const PLUGIN_AUGMENTATION_ENABLE_SETTING = 'visualization:enablePluginAugmentation'; -export const PLUGIN_AUGMENTATION_MAX_OBJECTS_SETTING = - 'visualization:enablePluginAugmentation.maxPluginObjects'; diff --git a/src/plugins/vis_augmenter/public/index.ts b/src/plugins/vis_augmenter/public/index.ts index 78657ba6c224..7f85dd47072b 100644 --- a/src/plugins/vis_augmenter/public/index.ts +++ b/src/plugins/vis_augmenter/public/index.ts @@ -30,3 +30,4 @@ export * from './constants'; export * from './vega'; export * from './saved_augment_vis'; export * from './test_constants'; +export { getSavedAugmentVisLoader } from './services'; diff --git a/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.test.ts b/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.test.ts index 29e68fc87644..c191b0a095b4 100644 --- a/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.test.ts +++ b/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.test.ts @@ -11,7 +11,7 @@ import { import { generateAugmentVisSavedObject, getMockAugmentVisSavedObjectClient } from './utils'; import { uiSettingsServiceMock } from '../../../../core/public/mocks'; import { setUISettings } from '../services'; -import { PLUGIN_AUGMENTATION_ENABLE_SETTING } from '../constants'; +import { PLUGIN_AUGMENTATION_ENABLE_SETTING } from '../../common/constants'; const uiSettingsMock = uiSettingsServiceMock.createStartContract(); setUISettings(uiSettingsMock); diff --git a/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts b/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts index 5e46dab32dfa..19bd50d4e538 100644 --- a/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts +++ b/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts @@ -12,7 +12,7 @@ import { import { createSavedAugmentVisClass } from './_saved_augment_vis'; import { VisLayerTypes } from '../types'; import { getUISettings } from '../services'; -import { PLUGIN_AUGMENTATION_ENABLE_SETTING } from '../constants'; +import { PLUGIN_AUGMENTATION_ENABLE_SETTING } from '../../common/constants'; // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface SavedObjectOpenSearchDashboardsServicesWithAugmentVis diff --git a/src/plugins/vis_augmenter/public/saved_augment_vis/utils/helpers.ts b/src/plugins/vis_augmenter/public/saved_augment_vis/utils/helpers.ts index b64a7818a68e..ff23a229b154 100644 --- a/src/plugins/vis_augmenter/public/saved_augment_vis/utils/helpers.ts +++ b/src/plugins/vis_augmenter/public/saved_augment_vis/utils/helpers.ts @@ -9,7 +9,7 @@ import { ISavedAugmentVis } from '../types'; import { PLUGIN_AUGMENTATION_ENABLE_SETTING, PLUGIN_AUGMENTATION_MAX_OBJECTS_SETTING, -} from '../../constants'; +} from '../../../common/constants'; /** * Create an augment vis saved object given an object that diff --git a/src/plugins/vis_augmenter/public/utils/utils.test.ts b/src/plugins/vis_augmenter/public/utils/utils.test.ts index c202cea87244..f208db763a61 100644 --- a/src/plugins/vis_augmenter/public/utils/utils.test.ts +++ b/src/plugins/vis_augmenter/public/utils/utils.test.ts @@ -17,8 +17,8 @@ import { generateVisLayer, VisLayerTypes, VisLayerExpressionFn, - PLUGIN_AUGMENTATION_ENABLE_SETTING, } from '../'; +import { PLUGIN_AUGMENTATION_ENABLE_SETTING } from '../../common/constants'; import { AggConfigs, AggTypesRegistryStart, IndexPattern } from '../../../data/common'; import { mockAggTypesRegistry } from '../../../data/common/search/aggs/test_helpers'; import { uiSettingsServiceMock } from '../../../../core/public/mocks'; diff --git a/src/plugins/vis_augmenter/public/utils/utils.ts b/src/plugins/vis_augmenter/public/utils/utils.ts index 40a85305bbe8..ead35fa4b33a 100644 --- a/src/plugins/vis_augmenter/public/utils/utils.ts +++ b/src/plugins/vis_augmenter/public/utils/utils.ts @@ -17,8 +17,8 @@ import { VisLayerFunctionDefinition, VisLayer, isVisLayerWithError, - PLUGIN_AUGMENTATION_ENABLE_SETTING, } from '../'; +import { PLUGIN_AUGMENTATION_ENABLE_SETTING } from '../../common/constants'; import { getUISettings } from '../services'; export const isEligibleForVisLayers = (vis: Vis): boolean => { diff --git a/src/plugins/vis_augmenter/server/plugin.ts b/src/plugins/vis_augmenter/server/plugin.ts index 46fa539eb485..22f7fdec707a 100644 --- a/src/plugins/vis_augmenter/server/plugin.ts +++ b/src/plugins/vis_augmenter/server/plugin.ts @@ -20,7 +20,7 @@ import { VisAugmenterPluginConfigType } from '../config'; import { PLUGIN_AUGMENTATION_ENABLE_SETTING, PLUGIN_AUGMENTATION_MAX_OBJECTS_SETTING, -} from './constants'; +} from '../common/constants'; // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface VisAugmenterPluginSetup {} diff --git a/src/plugins/visualizations/public/embeddable/create_vis_embeddable_from_object.ts b/src/plugins/visualizations/public/embeddable/create_vis_embeddable_from_object.ts index d908b45fc70c..ec95f7fb6f18 100644 --- a/src/plugins/visualizations/public/embeddable/create_vis_embeddable_from_object.ts +++ b/src/plugins/visualizations/public/embeddable/create_vis_embeddable_from_object.ts @@ -45,7 +45,7 @@ import { getTimeFilter, getCapabilities, } from '../services'; -import { getSavedAugmentVisLoader } from '../../../vis_augmenter/public'; +import { getSavedAugmentVisLoader } from '../services'; import { VisualizeEmbeddableFactoryDeps } from './visualize_embeddable_factory'; import { VISUALIZE_ENABLE_LABS_SETTING } from '../../common/constants'; import { SavedVisualizationsLoader } from '../saved_visualizations'; diff --git a/src/plugins/visualizations/public/services.ts b/src/plugins/visualizations/public/services.ts index 51527bb50662..27acaa52975c 100644 --- a/src/plugins/visualizations/public/services.ts +++ b/src/plugins/visualizations/public/services.ts @@ -53,6 +53,7 @@ import { UiActionsStart } from '../../ui_actions/public'; import { SavedVisualizationsLoader } from './saved_visualizations'; import { SavedObjectLoader } from '../../saved_objects/public'; import { EmbeddableStart } from '../../embeddable/public'; +import { getSavedAugmentVisLoader as getVisLoaderAugmenter } from '../../vis_augmenter/public'; export const [getUISettings, setUISettings] = createGetterSetter('UISettings'); @@ -111,3 +112,5 @@ export const [getSavedSearchLoader, setSavedSearchLoader] = createGetterSetter( 'Notifications' ); + +export const getSavedAugmentVisLoader = getVisLoaderAugmenter; From 67276c8477cb55feaf36bf3d7174905a99887b18 Mon Sep 17 00:00:00 2001 From: Ashish Agrawal Date: Wed, 17 May 2023 09:47:38 -0700 Subject: [PATCH 07/11] address comments Signed-off-by: Ashish Agrawal --- .../saved_augment_vis/saved_augment_vis.ts | 148 +++++++++--------- src/plugins/visualizations/public/plugin.ts | 6 +- src/plugins/visualizations/public/services.ts | 6 +- 3 files changed, 82 insertions(+), 78 deletions(-) diff --git a/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts b/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts index 19bd50d4e538..b19fcc149094 100644 --- a/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts +++ b/src/plugins/vis_augmenter/public/saved_augment_vis/saved_augment_vis.ts @@ -19,90 +19,90 @@ export interface SavedObjectOpenSearchDashboardsServicesWithAugmentVis extends SavedObjectOpenSearchDashboardsServices {} export type SavedAugmentVisLoader = ReturnType; -export function createSavedAugmentVisLoader( - services: SavedObjectOpenSearchDashboardsServicesWithAugmentVis -) { - const { savedObjectsClient } = services; - - class SavedObjectLoaderAugmentVis extends SavedObjectLoader { - private readonly config: IUiSettingsClient = getUISettings(); +export class SavedObjectLoaderAugmentVis extends SavedObjectLoader { + private readonly config: IUiSettingsClient = getUISettings(); - mapHitSource = (source: Record, id: string) => { - source.id = id; - source.visId = get(source, 'visReference.id', ''); + mapHitSource = (source: Record, id: string) => { + source.id = id; + source.visId = get(source, 'visReference.id', ''); - if (isEmpty(source.visReference)) { - source.error = 'visReference is missing in augment-vis saved object'; - return source; - } - if (isEmpty(source.visLayerExpressionFn)) { - source.error = 'visLayerExpressionFn is missing in augment-vis saved object'; - return source; - } - if (!(get(source, 'visLayerExpressionFn.type', '') in VisLayerTypes)) { - source.error = 'Unknown VisLayer expression function type'; - return source; - } + if (isEmpty(source.visReference)) { + source.error = 'visReference is missing in augment-vis saved object'; return source; - }; - - /** - * Updates hit.attributes to contain an id related to the referenced visualization - * (visId) and returns the updated attributes object. - * @param hit - * @returns {hit.attributes} The modified hit.attributes object, with an id and url field. - */ - mapSavedObjectApiHits(hit: { - references: any[]; - attributes: Record; - id: string; - }) { - // For now we are assuming only one vis reference per saved object. - // If we change to multiple, we will need to dynamically handle that - const visReference = hit.references[0]; - return this.mapHitSource({ ...hit.attributes, visReference }, hit.id); } - - /** - * Retrieve a saved object by id or create new one. - * Returns a promise that completes when the object finishes - * initializing. Throws exception when the setting is set to false. - * @param opts - * @returns {Promise} - */ - get(opts?: Record | string) { - this.isAugmentationEnabled(); - return super.get(opts); + if (isEmpty(source.visLayerExpressionFn)) { + source.error = 'visLayerExpressionFn is missing in augment-vis saved object'; + return source; } - - /** - * TODO: Rather than use a hardcoded limit, implement pagination. See - * https://github.com/elastic/kibana/issues/8044 for reference. - * - * @param search - * @param size - * @param fields - * @returns {Promise} - */ - findAll(search: string = '', size: number = 100, fields?: string[]) { - this.isAugmentationEnabled(); - return super.findAll(search, size, fields); + if (!(get(source, 'visLayerExpressionFn.type', '') in VisLayerTypes)) { + source.error = 'Unknown VisLayer expression function type'; + return source; } + return source; + }; - find(search: string = '', size: number = 100) { - this.isAugmentationEnabled(); - return super.find(search, size); - } + /** + * Updates hit.attributes to contain an id related to the referenced visualization + * (visId) and returns the updated attributes object. + * @param hit + * @returns {hit.attributes} The modified hit.attributes object, with an id and url field. + */ + mapSavedObjectApiHits(hit: { + references: any[]; + attributes: Record; + id: string; + }) { + // For now we are assuming only one vis reference per saved object. + // If we change to multiple, we will need to dynamically handle that + const visReference = hit.references[0]; + return this.mapHitSource({ ...hit.attributes, visReference }, hit.id); + } - private isAugmentationEnabled() { - const isAugmentationEnabled = this.config.get(PLUGIN_AUGMENTATION_ENABLE_SETTING, true); - if (!isAugmentationEnabled) { - throw new Error( - 'Visualization augmentation is disabled, please enable visualization:enablePluginAugmentation.' - ); - } + /** + * Retrieve a saved object by id or create new one. + * Returns a promise that completes when the object finishes + * initializing. Throws exception when the setting is set to false. + * @param opts + * @returns {Promise} + */ + get(opts?: Record | string) { + this.isAugmentationEnabled(); + return super.get(opts); + } + + /** + * TODO: Rather than use a hardcoded limit, implement pagination. See + * https://github.com/elastic/kibana/issues/8044 for reference. + * + * @param search + * @param size + * @param fields + * @returns {Promise} + */ + findAll(search: string = '', size: number = 100, fields?: string[]) { + this.isAugmentationEnabled(); + return super.findAll(search, size, fields); + } + + find(search: string = '', size: number = 100) { + this.isAugmentationEnabled(); + return super.find(search, size); + } + + private isAugmentationEnabled() { + const isAugmentationEnabled = this.config.get(PLUGIN_AUGMENTATION_ENABLE_SETTING, true); + if (!isAugmentationEnabled) { + throw new Error( + 'Visualization augmentation is disabled, please enable visualization:enablePluginAugmentation.' + ); } } +} + +export function createSavedAugmentVisLoader( + services: SavedObjectOpenSearchDashboardsServicesWithAugmentVis +) { + const { savedObjectsClient } = services; const SavedAugmentVis = createSavedAugmentVisClass(services); return new SavedObjectLoaderAugmentVis(SavedAugmentVis, savedObjectsClient); diff --git a/src/plugins/visualizations/public/plugin.ts b/src/plugins/visualizations/public/plugin.ts index 07b40066018c..1d9a56aa0505 100644 --- a/src/plugins/visualizations/public/plugin.ts +++ b/src/plugins/visualizations/public/plugin.ts @@ -95,7 +95,7 @@ import { } from './saved_visualizations/_saved_vis'; import { createSavedSearchesLoader } from '../../discover/public'; import { DashboardStart } from '../../dashboard/public'; -import { createSavedAugmentVisLoader } from '../../vis_augmenter/public'; +import { createSavedAugmentVisLoader, VisAugmenterStart } from '../../vis_augmenter/public'; /** * Interface for this plugin's returned setup/start contracts. @@ -133,6 +133,7 @@ export interface VisualizationsStartDeps { getAttributeService: DashboardStart['getAttributeService']; savedObjectsClient: SavedObjectsClientContract; notifications: NotificationsStart; + visAugmenter: VisAugmenterStart; } /** @@ -179,7 +180,7 @@ export class VisualizationsPlugin public start( core: CoreStart, - { data, expressions, uiActions, embeddable, dashboard }: VisualizationsStartDeps + { data, expressions, uiActions, embeddable, dashboard, visAugmenter }: VisualizationsStartDeps ): VisualizationsStart { const types = this.types.start(); setI18n(core.i18n); @@ -198,6 +199,7 @@ export class VisualizationsPlugin setAggs(data.search.aggs); setOverlays(core.overlays); setChrome(core.chrome); + setSavedAugmentVisLoader(visAugmenter.savedAugmentVisLoader); const savedVisualizationsLoader = createSavedVisLoader({ savedObjectsClient: core.savedObjects.client, indexPatterns: data.indexPatterns, diff --git a/src/plugins/visualizations/public/services.ts b/src/plugins/visualizations/public/services.ts index 27acaa52975c..a99a7010af28 100644 --- a/src/plugins/visualizations/public/services.ts +++ b/src/plugins/visualizations/public/services.ts @@ -53,7 +53,7 @@ import { UiActionsStart } from '../../ui_actions/public'; import { SavedVisualizationsLoader } from './saved_visualizations'; import { SavedObjectLoader } from '../../saved_objects/public'; import { EmbeddableStart } from '../../embeddable/public'; -import { getSavedAugmentVisLoader as getVisLoaderAugmenter } from '../../vis_augmenter/public'; +import { SavedObjectLoaderAugmentVis } from '../../vis_augmenter/public'; export const [getUISettings, setUISettings] = createGetterSetter('UISettings'); @@ -113,4 +113,6 @@ export const [getNotifications, setNotifications] = createGetterSetter('savedAugmentVisLoader'); From 6c5cb9e760ec259b5f4d6419fe4fe7dcffd3b16f Mon Sep 17 00:00:00 2001 From: Ashish Agrawal Date: Wed, 17 May 2023 10:00:31 -0700 Subject: [PATCH 08/11] nitpick fix Signed-off-by: Ashish Agrawal --- src/plugins/vis_augmenter/public/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/vis_augmenter/public/index.ts b/src/plugins/vis_augmenter/public/index.ts index 7f85dd47072b..78657ba6c224 100644 --- a/src/plugins/vis_augmenter/public/index.ts +++ b/src/plugins/vis_augmenter/public/index.ts @@ -30,4 +30,3 @@ export * from './constants'; export * from './vega'; export * from './saved_augment_vis'; export * from './test_constants'; -export { getSavedAugmentVisLoader } from './services'; From 7f553f30f7c9f644da9e663d6a7274769ddb65cf Mon Sep 17 00:00:00 2001 From: Ashish Agrawal Date: Thu, 18 May 2023 10:50:38 -0700 Subject: [PATCH 09/11] Fix the setting Signed-off-by: Ashish Agrawal --- src/plugins/visualizations/public/plugin.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/plugins/visualizations/public/plugin.ts b/src/plugins/visualizations/public/plugin.ts index 1d9a56aa0505..d66adbd79b5f 100644 --- a/src/plugins/visualizations/public/plugin.ts +++ b/src/plugins/visualizations/public/plugin.ts @@ -216,14 +216,6 @@ export class VisualizationsPlugin chrome: core.chrome, overlays: core.overlays, }); - const savedAugmentVisLoader = createSavedAugmentVisLoader({ - savedObjectsClient: core.savedObjects.client, - indexPatterns: data.indexPatterns, - search: data.search, - chrome: core.chrome, - overlays: core.overlays, - }); - setSavedAugmentVisLoader(savedAugmentVisLoader); setSavedSearchLoader(savedSearchLoader); setNotifications(core.notifications); return { From d60caa268a8971f31c5fb6e15212aaa93ca2576a Mon Sep 17 00:00:00 2001 From: Ashish Agrawal Date: Thu, 18 May 2023 16:11:02 -0700 Subject: [PATCH 10/11] fix dependency issue Signed-off-by: Ashish Agrawal --- src/plugins/visualizations/public/plugin.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/plugins/visualizations/public/plugin.ts b/src/plugins/visualizations/public/plugin.ts index d66adbd79b5f..07b40066018c 100644 --- a/src/plugins/visualizations/public/plugin.ts +++ b/src/plugins/visualizations/public/plugin.ts @@ -95,7 +95,7 @@ import { } from './saved_visualizations/_saved_vis'; import { createSavedSearchesLoader } from '../../discover/public'; import { DashboardStart } from '../../dashboard/public'; -import { createSavedAugmentVisLoader, VisAugmenterStart } from '../../vis_augmenter/public'; +import { createSavedAugmentVisLoader } from '../../vis_augmenter/public'; /** * Interface for this plugin's returned setup/start contracts. @@ -133,7 +133,6 @@ export interface VisualizationsStartDeps { getAttributeService: DashboardStart['getAttributeService']; savedObjectsClient: SavedObjectsClientContract; notifications: NotificationsStart; - visAugmenter: VisAugmenterStart; } /** @@ -180,7 +179,7 @@ export class VisualizationsPlugin public start( core: CoreStart, - { data, expressions, uiActions, embeddable, dashboard, visAugmenter }: VisualizationsStartDeps + { data, expressions, uiActions, embeddable, dashboard }: VisualizationsStartDeps ): VisualizationsStart { const types = this.types.start(); setI18n(core.i18n); @@ -199,7 +198,6 @@ export class VisualizationsPlugin setAggs(data.search.aggs); setOverlays(core.overlays); setChrome(core.chrome); - setSavedAugmentVisLoader(visAugmenter.savedAugmentVisLoader); const savedVisualizationsLoader = createSavedVisLoader({ savedObjectsClient: core.savedObjects.client, indexPatterns: data.indexPatterns, @@ -216,6 +214,14 @@ export class VisualizationsPlugin chrome: core.chrome, overlays: core.overlays, }); + const savedAugmentVisLoader = createSavedAugmentVisLoader({ + savedObjectsClient: core.savedObjects.client, + indexPatterns: data.indexPatterns, + search: data.search, + chrome: core.chrome, + overlays: core.overlays, + }); + setSavedAugmentVisLoader(savedAugmentVisLoader); setSavedSearchLoader(savedSearchLoader); setNotifications(core.notifications); return { From bb5dc5b71562a07948896e42721e4098f52dcfa5 Mon Sep 17 00:00:00 2001 From: Ashish Agrawal Date: Thu, 18 May 2023 16:24:54 -0700 Subject: [PATCH 11/11] fix comments Signed-off-by: Ashish Agrawal --- .../public/embeddable/create_vis_embeddable_from_object.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/visualizations/public/embeddable/create_vis_embeddable_from_object.ts b/src/plugins/visualizations/public/embeddable/create_vis_embeddable_from_object.ts index ec95f7fb6f18..2c937847ee61 100644 --- a/src/plugins/visualizations/public/embeddable/create_vis_embeddable_from_object.ts +++ b/src/plugins/visualizations/public/embeddable/create_vis_embeddable_from_object.ts @@ -44,8 +44,8 @@ import { getHttp, getTimeFilter, getCapabilities, + getSavedAugmentVisLoader, } from '../services'; -import { getSavedAugmentVisLoader } from '../services'; import { VisualizeEmbeddableFactoryDeps } from './visualize_embeddable_factory'; import { VISUALIZE_ENABLE_LABS_SETTING } from '../../common/constants'; import { SavedVisualizationsLoader } from '../saved_visualizations'; @@ -89,7 +89,7 @@ export const createVisEmbeddableFromObject = (deps: VisualizeEmbeddableFactoryDe const editable = getCapabilities().visualize.save as boolean; - const savedAugmentVisLoader = await getSavedAugmentVisLoader(); + const savedAugmentVisLoader = getSavedAugmentVisLoader(); return new VisualizeEmbeddable( getTimeFilter(),