Skip to content

[Unified Search] Fix date picker double click issue#218769

Closed
kowalczyk-krzysztof wants to merge 9 commits intoelastic:mainfrom
kowalczyk-krzysztof:fix/date-picker-double-click
Closed

[Unified Search] Fix date picker double click issue#218769
kowalczyk-krzysztof wants to merge 9 commits intoelastic:mainfrom
kowalczyk-krzysztof:fix/date-picker-double-click

Conversation

@kowalczyk-krzysztof
Copy link
Copy Markdown
Member

Summary

This PR fixes an issue where you would need to click the date picker two times if it was collapsed because unified search bar was expanded.

Closes: #177053

@kowalczyk-krzysztof kowalczyk-krzysztof added Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas t// release_note:skip Skip the PR/issue when compiling release notes backport:version Backport to applied version labels v8.19.0 labels Apr 22, 2025
@kowalczyk-krzysztof kowalczyk-krzysztof self-assigned this Apr 22, 2025

// ref.current.contains() is failing when the range is not in commonly used ranges
const refContainsTarget =
quickSelectButtonRef?.current?.getAttribute('itemid') === target?.getAttribute('itemid');
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Even though the HTML element is exactly the same, ref.current.contains() only works when the time range is one of the commonly used ones AND its label is visible. So an attribute check is needed.

quickSelectButtonRef?.current?.getAttribute('itemid') === target?.getAttribute('itemid');

// Check if the date range is in the commonly used ranges and prevent programmatic click
const isRangeInCommonlyUsed = commonlyUsedRanges.some(({ label }: { label: string }) =>
Copy link
Copy Markdown
Member Author

@kowalczyk-krzysztof kowalczyk-krzysztof Apr 22, 2025

Choose a reason for hiding this comment

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

For some reason, when time range is one of the commonly used ones and the label is visible (the time range can be both one of the common ones and display both from and to if you set it manually) a programmatic click causes a double click, which closes the popover.

The only reliable way of finding if the time range is both commonly used and displays the label I could find is checking the inner text of the label. This implementation works when you change the locale.

@kowalczyk-krzysztof kowalczyk-krzysztof added the Feature:Unified search Unified search related tasks label Apr 22, 2025
@kowalczyk-krzysztof kowalczyk-krzysztof marked this pull request as ready for review April 22, 2025 08:14
@kowalczyk-krzysztof kowalczyk-krzysztof requested a review from a team as a code owner April 22, 2025 08:14
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/kibana-presentation (Team:Presentation)

@kowalczyk-krzysztof
Copy link
Copy Markdown
Member Author

When manually going through the test case, the behavior works as expected, so it's a test only issue.

@kowalczyk-krzysztof kowalczyk-krzysztof marked this pull request as draft April 22, 2025 13:41
@kowalczyk-krzysztof kowalczyk-krzysztof marked this pull request as ready for review April 22, 2025 23:34
@kowalczyk-krzysztof kowalczyk-krzysztof requested a review from a team as a code owner April 22, 2025 23:34
Copy link
Copy Markdown
Contributor

@davismcphee davismcphee left a comment

Choose a reason for hiding this comment

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

Code-only review, Discover test changes LGTM.

return await this.testSubjects.exists('unifiedHistogramChart');
}

public async closeDatePickerPopover() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: Seems like this method would be better suited to a common FTR service like TimePickerPageObject since it's not really Discover specific.

@elasticmachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #7 / integrations Endpoint Exceptions "before all" hook for "should add event.module=endpoint to entry if only wildcard operator is present"

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
unifiedSearch 113 114 +1

Async chunks

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

id before after diff
unifiedSearch 349.7KB 350.3KB +571.0B
Unknown metric groups

API count

id before after diff
unifiedSearch 151 152 +1

History

cc @kowalczyk-krzysztof

@nreese nreese self-requested a review April 29, 2025 19:42
Copy link
Copy Markdown
Contributor

@nreese nreese left a comment

Choose a reason for hiding this comment

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

The UI is inconsistent based on the selected time range. When the time range is a commonly used time ranges, the quick select popover opens and remains open. When the time range is relative or absolute, the quick select popover opens and immediately closes. This inconsistency does not make sense and for users, its hard to tell why one works vs the other. Since the user clicked the "quick select button", I would expect the quick select popover to open and remain open regardless of the selected time range.

@kowalczyk-krzysztof
Copy link
Copy Markdown
Member Author

kowalczyk-krzysztof commented Apr 29, 2025

The UI is inconsistent based on the selected time range. When the time range is a commonly used time ranges, the quick select popover opens and remains open. When the time range is relative or absolute, the quick select popover opens and immediately closes. This inconsistency does not make sense and for users, its hard to tell why one works vs the other. Since the user clicked the "quick select button", I would expect the quick select popover to open and remain open regardless of the selected time range.

Yes the popover does close and reopens when the time isn't commonly used one, although it's not that visible. This is most likely because isQuickSelectOnly is programmatically controlled. Last times I asked about this, it was suggested to me that I should put a ref on the quick button and programmatically click it to open the popover. However, like you said, it still doesn't behave consistently.
@elastic/eui-team do you have any suggestions on how to solve this?

@acstll
Copy link
Copy Markdown
Contributor

acstll commented May 2, 2025

@elastic/eui-team do you have any suggestions on how to solve this?

@kowalczyk-krzysztof sorry it took a bit to get back to you!

I found 2 minor problems with the solution in this PR. The first one is that, because it checks for common ranges only, the programatic click won't happen for "custom" quick selections e.g. "Last 2 minutes" (those you can select in the very first row of the popover panel). The other problem is related to keyboard use: if focus is on the query input, and you hit the Tab key, you move to the data picker's quick button and the trigger clicks as well, moving focus into the panel, which might be not what you want.

I can understand why we suggested the programatic click approach, because fixing it from the EUI side is not straight-forward, but I'm thinking it might be worth evaluating the effort it would take, if possible. It's very edge-casey, but it could be considered a bug.

Did you consider other solutions like not using isQuickSelectOnly, or making it true only when a pretty range is not selected (absolute dates)?

I would want to discuss this with the entire team, early next week, to try and offer the best possible solution. I hope timing is OK.

@kowalczyk-krzysztof
Copy link
Copy Markdown
Member Author

@acstll
Thanks for taking a look at this

Did you consider other solutions like not using isQuickSelectOnly, or making it true only when a pretty range is not selected (absolute dates)?

I didn't want to change the isQuickSelectOnly logic because I'm not sure why it was designed to behave like it does, I don't have the context.

I would want to discuss this with the entire team, early next week, to try and offer the best possible solution. I hope timing is OK.

That would be awesome, thank you!

@acstll
Copy link
Copy Markdown
Contributor

acstll commented May 7, 2025

Thank you for the patience @kowalczyk-krzysztof

I have created an issue in EUI, because we would like to try and tackle this from EUI side, and make it so that the quick select popover remains open while toggling the isQuickSelect prop.

However, since we won't be able to prioritize this right away, we suggest you move forward with the fix in this PR. Then after elastic/eui#8689 is fixed, we could remove the fix.

Regarding the flash issue described above:

When the time range is relative or absolute, the quick select popover opens and immediately closes.

one idea to temporarily mitigate it would be adding a transition-delay of something like ~50ms to the popover panel…?

Let me know what you think.

@kowalczyk-krzysztof
Copy link
Copy Markdown
Member Author

Thank you for the patience @kowalczyk-krzysztof

I have created an issue in EUI, because we would like to try and tackle this from EUI side, and make it so that the quick select popover remains open while toggling the isQuickSelect prop.

However, since we won't be able to prioritize this right away, we suggest you move forward with the fix in this PR. Then after elastic/eui#8689 is fixed, we could remove the fix.

Regarding the flash issue described above:

When the time range is relative or absolute, the quick select popover opens and immediately closes.

one idea to temporarily mitigate it would be adding a transition-delay of something like ~50ms to the popover panel…?

Let me know what you think.

Sounds good. Thanks a lot for taking care of this. I'll play with transition-delay and see if it helps.
But first @nreese and @elastic/kibana-presentation - as codeowners of unified search, are you guys okay with this course of action or would you rather wait for an fix on EUI side? I picked this issue as part of papercuts project so I don't want to push a temporary solution on you guys.

@kowalczyk-krzysztof
Copy link
Copy Markdown
Member Author

I'll close this PR as I think it's better to wait for a proper fix.
Issue in EUI: elastic/eui#8689

@kowalczyk-krzysztof kowalczyk-krzysztof deleted the fix/date-picker-double-click branch August 31, 2025 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels Feature:Unified search Unified search related tasks release_note:skip Skip the PR/issue when compiling release notes Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas t// v8.19.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Date picker requires multiple clicks between query bar and date picker

5 participants