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 time picker #895

Merged
merged 6 commits into from
Nov 19, 2024
Merged

Date time picker #895

merged 6 commits into from
Nov 19, 2024

Conversation

thecalcc
Copy link
Contributor

@thecalcc thecalcc commented Nov 15, 2024

STT-109

@thecalcc thecalcc requested review from tomaskikutis and akintolga and removed request for akintolga November 15, 2024 07:44
app-typescript/components/DatePicker.tsx Outdated Show resolved Hide resolved
@@ -160,7 +161,8 @@ export class DatePicker extends React.PureComponent<IDatePicker, IState> {
tabindex={this.props.tabindex}
>
<Calendar
footerTemplate={this.props.required !== true ? () => (
className='sd-input__input'
footerTemplate={this.props.hideClear !== true ? () => (
Copy link
Member

Choose a reason for hiding this comment

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

maintain logic regarding "required"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a choice I made, because I didn't want to bloat the logic. I chose to bloat the interface instead and require users of the component to have to also pass hideClear. There's also a benefit to this I think - I don't couple the required logic with hiding the clear when you don't want it for other reasons.

Copy link
Member

Choose a reason for hiding this comment

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

It's a violation of a code contract between interface(props) and implementation. As a developer I say via props that field must not be empty, and you allow it to be empty - ignoring what was requested via props.

Bloat is a secondary issue compared to this. I don't see it as bloat either - being able to clear the value is a core function of any input.

app-typescript/components/DateTimePicker.tsx Outdated Show resolved Hide resolved

export class DateTimePicker extends React.PureComponent<IProps> {
handleTimeChange = (time: string) => {
const [hours, minutes] = time.split(':').map((x) => defaultTo(parseInt(x, 10), 0)); // handle NaN value
Copy link
Member

Choose a reason for hiding this comment

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

FYI there's also isNaN function

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'm aware. But in the case of using isNaN the whole expression becomes less readable in my opinion, because isNaN only checks whether the value is NaN, defaultTo does the same but also offers an immediate fallback. So in this case it is a better fit. Otherwise if you prefer a more explicit style, with isNaN it would look like isNan(x) ? 0 : parseInt(x, 10).

Copy link
Member

Choose a reason for hiding this comment

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

You can leave it as you prefer, I don't mind. I just wanted to point that isNan function exists. Personally I slightly prefer isNan approach, because it doesn't use libraries and person reading the code doesn't need to understand what the library function does. I dislike lodash specifically for making the same function compatible with many data types. It's good on one side, but on another, it's making it harder to look at code and infer from usage what's going on.

import * as React from 'react';
import {DatePicker} from '../components/DatePicker';
import {Spacer} from '@superdesk/common';
import {defaultTo, padStart} from 'lodash';
Copy link
Member

Choose a reason for hiding this comment

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

can you use padStart from standard library?

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

@@ -33,6 +33,8 @@ interface IDatePickerBase extends IInputWrapper {
}}
*/
locale?: DatePickerLocaleSettings;

// Hide does not mean show
Copy link
Member

Choose a reason for hiding this comment

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

light does not mean dark ;D You'd need to phrase clearer. Or drop it completelly which would be fine here too.

@thecalcc thecalcc merged commit b83ddc6 into superdesk:develop Nov 19, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants