From 224c2063234d5c5d6d17b2b960db6d0bd83fc48d Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 29 Jun 2021 13:56:53 -0400 Subject: [PATCH] Removing the title edit icon for read only (#103540) (#103699) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Jonathan Buttner <56361221+jonathan-buttner@users.noreply.github.com> --- .../public/components/case_view/index.tsx | 2 +- .../editable_title.test.tsx.snap | 1 - .../header_page/editable_title.test.tsx | 42 +++++++++++++------ .../components/header_page/editable_title.tsx | 11 +++-- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/x-pack/plugins/cases/public/components/case_view/index.tsx b/x-pack/plugins/cases/public/components/case_view/index.tsx index 0e49173a6b838..2fffd6464dbb1 100644 --- a/x-pack/plugins/cases/public/components/case_view/index.tsx +++ b/x-pack/plugins/cases/public/components/case_view/index.tsx @@ -381,7 +381,7 @@ export const CaseComponent = React.memo( data-test-subj="case-view-title" titleNode={ diff --git a/x-pack/plugins/cases/public/components/header_page/editable_title.test.tsx b/x-pack/plugins/cases/public/components/header_page/editable_title.test.tsx index 90a10a388d717..babfeb584677b 100644 --- a/x-pack/plugins/cases/public/components/header_page/editable_title.test.tsx +++ b/x-pack/plugins/cases/public/components/header_page/editable_title.test.tsx @@ -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( - - ); + const wrapper = shallow(); expect(wrapper).toMatchSnapshot(); }); + test('it does not show the edit icon when the user does not have edit permissions', () => { + const wrapper = mount( + + + + ); + + expect(wrapper.find('[data-test-subj="editable-title-edit-icon"]').exists()).toBeFalsy(); + }); + test('it shows the edit title input field', () => { const wrapper = mount( - + ); @@ -43,7 +61,7 @@ describe('EditableTitle', () => { test('it shows the submit button', () => { const wrapper = mount( - + ); @@ -58,7 +76,7 @@ describe('EditableTitle', () => { test('it shows the cancel button', () => { const wrapper = mount( - + ); @@ -73,7 +91,7 @@ describe('EditableTitle', () => { test('it DOES NOT shows the edit icon when in edit mode', () => { const wrapper = mount( - + ); @@ -88,7 +106,7 @@ describe('EditableTitle', () => { test('it switch to non edit mode when canceled', () => { const wrapper = mount( - + ); @@ -104,7 +122,7 @@ describe('EditableTitle', () => { const wrapper = mount( - + ); @@ -128,7 +146,7 @@ describe('EditableTitle', () => { const wrapper = mount( - + ); @@ -151,7 +169,7 @@ describe('EditableTitle', () => { const wrapper = mount( - + ); diff --git a/x-pack/plugins/cases/public/components/header_page/editable_title.tsx b/x-pack/plugins/cases/public/components/header_page/editable_title.tsx index b53560db6745b..c897f8a7bf832 100644 --- a/x-pack/plugins/cases/public/components/header_page/editable_title.tsx +++ b/x-pack/plugins/cases/public/components/header_page/editable_title.tsx @@ -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 = ({ - disabled = false, +const EditableTitleComponent: React.FC = ({ + userCanCrud = false, onSubmit, isLoading, title, @@ -106,9 +106,8 @@ const EditableTitleComponent: React.FC = ({ {isLoading && } - {!isLoading && ( + {!isLoading && userCanCrud && (