Skip to content

Commit

Permalink
[ML] transform components naming fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Aug 17, 2020
1 parent 65a4091 commit e76996a
Show file tree
Hide file tree
Showing 23 changed files with 90 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ import { EuiToolTip } from '@elastic/eui';

import { createCapabilityFailureMessage } from '../../../../lib/authorization';

export const cloneActionButtonText = i18n.translate(
'xpack.transform.transformList.cloneActionName',
export const cloneActionNameText = i18n.translate(
'xpack.transform.transformList.cloneActionNameText',
{
defaultMessage: 'Clone',
}
);

interface CloneActionProps {
interface CloneActionNameProps {
disabled: boolean;
}

export const CloneButton: FC<CloneActionProps> = ({ disabled }) => {
export const CloneActionName: FC<CloneActionNameProps> = ({ disabled }) => {
if (disabled) {
return (
<EuiToolTip position="top" content={createCapabilityFailureMessage('canStartStopTransform')}>
<>{cloneActionButtonText}</>
<>{cloneActionNameText}</>
</EuiToolTip>
);
}

return <>{cloneActionButtonText}</>;
return <>{cloneActionNameText}</>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { AuthorizationContext } from '../../../../lib/authorization';
import { TransformListAction, TransformListRow } from '../../../../common';
import { SECTION_SLUG } from '../../../../constants';

import { cloneActionButtonText, CloneButton } from './clone_button';
import { cloneActionNameText, CloneActionName } from './clone_action_name';

export type CloneAction = ReturnType<typeof useCloneAction>;
export const useCloneAction = (forceDisable: boolean) => {
Expand All @@ -28,9 +28,9 @@ export const useCloneAction = (forceDisable: boolean) => {

const action: TransformListAction = useMemo(
() => ({
name: (item: TransformListRow) => <CloneButton disabled={!canCreateTransform} />,
name: (item: TransformListRow) => <CloneActionName disabled={!canCreateTransform} />,
enabled: () => canCreateTransform && !forceDisable,
description: cloneActionButtonText,
description: cloneActionNameText,
icon: 'copy',
type: 'icon',
onClick: clickHandler,
Expand Down

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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { TRANSFORM_STATE } from '../../../../../../common';

import { DeleteAction } from './use_delete_action';

export const DeleteButtonModal: FC<DeleteAction> = ({
export const DeleteActionModal: FC<DeleteAction> = ({
closeModal,
deleteAndCloseModal,
deleteDestIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,22 @@
*/

import { shallow } from 'enzyme';
import React, { ComponentProps } from 'react';
import React from 'react';

import { TransformListRow } from '../../../../common';
import { DeleteButton } from './delete_button';

import transformListRow from '../../../../common/__mocks__/transform_list_row.json';
import { DeleteActionName, DeleteActionNameProps } from './delete_action_name';

jest.mock('../../../../../shared_imports');
jest.mock('../../../../../app/app_dependencies');

describe('Transform: Transform List Actions <DeleteAction />', () => {
test('Minimal initialization', () => {
const item: TransformListRow = transformListRow;
const props: ComponentProps<typeof DeleteButton> = {
forceDisable: false,
items: [item],
onClick: () => {},
const props: DeleteActionNameProps = {
canDeleteTransform: true,
disabled: false,
isBulkAction: false,
};

const wrapper = shallow(<DeleteButton {...props} />);
const wrapper = shallow(<DeleteActionName {...props} />);
expect(wrapper).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { TRANSFORM_STATE } from '../../../../../../common';
import { createCapabilityFailureMessage } from '../../../../lib/authorization';
import { TransformListRow } from '../../../../common';

export const deleteActionButtonText = i18n.translate(
'xpack.transform.transformList.deleteActionName',
export const deleteActionNameText = i18n.translate(
'xpack.transform.transformList.deleteActionNameText',
{
defaultMessage: 'Delete',
}
Expand All @@ -26,13 +26,13 @@ export const isDeleteActionDisabled = (items: TransformListRow[], forceDisable:
return forceDisable === true || disabled;
};

interface DeleteButtonProps {
export interface DeleteActionNameProps {
canDeleteTransform: boolean;
disabled: boolean;
isBulkAction: boolean;
}

export const DeleteButton: FC<DeleteButtonProps> = ({
export const DeleteActionName: FC<DeleteActionNameProps> = ({
canDeleteTransform,
disabled,
isBulkAction,
Expand Down Expand Up @@ -60,10 +60,10 @@ export const DeleteButton: FC<DeleteButtonProps> = ({

return (
<EuiToolTip position="top" content={content}>
<>{deleteActionButtonText}</>
<>{deleteActionNameText}</>
</EuiToolTip>
);
}

return <>{deleteActionButtonText}</>;
return <>{deleteActionNameText}</>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { DeleteButton } from './delete_button';
export { DeleteButtonModal } from './delete_button_modal';
export { DeleteActionModal } from './delete_action_modal';
export { useDeleteAction } from './use_delete_action';
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import { TransformListAction, TransformListRow } from '../../../../common';
import { useDeleteIndexAndTargetIndex, useDeleteTransforms } from '../../../../hooks';
import { AuthorizationContext } from '../../../../lib/authorization';

import { deleteActionButtonText, isDeleteActionDisabled, DeleteButton } from './delete_button';
import {
deleteActionNameText,
isDeleteActionDisabled,
DeleteActionName,
} from './delete_action_name';

export type DeleteAction = ReturnType<typeof useDeleteAction>;
export const useDeleteAction = (forceDisable: boolean) => {
Expand Down Expand Up @@ -66,7 +70,7 @@ export const useDeleteAction = (forceDisable: boolean) => {
const action: TransformListAction = useMemo(
() => ({
name: (item: TransformListRow) => (
<DeleteButton
<DeleteActionName
{...{
canDeleteTransform,
isBulkAction: false,
Expand All @@ -76,7 +80,7 @@ export const useDeleteAction = (forceDisable: boolean) => {
),
enabled: (item: TransformListRow) =>
!isDeleteActionDisabled([item], forceDisable) && canDeleteTransform,
description: deleteActionButtonText,
description: deleteActionNameText,
icon: 'trash',
type: 'icon',
onClick: (item: TransformListRow) => openModal([item]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@ import {
AuthorizationContext,
} from '../../../../lib/authorization';

export const editActionButtonText = i18n.translate('xpack.transform.transformList.editActionName', {
defaultMessage: 'Edit',
});
export const editActionNameText = i18n.translate(
'xpack.transform.transformList.editActionNameText',
{
defaultMessage: 'Edit',
}
);

export const EditButton: FC = () => {
export const EditActionName: FC = () => {
const { canCreateTransform } = useContext(AuthorizationContext).capabilities;

if (!canCreateTransform) {
return (
<EuiToolTip position="top" content={createCapabilityFailureMessage('canStartStopTransform')}>
<>{editActionButtonText}</>
<>{editActionNameText}</>
</EuiToolTip>
);
}

return <>{editActionButtonText}</>;
return <>{editActionNameText}</>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { EditButton } from './edit_button';
export { useEditAction } from './use_edit_action';
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, { useContext, useMemo, useState } from 'react';
import { TransformListAction, TransformListRow, TransformPivotConfig } from '../../../../common';
import { AuthorizationContext } from '../../../../lib/authorization';

import { editActionButtonText, EditButton } from './edit_button';
import { editActionNameText, EditActionName } from './edit_action_name';

export const useEditAction = (forceDisable: boolean) => {
const { canCreateTransform } = useContext(AuthorizationContext).capabilities;
Expand All @@ -24,9 +24,9 @@ export const useEditAction = (forceDisable: boolean) => {

const action: TransformListAction = useMemo(
() => ({
name: () => <EditButton />,
name: () => <EditActionName />,
enabled: () => canCreateTransform || !forceDisable,
description: editActionButtonText,
description: editActionNameText,
icon: 'pencil',
type: 'icon',
onClick: (item: TransformListRow) => showFlyout(item.config),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { StartButtonModal } from './start_button_modal';
export { StartActionModal } from './start_action_modal';
export { useStartAction } from './use_start_action';
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ import { EuiConfirmModal, EuiOverlayMask, EUI_MODAL_CONFIRM_BUTTON } from '@elas

import { StartAction } from './use_start_action';

export const StartButtonModal: FC<StartAction> = ({
closeModal,
isModalVisible,
items,
startAndCloseModal,
}) => {
export const StartActionModal: FC<StartAction> = ({ closeModal, items, startAndCloseModal }) => {
const isBulkAction = items.length > 1;

const bulkStartModalTitle = i18n.translate('xpack.transform.transformList.bulkStartModalTitle', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
*/

import { shallow } from 'enzyme';
import React, { ComponentProps } from 'react';
import React from 'react';

import { TransformListRow } from '../../../../common';
import { StartButton } from './start_button';
import { StartActionName, StartActionNameProps } from './start_action_name';

import transformListRow from '../../../../common/__mocks__/transform_list_row.json';

Expand All @@ -18,13 +18,12 @@ jest.mock('../../../../../app/app_dependencies');
describe('Transform: Transform List Actions <StartAction />', () => {
test('Minimal initialization', () => {
const item: TransformListRow = transformListRow;
const props: ComponentProps<typeof StartButton> = {
const props: StartActionNameProps = {
forceDisable: false,
items: [item],
onClick: () => {},
};

const wrapper = shallow(<StartButton {...props} />);
const wrapper = shallow(<StartActionName {...props} />);

expect(wrapper).toMatchSnapshot();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
} from '../../../../lib/authorization';
import { TransformListRow, isCompletedBatchTransform } from '../../../../common';

export const startActionButtonText = i18n.translate(
'xpack.transform.transformList.startActionName',
export const startActionNameText = i18n.translate(
'xpack.transform.transformList.startActionNameText',
{
defaultMessage: 'Start',
}
Expand All @@ -39,11 +39,11 @@ export const isStartActionDisabled = (
);
};

interface StartButtonProps {
export interface StartActionNameProps {
items: TransformListRow[];
forceDisable?: boolean;
}
export const StartButton: FC<StartButtonProps> = ({ items, forceDisable }) => {
export const StartActionName: FC<StartActionNameProps> = ({ items, forceDisable }) => {
const { canStartStopTransform } = useContext(AuthorizationContext).capabilities;
const isBulkAction = items.length > 1;

Expand Down Expand Up @@ -104,10 +104,10 @@ export const StartButton: FC<StartButtonProps> = ({ items, forceDisable }) => {
if ((forceDisable === true || actionIsDisabled) && content !== undefined) {
return (
<EuiToolTip position="top" content={content}>
<>{startActionButtonText}</>
<>{startActionNameText}</>
</EuiToolTip>
);
}

return <>{startActionButtonText}</>;
return <>{startActionNameText}</>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { AuthorizationContext } from '../../../../lib/authorization';
import { TransformListAction, TransformListRow } from '../../../../common';
import { useStartTransforms } from '../../../../hooks';

import { isStartActionDisabled, startActionButtonText, StartButton } from './start_button';
import { isStartActionDisabled, startActionNameText, StartActionName } from './start_action_name';

export type StartAction = ReturnType<typeof useStartAction>;
export const useStartAction = (forceDisable: boolean) => {
Expand Down Expand Up @@ -41,10 +41,12 @@ export const useStartAction = (forceDisable: boolean) => {

const action: TransformListAction = useMemo(
() => ({
name: (item: TransformListRow) => <StartButton items={[item]} forceDisable={forceDisable} />,
name: (item: TransformListRow) => (
<StartActionName items={[item]} forceDisable={forceDisable} />
),
available: (item: TransformListRow) => item.stats.state === TRANSFORM_STATE.STOPPED,
enabled: (item: TransformListRow) => !isStartActionDisabled([item], canStartStopTransform),
description: startActionButtonText,
description: startActionNameText,
icon: 'play',
type: 'icon',
onClick: (item: TransformListRow) => openModal([item]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
*/

import { shallow } from 'enzyme';
import React, { ComponentProps } from 'react';
import React from 'react';

import { TransformListRow } from '../../../../common';
import { StopButton } from './stop_button';
import { StopActionName, StopActionNameProps } from './stop_action_name';

import transformListRow from '../../../../common/__mocks__/transform_list_row.json';

Expand All @@ -18,12 +18,12 @@ jest.mock('../../../../../app/app_dependencies');
describe('Transform: Transform List Actions <StopAction />', () => {
test('Minimal initialization', () => {
const item: TransformListRow = transformListRow;
const props: ComponentProps<typeof StopButton> = {
const props: StopActionNameProps = {
forceDisable: false,
items: [item],
};

const wrapper = shallow(<StopButton {...props} />);
const wrapper = shallow(<StopActionName {...props} />);

expect(wrapper).toMatchSnapshot();
});
Expand Down
Loading

0 comments on commit e76996a

Please sign in to comment.