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

Date-range-picker Design to use Prev and Next Buttons in History and Logbook on mobiles #23228

Conversation

boern99
Copy link
Contributor

@boern99 boern99 commented Dec 9, 2024

Breaking change

Proposed change

@marcinbauer85: This is the implementation for the prepared design for #22947. As i discarded the first draft for moving date-range-picker to Top, the original Pull-Request was closed.
This is what it looks like now:

Desktop View:
image
Mobile View:
image
if it is this year it hides the year:
image

@wendevlin: Thank you, yes ha-textarea did the trick. Since you offered, that you can try to implement the design: feel free to make changes if would have done it in a better way ...

The Commit also includes an updated logic to be able to recognice a whole month, so that if for example January is selected and you click on next, it uses whole next month, even the month has a different timespan:
image
image

This change allows to remove "Previous month" and "Previous year", as the Previous-Button does exact the same.
I removed Previous Week, Previous Month and Previous Year, so that the date-Selector now better fits also on mobiles:
image
in comparison this is before the removal, Cancel and Select is depending on the resolution maybe out of view:
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:

@wendevlin
Copy link
Contributor

Hi @boern99,
awesome thanks, would have been better to review in 2 PRs, but we will manage it 🙂

Some things I notice:

  • In history on mobile the textarea grows, but logbook not
  • No space between textarea and prev button.

@boern99
Copy link
Contributor Author

boern99 commented Dec 10, 2024

@wendevlin: yes thought about 2 PRs but if next-buttons are hidden on mobile second PR would depend on the first PR.
I corrected testarea grows and spaces

@wendevlin wendevlin added the Noteworthy Marks a PR as noteworthy and should be in the release notes (in case it normally would not appear) label Dec 11, 2024
Copy link
Contributor

@wendevlin wendevlin left a comment

Choose a reason for hiding this comment

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

Just some tiny css changes left :)

src/components/ha-date-range-picker.ts Outdated Show resolved Hide resolved
src/components/ha-date-range-picker.ts Outdated Show resolved Hide resolved
src/components/ha-date-range-picker.ts Outdated Show resolved Hide resolved
src/components/ha-date-range-picker.ts Outdated Show resolved Hide resolved
@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.

@home-assistant home-assistant bot marked this pull request as draft December 11, 2024 09:18
.value=${this.timePicker
? formatDateTime(
? html`<ha-textarea
mobile2multiline
Copy link
Member

Choose a reason for hiding this comment

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

I don't feel like this should be part of ha-textarea. Also use mobile-multiline as a name otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

needed a way to display it in one-line, my solution was to add "white-space: nowrap;" for desktops: this ignores the nextline \n in the datestring. Have not found a better way change css for ha-textarea from outside

.label=${this.hass.localize(
"ui.components.date-range-picker.end_date"
"ui.components.selectors.selector.types.datetime"
Copy link
Member

Choose a reason for hiding this comment

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

Don't use the translation key of another selector, you can reference its value though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or use the already existing start_date and end_date? "Start date - End date" would be more explaining as "Date Time" for the range

Math.max(
3600000,
differenceInMilliseconds(this.endDate, this.startDate)
let dateRange: [Date, Date];
Copy link
Member

Choose a reason for hiding this comment

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

Lets extract the next and prev functions from hui-energy-period-selector and make them helper functions we can use here too.

Copy link
Contributor Author

@boern99 boern99 Dec 11, 2024

Choose a reason for hiding this comment

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

The new functions can deal with any-ranges and also shorter than one day. If selected a week the range is 7 days: so Week is not needed. Extra logic is only needed for month, as the timespans can be different. And the month-Logic can also shift between years without problem.

Copy link
Member

Choose a reason for hiding this comment

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

Still they share the same logic right? So we can combine them into 1 function we use in both places?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, took now a detailed look at it: you are right: we can combine them. Will upload a draft: hopefully that's the way it should be done ..

Comment on lines 775 to 776
margin-inline-end: 0;
margin-inline-start: initial;
Copy link
Member

Choose a reason for hiding this comment

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

If you remove margin-right, you should also remove these 2

@boern99
Copy link
Contributor Author

boern99 commented Dec 13, 2024

Changed shiftDateRange-function to be able to shift between timespans lower than one day.
Addressed this issue: #23149

@boern99 boern99 marked this pull request as ready for review December 13, 2024 13:19
@home-assistant home-assistant bot requested a review from wendevlin December 13, 2024 13:19
Comment on lines +68 to +118
export const shiftDateRange = (
startDate: Date,
endDate: Date,
forward: boolean,
locale: FrontendLocaleData,
config: any
): { start: Date; end: Date } => {
let start: Date;
let end: Date;
if (
(calcDateProperty(
startDate,
isFirstDayOfMonth,
locale,
config
) as boolean) &&
(calcDateProperty(endDate, isLastDayOfMonth, locale, config) as boolean)
) {
const difference =
((calcDateDifferenceProperty(
endDate,
startDate,
differenceInMonths,
locale,
config
) as number) +
1) *
(forward ? 1 : -1);
start = calcDate(startDate, addMonths, locale, config, difference);
end = calcDate(
calcDate(endDate, addMonths, locale, config, difference),
endOfMonth,
locale,
config
);
} else {
const difference =
((calcDateDifferenceProperty(
endDate,
startDate,
differenceInMilliseconds,
locale,
config
) as number) +
1) *
(forward ? 1 : -1);
start = calcDate(startDate, addMilliseconds, locale, config, difference);
end = calcDate(endDate, addMilliseconds, locale, config, difference);
}
return { start, end };
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think you can add unit tests for this in a seperate PR?

@wendevlin wendevlin merged commit 6f8ba6a into home-assistant:dev Dec 17, 2024
15 checks passed
@boern99 boern99 mentioned this pull request Dec 18, 2024
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed Noteworthy Marks a PR as noteworthy and should be in the release notes (in case it normally would not appear)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants