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

Clearable time selector #18590

Merged
merged 12 commits into from
Jul 25, 2024
Merged

Conversation

schelv
Copy link
Contributor

@schelv schelv commented Nov 9, 2023

Proposed change

The time selector can now be cleared:
image

The same selector after pressing the clear button:
image

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue or discussion:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

Summary by CodeRabbit

  • New Features

    • Introduced a clear button for time input components, allowing users to easily clear the selected time. The clear button is conditionally displayed based on specific properties (clearable, required, and disabled).
  • Enhancements

    • Updated time input components to support the clearable property for improved user control over input fields, including visual and functional updates to accommodate the new feature.

@schelv schelv marked this pull request as draft December 10, 2023 20:08
@schelv schelv marked this pull request as ready for review December 10, 2023 21:01
@schelv schelv force-pushed the clearable-time-selector branch 3 times, most recently from 7cae4f4 to 45845b4 Compare December 17, 2023 11:33
Copy link
Member

@Quentame Quentame left a comment

Choose a reason for hiding this comment

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

LGTM

@karwosts
Copy link
Contributor

Once we get this would be good to add for duration selector as well, can fix #19360

@bdraco
Copy link
Member

bdraco commented Apr 19, 2024

I think this will solve the issue where its not possible to clear a timeout without dropping back to YAML once its been set which seems like the root cause of home-assistant/core#109586

It also resolves quandary in home-assistant/core#115830 as it means it means we align the frontend to the backend

  • no timeout set (cleared), no timeout happens
  • 0 timeout set, times out right away

@bramkragten bramkragten added UX User experience related bug Needs UX Pull requests requiring a review from the Home Assistant design team and removed UX User experience related bug labels Apr 24, 2024
Copy link
Contributor

coderabbitai bot commented Jul 13, 2024

Walkthrough

Walkthrough

The changes introduce a clearable property across the HaBaseTimeInput, HaTimeSelector, and HaTimeInput components, enhancing the user experience by allowing users to clear input values via a dedicated button. This update includes the addition of an icon for the button, conditional rendering based on the property, and necessary style adjustments for a cohesive appearance.

Changes

File Path Change Summary
src/components/ha-base-time-input.ts Added clearable property, implemented _clearValue method for the clear button functionality, and updated styles.
src/components/ha-selector/ha-selector-time.ts Introduced clearable property in the HaTimeSelector class.
src/components/ha-time-input.ts Introduced clearable property in the HaTimeInput class; modified _timeChanged method to handle clearing logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant HaTimeInput
    participant HaBaseTimeInput
    participant HaTimeSelector
    
    User->>HaTimeInput: Trigger clear button
    HaTimeInput->>HaBaseTimeInput: Set value to undefined
    HaBaseTimeInput->>HaTimeSelector: Clear value
    HaTimeSelector-->>HaBaseTimeInput: Value cleared
    HaBaseTimeInput-->>HaTimeInput: Value cleared
    HaTimeInput-->>User: Value cleared
Loading

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f781395 and 274037e.

Files selected for processing (1)
  • src/components/ha-base-time-input.ts (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/components/ha-base-time-input.ts

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range, codebase verification and nitpick comments (2)
src/components/ha-time-input.ts (1)

66-67: Clarify the comment for eventValue being undefined.

The comment indicates that an undefined eventValue means the time selector is being cleared. Ensure that this is the intended behavior and that it is clearly documented.

-    // An undefined eventValue means the time selector is being cleared,
+    // An undefined eventValue means the time selector is being cleared.
+    // Ensure this behavior is clearly documented.
src/components/ha-base-time-input.ts (1)

270-272: Clarify the _clearValue method.

The _clearValue method triggers a value-changed event. Ensure that this behavior is clearly documented and that the method name reflects its functionality.

-  private _clearValue(): void {
-    fireEvent(this, "value-changed");
+  /**
+   * Clears the input value and triggers a value-changed event.
+   */
+  private _clearValue(): void {
+    fireEvent(this, "value-changed", { value: undefined });

Comment on lines +70 to +72
(!isNaN(eventValue.hours) ||
!isNaN(eventValue.minutes) ||
!isNaN(eventValue.seconds))
Copy link
Contributor

Choose a reason for hiding this comment

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

Use Number.isNaN instead of isNaN.

isNaN is unsafe as it attempts a type coercion. Use Number.isNaN instead for better type safety.

-      (!isNaN(eventValue.hours) ||
-        !isNaN(eventValue.minutes) ||
-        !isNaN(eventValue.seconds))
+      (!Number.isNaN(eventValue.hours) ||
+        !Number.isNaN(eventValue.minutes) ||
+        !Number.isNaN(eventValue.seconds))
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
(!isNaN(eventValue.hours) ||
!isNaN(eventValue.minutes) ||
!isNaN(eventValue.seconds))
(!Number.isNaN(eventValue.hours) ||
!Number.isNaN(eventValue.minutes) ||
!Number.isNaN(eventValue.seconds))
Tools
Biome

[error] 70-70: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)


[error] 71-71: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)


[error] 72-72: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)

@schelv
Copy link
Contributor Author

schelv commented Jul 13, 2024

@matthiasdebaat
I've moved the X to be inside of the input, added labels, and separated the dropdown. I'm not the right person to implement the rest of the design. I have no idea what I'm doing.😅

image

@matthiasdebaat
Copy link
Collaborator

It's already a great improvement, thanks! Can you extend this line?
CleanShot 2024-07-15 at 11 09 19@2x

@schelv
Copy link
Contributor Author

schelv commented Jul 15, 2024

It's already a great improvement, thanks! Can you extend this line? CleanShot 2024-07-15 at 11 09 19@2x

I've tried to, but could not find the css property responsible for that line.

@schelv
Copy link
Contributor Author

schelv commented Jul 17, 2024

@matthiasdebaat
image
🎉

@matthiasdebaat
Copy link
Collaborator

YOU ROCK! Thanks!

@silamon
Copy link
Contributor

silamon commented Jul 19, 2024

@matthiasdebaat , the current ux is good to go?

@matthiasdebaat
Copy link
Collaborator

@matthiasdebaat , the current ux is good to go?

One question, before it's good to go. Does this field have a adjacent label? Or do you need to add one above by yourself?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Comment on lines +66 to +72
// An undefined eventValue means the time selector is being cleared,
// the `value` variable will (intentionally) be left undefined.
if (
!isNaN(eventValue.hours) ||
!isNaN(eventValue.minutes) ||
!isNaN(eventValue.seconds)
eventValue !== undefined &&
(!isNaN(eventValue.hours) ||
!isNaN(eventValue.minutes) ||
!isNaN(eventValue.seconds))
Copy link
Contributor

Choose a reason for hiding this comment

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

Use Number.isNaN instead of isNaN.

isNaN is unsafe as it attempts a type coercion. Use Number.isNaN instead for better type safety.

-      (!isNaN(eventValue.hours) ||
-        !isNaN(eventValue.minutes) ||
-        !isNaN(eventValue.seconds))
+      (!Number.isNaN(eventValue.hours) ||
+        !Number.isNaN(eventValue.minutes) ||
+        !Number.isNaN(eventValue.seconds))
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// An undefined eventValue means the time selector is being cleared,
// the `value` variable will (intentionally) be left undefined.
if (
!isNaN(eventValue.hours) ||
!isNaN(eventValue.minutes) ||
!isNaN(eventValue.seconds)
eventValue !== undefined &&
(!isNaN(eventValue.hours) ||
!isNaN(eventValue.minutes) ||
!isNaN(eventValue.seconds))
// An undefined eventValue means the time selector is being cleared,
// the `value` variable will (intentionally) be left undefined.
if (
eventValue !== undefined &&
(!Number.isNaN(eventValue.hours) ||
!Number.isNaN(eventValue.minutes) ||
!Number.isNaN(eventValue.seconds))
Tools
Biome

[error] 70-70: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)


[error] 71-71: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)


[error] 72-72: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)

bramkragten
bramkragten previously approved these changes Jul 19, 2024
Copy link
Contributor

@silamon silamon left a comment

Choose a reason for hiding this comment

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

These assignments should be translatable.

src/components/ha-base-time-input.ts Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft July 19, 2024 14:10
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@silamon
Copy link
Contributor

silamon commented Jul 24, 2024

Whenever you're ready, feel free to hit the "ready to review" button. 🥇

@schelv schelv marked this pull request as ready for review July 25, 2024 11:34
@home-assistant home-assistant bot requested a review from silamon July 25, 2024 11:34
@silamon silamon removed the Needs UX Pull requests requiring a review from the Home Assistant design team label Jul 25, 2024
@silamon silamon merged commit 0358fe5 into home-assistant:dev Jul 25, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants