Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SLO][Embeddable] Fix Kibana reporting screenshot issue #169929

Merged
merged 5 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { toMountPoint } from '@kbn/react-kibana-mount';
import type { CoreStart } from '@kbn/core/public';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import type { EmbeddableSloProps, SloEmbeddableInput } from './types';
import type { SloEmbeddableInput, EmbeddableSloProps } from './types';

import { ObservabilityPublicPluginsStart } from '../../..';
import { SloConfiguration } from './slo_configuration';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';
import { SloSelector } from './slo_selector';

import type { EmbeddableSloProps } from './types';

interface SloConfigurationProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,19 @@ export class SLOEmbeddable extends AbstractEmbeddable<SloEmbeddableInput, Embedd
this.updateInput({ title });
}

public reportsEmbeddableLoad() {
return true;
}

public onRenderComplete() {
this.renderComplete.dispatchComplete();
}

public render(node: HTMLElement) {
super.render(node);
this.node = node;
// required for the export feature to work
this.node.setAttribute('data-shared-item', '');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed according to this. Otherwise reporting wouldn't work

this.setTitle(
this.input.title ||
i18n.translate('xpack.observability.sloEmbeddable.displayTitle', {
Expand All @@ -69,6 +80,7 @@ export class SLOEmbeddable extends AbstractEmbeddable<SloEmbeddableInput, Embedd
<KibanaContextProvider services={this.deps}>
<QueryClientProvider client={queryClient}>
<SloOverview
onRenderComplete={() => this.onRenderComplete()}
sloId={sloId}
sloInstanceId={sloInstanceId}
lastReloadRequestTime={this.input.lastReloadRequestTime}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ import { paths } from '../../../../common/locators/paths';

import { EmbeddableSloProps } from './types';

export function SloOverview({ sloId, sloInstanceId, lastReloadRequestTime }: EmbeddableSloProps) {
export function SloOverview({
sloId,
sloInstanceId,
lastReloadRequestTime,
onRenderComplete,
}: EmbeddableSloProps) {
const {
uiSettings,
application: { navigateToUrl },
Expand All @@ -39,6 +44,13 @@ export function SloOverview({ sloId, sloInstanceId, lastReloadRequestTime }: Emb
useEffect(() => {
refetch();
}, [lastReloadRequestTime, refetch]);
useEffect(() => {
if (!onRenderComplete) return;

if (!isLoading) {
onRenderComplete();
}
}, [isLoading, onRenderComplete]);

const percentFormat = uiSettings.get('format:percent:defaultPattern');
const isSloNotFound = !isLoading && slo === undefined;
Expand Down Expand Up @@ -97,6 +109,7 @@ export function SloOverview({ sloId, sloInstanceId, lastReloadRequestTime }: Emb
</LoadingContainer>
);
}

const TargetCopy = i18n.translate('xpack.observability.sloEmbeddable.overview.sloTargetLabel', {
defaultMessage: 'Target',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface EmbeddableSloProps {
sloId: string | undefined;
sloInstanceId: string | undefined;
lastReloadRequestTime?: number | undefined;
onRenderComplete?: () => void;
}

export type SloEmbeddableInput = EmbeddableInput & EmbeddableSloProps;