Skip to content

Commit

Permalink
Preparation for High Contrast Mode, ResponseOps domains
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Dec 5, 2024
1 parent 6178e82 commit 0c7a693
Show file tree
Hide file tree
Showing 26 changed files with 70 additions and 66 deletions.
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 @@ -34,6 +34,7 @@
"@kbn/alerts-as-data-utils",
"@kbn/core-http-browser-mocks",
"@kbn/core-notifications-browser-mocks",
"@kbn/shared-ux-table-persist"
"@kbn/shared-ux-table-persist",
"@kbn/core-user-profile-browser"
]
}
4 changes: 2 additions & 2 deletions packages/response-ops/rule_form/src/create_rule_form.tsx
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
4 changes: 2 additions & 2 deletions packages/response-ops/rule_form/src/edit_rule_form.tsx
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/response-ops/rule_form/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type { HttpStart } from '@kbn/core-http-browser';
import type { I18nStart } from '@kbn/core-i18n-browser';
import type { NotificationsStart } from '@kbn/core-notifications-browser';
import type { ThemeServiceStart } from '@kbn/core-theme-browser';
import type { UserProfileService } from '@kbn/core-user-profile-browser';
import type { SettingsStart } from '@kbn/core-ui-settings-browser';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
Expand Down Expand Up @@ -54,6 +55,7 @@ export interface RuleFormPlugins {
http: HttpStart;
i18n: I18nStart;
theme: ThemeServiceStart;
userProfile: UserProfileService;
application: ApplicationStart;
notifications: NotificationsStart;
charts: ChartsPluginSetup;
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
4 changes: 3 additions & 1 deletion x-pack/plugins/triggers_actions_ui/.storybook/decorator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const notifications: NotificationsStart = {
showErrorDialog: () => {},
};

const userProfile = { getUserProfile$: () => of(null) };

export const StorybookContextDecorator: FC<PropsWithChildren<StorybookContextDecoratorProps>> = (
props
) => {
Expand All @@ -75,7 +77,7 @@ export const StorybookContextDecorator: FC<PropsWithChildren<StorybookContextDec
return (
<I18nProvider>
<EuiThemeProvider darkMode={darkMode}>
<KibanaThemeProvider theme$={EMPTY}>
<KibanaThemeProvider theme$={EMPTY} userProfile={userProfile}>
<KibanaContextProvider
services={{
notifications,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export const renderApp = (deps: TriggersAndActionsUiServices) => {
};

export const App = ({ deps }: { deps: TriggersAndActionsUiServices }) => {
const { dataViews, i18n, theme } = deps;
const { dataViews } = deps;

setDataViewsService(dataViews);
return (
<KibanaRenderContextProvider i18n={i18n} theme={theme}>
<KibanaRenderContextProvider {...deps}>
<KibanaContextProvider services={{ ...deps }}>
<Router history={deps.history}>
<Routes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ export const renderApp = (deps: TriggersAndActionsUiServices) => {
};

export const App = ({ deps }: { deps: TriggersAndActionsUiServices }) => {
const { dataViews, i18n, theme } = deps;
const { dataViews } = deps;
const sections: Section[] = ['connectors', 'logs'];
const sectionsRegex = sections.join('|');

setDataViewsService(dataViews);
return (
<KibanaRenderContextProvider i18n={i18n} theme={theme}>
<KibanaRenderContextProvider {...deps}>
<KibanaContextProvider services={{ ...deps }}>
<Router history={deps.history}>
<QueryClientProvider client={queryClient}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export function useBulkEditResponse(props: UseBulkEditResponseProps) {
const {
i18n: i18nStart,
theme,
userProfile,
notifications: { toasts },
} = useKibana().services;

Expand Down Expand Up @@ -124,18 +125,22 @@ export function useBulkEditResponse(props: UseBulkEditResponseProps) {
if (numberOfErrors === total) {
toasts.addDanger({
title: failureMessage(numberOfErrors, translationMap[property]),
text: toMountPoint(renderToastErrorBody(response), { i18n: i18nStart, theme }),
text: toMountPoint(renderToastErrorBody(response), {
i18n: i18nStart,
theme,
userProfile,
}),
});
return;
}

// Some failure
toasts.addWarning({
title: someSuccessMessage(numberOfSuccess, numberOfErrors, translationMap[property]),
text: toMountPoint(renderToastErrorBody(response), { i18n: i18nStart, theme }),
text: toMountPoint(renderToastErrorBody(response), { i18n: i18nStart, theme, userProfile }),
});
},
[i18nStart, theme, toasts, renderToastErrorBody]
[i18nStart, theme, userProfile, toasts, renderToastErrorBody]
);

return useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const useBulkOperationToast = ({
const {
i18n,
theme,
userProfile,
notifications: { toasts },
} = useKibana().services;

Expand Down Expand Up @@ -122,7 +123,7 @@ export const useBulkOperationToast = ({
SINGLE_RULE_TITLE,
MULTIPLE_RULE_TITLE
),
text: toMountPoint(renderToastErrorBody(errors, 'danger'), { i18n, theme }),
text: toMountPoint(renderToastErrorBody(errors, 'danger'), { i18n, theme, userProfile }),
});
return;
}
Expand All @@ -135,10 +136,10 @@ export const useBulkOperationToast = ({
SINGLE_RULE_TITLE,
MULTIPLE_RULE_TITLE
),
text: toMountPoint(renderToastErrorBody(errors, 'warning'), { i18n, theme }),
text: toMountPoint(renderToastErrorBody(errors, 'warning'), { i18n, theme, userProfile }),
});
},
[i18n, theme, toasts, renderToastErrorBody]
[i18n, theme, userProfile, toasts, renderToastErrorBody]
);

return useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ export const renderApp = (deps: TriggersAndActionsUiServices) => {
};

export const App = ({ deps }: { deps: TriggersAndActionsUiServices }) => {
const { dataViews, i18n, theme } = deps;
const { dataViews } = deps;
const sections: Section[] = ['rules', 'logs'];

const sectionsRegex = sections.join('|');
setDataViewsService(dataViews);
return (
<KibanaRenderContextProvider i18n={i18n} theme={theme}>
<KibanaRenderContextProvider {...deps}>
<KibanaContextProvider services={{ ...deps }}>
<Router history={deps.history}>
<QueryClientProvider client={queryClient}>
Expand Down
Loading

0 comments on commit 0c7a693

Please sign in to comment.