Skip to content

Commit

Permalink
[SecuritySolution] Reset updated, changed and version when dupl…
Browse files Browse the repository at this point in the history
…icating a timeline (elastic#175110)

## Summary

Fixes elastic#173968

When duplicating a timeline (note: not the same as `save as new`), the
save status of the duplicate timeline wasn't displaying correctly
(elastic#173968). That's because we did
not reset the local values of `updated`, `changed` and `version`.


### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
  • Loading branch information
janmonschke authored Jan 22, 2024
1 parent f94860c commit 8d2bab7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,12 @@ describe('helpers', () => {
expect(dispatchAddTimeline).toHaveBeenCalledWith({
id: TimelineId.active,
savedTimeline: true,
timeline: mockTimelineModel,
timeline: {
...mockTimelineModel,
version: null,
updated: undefined,
changed: undefined,
},
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,18 +435,22 @@ export const dispatchUpdateTimeline =
preventSettingQuery,
}: UpdateTimeline): (() => void) =>
() => {
if (!isEmpty(timeline.indexNames)) {
let _timeline = timeline;
if (duplicate) {
_timeline = { ...timeline, updated: undefined, changed: undefined, version: null };
}
if (!isEmpty(_timeline.indexNames)) {
dispatch(
sourcererActions.setSelectedDataView({
id: SourcererScopeName.timeline,
selectedDataViewId: timeline.dataViewId,
selectedPatterns: timeline.indexNames,
selectedDataViewId: _timeline.dataViewId,
selectedPatterns: _timeline.indexNames,
})
);
}
if (
timeline.status === TimelineStatus.immutable &&
timeline.timelineType === TimelineType.template
_timeline.status === TimelineStatus.immutable &&
_timeline.timelineType === TimelineType.template
) {
dispatch(
dispatchSetRelativeRangeDatePicker({
Expand All @@ -461,24 +465,29 @@ export const dispatchUpdateTimeline =
dispatch(dispatchSetTimelineRangeDatePicker({ from, to }));
}
dispatch(
dispatchAddTimeline({ id, timeline, resolveTimelineConfig, savedTimeline: duplicate })
dispatchAddTimeline({
id,
timeline: _timeline,
resolveTimelineConfig,
savedTimeline: duplicate,
})
);
if (
!preventSettingQuery &&
timeline.kqlQuery != null &&
timeline.kqlQuery.filterQuery != null &&
timeline.kqlQuery.filterQuery.kuery != null &&
timeline.kqlQuery.filterQuery.kuery.expression !== ''
_timeline.kqlQuery != null &&
_timeline.kqlQuery.filterQuery != null &&
_timeline.kqlQuery.filterQuery.kuery != null &&
_timeline.kqlQuery.filterQuery.kuery.expression !== ''
) {
dispatch(
dispatchApplyKqlFilterQuery({
id,
filterQuery: {
kuery: {
kind: timeline.kqlQuery.filterQuery.kuery.kind ?? 'kuery',
expression: timeline.kqlQuery.filterQuery.kuery.expression || '',
kind: _timeline.kqlQuery.filterQuery.kuery.kind ?? 'kuery',
expression: _timeline.kqlQuery.filterQuery.kuery.expression || '',
},
serializedQuery: timeline.kqlQuery.filterQuery.serializedQuery || '',
serializedQuery: _timeline.kqlQuery.filterQuery.serializedQuery || '',
},
})
);
Expand Down

0 comments on commit 8d2bab7

Please sign in to comment.