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

[Oblt UX: Infrastructure and Services] Remove usage of deprecated React rendering utilities #180844

Merged
Show file tree
Hide file tree
Changes from 4 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
16 changes: 9 additions & 7 deletions x-pack/plugins/monitoring/public/alerts/lib/alerts_toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@
import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiSpacer, EuiLink } from '@elastic/eui';
import type { Observable } from 'rxjs';
import type { CoreTheme } from '@kbn/core/public';
import { toMountPoint } from '@kbn/kibana-react-plugin/public';
import { toMountPoint } from '@kbn/react-kibana-mount';
import { Legacy } from '../../legacy_shims';
import { MonitoringStartServices } from '../../types';

export interface EnableAlertResponse {
isSufficientlySecure?: boolean;
hasPermanentEncryptionKey?: boolean;
}

const showApiKeyAndEncryptionError = (theme$?: Observable<CoreTheme>) => {
const showApiKeyAndEncryptionError = (services: MonitoringStartServices) => {
const settingsUrl = Legacy.shims.docLinks.links.alerting.generalSettings;

Legacy.shims.toastNotifications.addWarning({
Expand All @@ -40,7 +39,7 @@ const showApiKeyAndEncryptionError = (theme$?: Observable<CoreTheme>) => {
})}
</EuiLink>
</div>,
{ theme$ }
services
),
});
};
Expand All @@ -58,11 +57,14 @@ const showAlertsCreatedConfirmation = () => {
});
};

export const showAlertsToast = (response: EnableAlertResponse, theme$?: Observable<CoreTheme>) => {
export const showAlertsToast = (
response: EnableAlertResponse,
services: MonitoringStartServices
) => {
const { isSufficientlySecure, hasPermanentEncryptionKey } = response;

if (isSufficientlySecure === false || hasPermanentEncryptionKey === false) {
showApiKeyAndEncryptionError(theme$);
showApiKeyAndEncryptionError(services);
} else {
showAlertsCreatedConfirmation();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { useRequestErrorHandler } from './use_request_error_handler';
import { EnableAlertResponse, showAlertsToast } from '../../alerts/lib/alerts_toast';
import { MonitoringStartServices } from '../../types';

export const useAlertsModal = () => {
const { services } = useKibana();
const { services } = useKibana<MonitoringStartServices>();
const handleRequestError = useRequestErrorHandler();

function shouldShowAlertsModal(alerts: {}) {
Expand Down Expand Up @@ -38,9 +39,9 @@ export const useAlertsModal = () => {
{}
)!;
window.localStorage.setItem('ALERTS_MODAL_DECISION_MADE', 'true');
showAlertsToast(response, services.theme?.theme$);
showAlertsToast(response, services);
} catch (err) {
await handleRequestError(err);
handleRequestError(err);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import { includes } from 'lodash';
import type { IHttpFetchError, ResponseErrorBody } from '@kbn/core-http-browser';
import { FormattedMessage } from '@kbn/i18n-react';
import { EuiButton, EuiSpacer, EuiText } from '@elastic/eui';
import { toMountPoint, useKibana } from '@kbn/kibana-react-plugin/public';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { toMountPoint } from '@kbn/react-kibana-mount';
import { formatMsg } from '../../lib/format_msg';
import { MonitoringStartPluginDependencies } from '../../types';
import { MonitoringStartServices } from '../../types';

export function formatMonitoringError(err: IHttpFetchError<ResponseErrorBody>) {
if (err.response?.status && err.response?.status !== -1) {
Expand All @@ -35,7 +36,7 @@ export function formatMonitoringError(err: IHttpFetchError<ResponseErrorBody>) {
}

export const useRequestErrorHandler = () => {
const { services } = useKibana<MonitoringStartPluginDependencies>();
const { services } = useKibana<MonitoringStartServices>();
const history = useHistory();
return useCallback(
(err: IHttpFetchError<ResponseErrorBody>) => {
Expand Down Expand Up @@ -64,18 +65,18 @@ export const useRequestErrorHandler = () => {
/>
</EuiButton>
</div>,
{ theme$: services.theme?.theme$ }
services
),
});
} else {
services.notifications?.toasts.addDanger({
title: i18n.translate('xpack.monitoring.ajaxErrorHandler.requestErrorNotificationTitle', {
defaultMessage: 'Monitoring Request Error',
}),
text: toMountPoint(formatMonitoringError(err), { theme$: services.theme?.theme$ }),
text: toMountPoint(formatMonitoringError(err), services),
});
}
},
[history, services.notifications?.toasts, services.theme]
[history, services]
);
};
Loading