Skip to content

Commit

Permalink
Add VisLayer error toasts when rendering vis
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
  • Loading branch information
ohltyler committed Mar 22, 2023
1 parent 79b9f50 commit 242510f
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/plugins/vis_augmenter/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ export {
SavedObjectOpenSearchDashboardsServicesWithAugmentVis,
} from './saved_augment_vis';

export { VisLayer, VisLayers, VisLayerTypes, VisLayerErrorTypes, VisLayerError } from './types';

export {
VisLayer,
VisLayers,
VisLayerTypes,
isVisLayerWithError,
VisLayerErrorTypes,
VisLayerError,
} from './types';
export * from './expressions';
export * from './utils';
export * from './saved_augment_vis';
6 changes: 6 additions & 0 deletions src/plugins/vis_augmenter/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,9 @@ export const isPointInTimeEventsVisLayer = (obj: any) => {
export const isValidVisLayer = (obj: any) => {
return obj?.type in VisLayerTypes;
};

export const isVisLayerWithError = (visLayer: VisLayer): boolean => {
// TODO: uncomment when rebased with initial error PR
// return visLayer.error !== undefined
return false;
};
13 changes: 12 additions & 1 deletion src/plugins/vis_augmenter/public/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import {
buildExpression,
ExpressionAstFunctionBuilder,
} from '../../../../plugins/expressions/public';
import { ISavedAugmentVis, SavedAugmentVisLoader, VisLayerFunctionDefinition } from '../';
import {
ISavedAugmentVis,
SavedAugmentVisLoader,
VisLayerFunctionDefinition,
VisLayer,
isVisLayerWithError,
} from '../';

// TODO: provide a deeper eligibility check.
// Tracked in https://github.com/opensearch-project/OpenSearch-Dashboards/issues/3268
Expand Down Expand Up @@ -58,3 +64,8 @@ export const buildPipelineFromAugmentVisSavedObjs = (objs: ISavedAugmentVis[]):
throw new Error('Expression function from augment-vis saved objects could not be generated');
}
};

export const getVisLayerErrors = (visLayers: VisLayer[]): Error => {
const visLayersWithErrors = visLayers.filter((visLayer) => isVisLayerWithError(visLayer));
return new Error('some aggregate view of vislayer failures');
};
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import {
} from '../../../expressions/public';
import { buildPipeline } from '../legacy/build_pipeline';
import { Vis, SerializedVis } from '../vis';
import { getExpressions, getUiActions } from '../services';
import { getExpressions, getNotifications, getUiActions } from '../services';
import { VIS_EVENT_TO_TRIGGER } from './events';
import { VisualizeEmbeddableFactoryDeps } from './visualize_embeddable_factory';
import { TriggerId } from '../../../ui_actions/public';
Expand All @@ -71,6 +71,7 @@ import {
isEligibleForVisLayers,
getAugmentVisSavedObjs,
buildPipelineFromAugmentVisSavedObjs,
getVisLayerErrors,
} from '../../../vis_augmenter/public';
import { VisSavedObject } from '../types';

Expand Down Expand Up @@ -404,6 +405,18 @@ export class VisualizeEmbeddable
this.abortController = new AbortController();
const abortController = this.abortController;

// TODO: remove after testing
const { toasts } = getNotifications();
toasts.addError(
new Error(
'The following plugin resources failed to load: <plugin-resource-1>, <plugin-resource-2>'
),
{
title: `Some of the plugin resources failed to load for ${this.vis.title} chart`,
toastMessage: ' ',
}
);

const visLayers = await this.fetchVisLayers(expressionParams, abortController);

this.expression = await buildPipeline(this.vis, {
Expand Down Expand Up @@ -517,7 +530,18 @@ export class VisualizeEmbeddable
visLayersPipelineInput,
expressionParams as Record<string, unknown>
)) as ExprVisLayers;
return exprVisLayers.layers;

const visLayers = exprVisLayers.layers;
const visLayerError = getVisLayerErrors(visLayers);

// TODO: clean up and test different formatting once how error is supposed to look is defined
const { toasts } = getNotifications();
toasts.addError(visLayerError, {
title: i18n.translate('visualizations.renderVisTitle', {
defaultMessage: 'Some test error',
}),
});
return visLayers;
}
return [] as VisLayers;
};
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/visualizations/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
Plugin,
ApplicationStart,
SavedObjectsClientContract,
NotificationsStart,
} from '../../../core/public';
import { TypesService, TypesSetup, TypesStart } from './vis_types';
import {
Expand All @@ -60,6 +61,7 @@ import {
setOverlays,
setSavedSearchLoader,
setEmbeddable,
setNotifications,
setSavedAugmentVisLoader,
} from './services';
import {
Expand Down Expand Up @@ -130,6 +132,7 @@ export interface VisualizationsStartDeps {
dashboard: DashboardStart;
getAttributeService: DashboardStart['getAttributeService'];
savedObjectsClient: SavedObjectsClientContract;
notifications: NotificationsStart;
}

/**
Expand Down Expand Up @@ -220,6 +223,7 @@ export class VisualizationsPlugin
overlays: core.overlays,
});
setSavedSearchLoader(savedSearchLoader);
setNotifications(core.notifications);
return {
...types,
showNewVisModal,
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/visualizations/public/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
IUiSettingsClient,
OverlayStart,
SavedObjectsStart,
NotificationsStart,
} from '../../../core/public';
import { TypesStart } from './vis_types';
import { createGetterSetter } from '../../opensearch_dashboards_utils/common';
Expand Down Expand Up @@ -111,3 +112,7 @@ export const [getSavedSearchLoader, setSavedSearchLoader] = createGetterSetter<S
export const [getSavedAugmentVisLoader, setSavedAugmentVisLoader] = createGetterSetter<
SavedAugmentVisLoader
>('SavedAugmentVisLoader');

export const [getNotifications, setNotifications] = createGetterSetter<NotificationsStart>(
'Notifications'
);

0 comments on commit 242510f

Please sign in to comment.