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

[Cloud Security] Fix for issue where date is not retained when opening new tab #205128

Merged
merged 6 commits into from
Jan 3, 2025

Conversation

animehart
Copy link
Contributor

@animehart animehart commented Dec 24, 2024

Summary

This PR addresses the issue where when user opens new tab by clicking on popout icon on Alerts Data grid on Alerts preview Contextual flyout, the date from original tab is not retained, as such there are scenario where user don't see any alerts on new tab because its defaulted to today when the alerts only exist from view days ago

Screen.Recording.2024-12-23.at.10.59.08.PM.mov

@animehart
Copy link
Contributor Author

/ci

@animehart animehart added v8.18.0 v9.0.0 Team:Cloud Security Cloud Security team related 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 labels Dec 24, 2024
@animehart animehart marked this pull request as ready for review December 24, 2024 16:58
@animehart animehart requested review from a team as code owners December 24, 2024 16:58
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-cloud-security-posture (Team:Cloud Security)

@Omolola-Akinleye Omolola-Akinleye self-requested a review December 30, 2024 17:27
Copy link
Contributor

@Omolola-Akinleye Omolola-Akinleye left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment on lines 19 to 30
return (
filterItems: FilterControlConfig | FilterControlConfig[],
openInNewTab = false,
timerange?: string
) => {
const urlFilterParams = encode(
formatPageFilterSearchParam(Array.isArray(filterItems) ? filterItems : [filterItems])
);

const timerangePath = timerange ? `&timerange=${timerange}` : '';
navigateTo({
deepLinkId: SecurityPageName.alerts,
path: `?${URL_PARAM_KEY.pageFilter}=${urlFilterParams}`,
path: `?${URL_PARAM_KEY.pageFilter}=${urlFilterParams}${timerangePath}`,
Copy link
Contributor

@JordanSh JordanSh Dec 31, 2024

Choose a reason for hiding this comment

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

Im wondering if we can't use the existing urlFilterParams and add timerange to them directly.
The problem the might occur with the current fix is that what happens if both urlFilterParams and timerangePath include a timerange filter?

the table file seems to include the needed functions to create this query. and the encoding is happening here on this hook file. so if we can insert the timerange filter from the table it would be ideal.

im approving, but please verify if that double timerange filter case can actually happen. if so, we probably need to address it before merging. i might also be missing the reason why this suggestion wont work so ill be glad if you could explain if you already tried it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmmmm so before this actually I Tried adding timerange on the Alerts page filter to no avail
but your question is a good one, I'm not 100% sure if its not doable on adding timerange directly on the pageFilter, Im going to ask Security Team about this

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes this could be a scenario that happens, but I think it is very unlikely, as developers would have to specifically pass a timerange AND a timestamp filter to this hook...

Also in the UI when using this hook, chances are that it would show the following message, letting the user know the filters have changed and would encourage them to look at them
Screenshot 2025-01-03 at 10 11 07 AM

And finally, I'm not expecting many people to use this new timerange prop many often, as the only usage at the moment is for the alerts_findings_details_table.tsx above, all the other instances are not opening in a new tab

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 tested and everything looks to be working as expected.

I left a small comment if you're OK adding some code documentation on the properties of the function that the hook returns.
Also, could you add some new unit test cases to cover the new prop?

Thanks!

Comment on lines 21 to 22
openInNewTab = false,
timerange?: string
Copy link
Contributor

Choose a reason for hiding this comment

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

Currently, no-one (except the usage in the file alerts_findings_details_table.tsx above) is using the openInNewTab property. It seems to me that the new timerange property is fully related to the fact that we want to open in a new tab. If openInNewTabis false, the user is just navigating to a different page in Kibana within the same browser tab, and the KQL bar and its date time picker remain the same (meaning the date and time are persisted).

I've been trying to find a good way to combine openInNewTab and timerange somehow together?, but I'm not liking any of the solutions I can come up with.

I'm ok keeping things as you have right now, but if you have an idea let me know!

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 adding these prop documentations?

    /**
     * Pass one or more filter control configurations to be applied to the alerts page filters
     */
    filterItems: FilterControlConfig | FilterControlConfig[],
    /**
     * If true, the alerts page will be opened in a new tab
     */
    openInNewTab = false,
    /**
     * Allows to customize the timerange url parameter. Should only be used in combination with the openInNewTab=true parameter
     */
    timerange?: string

Comment on lines 19 to 30
return (
filterItems: FilterControlConfig | FilterControlConfig[],
openInNewTab = false,
timerange?: string
) => {
const urlFilterParams = encode(
formatPageFilterSearchParam(Array.isArray(filterItems) ? filterItems : [filterItems])
);

const timerangePath = timerange ? `&timerange=${timerange}` : '';
navigateTo({
deepLinkId: SecurityPageName.alerts,
path: `?${URL_PARAM_KEY.pageFilter}=${urlFilterParams}`,
path: `?${URL_PARAM_KEY.pageFilter}=${urlFilterParams}${timerangePath}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes this could be a scenario that happens, but I think it is very unlikely, as developers would have to specifically pass a timerange AND a timestamp filter to this hook...

Also in the UI when using this hook, chances are that it would show the following message, letting the user know the filters have changed and would encourage them to look at them
Screenshot 2025-01-03 at 10 11 07 AM

And finally, I'm not expecting many people to use this new timerange prop many often, as the only usage at the moment is for the alerts_findings_details_table.tsx above, all the other instances are not opening in a new tab

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 adding the documentation and the tests!

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #8 / ConnectorFields renders Validation validates correctly if the provider config url is empty
  • [job] [logs] FTR Configs #33 / InfraOps App Metrics UI Node Details #Asset Type: host Osquery Tab should show a date picker

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 22.2MB 22.2MB +615.0B

History

@animehart animehart merged commit 32dbd14 into elastic:main Jan 3, 2025
8 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

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

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jan 3, 2025
…g new tab (elastic#205128)

## Summary

This PR addresses the issue where when user opens new tab by clicking on
popout icon on Alerts Data grid on Alerts preview Contextual flyout, the
date from original tab is not retained, as such there are scenario where
user don't see any alerts on new tab because its defaulted to today when
the alerts only exist from view days ago

https://github.com/user-attachments/assets/58a30d7d-18b3-47a8-ab4b-2ce143583368
(cherry picked from commit 32dbd14)
@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 Jan 3, 2025
…opening new tab (#205128) (#205538)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Cloud Security] Fix for issue where date is not retained when
opening new tab
(#205128)](#205128)

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

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

<!--BACKPORT [{"author":{"name":"Rickyanto
Ang","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-03T19:44:11Z","message":"[Cloud
Security] Fix for issue where date is not retained when opening new tab
(#205128)\n\n## Summary\r\n\r\nThis PR addresses the issue where when
user opens new tab by clicking on\r\npopout icon on Alerts Data grid on
Alerts preview Contextual flyout, the\r\ndate from original tab is not
retained, as such there are scenario where\r\nuser don't see any alerts
on new tab because its defaulted to today when\r\nthe alerts only exist
from view days
ago\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/58a30d7d-18b3-47a8-ab4b-2ce143583368","sha":"32dbd14519584b118861a209fdc841b011b5b5a0","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Cloud
Security","backport:prev-minor","v8.18.0"],"title":"[Cloud Security] Fix
for issue where date is not retained when opening new
tab","number":205128,"url":"https://github.com/elastic/kibana/pull/205128","mergeCommit":{"message":"[Cloud
Security] Fix for issue where date is not retained when opening new tab
(#205128)\n\n## Summary\r\n\r\nThis PR addresses the issue where when
user opens new tab by clicking on\r\npopout icon on Alerts Data grid on
Alerts preview Contextual flyout, the\r\ndate from original tab is not
retained, as such there are scenario where\r\nuser don't see any alerts
on new tab because its defaulted to today when\r\nthe alerts only exist
from view days
ago\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/58a30d7d-18b3-47a8-ab4b-2ce143583368","sha":"32dbd14519584b118861a209fdc841b011b5b5a0"}},"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/205128","number":205128,"mergeCommit":{"message":"[Cloud
Security] Fix for issue where date is not retained when opening new tab
(#205128)\n\n## Summary\r\n\r\nThis PR addresses the issue where when
user opens new tab by clicking on\r\npopout icon on Alerts Data grid on
Alerts preview Contextual flyout, the\r\ndate from original tab is not
retained, as such there are scenario where\r\nuser don't see any alerts
on new tab because its defaulted to today when\r\nthe alerts only exist
from view days
ago\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/58a30d7d-18b3-47a8-ab4b-2ce143583368","sha":"32dbd14519584b118861a209fdc841b011b5b5a0"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Rickyanto Ang <[email protected]>
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:Cloud Security Cloud Security team related v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Date filter is not retained when navigating from Alerts Contextual Flyout to Alerts page
6 participants