Skip to content

Commit

Permalink
[SecuritySolution] Fix issue with duplicate timeline reloading (elast…
Browse files Browse the repository at this point in the history
…ic#198652)

## Summary

Fixes: elastic#173240

Unsaved duplicated timelines will now show the save notification when
the user is trying to leave security solution without saving.

The PR also re-enables the `unsaved_timelines` cypress tests.


https://github.com/user-attachments/assets/429d23fc-0cd5-4f0a-bcc9-0fd025856b6e




### 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

---------

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
janmonschke and elasticmachine authored Nov 6, 2024
1 parent 0120b2a commit bde5e11
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('dispatchUpdateTimeline', () => {
...mockTimelineModel,
version: null,
updated: undefined,
changed: undefined,
changed: true,
},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export const useUpdateTimeline = () => {
}: UpdateTimeline) => {
let _timeline = timeline;
if (duplicate) {
_timeline = { ...timeline, updated: undefined, changed: undefined, version: null };
// Reset the `updated` and `version` fields because a duplicated timeline has not been saved yet.
// The `changed` field is set to true because the duplicated timeline needs to be saved.
_timeline = { ...timeline, updated: undefined, changed: true, version: null };
}
if (!isEmpty(_timeline.indexNames)) {
dispatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
openKibanaNavigation,
} from '../../../tasks/kibana_navigation';
import { login } from '../../../tasks/login';
import { visitWithTimeRange } from '../../../tasks/navigation';
import { visit, visitWithTimeRange } from '../../../tasks/navigation';
import {
closeTimelineUsingCloseButton,
openTimelineUsingToggle,
Expand All @@ -32,13 +32,14 @@ import {
} from '../../../tasks/serverless/navigation';
import {
addNameToTimelineAndSave,
closeTimeline,
createNewTimeline,
duplicateFirstTimeline,
populateTimeline,
} from '../../../tasks/timeline';
import { EXPLORE_URL, hostsUrl, MANAGE_URL } from '../../../urls/navigation';
import { EXPLORE_URL, hostsUrl, MANAGE_URL, TIMELINES_URL } from '../../../urls/navigation';

// FLAKY: https://github.com/elastic/kibana/issues/174068
describe.skip('[ESS] Save Timeline Prompts', { tags: ['@ess'] }, () => {
describe('[ESS] Save Timeline Prompts', { tags: ['@ess'] }, () => {
beforeEach(() => {
login();
visitWithTimeRange(hostsUrl('allHosts'));
Expand Down Expand Up @@ -119,6 +120,17 @@ describe.skip('[ESS] Save Timeline Prompts', { tags: ['@ess'] }, () => {
cy.get(TIMELINE_SAVE_MODAL).should('not.exist');
cy.url().should('not.contain', MANAGE_URL);
});

it('should prompt when a timeline is duplicated but not saved', () => {
addNameToTimelineAndSave('Original');
closeTimeline();
visit(TIMELINES_URL);
duplicateFirstTimeline();
closeTimeline();
openKibanaNavigation();
navigateFromKibanaCollapsibleTo(MANAGE_PAGE);
cy.get(APP_LEAVE_CONFIRM_MODAL).should('be.visible');
});
});

// In serverless it is not possible to use the navigation menu without closing the timeline
Expand Down Expand Up @@ -201,4 +213,14 @@ describe('[serverless] Save Timeline Prompts', { tags: ['@serverless'] }, () =>
navigateToExploreUsingBreadcrumb(); // explore has timelines disabled
cy.get(APP_LEAVE_CONFIRM_MODAL).should('not.exist');
});

it('should prompt when a timeline is duplicated but not saved', () => {
addNameToTimelineAndSave('Original');
closeTimeline();
visit(TIMELINES_URL);
duplicateFirstTimeline();
closeTimeline();
navigateToExplorePageInServerless(); // security page with timelines disabled
cy.get(APP_LEAVE_CONFIRM_MODAL).should('be.visible');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export const TIMELINES_PINNED_EVENT_COUNT = '[data-test-subj="pinned-event-count

export const TIMELINES_TABLE = '[data-test-subj="timelines-table"]';

export const DUPLICATE_TIMELINE = '[data-test-subj="open-duplicate"]';

export const TIMELINES_USERNAME = '[data-test-subj="username"]';

export const REFRESH_BUTTON = '[data-test-subj="refreshButton-linkIcon"]';
Expand Down
19 changes: 17 additions & 2 deletions x-pack/test/security_solution_cypress/cypress/tasks/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,22 @@ import {
QUERY_EVENT_COUNT,
TIMELINE_ENABLE_DISABLE_ALL_ROW_RENDERER,
TIMELINE_DISCOVER_FIELDS_BUTTON,
TIMELINE_TITLE,
} from '../screens/timeline';

import { REFRESH_BUTTON, TIMELINE, TIMELINES_TAB_TEMPLATE } from '../screens/timelines';
import {
DUPLICATE_TIMELINE,
REFRESH_BUTTON,
TIMELINE,
TIMELINES_TABLE,
TIMELINES_TAB_TEMPLATE,
} from '../screens/timelines';
import { waitForTabToBeLoaded } from './common';

import { closeFieldsBrowser, filterFieldsBrowser } from './fields_browser';
import { TIMELINE_CONTEXT_MENU_BTN } from '../screens/alerts';
import { LOADING_INDICATOR } from '../screens/security_header';
import { TOASTER } from '../screens/alerts_detection_rules';
import { COLLAPSED_ACTION_BTN, TOASTER } from '../screens/alerts_detection_rules';
import { RUNTIME_FIELD_INPUT, SAVE_FIELD_BUTTON } from '../screens/create_runtime_field';

const hostExistsQuery = 'host.name: *';
Expand Down Expand Up @@ -150,6 +157,14 @@ export const addNameAndDescriptionToTimeline = (
cy.get(TIMELINE_TITLE_INPUT).should('not.exist');
};

export const duplicateFirstTimeline = () => {
cy.get(TIMELINES_TABLE).within(() => {
cy.get(COLLAPSED_ACTION_BTN).first().click();
});
cy.get(DUPLICATE_TIMELINE).click();
cy.get(TIMELINE_TITLE).should('be.visible');
};

export const goToNotesTab = () => {
cy.get(NOTES_TAB_BUTTON).click();
cy.get(NOTES_TEXT_AREA).should('be.visible');
Expand Down

0 comments on commit bde5e11

Please sign in to comment.