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

[Infra UI] Add date picker to asset details #164450

Merged

Conversation

crespocarlos
Copy link
Contributor

@crespocarlos crespocarlos commented Aug 22, 2023

closes: #160378

Summary

This PR adds a date-picker to the Asset Details (full page and flyout)

Flyout
image

Full page view
image

Setting a date range

full_page_date_picker.mov

Brush event filter

chart_date_filter.mov

Bonus

The uptime link was removed since the UI won't work.

How to test

  • Start a local Kibana instance
  • Start metricbeat with system module enabled
  • Navigate to Infrastructure > Hosts
    • Click on a host name and check if the new Node Details page opened
      • Check if the date range is set with the same date range from the Host Detail view
  • Navigate to Infrastructure > Hosts
    • Open the flyout
    • Click on Open as page and check if the new Node Details page opened with the same date range from the Host Detail view
  • Navigate to Infrastructure > Inventory
    - With Show: Host selected, click on a waffle item to open the flyout, click on Open as page and check if the new Node Details page opened with the same date range from the Inventory UI

Validate if the date picker value is applied to all tabs that have the component (Overview, Metadata, Processes, Logs, Anomalies)
Validate if the date range changes when selecting a time range in the charts (in the flyout, the date range from the Hosts View must not change)

@apmmachine
Copy link
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • /oblt-deploy-serverless : Deploy a serverless Kibana instance using the Observability test environments.
  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@crespocarlos crespocarlos force-pushed the 160378-add-date-picker-to-asset-details branch from baec8be to ea4bf91 Compare August 22, 2023 13:19
<EuiIconTip
aria-label={i18n.translate(
'xpack.infra.metrics.nodeDetails.processesHeader.tooltipLabel',
<EuiFlexGroup direction="column" gutterSize="m">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to use flexbox instead of having <EuiSpacer size="m" /> to separate each section

@@ -218,14 +228,6 @@ const ProcessesTableBody = ({ items, currentTime }: TableBodyProps) => (
</>
);

const StyledTableBody = euiStyled(EuiTableBody)`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

euiStyled is marked as deprecated.

overflow: hidden;
text-overflow: ellipsis;
`;
const CodeLine = ({ command }: { command: string }) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

euiStyled is deprecated. Created this new component in order to replace it.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for changing those!

const [hostFlyoutState, setHostFlyoutState] = useHostFlyoutUrlState();

return source ? (
<AssetDetails
asset={{ id: name, name }}
assetType="host"
dateRange={searchCriteria.dateRange}
dateRange={parsedDateRange}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

With this change, we make sure the flyout will always open with the same date range. Previously, if the date picker had relative dates, each time the flyout opened a new absolute date would be calculated.

align-self: center;
`}
>
<EuiEmptyPrompt
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replacing with an EUI component

Comment on lines +458 to +467
{!hideDatePicker && (
<EuiFlexItem grow={false}>
<EuiSuperDatePicker
start={dateRange.from}
end={dateRange.to}
showUpdateButton={false}
onTimeChange={onTimeChange}
width="full"
/>
</EuiFlexItem>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't want to mess with other components that use the anomalies table. We might want to refactor this component in the future and split content and date picker into separate components

Comment on lines 83 to 92
// Retrocompatibility
const handleTabStateChange = ({ dateRange: newDateRange }: TabState) => {
if (newDateRange) {
setTimeRange({
from: newDateRange.from,
to: newDateRange.to,
interval: parsedTimeRange.interval,
});
}
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can remove this once we start storing the asset details state in the URL.

@crespocarlos crespocarlos added Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting v8.11.0 Feature:Metrics UI Metrics UI feature Feature:ObsHosts Hosts feature within Observability labels Aug 23, 2023
@crespocarlos crespocarlos changed the title 160378 add date picker to asset details [Infra UI] Add date picker to asset details Aug 23, 2023
@crespocarlos crespocarlos force-pushed the 160378-add-date-picker-to-asset-details branch from 21e007d to 8c1e5c7 Compare August 23, 2023 12:38
@crespocarlos
Copy link
Contributor Author

@elasticmachine merge upstream

@crespocarlos crespocarlos marked this pull request as ready for review August 23, 2023 13:45
@crespocarlos crespocarlos requested a review from a team as a code owner August 23, 2023 13:45
@elasticmachine
Copy link
Contributor

Pinging @elastic/infra-monitoring-ui (Team:Infra Monitoring UI)

@jennypavlova jennypavlova self-requested a review August 24, 2023 09:20
({
range,
preventDefault,
}: Parameters<NonNullable<LensEmbeddableInput['onBrushEnd']>>[0]) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Might make sense to add an alias for this type to make it a bit easier to read

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.

Copy link
Member

@jennypavlova jennypavlova left a comment

Choose a reason for hiding this comment

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

Good job! 👏 The new date picker works fine and the date value persists between the tabs. I have some questions as I think I found 2 issues that we can check:

In case the user changes the time range inside the flyout it persists when he opens the details page but when the back button is pressed the flyout loads with the default time range (not the selected one when the user left the page to see the details page):

Screen.Recording.2023-08-24.at.12.11.22.mov

When the user selects the date inside the flyout and refreshes the page/shares the URL the time range does not persist

Screen.Recording.2023-08-24.at.12.07.51.mov

I am not sure about that but sometimes when using "now" as "to" date it is converted to relative data and sometimes it stays as "now". Usually, when the "from" date is changed it changes to the relative date instead of "now" so what should be the expected behavior (should we use "now" or we should always convert to the relative date?):

Screen.Recording.2023-08-24.at.12.46.03.mov
Screen.Recording.2023-08-24.at.12.47.08.mov
Screenshot 2023-08-24 at 12 45 41

overflow: hidden;
text-overflow: ellipsis;
`;
const CodeLine = ({ command }: { command: string }) => {
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for changing those!

initialDateRange: TimeRange;
}

export function useDateRangeProvider({ initialDateRange }: UseAssetDetailsStateProps) {
Copy link
Member

Choose a reason for hiding this comment

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

When we have the date range persisted in the URL (the case of the flyout for example) should we first get the date range from the URL value (passed to the asset details component) and if we don't have it to fallback to default (the value selected in the host view / the 15m default)?

Copy link
Contributor Author

@crespocarlos crespocarlos Aug 24, 2023

Choose a reason for hiding this comment

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

You're completely right. I totally forgot to store the date range in the URL state.

]);
});

describe('#Date picker', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Nice ❤️

FlyoutTabIds.OVERVIEW,
FlyoutTabIds.LOGS,
FlyoutTabIds.METADATA,
FlyoutTabIds.PROCESSES,
Copy link
Member

Choose a reason for hiding this comment

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

Are the processes tab results affected by the new dates as in the process list API it will always check for 1-minute interval 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Never mind I saw that we plan to add a tooltip to explain that in this issue so I guess it should be fine.

@crespocarlos
Copy link
Contributor Author

Thanks @mykolaharmash and @jennypavlova for reviewing the PR.

In case the user changes the time range inside the flyout it persists when he opens the details page but when the back button is pressed the flyout loads with the default time range (not the selected one when the user left the page to see the details page):

That's an interesting use case. To achieve that we'd have to have a context provider to share the state between Hosts and Node Details. It's similar to this #164300, but the other way around. Perhaps we can rephrase that ticket to cover this use case?

When the user selects the date inside the flyout and refreshes the page/shares the URL the time range does not persist

Working on this.

I am not sure about that but sometimes when using "now" as "to" date it is converted to relative data and sometimes it stays as "now". Usually, when the "from" date is changed it changes to the relative date instead of "now" so what should be the expected behavior (should we use "now" or we should always convert to the relative date?):

Gotcha. The second video shows the problem. Will check

@crespocarlos
Copy link
Contributor Author

@elasticmachine merge upstream

@crespocarlos
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Member

@jennypavlova jennypavlova 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 the changes! I tried the navigation again and now the full page is setting the last one hour based on the "to" date - not the whole interval set in the flyout:

nav_to_full_page.mov

Is that intentional or it should be changed?

But going back to the flyout is fixed (the selected dates before navigating to the full page view are shown) the URL sharing and persisting after refresh as well 🎉

@@ -64,9 +64,11 @@ export const useMetricsTime = () => {
parseRange(urlState.time || DEFAULT_TIMERANGE)
);

const updateTimeRange = useCallback((range: MetricsTimeInput) => {
const updateTimeRange = useCallback((range: MetricsTimeInput, parseDate = true) => {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: maybe we can always pass a parsed date to this function so here we can simplify the logic, wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't want to change this function so much. We won't use it after this #164147 is done

@crespocarlos
Copy link
Contributor Author

Thanks for the changes! I tried the navigation again and now the full page is setting the last one hour based on the "to" date - not the whole interval set in the flyout:

nav_to_full_page.mov
Is that intentional or it should be changed?

@jennypavlova , thanks for thoroughly testing things! The link was doing what the inventory does: end date - 1h. I've fixed it and added a test to validate it.

@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
infra 2.0MB 2.0MB +241.0B

History

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

Copy link
Member

@jennypavlova jennypavlova left a comment

Choose a reason for hiding this comment

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

LGTM 🚀 Thank you for the fixes!

@crespocarlos crespocarlos merged commit c7dd76d into elastic:main Aug 25, 2023
@crespocarlos crespocarlos deleted the 160378-add-date-picker-to-asset-details branch August 25, 2023 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Metrics UI Metrics UI feature Feature:ObsHosts Hosts feature within Observability release_note:skip Skip the PR/issue when compiling release notes Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services v8.11.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Infra UI] Add date picker to the asset details
7 participants