-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Conversation
/ci |
Pinging @elastic/kibana-cloud-security-posture (Team:Cloud Security) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
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}`, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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
There was a problem hiding this 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!
openInNewTab = false, | ||
timerange?: string |
There was a problem hiding this comment.
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 openInNewTab
is 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!
There was a problem hiding this comment.
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
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}`, |
There was a problem hiding this comment.
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
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
There was a problem hiding this 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!
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Async chunks
History
|
Starting backport for target branches: 8.x |
…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)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…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]>
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