Skip to content

Commit

Permalink
use generic edit actions in the alerts embeddable
Browse files Browse the repository at this point in the history
  • Loading branch information
mgiota committed Jun 18, 2024
1 parent 56db7f8 commit 2339730
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { createBrowserHistory } from 'history';
import { Storage } from '@kbn/kibana-utils-plugin/public';
import type { StartServicesAccessor } from '@kbn/core-lifecycle-browser';
import { SLO_ALERTS_EMBEDDABLE_ID } from './constants';
import { SloEmbeddableDeps, SloAlertsEmbeddableState, SloAlertsApi } from './types';
import { SloAlertsEmbeddableState, SloAlertsApi } from './types';
import { SloPublicPluginsStart, SloPublicStart } from '../../../types';
import { SloAlertsWrapper } from './slo_alerts_wrapper';
const history = createBrowserHistory();
const queryClient = new QueryClient();
Expand All @@ -32,13 +34,18 @@ export const getAlertsPanelTitle = () =>
defaultMessage: 'SLO Alerts',
});

export function getAlertsEmbeddableFactory(deps: SloEmbeddableDeps, kibanaVersion: string) {
export function getAlertsEmbeddableFactory(
getStartServices: StartServicesAccessor<SloPublicPluginsStart, SloPublicStart>,
kibanaVersion: string
) {
const factory: ReactEmbeddableFactory<SloAlertsEmbeddableState, SloAlertsApi> = {
type: SLO_ALERTS_EMBEDDABLE_ID,
deserializeState: (state) => {
return state.rawState as SloAlertsEmbeddableState;
},
buildEmbeddable: async (state, buildApi, uuid, parentApi) => {
const [coreStart, pluginStart] = await getStartServices();
const deps = { ...coreStart, ...pluginStart };
const { titlesApi, titleComparators, serializeTitles } = initializeTitles(state);
const defaultTitle$ = new BehaviorSubject<string | undefined>(getAlertsPanelTitle());
const slos$ = new BehaviorSubject(state.slos);
Expand All @@ -48,6 +55,25 @@ export function getAlertsEmbeddableFactory(deps: SloEmbeddableDeps, kibanaVersio
{
...titlesApi,
defaultPanelTitle: defaultTitle$,
getTypeDisplayName: () =>
i18n.translate('xpack.slo.editSloAlertswEmbeddable.typeDisplayName', {
defaultMessage: 'configuration',
}),
isEditingEnabled: () => true,
onEdit: async () => {
try {
const { openSloConfiguration } = await import('./slo_alerts_open_configuration');

const result = await openSloConfiguration(
coreStart,
pluginStart,
api.getSloAlertsConfig()
);
api.updateSloAlertsConfig(result);
} catch (e) {
return Promise.reject();
}
},
serializeState: () => {
return {
rawState: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { SloIncludedCount } from './components/slo_included_count';
import { SloAlertsSummary } from './components/slo_alerts_summary';
import { SloAlertsTable } from './components/slo_alerts_table';
import type { SloItem, SloEmbeddableDeps } from './types';
import { EDIT_SLO_ALERTS_ACTION } from '../../../ui_actions/edit_slo_alerts_panel';
// import { EDIT_SLO_ALERTS_ACTION } from '../../../ui_actions/edit_slo_alerts_panel';

interface Props {
deps: SloEmbeddableDeps;
Expand Down Expand Up @@ -102,11 +102,11 @@ export function SloAlertsWrapper({
<EuiFlexItem grow={false}>
<EuiLink
onClick={() => {
const trigger = deps.uiActions.getTrigger(CONTEXT_MENU_TRIGGER);
deps.uiActions.getAction(EDIT_SLO_ALERTS_ACTION).execute({
trigger,
embeddable,
} as ActionExecutionContext);
// const trigger = deps.uiActions.getTrigger(CONTEXT_MENU_TRIGGER);
// deps.uiActions.getAction(EDIT_SLO_ALERTS_ACTION).execute({
// trigger,
// embeddable,
// } as ActionExecutionContext);
}}
data-test-subj="o11ySloAlertsWrapperSlOsIncludedLink"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
PublishesWritablePanelTitle,
PublishesPanelTitle,
EmbeddableApiContext,
HasEditCapabilities,
} from '@kbn/presentation-publishing';

export interface SloItem {
Expand All @@ -45,7 +46,8 @@ export type SloAlertsEmbeddableState = SerializedTitles & EmbeddableSloProps;
export type SloAlertsApi = DefaultEmbeddableApi<SloAlertsEmbeddableState> &
PublishesWritablePanelTitle &
PublishesPanelTitle &
HasSloAlertsConfig;
HasSloAlertsConfig &
HasEditCapabilities;

export interface HasSloAlertsConfig {
getSloAlertsConfig: () => EmbeddableSloProps;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/observability_solution/slo/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class SloPlugin
'./embeddable/slo/alerts/slo_alerts_embeddable_factory'
);

return getAlertsEmbeddableFactory(deps, kibanaVersion);
return getAlertsEmbeddableFactory(coreSetup.getStartServices, kibanaVersion);
}
);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
*/

import type { UiActionsSetup } from '@kbn/ui-actions-plugin/public';
import { CONTEXT_MENU_TRIGGER } from '@kbn/embeddable-plugin/public';
import type { CoreSetup } from '@kbn/core/public';
import { createEditSloAlertsPanelAction } from './edit_slo_alerts_panel';
import { createOverviewPanelAction } from './create_overview_panel_action';
import { createAddErrorBudgetPanelAction } from './create_error_budget_action';
import { createAddAlertsPanelAction } from './create_alerts_panel_action';
Expand All @@ -19,13 +17,11 @@ export function registerSloUiActions(
core: CoreSetup<SloPublicPluginsStart, SloPublicStart>
) {
// Initialize actions
const editSloAlertsPanelAction = createEditSloAlertsPanelAction(core.getStartServices);
const addOverviewPanelAction = createOverviewPanelAction(core.getStartServices);
const addErrorBudgetPanelAction = createAddErrorBudgetPanelAction(core.getStartServices);
const addAlertsPanelAction = createAddAlertsPanelAction(core.getStartServices);

// Assign triggers
uiActions.addTriggerAction(CONTEXT_MENU_TRIGGER, editSloAlertsPanelAction);
uiActions.addTriggerAction('ADD_PANEL_TRIGGER', addOverviewPanelAction);
uiActions.addTriggerAction('ADD_PANEL_TRIGGER', addErrorBudgetPanelAction);
uiActions.addTriggerAction('ADD_PANEL_TRIGGER', addAlertsPanelAction);
Expand Down

0 comments on commit 2339730

Please sign in to comment.