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 use of injecti18n in Embeddables plugin #44043

Merged
merged 3 commits into from
Aug 31, 2019
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 @@ -100,7 +100,7 @@ test('renders DashboardGrid', () => {
</KibanaContextProvider>
);

const panelElements = component.find('EmbeddableChildPanelUi');
const panelElements = component.find('EmbeddableChildPanel');
expect(panelElements.length).toBe(2);
});

Expand All @@ -115,7 +115,7 @@ test('renders DashboardGrid with no visualizations', async () => {
props.container.updateInput({ panels: {} });
await nextTick();
component.update();
expect(component.find('InjectIntl(EmbeddableChildPanelUi)').length).toBe(0);
expect(component.find('EmbeddableChildPanel').length).toBe(0);
});

test('DashboardGrid removes panel when removed from container', async () => {
Expand All @@ -132,7 +132,7 @@ test('DashboardGrid removes panel when removed from container', async () => {
props.container.updateInput({ panels: filteredPanels });
await nextTick();
component.update();
const panelElements = component.find('InjectIntl(EmbeddableChildPanelUi)');
const panelElements = component.find('EmbeddableChildPanel');
expect(panelElements.length).toBe(1);
});

Expand All @@ -148,7 +148,7 @@ test('DashboardGrid renders expanded panel', async () => {
await nextTick();
component.update();
// Both panels should still exist in the dom, so nothing needs to be re-fetched once minimized.
expect(component.find('InjectIntl(EmbeddableChildPanelUi)').length).toBe(2);
expect(component.find('EmbeddableChildPanel').length).toBe(2);

expect(
(component.find('DashboardGridUi').state() as { expandedPanelId?: string }).expandedPanelId
Expand All @@ -157,7 +157,7 @@ test('DashboardGrid renders expanded panel', async () => {
props.container.updateInput({ expandedPanelId: undefined });
await nextTick();
component.update();
expect(component.find('InjectIntl(EmbeddableChildPanelUi)').length).toBe(2);
expect(component.find('EmbeddableChildPanel').length).toBe(2);

expect(
(component.find('DashboardGridUi').state() as { expandedPanelId?: string }).expandedPanelId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export {
EditPanelAction,
Embeddable,
EmbeddableChildPanel,
EmbeddableChildPanelUiProps,
EmbeddableChildPanelProps,
EmbeddableFactory,
EmbeddableFactoryNotFoundError,
EmbeddableInput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import React from 'react';
import { mountWithIntl, nextTick } from 'test_utils/enzyme_helpers';
import { nextTick } from 'test_utils/enzyme_helpers';
import { EmbeddableChildPanel } from './embeddable_child_panel';
import { GetEmbeddableFactory } from '../types';
import { EmbeddableFactory } from '../embeddables';
Expand All @@ -32,6 +32,7 @@ import {
} from '../test_samples/embeddables/contact_card/contact_card_embeddable';
// eslint-disable-next-line
import { inspectorPluginMock } from '../../../../../../../../plugins/inspector/public/mocks';
import { mount } from 'enzyme';

test('EmbeddableChildPanel renders an embeddable when it is done loading', async () => {
const inspector = inspectorPluginMock.createStartContract();
Expand All @@ -58,9 +59,8 @@ test('EmbeddableChildPanel renders an embeddable when it is done loading', async

expect(newEmbeddable.id).toBeDefined();

const component = mountWithIntl(
<EmbeddableChildPanel.WrappedComponent
intl={null as any}
const component = mount(
<EmbeddableChildPanel
container={container}
embeddableId={newEmbeddable.id}
getActions={() => Promise.resolve([])}
Expand Down Expand Up @@ -97,9 +97,8 @@ test(`EmbeddableChildPanel renders an error message if the factory doesn't exist
{ getEmbeddableFactory } as any
);

const component = mountWithIntl(
<EmbeddableChildPanel.WrappedComponent
intl={null as any}
const component = mount(
<EmbeddableChildPanel
container={container}
embeddableId={'1'}
getActions={() => Promise.resolve([])}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import classNames from 'classnames';
import React from 'react';

import { EuiLoadingChart } from '@elastic/eui';
import { InjectedIntl, injectI18n } from '@kbn/i18n/react';
import { Subscription } from 'rxjs';
import { CoreStart } from 'src/core/public';
import { ErrorEmbeddable, IEmbeddable } from '../embeddables';
Expand All @@ -34,8 +33,7 @@ import {
} from '../types';
import { Start as InspectorStartContract } from '../../../../../../../../plugins/inspector/public';

export interface EmbeddableChildPanelUiProps {
intl: InjectedIntl;
export interface EmbeddableChildPanelProps {
embeddableId: string;
className?: string;
container: IContainer;
Expand All @@ -57,13 +55,13 @@ interface State {
* for the child to be initialized, showing a loading indicator until that is complete.
*/

class EmbeddableChildPanelUi extends React.Component<EmbeddableChildPanelUiProps, State> {
export class EmbeddableChildPanel extends React.Component<EmbeddableChildPanelProps, State> {
[panel: string]: any;
public mounted: boolean;
public embeddable!: IEmbeddable | ErrorEmbeddable;
private subscription?: Subscription;

constructor(props: EmbeddableChildPanelUiProps) {
constructor(props: EmbeddableChildPanelProps) {
super(props);
this.state = {
loading: true,
Expand Down Expand Up @@ -114,5 +112,3 @@ class EmbeddableChildPanelUi extends React.Component<EmbeddableChildPanelUiProps
);
}
}

export const EmbeddableChildPanel = injectI18n(EmbeddableChildPanelUi);
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ import {
EuiModalBody,
EuiModalHeaderTitle,
} from '@elastic/eui';
import { injectI18n, FormattedMessage, InjectedIntl } from '@kbn/i18n/react';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { IEmbeddable } from '../../../../';

interface CustomizePanelProps {
embeddable: IEmbeddable;
updateTitle: (newTitle: string | undefined) => void;
intl: InjectedIntl;
}

interface State {
title: string | undefined;
hideTitle: boolean;
}

export class CustomizePanelModalUi extends Component<CustomizePanelProps, State> {
export class CustomizePanelModal extends Component<CustomizePanelProps, State> {
constructor(props: CustomizePanelProps) {
super(props);
this.state = {
Expand All @@ -53,23 +53,23 @@ export class CustomizePanelModalUi extends Component<CustomizePanelProps, State>
};
}

updateTitle = (title: string | undefined) => {
private updateTitle = (title: string | undefined) => {
// An empty string will mean "use the default value", which is represented by setting
// title to undefined (where as an empty string is actually used to indicate "hide title").
this.setState({ title: title === '' ? undefined : title });
};

reset = () => {
private reset = () => {
this.setState({ title: undefined });
};

onHideTitleToggle = () => {
private onHideTitleToggle = () => {
this.setState(prevState => ({
hideTitle: !prevState.hideTitle,
}));
};

save = () => {
private save = () => {
if (this.state.hideTitle) {
this.props.updateTitle('');
} else {
Expand All @@ -88,7 +88,6 @@ export class CustomizePanelModalUi extends Component<CustomizePanelProps, State>
</EuiModalHeader>

<EuiModalBody>
{' '}
<EuiFormRow>
<EuiSwitch
checked={!this.state.hideTitle}
Expand All @@ -104,10 +103,12 @@ export class CustomizePanelModalUi extends Component<CustomizePanelProps, State>
/>
</EuiFormRow>
<EuiFormRow
label={this.props.intl.formatMessage({
id: 'embeddableApi.customizePanel.modal.optionsMenuForm.panelTitleFormRowLabel',
defaultMessage: 'Panel title',
})}
label={i18n.translate(
'embeddableApi.customizePanel.modal.optionsMenuForm.panelTitleFormRowLabel',
{
defaultMessage: 'Panel title',
}
)}
>
<EuiFieldText
id="panelTitleInput"
Expand All @@ -118,10 +119,12 @@ export class CustomizePanelModalUi extends Component<CustomizePanelProps, State>
placeholder={this.props.embeddable.getOutput().defaultTitle}
value={this.state.title || ''}
onChange={e => this.updateTitle(e.target.value)}
aria-label={this.props.intl.formatMessage({
id: 'embeddableApi.customizePanel.modal.optionsMenuForm.panelTitleInputAriaLabel',
defaultMessage: 'Enter a custom title for your panel',
})}
aria-label={i18n.translate(
'embeddableApi.customizePanel.modal.optionsMenuForm.panelTitleInputAriaLabel',
{
defaultMessage: 'Enter a custom title for your panel',
}
)}
append={
<EuiButtonEmpty
data-test-subj="resetCustomEmbeddablePanelTitle"
Expand All @@ -141,7 +144,6 @@ export class CustomizePanelModalUi extends Component<CustomizePanelProps, State>
<EuiButtonEmpty
onClick={() => this.props.updateTitle(this.props.embeddable.getOutput().title)}
>
{' '}
<FormattedMessage
id="embeddableApi.customizePanel.modal.cancel"
defaultMessage="Cancel"
Expand All @@ -159,5 +161,3 @@ export class CustomizePanelModalUi extends Component<CustomizePanelProps, State>
);
}
}

export const CustomizePanelModal = injectI18n(CustomizePanelModalUi);
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,33 @@
import React, { ChangeEvent } from 'react';

import { EuiButtonEmpty, EuiFieldText, EuiFormRow } from '@elastic/eui';
import { FormattedMessage, InjectedIntl, injectI18n } from '@kbn/i18n/react';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';

export interface Props {
export interface PanelOptionsMenuFormProps {
title?: string;
onReset: () => void;
onUpdatePanelTitle: (newPanelTitle: string) => void;
}

interface PanelOptionsMenuFormUiProps extends Props {
intl: InjectedIntl;
}

function CustomizeTitleFormUi({
export function CustomizeTitleForm({
title,
onReset,
onUpdatePanelTitle,
intl,
}: PanelOptionsMenuFormUiProps) {
}: PanelOptionsMenuFormProps) {
function onInputChange(event: ChangeEvent<HTMLInputElement>) {
onUpdatePanelTitle(event.target.value);
}

return (
<div className="embPanel__optionsMenuForm" data-test-subj="dashboardPanelTitleInputMenuItem">
<EuiFormRow
label={intl.formatMessage({
id: 'embeddableApi.customizeTitle.optionsMenuForm.panelTitleFormRowLabel',
defaultMessage: 'Panel title',
})}
label={i18n.translate(
'embeddableApi.customizeTitle.optionsMenuForm.panelTitleFormRowLabel',
{
defaultMessage: 'Panel title',
}
)}
>
<EuiFieldText
id="panelTitleInput"
Expand All @@ -57,10 +55,12 @@ function CustomizeTitleFormUi({
type="text"
value={title}
onChange={onInputChange}
aria-label={intl.formatMessage({
id: 'embeddableApi.customizeTitle.optionsMenuForm.panelTitleInputAriaLabel',
defaultMessage: 'Changes to this input are applied immediately. Press enter to exit.',
})}
aria-label={i18n.translate(
'embeddableApi.customizeTitle.optionsMenuForm.panelTitleInputAriaLabel',
{
defaultMessage: 'Changes to this input are applied immediately. Press enter to exit.',
}
)}
/>
</EuiFormRow>

Expand All @@ -73,5 +73,3 @@ function CustomizeTitleFormUi({
</div>
);
}

export const CustomizeTitleForm = injectI18n(CustomizeTitleFormUi);
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/

import { i18n } from '@kbn/i18n';
import { EuiContextMenuPanelDescriptor, EuiBadge } from '@elastic/eui';
import { InjectedIntl, injectI18n } from '@kbn/i18n/react';
import classNames from 'classnames';
import React from 'react';
import { PanelOptionsMenu } from './panel_options_menu';
Expand All @@ -35,10 +34,6 @@ export interface PanelHeaderProps {
embeddable: IEmbeddable;
}

interface PanelHeaderUiProps extends PanelHeaderProps {
intl: InjectedIntl;
}

function renderBadges(badges: Action[], embeddable: IEmbeddable) {
return badges.map(badge => (
<EuiBadge
Expand All @@ -52,16 +47,15 @@ function renderBadges(badges: Action[], embeddable: IEmbeddable) {
));
}

function PanelHeaderUi({
export function PanelHeader({
title,
isViewMode,
hidePanelTitles,
getActionContextMenuPanel,
intl,
closeContextMenu,
badges,
embeddable,
}: PanelHeaderUiProps) {
}: PanelHeaderProps) {
const classes = classNames('embPanel__header', {
'embPanel__header--floater': !title || hidePanelTitles,
});
Expand Down Expand Up @@ -90,15 +84,12 @@ function PanelHeaderUi({
data-test-subj="dashboardPanelTitle"
className="embPanel__title embPanel__dragger"
title={title}
aria-label={intl.formatMessage(
{
id: 'embeddableApi.panel.dashboardPanelAriaLabel',
defaultMessage: 'Dashboard panel: {title}',
},
{
aria-label={i18n.translate('embeddableApi.panel.dashboardPanelAriaLabel', {
defaultMessage: 'Dashboard panel: {title}',
values: {
title,
}
)}
},
})}
>
{showTitle ? `${title} ` : ''}
{renderBadges(badges, embeddable)}
Expand All @@ -112,5 +103,3 @@ function PanelHeaderUi({
</div>
);
}

export const PanelHeader = injectI18n(PanelHeaderUi);
Loading