Skip to content

Commit

Permalink
fix title of delete modal
Browse files Browse the repository at this point in the history
  • Loading branch information
angorayc committed Mar 19, 2020
1 parent b1465a8 commit 6aaaca2
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('DeleteTimelineModal', () => {
test('it renders the expected title when a timeline is selected', () => {
const wrapper = mountWithIntl(
<DeleteTimelineModal
title={'"Privilege Escalation"'}
title={'Privilege Escalation'}
onDelete={jest.fn()}
closeModal={jest.fn()}
/>
Expand All @@ -32,7 +32,7 @@ describe('DeleteTimelineModal', () => {
test('it trims leading whitespace around the title', () => {
const wrapper = mountWithIntl(
<DeleteTimelineModal
title={' "Leading and trailing whitespace" '}
title={' Leading and trailing whitespace '}
onDelete={jest.fn()}
closeModal={jest.fn()}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,50 @@

import { EuiConfirmModal, EUI_MODAL_CONFIRM_BUTTON } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import React, { useCallback, useState } from 'react';
import React, { useCallback } from 'react';
import { isEmpty } from 'lodash/fp';

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

interface Props {
title?: string | JSX.Element | null;
title?: string | null;
onDelete: () => void;
closeModal: () => void;
}

export const DELETE_TIMELINE_MODAL_WIDTH = 600; // px

const getDeletedTitles = (title: string | JSX.Element | null | undefined) => {
if (title != null && React.isValidElement(title)) {
return title;
} else if (title != null && typeof title === 'string' && title.trim().length > 0) {
return title.trim();
}
return `"${i18n.UNTITLED_TIMELINE}"`;
};

/**
* Renders a modal that confirms deletion of a timeline
*/
export const DeleteTimelineModal = React.memo<Props>(({ title, closeModal, onDelete }) => (
<EuiConfirmModal
buttonColor="danger"
cancelButtonText={i18n.CANCEL}
confirmButtonText={i18n.DELETE}
defaultFocusedButton={EUI_MODAL_CONFIRM_BUTTON}
onCancel={closeModal}
onConfirm={onDelete}
title={
export const DeleteTimelineModal = React.memo<Props>(({ title, closeModal, onDelete }) => {
const getTitle = useCallback(() => {
const trimmedTitle = title != null ? title.trim() : '';
const titleResult = !isEmpty(trimmedTitle) ? trimmedTitle : i18n.UNTITLED_TIMELINE;
return (
<FormattedMessage
id="xpack.siem.open.timeline.deleteTimelineModalTitle"
defaultMessage={'Delete "{title}"?'}
data-test-subj="title"
defaultMessage="Delete {title}?"
values={{
title: getDeletedTitles(title),
title: titleResult,
}}
/>
}
>
<div data-test-subj="warning">{i18n.DELETE_WARNING}</div>
</EuiConfirmModal>
));
);
}, [title]);
return (
<EuiConfirmModal
buttonColor="danger"
cancelButtonText={i18n.CANCEL}
confirmButtonText={i18n.DELETE}
defaultFocusedButton={EUI_MODAL_CONFIRM_BUTTON}
onCancel={closeModal}
onConfirm={onDelete}
title={getTitle()}
>
<div data-test-subj="warning">{i18n.DELETE_WARNING}</div>
</EuiConfirmModal>
);
});

DeleteTimelineModal.displayName = 'DeleteTimelineModal';
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface Props {
onComplete?: () => void;
isModalOpen: boolean;
savedObjectIds: string[];
title: string | JSX.Element | null;
title: string | null;
}
/**
* Renders a button that when clicked, displays the `Delete Timeline` modal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const useEditTimelinBatchActions = ({
title={
selectedItems?.length !== 1
? i18n.SELECTED_TIMELINES(selectedItems?.length ?? 0)
: `"${selectedItems[0]?.title}"`
: selectedItems[0]?.title ?? ''
}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const OpenTimeline = React.memo<OpenTimelineProps>(
isDeleteTimelineModalOpen={isDeleteTimelineModalOpen}
isEnableDownloader={isEnableDownloader}
onComplete={onCompleteEditTimelineAction}
title={actionItem?.title ?? i18n.SELECTED_TIMELINES(1)}
title={actionItem?.title ?? i18n.UNTITLED_TIMELINE}
/>

<EuiPanel className={OPEN_TIMELINE_CLASS_NAME}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,17 @@ const getGlobalEventNotesByTimelineId = (currentNotes: NoteSavedObject[]): Expor

return (
currentNotes.reduce((acc, note) => {
if (note.eventId == null)
if (note.eventId == null) {
return {
...acc,
globalNotes: [...acc.globalNotes, note],
};
else
} else {
return {
...acc,
eventNotes: [...acc.eventNotes, note],
};
}
}, initialNotes) ?? initialNotes
);
};
Expand Down

0 comments on commit 6aaaca2

Please sign in to comment.