Skip to content

Commit

Permalink
fix 'Save modal dark theme issues in Discover, Dashboard, and Maps' (#…
Browse files Browse the repository at this point in the history
…149147)

Fixes #149130 and
#142636

PR updates `showSaveModal` to wrap modal in `KibanaThemeProvider` to
resolve dark theme issues. Rather than passing in theme$ as a new
parameter, theme$ is imported from within the plugin itself.

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
nreese and kibanamachine authored Jan 19, 2023
1 parent ff5101d commit d5f6fe8
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export function runSaveAs(this: DashboardContainer) {
timefilter: { timefilter },
},
},
coreContext: { i18nContext },
savedObjectsTagging: { hasApi: hasSavedObjectsTagging },
dashboardSavedObject: { checkForDuplicateDashboardTitle, saveDashboardStateToSavedObject },
} = pluginServices.getServices();
Expand Down Expand Up @@ -125,7 +124,7 @@ export function runSaveAs(this: DashboardContainer) {
/>
);
this.clearOverlays();
showSaveModal(dashboardSaveModal, i18nContext);
showSaveModal(dashboardSaveModal);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export async function onSaveSearch({
onClose={onClose ?? (() => {})}
/>
);
showSaveModal(saveModal, services.core.i18n.Context);
showSaveModal(saveModal);
}

const SaveSearchObjectModal: React.FC<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ export const mockAttributeService = <
const core = customCore ? customCore : coreMock.createStart();
return new AttributeService<A, V, R, M>(
type,
jest.fn(),
core.i18n.Context,
core.notifications.toasts,
options,
jest.fn().mockReturnValue(() => ({ getDisplayName: () => type }))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
import React from 'react';
import { i18n } from '@kbn/i18n';
import { get, omit } from 'lodash';
import { I18nStart, NotificationsStart } from '@kbn/core/public';
import { SavedObjectSaveModal, OnSaveProps, SaveResult } from '@kbn/saved-objects-plugin/public';
import { NotificationsStart } from '@kbn/core/public';
import {
SavedObjectSaveModal,
OnSaveProps,
SaveResult,
showSaveModal,
} from '@kbn/saved-objects-plugin/public';
import {
EmbeddableInput,
SavedObjectEmbeddableInput,
Expand Down Expand Up @@ -61,11 +66,6 @@ export class AttributeService<
> {
constructor(
private type: string,
private showSaveModal: (
saveModal: React.ReactElement,
I18nContext: I18nStart['Context']
) => void,
private i18nContext: I18nStart['Context'],
private toasts: NotificationsStart['toasts'],
private options: AttributeServiceOptions<SavedObjectAttributes, MetaInfo>,
getEmbeddableFactory?: (embeddableFactoryId: string) => EmbeddableFactory
Expand Down Expand Up @@ -178,7 +178,7 @@ export class AttributeService<
}
};
if (saveOptions && (saveOptions as { showSaveModal: boolean }).showSaveModal) {
this.showSaveModal(
showSaveModal(
<SavedObjectSaveModal
onSave={onSave}
onClose={() => {}}
Expand All @@ -190,8 +190,7 @@ export class AttributeService<
showCopyOnSave={false}
objectType={this.type}
showDescription={false}
/>,
this.i18nContext
/>
);
}
});
Expand Down
11 changes: 2 additions & 9 deletions src/plugins/embeddable/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React from 'react';
import { Subscription } from 'rxjs';
import { identity } from 'lodash';
import type { SerializableRecord } from '@kbn/utility-types';
import { getSavedObjectFinder, showSaveModal } from '@kbn/saved-objects-plugin/public';
import { getSavedObjectFinder } from '@kbn/saved-objects-plugin/public';
import { UiActionsSetup, UiActionsStart } from '@kbn/ui-actions-plugin/public';
import { Start as InspectorStart } from '@kbn/inspector-plugin/public';
import {
Expand Down Expand Up @@ -211,14 +211,7 @@ export class EmbeddablePublicPlugin implements Plugin<EmbeddableSetup, Embeddabl
getEmbeddableFactory: this.getEmbeddableFactory,
getEmbeddableFactories: this.getEmbeddableFactories,
getAttributeService: (type: string, options) =>
new AttributeService(
type,
showSaveModal,
core.i18n.Context,
core.notifications.toasts,
options,
this.getEmbeddableFactory
),
new AttributeService(type, core.notifications.toasts, options, this.getEmbeddableFactory),
getStateTransfer: (storage?: Storage) =>
storage
? new EmbeddableStateTransfer(
Expand Down
17 changes: 17 additions & 0 deletions src/plugins/saved_objects/public/kibana_services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { CoreStart } from '@kbn/core/public';

let coreStart: CoreStart;
export function setStartServices(core: CoreStart) {
coreStart = core;
}

export const getI18n = () => coreStart.i18n;
export const getTheme = () => coreStart.theme;
2 changes: 2 additions & 0 deletions src/plugins/saved_objects/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from './saved_object';
import { PER_PAGE_SETTING, LISTING_LIMIT_SETTING } from '../common';
import { SavedObject } from './types';
import { setStartServices } from './kibana_services';

export interface SavedObjectSetup {
registerDecorator: (config: SavedObjectDecoratorConfig<any>) => void;
Expand Down Expand Up @@ -63,6 +64,7 @@ export class SavedObjectsPublicPlugin
};
}
public start(core: CoreStart, { data, dataViews }: SavedObjectsStartDeps) {
setStartServices(core);
return {
SavedObjectClass: createSavedObjectClass(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import React from 'react';
import ReactDOM from 'react-dom';

import { I18nStart } from '@kbn/core/public';
import { KibanaThemeProvider } from '@kbn/kibana-react-plugin/public';
import { getI18n, getTheme } from '../kibana_services';

/**
* Represents the result of trying to persist the saved object.
Expand All @@ -31,7 +32,6 @@ interface MinimalSaveModalProps {

export function showSaveModal(
saveModal: React.ReactElement<MinimalSaveModalProps>,
I18nContext: I18nStart['Context'],
Wrapper?: React.FC
) {
const container = document.createElement('div');
Expand All @@ -57,13 +57,11 @@ export function showSaveModal(
onClose: closeModal,
});

const wrappedElement = Wrapper ? (
<I18nContext>
<Wrapper>{element}</Wrapper>
</I18nContext>
) : (
<I18nContext>{element}</I18nContext>
const I18nContext = getI18n().Context;
ReactDOM.render(
<KibanaThemeProvider theme$={getTheme().theme$}>
<I18nContext>{Wrapper ? <Wrapper>{element}</Wrapper> : element}</I18nContext>
</KibanaThemeProvider>,
container
);

ReactDOM.render(wrappedElement, container);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { parse } from 'query-string';

import { Capabilities } from '@kbn/core/public';
import { TopNavMenuData } from '@kbn/navigation-plugin/public';
import { KibanaThemeProvider } from '@kbn/kibana-react-plugin/public';
import {
showSaveModal,
SavedObjectSaveModalOrigin,
Expand Down Expand Up @@ -598,18 +597,7 @@ export const getTopNavConfig = (
);
}

const WrapperComponent = ({ children }: { children?: React.ReactNode }) => {
const ContextProvider = !originatingApp
? presentationUtil.ContextProvider
: React.Fragment;
return (
<KibanaThemeProvider theme$={theme.theme$}>
<ContextProvider>{children}</ContextProvider>
</KibanaThemeProvider>
);
};

showSaveModal(saveModal, I18nContext, WrapperComponent);
showSaveModal(saveModal, presentationUtil.ContextProvider);
},
},
]
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/graph/public/apps/workspace_route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { I18nProvider } from '@kbn/i18n-react';
import { Provider } from 'react-redux';
import { useHistory } from 'react-router-dom';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { showSaveModal } from '@kbn/saved-objects-plugin/public';
import { Workspace } from '../types';
import { createGraphStore } from '../state_management';
import { createWorkspace } from '../services/workspace/graph_client_workspace';
Expand Down Expand Up @@ -108,12 +107,10 @@ export const WorkspaceRoute = ({
http: coreStart.http,
overlays: coreStart.overlays,
savedObjectsClient,
showSaveModal,
savePolicy: graphSavePolicy,
changeUrl: (newUrl) => history.push(newUrl),
notifyReact: () => setRenderCounter((cur) => cur + 1),
chrome,
I18nContext: coreStart.i18n.Context,
handleSearchQueryError,
})
);
Expand Down
12 changes: 4 additions & 8 deletions x-pack/plugins/graph/public/services/save_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
* 2.0.
*/

import React, { ReactElement } from 'react';
import { I18nStart, OverlayStart, SavedObjectsClientContract } from '@kbn/core/public';
import React from 'react';
import { OverlayStart, SavedObjectsClientContract } from '@kbn/core/public';
import { SaveResult } from '@kbn/saved-objects-plugin/public';
import { showSaveModal } from '@kbn/saved-objects-plugin/public';
import { GraphWorkspaceSavedObject, GraphSavePolicy } from '../types';
import { SaveModal, OnSaveGraphProps } from '../components/save_modal';

Expand All @@ -31,16 +32,12 @@ export function openSaveModal({
hasData,
workspace,
saveWorkspace,
showSaveModal,
I18nContext,
services,
}: {
savePolicy: GraphSavePolicy;
hasData: boolean;
workspace: GraphWorkspaceSavedObject;
saveWorkspace: SaveWorkspaceHandler;
showSaveModal: (el: ReactElement, I18nContext: I18nStart['Context']) => void;
I18nContext: I18nStart['Context'];
services: SaveWorkspaceServices;
}) {
const currentTitle = workspace.title;
Expand Down Expand Up @@ -79,7 +76,6 @@ export function openSaveModal({
title={workspace.title}
description={workspace.description}
showCopyOnSave={Boolean(workspace.id)}
/>,
I18nContext
/>
);
}
4 changes: 0 additions & 4 deletions x-pack/plugins/graph/public/state_management/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ export function createMockGraphStore({
return { id: '123', title: 'test-pattern' } as unknown as DataView;
}),
},
I18nContext: jest
.fn()
.mockImplementation(({ children }: { children: React.ReactNode }) => children),
notifications: {
toasts: {
addDanger: jest.fn(),
Expand All @@ -78,7 +75,6 @@ export function createMockGraphStore({
http: {} as HttpStart,
notifyReact: jest.fn(),
savePolicy: 'configAndData',
showSaveModal: jest.fn(),
overlays: {
openModal: jest.fn(),
} as unknown as OverlayStart,
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/graph/public/state_management/persistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ function showModal(
savePolicy: deps.savePolicy,
hasData: workspace.nodes.length > 0 || workspace.blocklistedNodes.length > 0,
workspace: savedWorkspace,
showSaveModal: deps.showSaveModal,
saveWorkspace: saveWorkspaceHandler,
I18nContext: deps.I18nContext,
services: {
savedObjectsClient: deps.savedObjectsClient,
overlays: deps.overlays,
Expand Down
5 changes: 1 addition & 4 deletions x-pack/plugins/graph/public/state_management/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

import createSagaMiddleware, { SagaMiddleware } from 'redux-saga';
import { combineReducers, createStore, Store, AnyAction, Dispatch, applyMiddleware } from 'redux';
import { ChromeStart, I18nStart, OverlayStart, SavedObjectsClientContract } from '@kbn/core/public';
import { ChromeStart, OverlayStart, SavedObjectsClientContract } from '@kbn/core/public';
import { CoreStart } from '@kbn/core/public';
import { ReactElement } from 'react';
import {
fieldsReducer,
FieldsState,
Expand Down Expand Up @@ -48,12 +47,10 @@ export interface GraphStoreDependencies {
http: CoreStart['http'];
overlays: OverlayStart;
savedObjectsClient: SavedObjectsClientContract;
showSaveModal: (el: ReactElement, I18nContext: I18nStart['Context']) => void;
savePolicy: GraphSavePolicy;
changeUrl: (newUrl: string) => void;
notifyReact: () => void;
chrome: ChromeStart;
I18nContext: I18nStart['Context'];
basePath: string;
handleSearchQueryError: (err: Error | string) => void;
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/lens/public/embeddable/embeddable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const attributeServiceMockFromSavedVis = (document: Document): LensAttributeServ
LensByValueInput,
LensByReferenceInput,
LensUnwrapMetaInfo
>('lens', jest.fn(), core.i18n.Context, core.notifications.toasts, options);
>('lens', core.notifications.toasts, options);
service.unwrapAttributes = jest.fn((input: LensByValueInput | LensByReferenceInput) => {
return Promise.resolve({
attributes: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
getMapsCapabilities,
getIsAllowByValueEmbeddables,
getInspector,
getCoreI18n,
getSavedObjectsClient,
getCoreOverlays,
getSavedObjectsTagging,
Expand Down Expand Up @@ -249,7 +248,7 @@ export function getTopNavConfig({
);
}

showSaveModal(saveModal, getCoreI18n().Context, PresentationUtilContext);
showSaveModal(saveModal, PresentationUtilContext);
},
});

Expand Down

0 comments on commit d5f6fe8

Please sign in to comment.