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

Remove react references from core OverlayService apis #48431

Merged
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
bb08083
move/rename overlay mount and unmount types from banner to parent module
pgayvallet Oct 15, 2019
0dccba9
migrate openModal / modalService
pgayvallet Oct 16, 2019
d6c6bd5
migrate openFlyout / flyout service
pgayvallet Oct 17, 2019
dd2e3d3
remove CoreStart export from kibana-react
pgayvallet Oct 23, 2019
390503b
adapt some calls to new signature
pgayvallet Oct 23, 2019
052e39d
updates core doc
pgayvallet Oct 17, 2019
6a38024
adapt new calls
pgayvallet Oct 24, 2019
cf6f965
adapt js call
pgayvallet Oct 24, 2019
f47fc6d
add flex layout on mountWrapper component to avoid losing scroll on o…
pgayvallet Oct 24, 2019
bb1c085
create proper flyout/modal services
pgayvallet Oct 24, 2019
7132dbd
update generated doc
pgayvallet Oct 24, 2019
f6f4fbe
update snapshot on data/query_bar
pgayvallet Oct 24, 2019
34ecb11
use ReactNode instead of ReactElement
pgayvallet Oct 28, 2019
e55d9c0
rename mountForComponent to reactMount
pgayvallet Oct 28, 2019
cfaf20e
Merge remote-tracking branch 'upstream/master' into kbn-37894-NP-agno…
pgayvallet Oct 28, 2019
2cfde6e
Merge remote-tracking branch 'upstream/master' into kbn-37894-NP-agno…
pgayvallet Oct 28, 2019
0053270
Merge remote-tracking branch 'upstream/master' into kbn-37894-NP-agno…
pgayvallet Nov 18, 2019
78b5378
change reactMount usages to toMountPoint
pgayvallet Nov 18, 2019
db390cb
remove duplicate MountPoint type in overlays
pgayvallet Nov 18, 2019
f08fdfe
remove duplicate mount utilities from overlays
pgayvallet Nov 18, 2019
892bcde
allow to specify custom class name to MountWrapper
pgayvallet Nov 18, 2019
25c332f
Allow to specialize MountPoint on HTMLElement subtypes
pgayvallet Nov 18, 2019
d64f550
updates generated doc
pgayvallet Nov 18, 2019
e26120b
undeprecates openFlyout/openModal & remove direct subservice access f…
pgayvallet Nov 18, 2019
3ac8feb
adapt toast api to get i18n context from service
pgayvallet Nov 19, 2019
54916e9
use MountPoint instead of inline definition
pgayvallet Nov 19, 2019
0ae0157
Merge remote-tracking branch 'upstream/master' into kbn-37894-NP-agno…
pgayvallet Nov 19, 2019
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 @@ -9,5 +9,5 @@ A function that should mount DOM content inside the provided container element a
<b>Signature:</b>

```typescript
export declare type MountPoint = (element: HTMLElement) => UnmountCallback;
export declare type MountPoint<T extends HTMLElement = HTMLElement> = (element: T) => UnmountCallback;
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export interface OverlayStart
| Property | Type | Description |
| --- | --- | --- |
| [banners](./kibana-plugin-public.overlaystart.banners.md) | <code>OverlayBannersStart</code> | [OverlayBannersStart](./kibana-plugin-public.overlaybannersstart.md) |
| [openFlyout](./kibana-plugin-public.overlaystart.openflyout.md) | <code>(flyoutChildren: React.ReactNode, flyoutProps?: {</code><br/><code> closeButtonAriaLabel?: string;</code><br/><code> 'data-test-subj'?: string;</code><br/><code> }) =&gt; OverlayRef</code> | |
| [openModal](./kibana-plugin-public.overlaystart.openmodal.md) | <code>(modalChildren: React.ReactNode, modalProps?: {</code><br/><code> className?: string;</code><br/><code> closeButtonAriaLabel?: string;</code><br/><code> 'data-test-subj'?: string;</code><br/><code> }) =&gt; OverlayRef</code> | |
| [openFlyout](./kibana-plugin-public.overlaystart.openflyout.md) | <code>OverlayFlyoutStart['open']</code> | |
| [openModal](./kibana-plugin-public.overlaystart.openmodal.md) | <code>OverlayModalStart['open']</code> | |

Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

## OverlayStart.openFlyout property


<b>Signature:</b>

```typescript
openFlyout: (flyoutChildren: React.ReactNode, flyoutProps?: {
closeButtonAriaLabel?: string;
'data-test-subj'?: string;
}) => OverlayRef;
openFlyout: OverlayFlyoutStart['open'];
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@

## OverlayStart.openModal property


<b>Signature:</b>

```typescript
openModal: (modalChildren: React.ReactNode, modalProps?: {
className?: string;
closeButtonAriaLabel?: string;
'data-test-subj'?: string;
}) => OverlayRef;
openModal: OverlayModalStart['open'];
```
55 changes: 33 additions & 22 deletions src/core/public/notifications/toasts/error_toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import React from 'react';
import ReactDOM from 'react-dom';

import {
EuiButton,
Expand All @@ -29,7 +30,7 @@ import {
EuiModalHeaderTitle,
} from '@elastic/eui';
import { EuiSpacer } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { FormattedMessage, I18nProvider } from '@kbn/i18n/react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point, this stateful import will probably go away. Can we pass this Provider down from the I18n service to future-proof this a bit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. However, the stateful import is also used in kibana_react'stoMountPoint

import { I18nProvider } from '@kbn/i18n/react';
import { MountPoint } from 'kibana/public';
/**
* MountPoint converter for react nodes.
*
* @param node to get a mount point for
*/
export const toMountPoint = (node: React.ReactNode): MountPoint => {
const mount = (element: HTMLElement) => {
ReactDOM.render(<I18nProvider>{node}</I18nProvider>, element);
return () => ReactDOM.unmountComponentAtNode(element);
};
// only used for tests and snapshots serialization
if (process.env.NODE_ENV !== 'production') {
mount.__reactMount__ = node;
}
return mount;
};

Should this be a concern?


import { OverlayStart } from '../../overlays';

Expand All @@ -40,6 +41,11 @@ interface ErrorToastProps {
openModal: OverlayStart['openModal'];
}

const mount = (component: React.ReactElement) => (element: HTMLElement) => {
ReactDOM.render(<I18nProvider>{component}</I18nProvider>, element);
return () => ReactDOM.unmountComponentAtNode(element);
};

/**
* This should instead be replaced by the overlay service once it's available.
* This does not use React portals so that if the parent toast times out, this modal
Expand All @@ -52,27 +58,32 @@ function showErrorDialog({
openModal,
}: Pick<ErrorToastProps, 'error' | 'title' | 'openModal'>) {
const modal = openModal(
<React.Fragment>
<EuiModalHeader>
<EuiModalHeaderTitle>{title}</EuiModalHeaderTitle>
</EuiModalHeader>
<EuiModalBody>
<EuiCallOut size="s" color="danger" iconType="alert" title={error.message} />
{error.stack && (
<React.Fragment>
<EuiSpacer size="s" />
<EuiCodeBlock isCopyable={true} paddingSize="s">
{error.stack}
</EuiCodeBlock>
</React.Fragment>
)}
</EuiModalBody>
<EuiModalFooter>
<EuiButton onClick={() => modal.close()} fill>
<FormattedMessage id="core.notifications.errorToast.closeModal" defaultMessage="Close" />
</EuiButton>
</EuiModalFooter>
</React.Fragment>
mount(
<React.Fragment>
<EuiModalHeader>
<EuiModalHeaderTitle>{title}</EuiModalHeaderTitle>
</EuiModalHeader>
<EuiModalBody>
<EuiCallOut size="s" color="danger" iconType="alert" title={error.message} />
{error.stack && (
<React.Fragment>
<EuiSpacer size="s" />
<EuiCodeBlock isCopyable={true} paddingSize="s">
{error.stack}
</EuiCodeBlock>
</React.Fragment>
)}
</EuiModalBody>
<EuiModalFooter>
<EuiButton onClick={() => modal.close()} fill>
<FormattedMessage
id="core.notifications.errorToast.closeModal"
defaultMessage="Close"
/>
</EuiButton>
</EuiModalFooter>
</React.Fragment>
)
);
}

Expand Down
70 changes: 0 additions & 70 deletions src/core/public/overlays/__snapshots__/flyout.test.tsx.snap

This file was deleted.

64 changes: 0 additions & 64 deletions src/core/public/overlays/__snapshots__/modal.test.tsx.snap

This file was deleted.

1 change: 1 addition & 0 deletions src/core/public/overlays/_index.scss
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@import './banners/index';
@import './mount_wrapper';
5 changes: 5 additions & 0 deletions src/core/public/overlays/_mount_wrapper.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.kbnOverlayMountWrapper {
display: flex;
flex-direction: column;
height: 100%;
}
4 changes: 0 additions & 4 deletions src/core/public/overlays/banners/banners_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,16 @@ export class OverlayBannersService {
if (!banners$.value.has(id)) {
return false;
}

banners$.next(banners$.value.remove(id));

return true;
},

replace(id: string | undefined, mount: MountPoint, priority = 0) {
if (!id || !banners$.value.has(id)) {
return this.add(mount, priority);
}

const nextId = genId();
const nextBanner = { id: nextId, mount, priority };

banners$.next(banners$.value.remove(id).add(nextId, nextBanner));
return nextId;
},
Expand Down

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

Loading