-
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
[Infra UI] Store asset details page state in the URL state #164601
[Infra UI] Store asset details page state in the URL state #164601
Conversation
fc75cb3
to
844d428
Compare
072f5b6
to
4c44838
Compare
4c44838
to
a526204
Compare
x-pack/plugins/infra/public/pages/metrics/metric_detail/asset_detail_page.tsx
Show resolved
Hide resolved
Pinging @elastic/infra-monitoring-ui (Team:Infra Monitoring UI) |
@elasticmachine merge upstream |
/oblt-deploy |
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.
Great job Mycola 👏!
I quickly tested it and everything seems to be working. Just a few comments and one adjustments in the use_asset_details_url_state
regarding the itemId
attribute.
x-pack/plugins/infra/public/pages/metrics/metric_detail/asset_detail_page.tsx
Show resolved
Hide resolved
@@ -53,10 +53,10 @@ const FlyoutTabIdRT = rt.union([ | |||
rt.literal(FlyoutTabIds.OSQUERY), | |||
]); | |||
|
|||
const HostFlyoutStateRT = rt.intersection([ | |||
const AssetDetailsStateRT = rt.intersection([ | |||
rt.type({ | |||
itemId: rt.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.
The itemId
is only used in the use_hosts_table
. It can be moved over to the use_hosts_table
state. With that, the asset_details_url_state
will contain only attributes relevant to the Asset Details component. Wdyt?
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.
Good point, will move it to the useHostsTableUrlState
@@ -28,21 +28,14 @@ export type TabIds = `${FlyoutTabIds}`; | |||
|
|||
export interface OverridableTabState { |
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.
Nice!
@@ -140,7 +140,7 @@ export const useHostsTable = () => { | |||
} = useKibanaContextForPlugin(); | |||
const { dataView } = useMetricsDataViewContext(); | |||
|
|||
const [hostFlyoutState, setHostFlyoutState] = useHostFlyoutUrlState(); | |||
const [hostFlyoutState, setHostFlyoutState] = useAssetDetailsUrlState(); |
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.
We're only using the useAssetDetailsUrlState
to get the itemId
and control the flyout's visibility. It seems like this attribute should be owned by the use_hosts_table
.
The URL state I'm thinking of is the useHostsTableUrlState
. Looks like itemId
could be moved to that hook .
x-pack/plugins/infra/public/pages/metrics/metric_detail/asset_detail_page.tsx
Outdated
Show resolved
Hide resolved
* running effects (like updating the URL) before | ||
* refreshing the page. | ||
*/ | ||
await pageObjects.common.sleep(1000); |
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.
Q: Have you encountered any problems due to a delay in updating the state before refreshing the page?
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.
Yeah, unfortunately sometimes the browser starts to refresh before URL is changed. I assume it's because we don't write to the URL directly but rather use router hooks, making URL updates basically part of the react rendering cycle. Which is convenient for business logic of course, but for these kinds of tests I could not find a better solution other than to introduce an artificial delay, unfortunately 😔
await searchInput.type('test'); | ||
await refreshPageWithDelay(); | ||
|
||
expect(await searchInput.getAttribute('value')).to.be('test'); |
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.
Asserts after page refresh are tricky and often cause flakiness.
The "safest" approach would be to wrap the expect
in a retry.try
function.
retry.try(async () => {
expect(await searchInput.getAttribute('value')).to.be('test');
})
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.
Good to know, thanks!
@@ -284,6 +294,16 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { | |||
}); | |||
}); | |||
|
|||
it('preserves selected tab between page reloads', async () => { |
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.
It might be better to centralize these "preserves..." test scenarios in the node_details
test suite. The host_view
suite would become less focused on the asset details functionality, while the node_details
could focus on more in-depth test cases. Wdyt?
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.
agree 👍
AssetDetailsProps, | ||
'asset' | 'assetType' | 'overrides' | 'onTabsStateChange' | 'renderMode' | ||
>; | ||
state: Pick<AssetDetailsProps, 'asset' | 'assetType' | 'overrides' | 'renderMode'>; | ||
} | ||
|
||
export function useAssetDetailsState({ state }: UseAssetDetailsStateProps) { |
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'm under the impression that the names here have become confusing with the introduction of the use_asset_details_url_state
. I wonder if it should be called something along the lines of useAssetDetailsRenderInfo
.
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.
makes sense, will rename 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.
Well done! Checked it and it works fine 🙌 Added some small comments (nothing blocking the PR)
x-pack/plugins/infra/public/components/asset_details/hooks/use_date_range.ts
Outdated
Show resolved
Hide resolved
@@ -6,7 +6,7 @@ | |||
*/ | |||
|
|||
import React from 'react'; | |||
import { AssetDetailsStateProvider } from './hooks/use_asset_details_state'; | |||
import { AssetDetailsRenderPropsProvider } from './hooks/use_asset_details_render_props'; |
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.
Settled on AssetDetailsRenderProps
name, seemed like it better conveys the purpose, but let me know if that does not look right 🙌
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.
nice!
💚 Build Succeeded
Metrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: |
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 🚀 ! Thanks for applying the suggestions.
Closes #164147
Summary
This PR moves the responsibility of updating the URL state into the
<AssetDetails>
instead of providing callbacks for parent components to manage the state themselves. This way logic for updating the URL state is centralized and shared between the Host details flyout and the Host details page.How to test