Skip to content

Commit 6aaaca2

Browse files
committed
fix title of delete modal
1 parent b1465a8 commit 6aaaca2

6 files changed

Lines changed: 34 additions & 34 deletions

File tree

x-pack/legacy/plugins/siem/public/components/open_timeline/delete_timeline_modal/delete_timeline_modal.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('DeleteTimelineModal', () => {
1515
test('it renders the expected title when a timeline is selected', () => {
1616
const wrapper = mountWithIntl(
1717
<DeleteTimelineModal
18-
title={'"Privilege Escalation"'}
18+
title={'Privilege Escalation'}
1919
onDelete={jest.fn()}
2020
closeModal={jest.fn()}
2121
/>
@@ -32,7 +32,7 @@ describe('DeleteTimelineModal', () => {
3232
test('it trims leading whitespace around the title', () => {
3333
const wrapper = mountWithIntl(
3434
<DeleteTimelineModal
35-
title={' "Leading and trailing whitespace" '}
35+
title={' Leading and trailing whitespace '}
3636
onDelete={jest.fn()}
3737
closeModal={jest.fn()}
3838
/>

x-pack/legacy/plugins/siem/public/components/open_timeline/delete_timeline_modal/delete_timeline_modal.tsx

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,50 @@
66

77
import { EuiConfirmModal, EUI_MODAL_CONFIRM_BUTTON } from '@elastic/eui';
88
import { FormattedMessage } from '@kbn/i18n/react';
9-
import React, { useCallback, useState } from 'react';
9+
import React, { useCallback } from 'react';
10+
import { isEmpty } from 'lodash/fp';
1011

1112
import * as i18n from '../translations';
1213

1314
interface Props {
14-
title?: string | JSX.Element | null;
15+
title?: string | null;
1516
onDelete: () => void;
1617
closeModal: () => void;
1718
}
1819

1920
export const DELETE_TIMELINE_MODAL_WIDTH = 600; // px
2021

21-
const getDeletedTitles = (title: string | JSX.Element | null | undefined) => {
22-
if (title != null && React.isValidElement(title)) {
23-
return title;
24-
} else if (title != null && typeof title === 'string' && title.trim().length > 0) {
25-
return title.trim();
26-
}
27-
return `"${i18n.UNTITLED_TIMELINE}"`;
28-
};
29-
3022
/**
3123
* Renders a modal that confirms deletion of a timeline
3224
*/
33-
export const DeleteTimelineModal = React.memo<Props>(({ title, closeModal, onDelete }) => (
34-
<EuiConfirmModal
35-
buttonColor="danger"
36-
cancelButtonText={i18n.CANCEL}
37-
confirmButtonText={i18n.DELETE}
38-
defaultFocusedButton={EUI_MODAL_CONFIRM_BUTTON}
39-
onCancel={closeModal}
40-
onConfirm={onDelete}
41-
title={
25+
export const DeleteTimelineModal = React.memo<Props>(({ title, closeModal, onDelete }) => {
26+
const getTitle = useCallback(() => {
27+
const trimmedTitle = title != null ? title.trim() : '';
28+
const titleResult = !isEmpty(trimmedTitle) ? trimmedTitle : i18n.UNTITLED_TIMELINE;
29+
return (
4230
<FormattedMessage
4331
id="xpack.siem.open.timeline.deleteTimelineModalTitle"
32+
defaultMessage={'Delete "{title}"?'}
4433
data-test-subj="title"
45-
defaultMessage="Delete {title}?"
4634
values={{
47-
title: getDeletedTitles(title),
35+
title: titleResult,
4836
}}
4937
/>
50-
}
51-
>
52-
<div data-test-subj="warning">{i18n.DELETE_WARNING}</div>
53-
</EuiConfirmModal>
54-
));
38+
);
39+
}, [title]);
40+
return (
41+
<EuiConfirmModal
42+
buttonColor="danger"
43+
cancelButtonText={i18n.CANCEL}
44+
confirmButtonText={i18n.DELETE}
45+
defaultFocusedButton={EUI_MODAL_CONFIRM_BUTTON}
46+
onCancel={closeModal}
47+
onConfirm={onDelete}
48+
title={getTitle()}
49+
>
50+
<div data-test-subj="warning">{i18n.DELETE_WARNING}</div>
51+
</EuiConfirmModal>
52+
);
53+
});
5554

5655
DeleteTimelineModal.displayName = 'DeleteTimelineModal';

x-pack/legacy/plugins/siem/public/components/open_timeline/delete_timeline_modal/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface Props {
2121
onComplete?: () => void;
2222
isModalOpen: boolean;
2323
savedObjectIds: string[];
24-
title: string | JSX.Element | null;
24+
title: string | null;
2525
}
2626
/**
2727
* Renders a button that when clicked, displays the `Delete Timeline` modal

x-pack/legacy/plugins/siem/public/components/open_timeline/edit_timeline_batch_actions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const useEditTimelinBatchActions = ({
7474
title={
7575
selectedItems?.length !== 1
7676
? i18n.SELECTED_TIMELINES(selectedItems?.length ?? 0)
77-
: `"${selectedItems[0]?.title}"`
77+
: selectedItems[0]?.title ?? ''
7878
}
7979
/>
8080

x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export const OpenTimeline = React.memo<OpenTimelineProps>(
104104
isDeleteTimelineModalOpen={isDeleteTimelineModalOpen}
105105
isEnableDownloader={isEnableDownloader}
106106
onComplete={onCompleteEditTimelineAction}
107-
title={actionItem?.title ?? i18n.SELECTED_TIMELINES(1)}
107+
title={actionItem?.title ?? i18n.UNTITLED_TIMELINE}
108108
/>
109109

110110
<EuiPanel className={OPEN_TIMELINE_CLASS_NAME}>

x-pack/legacy/plugins/siem/server/lib/timeline/routes/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,17 @@ const getGlobalEventNotesByTimelineId = (currentNotes: NoteSavedObject[]): Expor
8080

8181
return (
8282
currentNotes.reduce((acc, note) => {
83-
if (note.eventId == null)
83+
if (note.eventId == null) {
8484
return {
8585
...acc,
8686
globalNotes: [...acc.globalNotes, note],
8787
};
88-
else
88+
} else {
8989
return {
9090
...acc,
9191
eventNotes: [...acc.eventNotes, note],
9292
};
93+
}
9394
}, initialNotes) ?? initialNotes
9495
);
9596
};

0 commit comments

Comments
 (0)