Skip to content

Commit

Permalink
fix from server side
Browse files Browse the repository at this point in the history
  • Loading branch information
angorayc committed Oct 1, 2020
1 parent 4872f27 commit 21fcf02
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
EuiModalBody,
EuiModalHeader,
EuiSpacer,
EuiCallOut,
} from '@elastic/eui';
import React, { useState } from 'react';
import styled from 'styled-components';
Expand All @@ -21,18 +20,13 @@ import { AddNote } from './add_note';
import { columns } from './columns';
import { AssociateNote, GetNewNoteId, NotesCount, search, UpdateNote } from './helpers';
import { TimelineStatusLiteral, TimelineStatus } from '../../../../common/types/timeline';
import { Loader } from '../../../common/components/loader';
import { useShallowEqualSelector } from '../../../common/hooks/use_selector';
import { timelineSelectors } from '../../store/timeline';
import { SAVE_NOTE_HINT } from './translations';

interface Props {
associateNote: AssociateNote;
getNotesByIds: (noteIds: string[]) => Note[];
getNewNoteId: GetNewNoteId;
noteIds: string[];
status: TimelineStatusLiteral;
timelineId: string;
updateNote: UpdateNote;
}

Expand All @@ -48,23 +42,18 @@ InMemoryTable.displayName = 'InMemoryTable';

/** A view for entering and reviewing notes */
export const Notes = React.memo<Props>(
({ associateNote, getNotesByIds, getNewNoteId, noteIds, status, timelineId, updateNote }) => {
({ associateNote, getNotesByIds, getNewNoteId, noteIds, status, updateNote }) => {
const [newNote, setNewNote] = useState('');
const isImmutable = status === TimelineStatus.immutable;

const currentTimeline = useShallowEqualSelector((state) =>
timelineSelectors.selectTimeline(state, timelineId)
);
const showAddNote = !isImmutable && currentTimeline.savedObjectId != null;

return (
<>
<EuiModalHeader>
<NotesCount noteIds={noteIds} />
</EuiModalHeader>

<EuiModalBody>
{showAddNote && (
{!isImmutable && (
<AddNote
associateNote={associateNote}
getNewNoteId={getNewNoteId}
Expand All @@ -73,10 +62,6 @@ export const Notes = React.memo<Props>(
updateNote={updateNote}
/>
)}
{!showAddNote && currentTimeline.isSaving && (
<Loader data-test-subj="loading-spinner" size="xl" />
)}
{!showAddNote && !currentTimeline.isSaving && <EuiCallOut title={SAVE_NOTE_HINT} />}
<EuiSpacer size="s" />
<InMemoryTable
data-test-subj="notes-table"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,3 @@ export const COPY_TO_CLIPBOARD = i18n.translate(
defaultMessage: 'Copy to Clipboard',
}
);

export const SAVE_NOTE_HINT = i18n.translate('xpack.securitySolution.notes.saveNoteCallOutTitle', {
defaultMessage: 'Add a title to current timeline before adding a note',
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ interface AddEventNoteActionProps {
showNotes: boolean;
status: TimelineStatus;
timelineType: TimelineType;
timelineId: string;
toggleShowNotes: () => void;
updateNote: UpdateNote;
}
Expand All @@ -32,7 +31,6 @@ const AddEventNoteActionComponent: React.FC<AddEventNoteActionProps> = ({
showNotes,
status,
timelineType,
timelineId,
toggleShowNotes,
updateNote,
}) => (
Expand All @@ -47,7 +45,6 @@ const AddEventNoteActionComponent: React.FC<AddEventNoteActionProps> = ({
size="s"
status={status}
timelineType={timelineType}
timelineId={timelineId}
toggleShowNotes={toggleShowNotes}
toolTip={
timelineType === TimelineType.template ? i18n.NOTES_DISABLE_TOOLTIP : i18n.NOTES_TOOLTIP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ export const EventColumnView = React.memo<Props>(
updateNote={updateNote}
status={status}
timelineType={timelineType}
timelineId={timelineId}
/>,
<PinEventAction
key="pin-event"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ interface NotesButtonProps {
toolTip?: string;
updateNote: UpdateNote;
timelineType: TimelineTypeLiteral;
timelineId: string;
}

const getNewNoteId = (): string => uuid.v4();
Expand Down Expand Up @@ -367,7 +366,6 @@ const NotesButtonComponent = React.memo<NotesButtonProps>(
text,
updateNote,
timelineType,
timelineId,
}) => (
<ButtonContainer animate={animate} data-test-subj="timeline-notes-button-container">
<>
Expand All @@ -388,7 +386,6 @@ const NotesButtonComponent = React.memo<NotesButtonProps>(
getNewNoteId={getNewNoteId}
getNotesByIds={getNotesByIds}
status={status}
timelineId={timelineId}
noteIds={noteIds}
updateNote={updateNote}
/>
Expand All @@ -411,7 +408,6 @@ export const NotesButton = React.memo<NotesButtonProps>(
size,
status,
timelineType,
timelineId,
toggleShowNotes,
toolTip,
text,
Expand All @@ -430,7 +426,6 @@ export const NotesButton = React.memo<NotesButtonProps>(
text={text}
updateNote={updateNote}
timelineType={timelineType}
timelineId={timelineId}
/>
) : (
<EuiToolTip content={toolTip || ''} data-test-subj="timeline-notes-tool-tip">
Expand All @@ -446,7 +441,6 @@ export const NotesButton = React.memo<NotesButtonProps>(
text={text}
updateNote={updateNote}
timelineType={timelineType}
timelineId={timelineId}
/>
</EuiToolTip>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export const PropertiesLeft = React.memo<Props>(
toolTip={i18n.NOTES_TOOL_TIP}
updateNote={updateNote}
timelineType={timelineType}
timelineId={timelineId}
/>
</EuiFlexItem>
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ const PropertiesRightComponent: React.FC<PropertiesRightComponentProps> = ({
toggleShowNotes={onToggleShowNotes}
toolTip={i18n.NOTES_TOOL_TIP}
updateNote={updateNote}
timelineId={timelineId}
/>
</EuiFlexItem>
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { noteSavedObjectType } from './saved_object_mappings';
import { pickSavedTimeline } from '../timeline/pick_saved_timeline';
import { convertSavedObjectToSavedTimeline } from '../timeline/convert_saved_object_to_savedtimeline';
import { timelineSavedObjectType } from '../timeline/saved_object_mappings';
import { TimelineStatus } from '../../../common/types/timeline';

export interface Note {
deleteNote: (request: FrameworkRequest, noteIds: string[]) => Promise<void>;
Expand Down Expand Up @@ -148,10 +149,10 @@ export const persistNote = async (
note.timelineId == null
? await (async () => {
const timelineResult = convertSavedObjectToSavedTimeline(
await savedObjectsClient.create(
timelineSavedObjectType,
pickSavedTimeline(null, {}, request.user)
)
await savedObjectsClient.create(timelineSavedObjectType, {
...pickSavedTimeline(null, {}, request.user),
status: TimelineStatus.draft,
})
);
note.timelineId = timelineResult.savedObjectId;
return timelineResult.version;
Expand Down

0 comments on commit 21fcf02

Please sign in to comment.