Skip to content

Commit

Permalink
Removing the title edit icon for read only (elastic#103540) (elastic#…
Browse files Browse the repository at this point in the history
…103699)

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Jonathan Buttner <[email protected]>
  • Loading branch information
kibanamachine and jonathan-buttner authored Jun 29, 2021
1 parent 9db4272 commit 224c206
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/public/components/case_view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ export const CaseComponent = React.memo<CaseComponentProps>(
data-test-subj="case-view-title"
titleNode={
<EditableTitle
disabled={!userCanCrud}
userCanCrud={userCanCrud}
isLoading={isLoading && updateKey === 'title'}
title={caseData.title}
onSubmit={onSubmitTitle}
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 @@ -10,25 +10,43 @@ import React from 'react';

import '../../common/mock/match_media';
import { TestProviders } from '../../common/mock';
import { EditableTitle } from './editable_title';
import { EditableTitle, EditableTitleProps } from './editable_title';
import { useMountAppended } from '../../utils/use_mount_appended';

describe('EditableTitle', () => {
const mount = useMountAppended();
const submitTitle = jest.fn();
const defaultProps: EditableTitleProps = {
title: 'Test title',
onSubmit: submitTitle,
isLoading: false,
userCanCrud: true,
};

beforeEach(() => {
jest.clearAllMocks();
});

test('it renders', () => {
const wrapper = shallow(
<EditableTitle title="Test title" onSubmit={submitTitle} isLoading={false} />
);
const wrapper = shallow(<EditableTitle {...defaultProps} />);

expect(wrapper).toMatchSnapshot();
});

test('it does not show the edit icon when the user does not have edit permissions', () => {
const wrapper = mount(
<TestProviders>
<EditableTitle {...{ ...defaultProps, userCanCrud: false }} />
</TestProviders>
);

expect(wrapper.find('[data-test-subj="editable-title-edit-icon"]').exists()).toBeFalsy();
});

test('it shows the edit title input field', () => {
const wrapper = mount(
<TestProviders>
<EditableTitle title="Test title" onSubmit={submitTitle} isLoading={false} />
<EditableTitle {...defaultProps} />
</TestProviders>
);

Expand All @@ -43,7 +61,7 @@ describe('EditableTitle', () => {
test('it shows the submit button', () => {
const wrapper = mount(
<TestProviders>
<EditableTitle title="Test title" onSubmit={submitTitle} isLoading={false} />
<EditableTitle {...defaultProps} />
</TestProviders>
);

Expand All @@ -58,7 +76,7 @@ describe('EditableTitle', () => {
test('it shows the cancel button', () => {
const wrapper = mount(
<TestProviders>
<EditableTitle title="Test title" onSubmit={submitTitle} isLoading={false} />
<EditableTitle {...defaultProps} />
</TestProviders>
);

Expand All @@ -73,7 +91,7 @@ describe('EditableTitle', () => {
test('it DOES NOT shows the edit icon when in edit mode', () => {
const wrapper = mount(
<TestProviders>
<EditableTitle title="Test title" onSubmit={submitTitle} isLoading={false} />
<EditableTitle {...defaultProps} />
</TestProviders>
);

Expand All @@ -88,7 +106,7 @@ describe('EditableTitle', () => {
test('it switch to non edit mode when canceled', () => {
const wrapper = mount(
<TestProviders>
<EditableTitle title="Test title" onSubmit={submitTitle} isLoading={false} />
<EditableTitle {...defaultProps} />
</TestProviders>
);

Expand All @@ -104,7 +122,7 @@ describe('EditableTitle', () => {

const wrapper = mount(
<TestProviders>
<EditableTitle title="Test title" onSubmit={submitTitle} isLoading={false} />
<EditableTitle {...defaultProps} />
</TestProviders>
);

Expand All @@ -128,7 +146,7 @@ describe('EditableTitle', () => {

const wrapper = mount(
<TestProviders>
<EditableTitle title={title} onSubmit={submitTitle} isLoading={false} />
<EditableTitle {...{ ...defaultProps, title }} />
</TestProviders>
);

Expand All @@ -151,7 +169,7 @@ describe('EditableTitle', () => {

const wrapper = mount(
<TestProviders>
<EditableTitle title="Test title" onSubmit={submitTitle} isLoading={false} />
<EditableTitle {...defaultProps} />
</TestProviders>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ const MySpinner = styled(EuiLoadingSpinner)`
`}
`;

interface Props {
disabled?: boolean;
export interface EditableTitleProps {
userCanCrud: boolean;
isLoading: boolean;
title: string | React.ReactNode;
onSubmit: (title: string) => void;
}

const EditableTitleComponent: React.FC<Props> = ({
disabled = false,
const EditableTitleComponent: React.FC<EditableTitleProps> = ({
userCanCrud = false,
onSubmit,
isLoading,
title,
Expand Down Expand Up @@ -106,9 +106,8 @@ const EditableTitleComponent: React.FC<Props> = ({
</EuiFlexItem>
<EuiFlexItem grow={false}>
{isLoading && <MySpinner data-test-subj="editable-title-loading" />}
{!isLoading && (
{!isLoading && userCanCrud && (
<MyEuiButtonIcon
isDisabled={disabled}
aria-label={i18n.EDIT_TITLE_ARIA(title as string)}
iconType="pencil"
onClick={onClickEditIcon}
Expand Down

0 comments on commit 224c206

Please sign in to comment.