Skip to content

Commit

Permalink
Preparation for High Contrast Mode, Security domains
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Dec 2, 2024
1 parent 6c0cf0e commit 7df939a
Show file tree
Hide file tree
Showing 54 changed files with 184 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const CreateRuleForm = (props: CreateRuleFormProps) => {
onSubmit,
} = props;

const { http, docLinks, notifications, ruleTypeRegistry, i18n, theme } = plugins;
const { http, docLinks, notifications, ruleTypeRegistry, ...deps } = plugins;
const { toasts } = notifications;

const { mutate, isLoading: isSaving } = useCreateRule({
Expand All @@ -82,7 +82,7 @@ export const CreateRuleForm = (props: CreateRuleFormProps) => {
...(message.details && {
text: toMountPoint(
<RuleFormCircuitBreakerError>{message.details}</RuleFormCircuitBreakerError>,
{ i18n, theme }
deps
),
}),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const EditRuleForm = (props: EditRuleFormProps) => {
onCancel,
onSubmit,
} = props;
const { http, notifications, docLinks, ruleTypeRegistry, i18n, theme, application } = plugins;
const { http, notifications, docLinks, ruleTypeRegistry, application, ...deps } = plugins;
const { toasts } = notifications;

const { mutate, isLoading: isSaving } = useUpdateRule({
Expand All @@ -63,7 +63,7 @@ export const EditRuleForm = (props: EditRuleFormProps) => {
...(message.details && {
text: toMountPoint(
<RuleFormCircuitBreakerError>{message.details}</RuleFormCircuitBreakerError>,
{ i18n, theme }
deps
),
}),
});
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-alerts-ui-shared/src/rule_form/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { DocLinksStart } from '@kbn/core-doc-links-browser';
import type { HttpStart } from '@kbn/core-http-browser';
import type { I18nStart } from '@kbn/core-i18n-browser';
import type { ThemeServiceStart } from '@kbn/core-theme-browser';
import type { UserProfileService } from '@kbn/core-user-profile-browser';
import type { ApplicationStart } from '@kbn/core-application-browser';
import type { NotificationsStart } from '@kbn/core-notifications-browser';
import type { ChartsPluginSetup } from '@kbn/charts-plugin/public';
Expand Down Expand Up @@ -53,6 +54,7 @@ export interface RuleFormPlugins {
http: HttpStart;
i18n: I18nStart;
theme: ThemeServiceStart;
userProfile: UserProfileService;
application: ApplicationStart;
notifications: NotificationsStart;
charts: ChartsPluginSetup;
Expand Down
3 changes: 2 additions & 1 deletion packages/kbn-alerts-ui-shared/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@kbn/core-http-browser-mocks",
"@kbn/core-notifications-browser-mocks",
"@kbn/kibana-react-plugin",
"@kbn/shared-ux-table-persist"
"@kbn/shared-ux-table-persist",
"@kbn/core-user-profile-browser"
]
}
4 changes: 2 additions & 2 deletions packages/kbn-mock-idp-plugin/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const plugin: PluginInitializer<
]);

ReactDOM.render(
<KibanaThemeProvider theme={coreStart.theme}>
<KibanaThemeProvider {...coreStart}>
<KibanaContextProvider services={coreStart}>
<I18nProvider>
<LoginPage />
Expand All @@ -69,7 +69,7 @@ export const plugin: PluginInitializer<
order: 4000 + 1, // Make sure it comes after the user menu
mount: (element: HTMLElement) => {
ReactDOM.render(
<KibanaThemeProvider theme={coreStart.theme}>
<KibanaThemeProvider {...coreStart}>
<KibanaContextProvider services={coreStart}>
<I18nProvider>
<RoleSwitcher />
Expand Down
4 changes: 3 additions & 1 deletion packages/kbn-mock-idp-plugin/public/reload_page_toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import React from 'react';
import type { I18nStart } from '@kbn/core-i18n-browser';
import type { ToastInput } from '@kbn/core-notifications-browser';
import type { ThemeServiceStart } from '@kbn/core-theme-browser';
import type { UserProfileService } from '@kbn/core-user-profile-browser';
import { toMountPoint } from '@kbn/react-kibana-mount';
import type { AuthenticatedUser } from '@kbn/security-plugin-types-common';

Expand All @@ -26,6 +27,7 @@ export const DATA_TEST_SUBJ_PAGE_RELOAD_BUTTON = 'pageReloadButton';
*/
export const createReloadPageToast = (options: {
user: Pick<AuthenticatedUser, 'roles'>;
userProfile: UserProfileService;
theme: ThemeServiceStart;
i18n: I18nStart;
}): ToastInput => {
Expand All @@ -43,7 +45,7 @@ export const createReloadPageToast = (options: {
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>,
{ i18n: options.i18n, theme: options.theme }
options
),
color: 'success',
toastLifeTimeMs: 0x7fffffff, // Do not auto-hide toast since page is in an unknown state
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-mock-idp-plugin/public/role_switcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const RoleSwitcher = () => {
services.notifications.toasts.add(
createReloadPageToast({
user: authenticateUserState.value,
userProfile: services.userProfile,
theme: services.theme,
i18n: services.i18n,
})
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-mock-idp-plugin/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
"@kbn/mock-idp-utils",
"@kbn/cloud-plugin",
"@kbn/es",
"@kbn/core-user-profile-browser",
]
}
1 change: 1 addition & 0 deletions packages/kbn-user-profile-components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type {
export type {
UserProfileData,
UserSettingsData,
ContrastModeValue,
DarkModeValue,
UserProfileAvatarData,
} from './src/types';
Expand Down
6 changes: 4 additions & 2 deletions packages/kbn-user-profile-components/src/services.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import React, { useContext } from 'react';
import type { I18nStart } from '@kbn/core-i18n-browser';
import type { NotificationsStart, ToastOptions } from '@kbn/core-notifications-browser';
import type { ThemeServiceStart } from '@kbn/core-theme-browser';
import type { UserProfileService } from '@kbn/core-user-profile-browser';
import type { toMountPoint } from '@kbn/react-kibana-mount';

import type { UserProfileAPIClient } from './types';
Expand Down Expand Up @@ -47,6 +48,7 @@ export interface UserProfilesKibanaDependencies {
core: {
notifications: NotificationsStart;
theme: ThemeServiceStart;
userProfile: UserProfileService;
i18n: I18nStart;
};
security: {
Expand All @@ -70,7 +72,7 @@ export const UserProfilesKibanaProvider: FC<PropsWithChildren<UserProfilesKibana
...services
}) => {
const {
core: { notifications, i18n, theme },
core: { notifications, ...startServices },
security: { userProfiles: userProfileApiClient },
toMountPoint: toMountPointUtility,
} = services;
Expand All @@ -86,7 +88,7 @@ export const UserProfilesKibanaProvider: FC<PropsWithChildren<UserProfilesKibana
notifications.toasts.addSuccess(
{
title,
text: text ? toMountPointUtility(text, { i18n, theme }) : undefined,
text: text ? toMountPointUtility(text, startServices) : undefined,
},
toastOptions
);
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-user-profile-components/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ export interface UserProfileAvatarData {

export type DarkModeValue = '' | 'dark' | 'light';

export type ContrastModeValue = '' | 'standard' | 'high';

/**
* User settings stored in the data object of the User Profile
*/
export interface UserSettingsData {
darkMode?: DarkModeValue;
contrastMode?: ContrastModeValue;
solutionNavOptOut?: boolean;
}

Expand Down
1 change: 1 addition & 0 deletions packages/kbn-user-profile-components/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@kbn/react-kibana-mount",
"@kbn/core-i18n-browser",
"@kbn/test-jest-helpers",
"@kbn/core-user-profile-browser",
],
"exclude": [
"target/**/*",
Expand Down
19 changes: 5 additions & 14 deletions x-pack/examples/triggers_actions_ui_example/public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface TriggersActionsUiExampleComponentParams {
docLinks: CoreStart['docLinks'];
i18n: CoreStart['i18n'];
theme: CoreStart['theme'];
userProfile: CoreStart['userProfile'];
settings: CoreStart['settings'];
history: ScopedHistory;
triggersActionsUi: TriggersAndActionsUIPublicPluginStart;
Expand All @@ -63,12 +64,11 @@ const TriggersActionsUiExampleApp = ({
notifications,
settings,
docLinks,
i18n,
theme,
data,
charts,
dataViews,
unifiedSearch,
...startServices
}: TriggersActionsUiExampleComponentParams) => {
return (
<Router history={history}>
Expand Down Expand Up @@ -193,15 +193,14 @@ const TriggersActionsUiExampleApp = ({
application,
notifications,
docLinks,
i18n,
theme,
charts,
data,
dataViews,
unifiedSearch,
settings,
ruleTypeRegistry: triggersActionsUi.ruleTypeRegistry,
actionTypeRegistry: triggersActionsUi.actionTypeRegistry,
...startServices,
}}
/>
</Page>
Expand All @@ -218,15 +217,14 @@ const TriggersActionsUiExampleApp = ({
application,
notifications,
docLinks,
theme,
i18n,
charts,
data,
dataViews,
unifiedSearch,
settings,
ruleTypeRegistry: triggersActionsUi.ruleTypeRegistry,
actionTypeRegistry: triggersActionsUi.actionTypeRegistry,
...startServices,
}}
/>
</Page>
Expand All @@ -245,7 +243,6 @@ export const renderApp = (
deps: TriggersActionsUiExamplePublicStartDeps,
{ appBasePath, element, history }: AppMountParameters
) => {
const { http, notifications, docLinks, application, i18n, theme, settings } = core;
const { triggersActionsUi } = deps;
const { ruleTypeRegistry, actionTypeRegistry } = triggersActionsUi;

Expand All @@ -263,19 +260,13 @@ export const renderApp = (
<IntlProvider locale="en">
<TriggersActionsUiExampleApp
history={history}
http={http}
notifications={notifications}
application={application}
docLinks={docLinks}
i18n={i18n}
theme={theme}
settings={settings}
triggersActionsUi={deps.triggersActionsUi}
data={deps.data}
charts={deps.charts}
dataViews={deps.dataViews}
dataViewsEditor={deps.dataViewsEditor}
unifiedSearch={deps.unifiedSearch}
{...core}
/>
</IntlProvider>
</QueryClientProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,11 @@ export const renderApp = ({
kibanaVersion: string;
}) => {
const { element, history } = mountParams;
const { i18n, theme } = core;

const queryClient = new QueryClient();

ReactDOM.render(
<KibanaRenderContextProvider i18n={i18n} theme={theme}>
<KibanaRenderContextProvider {...core}>
<KibanaContextProvider
services={{
...core,
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/cases/public/common/lib/kibana/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { CoreStart } from '@kbn/core/public';
import type { CasesUiConfigType } from '../../../../common/ui/types';
import type { CasesPublicStartDependencies } from '../../../types';

type GlobalServices = Pick<CoreStart, 'application' | 'http' | 'theme'> &
type GlobalServices = Pick<CoreStart, 'application' | 'http' | 'theme' | 'userProfile'> &
Pick<CasesPublicStartDependencies, 'serverless'>;

export class KibanaServices {
Expand All @@ -23,12 +23,12 @@ export class KibanaServices {
http,
serverless,
kibanaVersion,
theme,
...startServices
}: GlobalServices & {
kibanaVersion: string;
config: CasesUiConfigType;
}) {
this.services = { application, http, theme, serverless };
this.services = { application, http, serverless, ...startServices };
this.kibanaVersion = kibanaVersion;
this.config = config;
}
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/cases/public/common/mock/test_providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const TestProvidersComponent: React.FC<TestProviderProps> = ({
};

return (
<KibanaRenderContextProvider i18n={coreStart.i18n} theme={coreStart.theme}>
<KibanaRenderContextProvider {...coreStart}>
<KibanaContextProvider services={services}>
<MemoryRouter>
<CasesProvider value={casesProviderValue} queryClient={queryClient}>
Expand Down Expand Up @@ -178,7 +178,7 @@ export const createAppMockRenderer = ({
getFilesClient,
};
const AppWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => (
<KibanaRenderContextProvider i18n={coreStart.i18n} theme={coreStart.theme}>
<KibanaRenderContextProvider {...coreStart}>
<KibanaContextProvider services={services}>
<MemoryRouter>
<CasesProvider value={casesProviderValue} queryClient={queryClient}>
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/cases/public/common/use_cases_toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const getErrorMessage = (error: Error | ServerError): string => {

export const useCasesToast = () => {
const { appId } = useApplication();
const { application, i18n, theme } = useKibana().services;
const { application, i18n, theme, userProfile } = useKibana().services;
const { getUrlForApp, navigateToUrl } = application;

const toasts = useToasts();
Expand Down Expand Up @@ -148,13 +148,13 @@ export const useCasesToast = () => {
return toasts.addSuccess({
color: 'success',
iconType: 'check',
title: toMountPoint(<TruncatedText text={renderTitle} />, { i18n, theme }),
title: toMountPoint(<TruncatedText text={renderTitle} />, { i18n, theme, userProfile }),
text: toMountPoint(
<CaseToastSuccessContent
content={renderContent}
onViewCaseClick={url != null ? onViewCaseClick : undefined}
/>,
{ i18n, theme }
{ i18n, theme, userProfile }
),
});
},
Expand All @@ -177,7 +177,7 @@ export const useCasesToast = () => {
});
},
}),
[i18n, theme, appId, getUrlForApp, navigateToUrl, toasts]
[i18n, theme, userProfile, appId, getUrlForApp, navigateToUrl, toasts]
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ const ActionWrapperWithContext: React.FC<PropsWithChildren<Props>> = ({
casesActionContextProps,
currentAppId,
}) => {
const { application, i18n, theme } = useKibana().services;
const { application, ...startServices } = useKibana().services;

const owner = getCaseOwnerByAppId(currentAppId);
const casePermissions = canUseCases(application.capabilities)(owner ? [owner] : undefined);
// TODO: Remove when https://github.com/elastic/kibana/issues/143201 is developed
const syncAlerts = owner === SECURITY_SOLUTION_OWNER;

return (
<KibanaRenderContextProvider i18n={i18n} theme={theme}>
<KibanaRenderContextProvider {...startServices}>
<CasesProvider
value={{
...casesActionContextProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function openModal(
>
<AddExistingCaseModalWrapper lensApi={lensApi} onClose={onClose} onSuccess={onSuccess} />
</ActionWrapper>,
{ i18n: services.core.i18n, theme: services.core.theme }
services.core
);

mount(targetDomElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe('useUserProfileForm', () => {
"initials": "fn",
},
"userSettings": Object {
"contrastMode": "standard",
"darkMode": "",
},
},
Expand Down
Loading

0 comments on commit 7df939a

Please sign in to comment.