Skip to content

Commit 755ac96

Browse files
cleanup
1 parent 93b957e commit 755ac96

File tree

5 files changed

+25
-37
lines changed

5 files changed

+25
-37
lines changed

x-pack/plugins/security_solution/public/common/store/app/selectors.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { createSelector } from 'reselect';
1010
import { Note } from '../../lib/note';
1111
import { ErrorModel, NotesById } from './model';
1212
import { State } from '../types';
13+
import { TimelineResultNote } from '../../../timelines/components/open_timeline/types';
1314

1415
const selectNotesById = (state: State): NotesById => state.app.notesById;
1516

@@ -25,16 +26,15 @@ export const getNotes = memoizeOne((notesById: NotesById, noteIds: string[]): No
2526
}, [])
2627
);
2728

28-
export const selectNotesByTimelineSavedObjectId = (
29-
state: State,
30-
timelineSavedObjectId: string
31-
): Note[] =>
32-
values(state.app.notesById).reduce((acc: Note[], note: Note) => {
33-
if (note.timelineId === timelineSavedObjectId) {
34-
return [...acc, note];
35-
}
36-
return acc;
37-
}, []);
29+
export const getNotesAsCommentsList = (notesById: NotesById): TimelineResultNote[] =>
30+
values(notesById).map((note) => ({
31+
eventId: note.eventId,
32+
savedObjectId: note.saveObjectId,
33+
note: note.note,
34+
noteId: note.id,
35+
updated: (note.lastEdit ?? note.created).getTime(),
36+
updatedBy: note.user,
37+
}));
3838

3939
export const selectNotesByIdSelector = createSelector(
4040
selectNotesById,
@@ -44,7 +44,7 @@ export const selectNotesByIdSelector = createSelector(
4444
export const notesByIdsSelector = () =>
4545
createSelector(selectNotesById, (notesById: NotesById) => notesById);
4646

47-
export const selectNotesByTimelineSavedObjectIdSelector = () =>
48-
createSelector(selectNotesByTimelineSavedObjectId, (notes: Note[]) => notes);
47+
export const selectNotesAsCommentsListSelector = () =>
48+
createSelector(selectNotesById, getNotesAsCommentsList);
4949

5050
export const errorsSelector = () => createSelector(getErrors, (errors) => errors);

x-pack/plugins/security_solution/public/timelines/components/notes/translations.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,7 @@ export const COPY_TO_CLIPBOARD = i18n.translate(
5050
defaultMessage: 'Copy to Clipboard',
5151
}
5252
);
53+
54+
export const CREATED_BY = i18n.translate('xpack.securitySolution.notes.createdByLabel', {
55+
defaultMessage: 'Created by',
56+
});

x-pack/plugins/security_solution/public/timelines/components/open_timeline/note_previews/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const ToggleEventDetailsButtonComponent: React.FC<ToggleEventDetailsButtonProps>
4040
event: {
4141
eventId,
4242
// we don't store yet info about event index name in note
43-
indexName: '*',
43+
indexName: '',
4444
loading: false,
4545
},
4646
})

x-pack/plugins/security_solution/public/timelines/components/timeline/notes_tab_content/index.tsx

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { TimelineStatus } from '../../../../../common/types/timeline';
2727
import { appSelectors } from '../../../../common/store/app';
2828
import { timelineDefaults } from '../../../store/timeline/defaults';
2929
import { AddNote } from '../../notes/add_note';
30-
import { NOTES } from '../../notes/translations';
30+
import { CREATED_BY, NOTES } from '../../notes/translations';
3131
import { PARTICIPANTS } from '../../../../cases/translations';
3232
import { NotePreviews } from '../../open_timeline/note_previews';
3333
import { TimelineResultNote } from '../../open_timeline/types';
@@ -122,38 +122,22 @@ interface NotesTabContentProps {
122122
const NotesTabContentComponent: React.FC<NotesTabContentProps> = ({ timelineId }) => {
123123
const dispatch = useDispatch();
124124
const getTimeline = useMemo(() => timelineSelectors.getTimelineByIdSelector(), []);
125-
const {
126-
createdBy,
127-
expandedEvent,
128-
savedObjectId,
129-
status: timelineStatus,
130-
} = useDeepEqualSelector((state) =>
125+
const { createdBy, expandedEvent, status: timelineStatus } = useDeepEqualSelector((state) =>
131126
pick(
132-
['createdBy', 'expandedEvent', 'status', 'savedObjectId'],
127+
['createdBy', 'expandedEvent', 'status'],
133128
getTimeline(state, timelineId) ?? timelineDefaults
134129
)
135130
);
136131

137132
const { browserFields, docValueFields } = useSourcererScope(SourcererScopeName.timeline);
138133

139-
const getNotesByTimelineSavedObjectId = useMemo(
140-
() => appSelectors.selectNotesByTimelineSavedObjectIdSelector(),
134+
const getNotesAsCommentsList = useMemo(
135+
() => appSelectors.selectNotesAsCommentsListSelector(),
141136
[]
142137
);
143138
const [newNote, setNewNote] = useState('');
144139
const isImmutable = timelineStatus === TimelineStatus.immutable;
145-
const notes: TimelineResultNote[] = useDeepEqualSelector((state) => {
146-
const notesByTimelineId = getNotesByTimelineSavedObjectId(state, savedObjectId);
147-
148-
return notesByTimelineId.map((note) => ({
149-
eventId: note.eventId,
150-
savedObjectId: note.saveObjectId,
151-
note: note.note,
152-
noteId: note.id,
153-
updated: (note.lastEdit ?? note.created).getTime(),
154-
updatedBy: note.user,
155-
}));
156-
});
140+
const notes: TimelineResultNote[] = useDeepEqualSelector(getNotesAsCommentsList);
157141

158142
const participants = useMemo(() => uniqBy('updatedBy', notes), [notes]);
159143

@@ -181,7 +165,7 @@ const NotesTabContentComponent: React.FC<NotesTabContentProps> = ({ timelineId }
181165
<>
182166
<EuiSpacer size="m" />
183167
<EuiTitle size="xs">
184-
<h4>{'Created by'}</h4>
168+
<h4>{CREATED_BY}</h4>
185169
</EuiTitle>
186170
<EuiHorizontalRule margin="s" />
187171
<UsernameWithAvatar username={createdBy} />

x-pack/plugins/security_solution/server/search_strategy/timeline/factory/events/details/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const timelineEventsDetails: SecuritySolutionTimelineFactory<TimelineEven
2727
response: IEsSearchResponse<unknown>
2828
): Promise<TimelineEventsDetailsStrategyResponse> => {
2929
const { indexName, eventId, docValueFields = [] } = options;
30-
const fieldsData = cloneDeep(response.rawResponse.hits.hits[0].fields ?? {});
30+
const fieldsData = cloneDeep(response.rawResponse.hits.hits[0]?.fields ?? {});
3131
const hitsData = cloneDeep(response.rawResponse.hits.hits[0] ?? {});
3232
delete hitsData._source;
3333
delete hitsData.fields;

0 commit comments

Comments
 (0)