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

[EuiProvider/Security Solution] Remove usage of deprecated React rendering utilities #181099

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
aba52ae
[Security Solution] Remove usage of deprecated React rendering utilities
tsullivan Apr 17, 2024
03353bd
Shorten list of notified code owners
tsullivan Apr 18, 2024
e1ab2d1
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Apr 18, 2024
6f28ac5
Restore EuiThemeProvider
tsullivan Apr 18, 2024
7e947e9
fix tests
tsullivan Apr 22, 2024
f6f0a36
Merge branch 'main' into sharedux/cleanup-tomountpoint-deprecations-viii
tsullivan Apr 23, 2024
91b622d
Merge branch 'main' into sharedux/cleanup-tomountpoint-deprecations-viii
tsullivan Apr 24, 2024
dde3a73
Merge branch 'main' into sharedux/cleanup-tomountpoint-deprecations-viii
tsullivan Apr 24, 2024
4b5461e
Merge branch 'main' into sharedux/cleanup-tomountpoint-deprecations-viii
tsullivan Apr 25, 2024
583887c
Merge branch 'main' into sharedux/cleanup-tomountpoint-deprecations-viii
tsullivan Apr 25, 2024
130c830
Merge branch 'main' into sharedux/cleanup-tomountpoint-deprecations-viii
tsullivan Apr 25, 2024
1048c2d
Merge branch 'main' into sharedux/cleanup-tomountpoint-deprecations-viii
tsullivan Apr 26, 2024
3853892
Merge branch 'sharedux/cleanup-tomountpoint-deprecations-viii' of git…
tsullivan Apr 26, 2024
d84799d
Merge branch 'main' into sharedux/cleanup-tomountpoint-deprecations-viii
tsullivan Apr 26, 2024
2d519a2
Merge branch 'main' into sharedux/cleanup-tomountpoint-deprecations-viii
tsullivan Apr 26, 2024
90102e9
Test fix for mounting of OutPortal
tsullivan Apr 26, 2024
9cfd3ee
Merge branch 'main' into sharedux/cleanup-tomountpoint-deprecations-viii
tsullivan Apr 27, 2024
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
73 changes: 32 additions & 41 deletions x-pack/plugins/security_solution/public/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import React, { memo } from 'react';
import type { Store, Action } from 'redux';
import { Provider as ReduxStoreProvider } from 'react-redux';

import { KibanaThemeProvider } from '@kbn/kibana-react-plugin/public';
import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render';
import type { AppMountParameters } from '@kbn/core/public';

import { EuiThemeProvider } from '@kbn/kibana-react-plugin/common';
import { CellActionsProvider } from '@kbn/cell-actions';
import { KibanaErrorBoundary, KibanaErrorBoundaryProvider } from '@kbn/shared-ux-error-boundary';
import { NavigationProvider } from '@kbn/security-solution-navigation';
import { UpsellingProvider } from '../common/components/upselling_provider';
import { ManageUserInfo } from '../detections/components/user_info';
Expand All @@ -43,8 +42,6 @@ interface StartAppComponent {
const StartAppComponent: FC<StartAppComponent> = ({ children, history, store, theme$ }) => {
const services = useKibana().services;
const {
i18n,
analytics,
application: { capabilities },
uiActions,
upselling,
Expand All @@ -53,43 +50,37 @@ const StartAppComponent: FC<StartAppComponent> = ({ children, history, store, th
const darkMode = useDarkMode();

return (
<KibanaErrorBoundaryProvider analytics={analytics}>
<KibanaErrorBoundary>
<i18n.Context>
<ManageGlobalToaster>
<ReduxStoreProvider store={store}>
<KibanaThemeProvider theme$={theme$}>
<EuiThemeProvider darkMode={darkMode}>
<MlCapabilitiesProvider>
<UserPrivilegesProvider kibanaCapabilities={capabilities}>
<ManageUserInfo>
<NavigationProvider core={services}>
<ReactQueryClientProvider>
<CellActionsProvider
getTriggerCompatibleActions={uiActions.getTriggerCompatibleActions}
>
<UpsellingProvider upsellingService={upselling}>
<DiscoverInTimelineContextProvider>
<AssistantProvider>
<PageRouter history={history}>{children}</PageRouter>
</AssistantProvider>
</DiscoverInTimelineContextProvider>
</UpsellingProvider>
</CellActionsProvider>
</ReactQueryClientProvider>
</NavigationProvider>
</ManageUserInfo>
</UserPrivilegesProvider>
</MlCapabilitiesProvider>
</EuiThemeProvider>
</KibanaThemeProvider>
<ErrorToastDispatcher />
<GlobalToaster />
</ReduxStoreProvider>
</ManageGlobalToaster>
</i18n.Context>
</KibanaErrorBoundary>
</KibanaErrorBoundaryProvider>
<KibanaRenderContextProvider {...services}>
<ManageGlobalToaster>
<ReduxStoreProvider store={store}>
<EuiThemeProvider darkMode={darkMode}>
<MlCapabilitiesProvider>
<UserPrivilegesProvider kibanaCapabilities={capabilities}>
<ManageUserInfo>
<NavigationProvider core={services}>
<ReactQueryClientProvider>
<CellActionsProvider
getTriggerCompatibleActions={uiActions.getTriggerCompatibleActions}
>
<UpsellingProvider upsellingService={upselling}>
<DiscoverInTimelineContextProvider>
<AssistantProvider>
<PageRouter history={history}>{children}</PageRouter>
</AssistantProvider>
</DiscoverInTimelineContextProvider>
</UpsellingProvider>
</CellActionsProvider>
</ReactQueryClientProvider>
</NavigationProvider>
</ManageUserInfo>
</UserPrivilegesProvider>
</MlCapabilitiesProvider>
</EuiThemeProvider>
<ErrorToastDispatcher />
<GlobalToaster />
</ReduxStoreProvider>
</ManageGlobalToaster>
</KibanaRenderContextProvider>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jest.mock('react-redux', () => {
};
});

jest.mock('@kbn/kibana-react-plugin/public', () => {
const original = jest.requireActual('@kbn/kibana-react-plugin/public');
jest.mock('@kbn/react-kibana-mount', () => {
const original = jest.requireActual('@kbn/react-kibana-mount');

return {
...original,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ jest.mock('react-redux', () => {
};
});

jest.mock('@kbn/kibana-react-plugin/public', () => {
const original = jest.requireActual('@kbn/kibana-react-plugin/public');
jest.mock('@kbn/react-kibana-mount', () => {
const original = jest.requireActual('@kbn/react-kibana-mount');

return {
...original,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ jest.mock('react-redux', () => {
};
});

jest.mock('@kbn/kibana-react-plugin/public', () => {
const original = jest.requireActual('@kbn/kibana-react-plugin/public');
jest.mock('@kbn/react-kibana-mount', () => {
const original = jest.requireActual('@kbn/react-kibana-mount');

return {
...original,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ jest.mock('react-redux', () => {
};
});

jest.mock('@kbn/kibana-react-plugin/public', () => {
const original = jest.requireActual('@kbn/kibana-react-plugin/public');
jest.mock('@kbn/react-kibana-mount', () => {
const original = jest.requireActual('@kbn/react-kibana-mount');

return {
...original,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ jest.mock('react-redux', () => {
};
});

jest.mock('@kbn/kibana-react-plugin/public', () => {
const original = jest.requireActual('@kbn/kibana-react-plugin/public');
jest.mock('@kbn/react-kibana-mount', () => {
const original = jest.requireActual('@kbn/react-kibana-mount');

return {
...original,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React, { useCallback } from 'react';
import { EuiLink } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { toMountPoint } from '@kbn/kibana-react-plugin/public';
import { toMountPoint } from '@kbn/react-kibana-mount';
import { useKibana } from '../../lib/kibana';
import { DEFAULT_INDEX_KEY } from '../../../../common/constants';
import * as i18n from './translations';
Expand All @@ -19,7 +19,7 @@ import { ensurePatternFormat } from '../../../../common/utils/sourcerer';
export const useUpdateDataView = (
onOpenAndReset: () => void
): ((missingPatterns: string[]) => Promise<boolean>) => {
const { theme, uiSettings } = useKibana().services;
const { uiSettings, ...startServices } = useKibana().services;
const { addSuccess, addError } = useAppToasts();
return useCallback(
async (missingPatterns: string[]): Promise<boolean> => {
Expand All @@ -40,8 +40,8 @@ export const useUpdateDataView = (
if (isUiSettingsSuccess) {
addSuccess({
color: 'success',
title: toMountPoint(i18n.SUCCESS_TOAST_TITLE, { theme$: theme.theme$ }),
text: toMountPoint(<RefreshButton />, { theme$: theme.theme$ }),
title: toMountPoint(i18n.SUCCESS_TOAST_TITLE, startServices),
text: toMountPoint(<RefreshButton />, startServices),
iconType: undefined,
toastLifeTimeMs: 600000,
});
Expand All @@ -67,6 +67,6 @@ export const useUpdateDataView = (
});
return false;
},
[addError, addSuccess, onOpenAndReset, theme.theme$, uiSettings]
[addError, addSuccess, onOpenAndReset, uiSettings, startServices]
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const useSaveToLibrary = ({
}: {
attributes: LensAttributes | undefined | null;
}) => {
const { lens, theme, i18n } = useKibana().services;
const { lens, ...startServices } = useKibana().services;
const { SaveModalComponent, canUseEditor } = lens;
const getSecuritySolutionUrl = useGetSecuritySolutionUrl();
const { redirectTo, getEditOrCreateDashboardPath } = useRedirectToDashboardFromLens({
Expand All @@ -45,11 +45,11 @@ export const useSaveToLibrary = ({
}
redirectTo={redirectTo}
/>,
{ theme, i18n }
startServices
);

mount(targetDomElement);
}, [SaveModalComponent, attributes, getEditOrCreateDashboardPath, i18n, redirectTo, theme]);
}, [SaveModalComponent, attributes, getEditOrCreateDashboardPath, redirectTo, startServices]);

const disableVisualizations = useMemo(
() => !canUseEditor() || attributes == null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import type { ReactNode } from 'react';
import React, { memo } from 'react';
import { Provider } from 'react-redux';
import { I18nProvider } from '@kbn/i18n-react';
import { Router } from '@kbn/shared-ux-router';
import type { History } from 'history';
import useObservable from 'react-use/lib/useObservable';
import type { Store } from 'redux';
import { EuiThemeProvider } from '@kbn/kibana-react-plugin/common';
import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import type { CoreStart } from '@kbn/core/public';
import { NavigationProvider } from '@kbn/security-solution-navigation';
Expand All @@ -36,14 +36,14 @@ export const AppRootProvider = memo<{
startServices: StartServices;
queryClient: QueryClient;
children: ReactNode | ReactNode[];
}>(({ store, history, coreStart, depsStart: { data }, queryClient, startServices, children }) => {
}>(({ store, history, coreStart, queryClient, startServices, children }) => {
const { theme: themeStart } = coreStart;
const theme = useObservable(themeStart.theme$, themeStart.getTheme());
const isDarkMode = theme.darkMode;

return (
<Provider store={store}>
<I18nProvider>
<KibanaRenderContextProvider {...coreStart}>
<Provider store={store}>
<KibanaContextProvider services={startServices}>
<EuiThemeProvider darkMode={isDarkMode}>
<QueryClientProvider client={queryClient}>
Expand All @@ -61,8 +61,8 @@ export const AppRootProvider = memo<{
</QueryClientProvider>
</EuiThemeProvider>
</KibanaContextProvider>
</I18nProvider>
</Provider>
</Provider>
</KibanaRenderContextProvider>
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
import type { EuiContextMenuPanelDescriptor } from '@elastic/eui';
import { EuiButton, EuiFlexGroup, EuiFlexItem, EuiTextColor } from '@elastic/eui';
import type { Toast } from '@kbn/core/public';
import { toMountPoint } from '@kbn/kibana-react-plugin/public';
import { toMountPoint } from '@kbn/react-kibana-mount';
import { euiThemeVars } from '@kbn/ui-theme';
import React, { useCallback } from 'react';
import { useKibana } from '../../../../../common/lib/kibana';
import { convertRulesFilterToKQL } from '../../../../../../common/detection_engine/rule_management/rule_filtering';
import { DuplicateOptions } from '../../../../../../common/detection_engine/rule_management/constants';
import type {
Expand Down Expand Up @@ -65,6 +66,7 @@ export const useBulkActions = ({
completeBulkEditForm,
executeBulkActionsDryRun,
}: UseBulkActionsArgs) => {
const { services: startServices } = useKibana();
const hasMlPermissions = useHasMlPermissions();
const rulesTableContext = useRulesTableContext();
const hasActionsPrivileges = useHasActionsPrivileges();
Expand Down Expand Up @@ -258,7 +260,8 @@ export const useBulkActions = ({
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</>
</>,
startServices
),
iconType: undefined,
},
Expand Down Expand Up @@ -481,6 +484,7 @@ export const useBulkActions = ({
executeBulkActionsDryRun,
filterOptions,
completeBulkEditForm,
startServices,
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const RiskScoreEnableButtonComponent = ({
};
}) => {
const spaceId = useSpaceId();
const { http, notifications, theme, dashboard } = useKibana().services;
const { http, dashboard, ...startServices } = useKibana().services;
const { renderDocLink, renderDashboardLink } = useRiskScoreToastContent(riskScoreEntity);
const { fetch, isLoading } = useFetch(REQUEST_NAMES.ENABLE_RISK_SCORE, installRiskScoreModule);
const isRiskEngineEnabled = useIsExperimentalFeatureEnabled('riskScoringRoutesEnabled');
Expand All @@ -44,27 +44,25 @@ const RiskScoreEnableButtonComponent = ({
fetch({
dashboard,
http,
notifications,
refetch,
renderDashboardLink,
renderDocLink,
riskScoreEntity,
spaceId,
theme,
timerange,
startServices,
});
}, [
dashboard,
fetch,
http,
notifications,
refetch,
renderDashboardLink,
renderDocLink,
riskScoreEntity,
spaceId,
theme,
timerange,
startServices,
]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ const RiskScoreRestartButtonComponent = ({
const spaceId = useSpaceId();

const { renderDocLink } = useRiskScoreToastContent(riskScoreEntity);
const { http, notifications } = useKibana().services;
const { http, ...startServices } = useKibana().services;

const onClick = useCallback(async () => {
fetch({
http,
notifications,
refetch,
renderDocLink,
riskScoreEntity,
spaceId,
startServices,
});
}, [fetch, http, notifications, refetch, renderDocLink, riskScoreEntity, spaceId]);
}, [fetch, http, refetch, renderDocLink, riskScoreEntity, spaceId, startServices]);

return (
<EuiButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { coreMock } from '@kbn/core/public/mocks';
import type { HttpSetup } from '@kbn/core/public';
import { RiskScoreEntity } from '../../../../common/search_strategy';
import {
Expand All @@ -26,6 +28,7 @@ import {

jest.mock('../../deprecated_risk_engine/api');

const startServices = coreMock.createStart();
const mockHttp = {
post: jest.fn(),
} as unknown as HttpSetup;
Expand All @@ -45,6 +48,7 @@ describe.each([RiskScoreEntity.host, RiskScoreEntity.user])(
spaceId: mockSpaceId,
timerange: mockTimerange,
riskScoreEntity,
startServices,
});
});

Expand Down Expand Up @@ -78,6 +82,7 @@ describe.each([[RiskScoreEntity.host], [RiskScoreEntity.user]])(
http: mockHttp,
spaceId: mockSpaceId,
riskScoreEntity,
startServices,
});
});

Expand Down Expand Up @@ -146,6 +151,7 @@ describe.each([[RiskScoreEntity.host], [RiskScoreEntity.user]])(
refetch: mockRefetch,
riskScoreEntity,
spaceId: mockSpaceId,
startServices,
});
});

Expand Down
Loading