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

add KibanaThemeProvider support for kibana-app-services #122370

Merged
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 @@ -41,6 +41,7 @@ import { uiActionsPluginMock } from '../../../../ui_actions/public/mocks';
import { getStubPluginServices } from '../../../../presentation_util/public';

const presentationUtil = getStubPluginServices();
const theme = coreMock.createStart().theme;

const options: DashboardContainerServices = {
// TODO: clean up use of any
Expand All @@ -55,7 +56,7 @@ const options: DashboardContainerServices = {
uiActions: {} as any,
uiSettings: uiSettingsServiceMock.createStartContract(),
http: coreMock.createStart().http,
theme: coreMock.createStart().theme,
theme,
presentationUtil,
};

Expand Down Expand Up @@ -251,6 +252,7 @@ test('DashboardContainer in edit mode shows edit mode actions', async () => {
overlays={{} as any}
inspector={inspector}
SavedObjectFinder={() => null}
theme={theme}
/>
</presentationUtil.ContextProvider>
</KibanaContextProvider>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ export const DashboardListing = ({
listingLimit,
tableColumns,
}}
theme={core.theme}
>
<DashboardUnsavedListing
redirectTo={redirectTo}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export function DashboardTopNav({
overlays: core.overlays,
SavedObjectFinder: getSavedObjectFinder(core.savedObjects, uiSettings),
reportUiCounter: usageCollection?.reportUiCounter,
theme: core.theme,
}),
}));
}
Expand All @@ -171,6 +172,7 @@ export function DashboardTopNav({
core.notifications,
core.savedObjects,
core.overlays,
core.theme,
uiSettings,
usageCollection,
]);
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/data/public/actions/apply_filter_action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { i18n } from '@kbn/i18n';
import { ThemeServiceSetup } from 'kibana/public';
import { toMountPoint } from '../../../kibana_react/public';
import { Action, createAction, IncompatibleActionError } from '../../../ui_actions/public';
import { getOverlays, getIndexPatterns } from '../services';
Expand All @@ -32,7 +33,8 @@ async function isCompatible(context: ApplyGlobalFilterActionContext) {

export function createFilterAction(
filterManager: FilterManager,
timeFilter: TimefilterContract
timeFilter: TimefilterContract,
theme: ThemeServiceSetup
): Action {
return createAction({
type: ACTION_GLOBAL_APPLY_FILTER,
Expand Down Expand Up @@ -77,7 +79,8 @@ export function createFilterAction(
overlay.close();
resolve(filterSelection);
}
)
),
{ theme$: theme.theme$ }
),
{
'data-test-subj': 'test',
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
setOverlays,
setSearchService,
setUiSettings,
setTheme,
} from './services';
import { createSearchBar } from './ui/search_bar/create_search_bar';
import {
Expand Down Expand Up @@ -82,6 +83,7 @@ export class DataPublicPlugin
const startServices = createStartServicesGetter(core.getStartServices);

this.usageCollection = usageCollection;
setTheme(core.theme);

const searchService = this.searchService.setup(core, {
bfetch,
Expand All @@ -98,7 +100,7 @@ export class DataPublicPlugin

uiActions.registerTrigger(applyFilterTrigger);
uiActions.registerAction(
createFilterAction(queryService.filterManager, queryService.timefilter.timefilter)
createFilterAction(queryService.filterManager, queryService.timefilter.timefilter, core.theme)
);

inspector.registerView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { handleResponse } from './handle_response';
import { notificationServiceMock } from '../../../../../core/public/notifications/notifications_service.mock';
import { setNotifications } from '../../services';
import { IKibanaSearchResponse } from 'src/plugins/data/common';
import { themeServiceMock } from 'src/core/public/mocks';

jest.mock('@kbn/i18n', () => {
return {
Expand All @@ -22,6 +23,8 @@ jest.mock('@kbn/i18n', () => {
};
});

const theme = themeServiceMock.createStartContract();

describe('handleResponse', () => {
const notifications = notificationServiceMock.createStartContract();

Expand All @@ -37,7 +40,7 @@ describe('handleResponse', () => {
timed_out: true,
},
} as IKibanaSearchResponse<any>;
const result = handleResponse(request, response);
const result = handleResponse(request, response, theme);
expect(result).toBe(response);
expect(notifications.toasts.addWarning).toBeCalled();
expect((notifications.toasts.addWarning as jest.Mock).mock.calls[0][0].title).toMatch(
Expand All @@ -57,7 +60,7 @@ describe('handleResponse', () => {
},
},
} as IKibanaSearchResponse<any>;
const result = handleResponse(request, response);
const result = handleResponse(request, response, theme);
expect(result).toBe(response);
expect(notifications.toasts.addWarning).toBeCalled();
expect((notifications.toasts.addWarning as jest.Mock).mock.calls[0][0].title).toMatch(
Expand All @@ -70,7 +73,7 @@ describe('handleResponse', () => {
const response = {
rawResponse: {},
} as IKibanaSearchResponse<any>;
const result = handleResponse(request, response);
const result = handleResponse(request, response, theme);
expect(result).toBe(response);
});
});
17 changes: 14 additions & 3 deletions src/plugins/data/public/search/fetch/handle_response.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ import { i18n } from '@kbn/i18n';
import { EuiSpacer } from '@elastic/eui';
import { IKibanaSearchResponse } from 'src/plugins/data/common';
import { ShardFailureOpenModalButton } from '../../ui/shard_failure_modal';
import { ThemeServiceStart } from '../../../../../core/public';
import { toMountPoint } from '../../../../kibana_react/public';
import { getNotifications } from '../../services';
import type { SearchRequest } from '..';

export function handleResponse(request: SearchRequest, response: IKibanaSearchResponse) {
export function handleResponse(
request: SearchRequest,
response: IKibanaSearchResponse,
theme: ThemeServiceStart
) {
const { rawResponse } = response;

if (rawResponse.timed_out) {
Expand Down Expand Up @@ -45,8 +50,14 @@ export function handleResponse(request: SearchRequest, response: IKibanaSearchRe
<>
{description}
<EuiSpacer size="s" />
<ShardFailureOpenModalButton request={request.body} response={rawResponse} title={title} />
</>
<ShardFailureOpenModalButton
request={request.body}
response={rawResponse}
theme={theme}
title={title}
/>
</>,
{ theme$: theme.theme$ }
);

getNotifications().toasts.addWarning({ title, text });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import type { MockedKeys } from '@kbn/utility-types/jest';
import { CoreSetup, CoreStart } from '../../../../../core/public';
import { coreMock } from '../../../../../core/public/mocks';
import { coreMock, themeServiceMock } from '../../../../../core/public/mocks';
import { IEsSearchRequest } from '../../../common/search';
import { SearchInterceptor } from './search_interceptor';
import { AbortError } from '../../../../kibana_utils/public';
Expand Down Expand Up @@ -120,6 +120,7 @@ describe('SearchInterceptor', () => {
uiSettings: mockCoreSetup.uiSettings,
http: mockCoreSetup.http,
session: sessionService,
theme: themeServiceMock.createSetupContract(),
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
tap,
} from 'rxjs/operators';
import { PublicMethodsOf } from '@kbn/utility-types';
import { CoreSetup, CoreStart, ToastsSetup } from 'kibana/public';
import { CoreSetup, CoreStart, ThemeServiceSetup, ToastsSetup } from 'kibana/public';
import { i18n } from '@kbn/i18n';
import { BatchedFunc, BfetchPublicSetup } from 'src/plugins/bfetch/public';
import {
Expand Down Expand Up @@ -60,6 +60,7 @@ export interface SearchInterceptorDeps {
toasts: ToastsSetup;
usageCollector?: SearchUsageCollector;
session: ISessionService;
theme: ThemeServiceSetup;
}

const MAX_CACHE_ITEMS = 50;
Expand Down Expand Up @@ -377,7 +378,7 @@ export class SearchInterceptor {
private showTimeoutErrorToast = (e: SearchTimeoutError, sessionId?: string) => {
this.deps.toasts.addDanger({
title: 'Timed out',
text: toMountPoint(e.getErrorMessage(this.application)),
text: toMountPoint(e.getErrorMessage(this.application), { theme$: this.deps.theme.theme$ }),
});
};

Expand All @@ -392,7 +393,9 @@ export class SearchInterceptor {
this.deps.toasts.addWarning(
{
title: 'Your search session is still running',
text: toMountPoint(SearchSessionIncompleteWarning(this.docLinks)),
text: toMountPoint(SearchSessionIncompleteWarning(this.docLinks), {
theme$: this.deps.theme.theme$,
}),
},
{
toastLifeTimeMs: 60000,
Expand Down Expand Up @@ -423,14 +426,14 @@ export class SearchInterceptor {
title: i18n.translate('data.search.esErrorTitle', {
defaultMessage: 'Cannot retrieve search results',
}),
text: toMountPoint(e.getErrorMessage(this.application)),
text: toMountPoint(e.getErrorMessage(this.application), { theme$: this.deps.theme.theme$ }),
});
} else if (e.constructor.name === 'HttpFetchError') {
this.deps.toasts.addDanger({
title: i18n.translate('data.search.httpErrorTitle', {
defaultMessage: 'Cannot retrieve your data',
}),
text: toMountPoint(getHttpError(e.message)),
text: toMountPoint(getHttpError(e.message), { theme$: this.deps.theme.theme$ }),
});
} else {
this.deps.toasts.addError(e, {
Expand Down
Loading