Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution][Notes] - fix pinning behavior in document notes #194473

Merged
merged 4 commits into from
Oct 4, 2024

Conversation

christineweng
Copy link
Contributor

@christineweng christineweng commented Sep 30, 2024

Summary

Fixed some pinning behaviors in new notes system, namely:

  • Pinning is greyed out only when an event has a note attached to the current timeline, else pinning should work as usual (related: [Bug][Security Solution] - Unable to pin event with existing note #193738)
  • Adding a note and attaching to current timeline automatically pins the event
  • Pinned tab and pinning capability are updated when a note attached to current timeline is deleted

Feature flag: securitySolutionNotesEnabled

Screen.Recording.2024-10-01.at.4.26.25.PM.mov

Checklist

@christineweng christineweng added release_note:skip Skip the PR/issue when compiling release notes v9.0.0 Team:Threat Hunting Security Solution Threat Hunting Team Team:Threat Hunting:Investigations Security Solution Investigations Team backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) v8.16.0 labels Sep 30, 2024
@christineweng christineweng self-assigned this Sep 30, 2024
@christineweng christineweng changed the title [Security Solution][Notes] - fetch notes by saved object ids [Security Solution][Notes] - fix pinning behavior in document notes Oct 1, 2024
@christineweng christineweng marked this pull request as ready for review October 1, 2024 21:29
@christineweng christineweng requested review from a team as code owners October 1, 2024 21:29
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-threat-hunting (Team:Threat Hunting)

@elasticmachine
Copy link
Contributor

Pinging @elastic/security-threat-hunting-investigations (Team:Threat Hunting:Investigations)

Copy link
Contributor

@PhilippeOberti PhilippeOberti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm desk testing at the moment but left a couple of implementation notes, let me know what you think!

@@ -88,11 +94,22 @@ export const AddNote = memo(
},
})
);

// Automatically pin an associated event if it's attached to a timeline and it's not pinned yet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you be ok with passing a callback as props instead than having the code here? Something like onNoteAdded. The reason is when I created those components, I made sure (as much as possible) that they would not be anything timeline-specific code (as these are notes and shouldn't really know about timeline, alerts...)

I understand that there are a couple of places in this file called timelineId but that is just because currently the api is using that word. Ideally we would want to rename all those variables in the frontend by savedObjectId as a note can be associated with pretty much any savedObjectId, not just timeline ones...

Does that makes sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is a great feedback but i have a question on a separate scenario.

Consider below scenario:

  1. If I add a note on an alert in AlertTable.
  2. Then I add that event to a timeline.

Now since that event is attached to the timeline, should it already be pinned to that timeline?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope because in your scenario, you created a note attached to a document only. Having an event in a timeline doesn't mean that all its note will be associated with that timeline. You can still create note NOT associated with the timeline by unchecking the Attach to timeline checkbox.
The pin icon only reflects note that have been associated with a timelineId.

Does that make sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does make sense. In that case, do you think we should be more clear with the modal message which says Event cannot be unpinned because there are notes attached. It should rather say something along the lines of Event cannot be unpinned because this event and timeline have notes attached.

Not a big issue but something to keep a note of.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes that makes sense, we can get with @nastasha-solomon for the proper wording. Something like This event cannot be unpinned because it has notes associated with this current timeline.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really have a good answer at this time. I'll think about it some more!

Copy link
Contributor

@nastasha-solomon nastasha-solomon Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok I gotcha now. From the flyout (at least from now), there's no easy way to tell when a note is associated with a specific Timeline. Adding more text into the tooltip wouldn't necessarily help with that. Users would still need to go to the Notes management page to determine which notes are associated with certain Timelines.

One possibility is to move forward with the original language (This event cannot be unpinned because it has notes associated with a Timeline) and link to the docs. For example:

This event cannot be unpinned because it has notes associated with a Timeline. Learn more

It's not the best UX, but it might be a better experience than forcing users to read a multi-sentence tooltip message. The docs could also provide more guidance for figuring out when notes are associated with Timelines so users don't need to figure that out on their own.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the best we can do with the time we have right now yes. Thank you @nastasha-solomon

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Connected with @nastasha-solomon offline, we are going with This event cannot be unpinned because it has notes in Timeline. at this time.

When the docs issue is available, consider adding a link at the end: This event cannot be unpinned because it has notes in Timeline. Learn more (ticket here)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the collaboration here 🎆 🎆 . Thanks all.

@logeekal
Copy link
Contributor

logeekal commented Oct 2, 2024

Hey @christineweng , Consider adding an integration test here. This would ensure that this functionality works with both securitySolutionNotesEnabled true and false.

describe('Leading actions - pin', () => {
describe('securitySolutionNotesEnabled = true', () => {
beforeEach(() => {
(useIsExperimentalFeatureEnabled as jest.Mock).mockImplementation(
jest.fn((feature: keyof ExperimentalFeatures) => {

Copy link
Contributor

@logeekal logeekal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing blocking but some thoughts and questions. Let me know what you think.

I desk tested and all scenarios seem to be working fine except the one I mentioned below on add_note.tsx.

: timelineNoteIds;
}, [documentBasedNotes, timelineNoteIds, securitySolutionNotesEnabled]);
/* note ids specific to the current timeline, it is used to enable/disable pinning */
const noteIdsInTimeline = useMemo(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is a little misleading for couple of reasons:

  1. These actions can run in both timeline and non-timeline environment. so noteIdsInTimeline will be an empty array outside timeline table ( for example, alert table ) which i think is misleading. Not your fault because there exists timelineNoteIds which also does the same. Although I see that noteIdsInTimeline is using timelineNoteIds, do you think there is value in combining both of them and comment the difference between them?

  2. @PhilippeOberti , i think we should plan to clear/remove eventIdToNoteIds since that is not being used in latest when securitySolutionNotesEnabled is true. What do you think?

Copy link
Contributor

@PhilippeOberti PhilippeOberti Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I don't think we should touch anything related to the old note system, it means in this case timelineNoteIds. The reason there is some confusion here (and in a couple of other places) is because I wanted to have the new system to be completely separate from the old note one, for 2 reasons:
  • less risk to break an existing functionality
  • easier to remove the old code when the time comes (hopefully soon)
  1. the plan is to replace the securitySolutionNotesEnabled feature flag with a new securitySolutionNotesDisabled feature flag to enable the new notes system by default in 8.16. Then probably wait a release or two (or wait for 9.0.0 to remove the old system entirely and clean all this up (ticket)

Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@logeekal i think the confusion also stems from the fact that pinning and old notes are only available in timeline, but were not obvious in the actions. The complexity increases now that notes can be outside of timeline, so the "if the event has notes it must be pinned" logic no longer applies.

I have merged the 2 variables as you suggested with added comments. I also think once the old notes system is removed, we should refactor/rewrite the pin action to have the timeline logic inside.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @christineweng and @PhilippeOberti , I agree with both of you and leave the decision to you. Current change by @christineweng also looks pretty good to me and much more clear. Thanks 🙏 .

@@ -88,11 +94,22 @@ export const AddNote = memo(
},
})
);

// Automatically pin an associated event if it's attached to a timeline and it's not pinned yet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is a great feedback but i have a question on a separate scenario.

Consider below scenario:

  1. If I add a note on an alert in AlertTable.
  2. Then I add that event to a timeline.

Now since that event is attached to the timeline, should it already be pinned to that timeline?

Copy link
Contributor

@PhilippeOberti PhilippeOberti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for making the changes, this is perfect!

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 20.5MB 20.5MB +1.7KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @christineweng

@christineweng christineweng merged commit 883dfa8 into elastic:main Oct 4, 2024
40 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/11171977869

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Oct 4, 2024
…lastic#194473)

## Summary

Fixed some pinning behaviors in new notes system, namely:

- Pinning is greyed out only when an event has a note attached to the
**current** timeline, else pinning should work as usual (related:
elastic#193738)
- Adding a note and attaching to current timeline automatically pins the
event
- Pinned tab and pinning capability are updated when a note attached to
current timeline is deleted

Feature flag: `securitySolutionNotesEnabled`

https://github.com/user-attachments/assets/0163d4a4-354c-4928-a337-40a93f6c7b2a

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

(cherry picked from commit 883dfa8)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Oct 4, 2024
…otes (#194473) (#194890)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Security Solution][Notes] - fix pinning behavior in document notes
(#194473)](#194473)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"christineweng","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-04T00:42:26Z","message":"[Security
Solution][Notes] - fix pinning behavior in document notes
(#194473)\n\n## Summary\r\n\r\nFixed some pinning behaviors in new notes
system, namely:\r\n\r\n- Pinning is greyed out only when an event has a
note attached to the\r\n**current** timeline, else pinning should work
as usual
(related:\r\nhttps://github.com//issues/193738)\r\n-
Adding a note and attaching to current timeline automatically pins
the\r\nevent\r\n- Pinned tab and pinning capability are updated when a
note attached to\r\ncurrent timeline is deleted\r\n\r\nFeature flag:
`securitySolutionNotesEnabled`\r\n\r\n\r\nhttps://github.com/user-attachments/assets/0163d4a4-354c-4928-a337-40a93f6c7b2a\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"883dfa8ae887c1ee57049a45d8ed8ceb7c2a34d6","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Threat
Hunting","Team:Threat
Hunting:Investigations","backport:prev-minor","v8.16.0"],"title":"[Security
Solution][Notes] - fix pinning behavior in document
notes","number":194473,"url":"https://github.com/elastic/kibana/pull/194473","mergeCommit":{"message":"[Security
Solution][Notes] - fix pinning behavior in document notes
(#194473)\n\n## Summary\r\n\r\nFixed some pinning behaviors in new notes
system, namely:\r\n\r\n- Pinning is greyed out only when an event has a
note attached to the\r\n**current** timeline, else pinning should work
as usual
(related:\r\nhttps://github.com//issues/193738)\r\n-
Adding a note and attaching to current timeline automatically pins
the\r\nevent\r\n- Pinned tab and pinning capability are updated when a
note attached to\r\ncurrent timeline is deleted\r\n\r\nFeature flag:
`securitySolutionNotesEnabled`\r\n\r\n\r\nhttps://github.com/user-attachments/assets/0163d4a4-354c-4928-a337-40a93f6c7b2a\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"883dfa8ae887c1ee57049a45d8ed8ceb7c2a34d6"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/194473","number":194473,"mergeCommit":{"message":"[Security
Solution][Notes] - fix pinning behavior in document notes
(#194473)\n\n## Summary\r\n\r\nFixed some pinning behaviors in new notes
system, namely:\r\n\r\n- Pinning is greyed out only when an event has a
note attached to the\r\n**current** timeline, else pinning should work
as usual
(related:\r\nhttps://github.com//issues/193738)\r\n-
Adding a note and attaching to current timeline automatically pins
the\r\nevent\r\n- Pinned tab and pinning capability are updated when a
note attached to\r\ncurrent timeline is deleted\r\n\r\nFeature flag:
`securitySolutionNotesEnabled`\r\n\r\n\r\nhttps://github.com/user-attachments/assets/0163d4a4-354c-4928-a337-40a93f6c7b2a\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"883dfa8ae887c1ee57049a45d8ed8ceb7c2a34d6"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: christineweng <[email protected]>
tiansivive pushed a commit to tiansivive/kibana that referenced this pull request Oct 7, 2024
…lastic#194473)

## Summary

Fixed some pinning behaviors in new notes system, namely:

- Pinning is greyed out only when an event has a note attached to the
**current** timeline, else pinning should work as usual (related:
elastic#193738)
- Adding a note and attaching to current timeline automatically pins the
event
- Pinned tab and pinning capability are updated when a note attached to
current timeline is deleted

Feature flag: `securitySolutionNotesEnabled`


https://github.com/user-attachments/assets/0163d4a4-354c-4928-a337-40a93f6c7b2a


### 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) release_note:skip Skip the PR/issue when compiling release notes Team:Threat Hunting:Investigations Security Solution Investigations Team Team:Threat Hunting Security Solution Threat Hunting Team v8.16.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants