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

'DateSelector' #161

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open

'DateSelector' #161

wants to merge 18 commits into from

Conversation

kirtisharma1
Copy link
Collaborator

No description provided.

Copy link

@accesslint accesslint bot left a comment

Choose a reason for hiding this comment

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

There are accessibility issues in these changes.

]
}
selectedOption={9}
/>
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

]
}
selectedOption="December"
/>
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.


const DaySelector = (
<Select
onChange={e => {
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.


const MonthSelector = (
<Select
onChange={e => {
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.


const YearSelector = (
<Select
onChange={e => {
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

]
}
selectedOption={2019}
/>
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

Copy link

@accesslint accesslint bot left a comment

Choose a reason for hiding this comment

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

There are accessibility issues in these changes.


const MonthSelector = (
<Select
onChange={e => {
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.


const YearSelector = (
<Select
onChange={e => {
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

Copy link

@accesslint accesslint bot left a comment

Choose a reason for hiding this comment

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

There are accessibility issues in these changes.


const MonthSelector = (
<Select
onChange={e => {
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.


const YearSelector = (
<Select
onChange={e => {
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

Copy link

@accesslint accesslint bot left a comment

Choose a reason for hiding this comment

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

There are accessibility issues in these changes.

<>
<label htmlFor="date" style={{display: 'none'}}>Date</label>
<Select
onChange={e => {
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

Month
</label>
<Select
onChange={e => {
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

<>
<label htmlFor="year" style={{display: 'none'}}>Year</label>
<Select
onChange={e => {
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

Copy link

@accesslint accesslint bot left a comment

Choose a reason for hiding this comment

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

👏 You fixed the issue(s)! Great work.

@@ -7,7 +7,7 @@ import styles from './Select.style';
type Props = {
id: string,
className?: string,
name: string,
name?: string,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Name should be mandatory

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated

@@ -37,7 +37,7 @@ const Select = ({
>
{placeholder && <option value="">{placeholder}</option>}
{options.map(opt => (
<option key={opt} value={opt}>
<option key={`${name}_${opt}`} value={opt}>
Copy link
Collaborator

@vinodloha vinodloha Dec 10, 2019

Choose a reason for hiding this comment

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

Nice, instead of ${opt} use index that will avoid white space

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

import Select from '../../atoms/Select';
import Label from '../../atoms/Label';

const monthOptions = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

How will these change if locale changes to lets say French or Spanish

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can get this dynamically, from browser itself and then we will no longer need to take care of locales

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

implemented

];

const DateSelector = (props: Props): Node => {
const { className, format, startDate, endDate } = props;
Copy link
Collaborator

@vinodloha vinodloha Dec 10, 2019

Choose a reason for hiding this comment

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

Move this line at like 31

(props: Props) --> { className, format, startDate, endDate } will achieve same thing

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

const DateSelector = (props: Props): Node => {
const { className, format, startDate, endDate } = props;
const [selectedDate, setSelectedDate] = useState(new Date());
const [newStartDate, setNewStartDate] = useState(
Copy link
Collaborator

Choose a reason for hiding this comment

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

How is startDate and newStartDate diff?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed the startDate from state

new Date(new Date().setFullYear(new Date().getFullYear() - 100))
);
const [newEndDate, setNewEndDate] = useState(
new Date(new Date().setFullYear(new Date().getFullYear() + 50))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where did you find this 50 or 100 number?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Those were for the default start and end date

Copy link
Collaborator

@vinodloha vinodloha left a comment

Choose a reason for hiding this comment

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

Looks like a good progress but still far way from being complete

setNewStartDate(new Date(startDate));
} else {
const d = new Date();
setNewStartDate(new Date(d.setFullYear(d.getFullYear() - 100)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

new Date(d.setFullYear(d.getFullYear() - 100) get repeated too often, create a method for it

);

const setDate = dateType => {
if (dateType === 'start') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Such else and If cases produce duplicate code, the same function should be able to handle or set start or end date

the old diff is + and - that can be managed with a small ? : ;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed the logic

const days = [];
let startDay = 1;
let endDay = noOfDays;
if (
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand what this logic below is doing, first line itself has given you all the values.

You must break this complexity

Copy link
Collaborator Author

@kirtisharma1 kirtisharma1 Dec 16, 2019

Choose a reason for hiding this comment

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

That was a mistake. Made changes

) {
endDay = newEndDate.getDate();
}
for (let i = startDay; i <= endDay; i += 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hope you know end date and start date are optional features so that might be required or might not be in some use-cases

Copy link
Collaborator Author

@kirtisharma1 kirtisharma1 Dec 16, 2019

Choose a reason for hiding this comment

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

these are optional features but to show default start and end dates I'm using these


const getMonthOptions = () => {
let months = [...monthOptions];
if (selectedDate.getFullYear() === newStartDate.getFullYear()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

So much of duplication

};

const DaySelector = (
<Label htmlFor="day">
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where is text for label? don't use the label to wrap the field set relation ship with for htmlFor="{${id}_day}"

new Date(selectedDate.getFullYear(), selectedDate.getMonth(), e.target.value)
);
}}
id="day"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't hard code id, create one from the one passed for whole component

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated

id="day"
name="day"
className={classNames('date', className)}
disabled={false}
Copy link
Collaborator

Choose a reason for hiding this comment

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

disabled={false} ??? hard coding

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated


return (
<div className={className}>
{(format.toLowerCase() === 'ddmmyy' || format.toLowerCase() === 'ddmmyyyy') && [
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer switch cases

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Implemented

children: Node,
className?: string,
format?: Format,
startDate: number,
Copy link
Collaborator

Choose a reason for hiding this comment

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

startDate and endDate are also optional

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated

@vinodloha vinodloha added invalid This doesn't seem right and removed invalid This doesn't seem right labels Dec 11, 2019
@@ -50,6 +50,7 @@ Select.defaultProps = {
placeholder: '',
className: '',
elementLocator: '',
name: 'optionName',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Name should not be part of default props also don't like how we are setting empty default values, please fix it too

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated.

Copy link
Collaborator

@vinodloha vinodloha left a comment

Choose a reason for hiding this comment

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

Please work on review comments

@vinodloha vinodloha changed the base branch from feature/design-system-basics to develop December 15, 2019 17:58
Copy link

@accesslint accesslint bot left a comment

Choose a reason for hiding this comment

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

There are accessibility issues in these changes.

]
}
selectedOption={16}
/>
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

name="month"
onChange={[Function]}
options={Array []}
/>
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

<>
<Label htmlFor={`${id}-day`} />
<Select
onChange={e => {
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

<>
<Label htmlFor={`${id}-month`} />
<Select
onChange={e => {
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

]
}
selectedOption={2019}
/>
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

<>
<Label htmlFor={`${id}-year`} />
<Select
onChange={e => {
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

Copy link

@accesslint accesslint bot left a comment

Choose a reason for hiding this comment

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

There are accessibility issues in these changes.

]
}
selectedOption={17}
/>
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

name="month"
onChange={[Function]}
options={Array []}
/>
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

]
}
selectedOption={2019}
/>
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

Copy link

@accesslint accesslint bot left a comment

Choose a reason for hiding this comment

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

There are accessibility issues in these changes.

]
}
selectedOption={17}
/>
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

name="month"
onChange={[Function]}
options={Array []}
/>
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

<>
<Label htmlFor={`${id}-day`}>{dateLabel}</Label>
<Select
onChange={e => {
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

<>
<Label htmlFor={`${id}-month`}>{monthLabel}</Label>
<Select
onChange={e => {
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

]
}
selectedOption={2019}
/>
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

<>
<Label htmlFor={`${id}-year`}>{yearLabel}</Label>
<Select
onChange={e => {
Copy link

Choose a reason for hiding this comment

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

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

placeholder: '',
className: '',
elementLocator: '',
selectedOption: 'select',
Copy link
Collaborator

Choose a reason for hiding this comment

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

By default selected option should be null

selectedOption: 'select',
placeholder: 'Select',
className: 'select',
elementLocator: 'select',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Set elementLocator default value as null

) {
startDay = startDate.getDate();
}
if (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Still there is redundant code we can reduce, for example:

  1. These 2 If conditions were we are startDay and endDay could be returned by a function.


const getMonthOptions = () => {
let monthOptions = [...months];
if (selectedDate.getFullYear() === startDate.getFullYear()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, this could be returned by a function and also clear case of If or else.


const getYearOptions = () => {
const years = [];
for (let i = startDate.getFullYear(); i <= endDate.getFullYear(); i += 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

);

const renderSelector = value => {
switch (value.toLowerCase()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice

@@ -0,0 +1,17 @@
// @flow

type Format = 'ddmmyy' | 'ddmmyyyy' | 'mmddyy' | 'mmddyyyy' | 'mmyy' | 'mmyyyy';
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice

@vinodloha
Copy link
Collaborator

@kirtisharma1 please resolve Conflict.

Also Every select box should have a label. Lets place that at top of the select box.

startDate: new Date(),
endDate: new Date(new Date().setFullYear(new Date().getFullYear() + 50)),
locale: 'default',
dateLabel: 'Date',
Copy link
Collaborator

@vinodloha vinodloha Dec 19, 2019

Choose a reason for hiding this comment

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

Don't set below as default value, Make them mandatory, Remove the showLabel: false. For accessibility its important that every field has a label.

  1. dateLabel: 'Date',
  2. monthLabel: 'Month',
  3. yearLabel: 'Year',

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.

None yet

2 participants