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

Age Range Field #866

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Age Range Field #866

wants to merge 9 commits into from

Conversation

zDudaHang
Copy link
Contributor

closes #865

@wesleydecezere wesleydecezere self-assigned this Oct 21, 2024
@@ -0,0 +1,15 @@
import { AgeRangeUnitEnum, UNIT_OPTIONS } from './model'

export function getAvaibleAgeRangeUnits(excludedAgeRangeUnits: AgeRangeUnitEnum[]): AgeRangeUnitEnum[] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't there be test for this?

import { LocaleConfiguration } from '../../i18n'
import { AgeRangeUnitEnum } from './model'

export function convertUnitAgeRangeEnumToLocaleText(
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't there be test for this?

})
})

it('should show only avaible unit options when the button is clicked', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

typo in available

end?: string
}

export interface AgeRangeInputProps {
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 really need to declare all these properties?

I believe you can work with something like InputProps or React.InputHTMLAttributes<HTMLInputElement>.

@lucasjoao lucasjoao removed their assignment Oct 22, 2024
const handleClickUnitOptionsButton = () => setOpen((state) => !state)

const handleChangeStart = (e: React.ChangeEvent<HTMLInputElement>) => {
let start: number = null
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let start: number = null
let start: number = value?.start

Then the else below isn't needed


export function convertUnitAgeRangeEnumToLocaleText(
ageRangeUnitEnum: AgeRangeUnitEnum,
locale: LocaleConfiguration
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
locale: LocaleConfiguration
{ ageRange }: LocaleConfiguration

unitOptions = unitOptions.filter((unit) => !excludedAgeRangeUnits.includes(unit))
}

if (unitOptions.length === 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Isn't there an isEmpty function in the project?

describe('Unit dropdown', () => {
it('should show all unit options when the button is clicked', async () => {
const { getByTestId } = render(<AgeRangeField />)
const button = getByTestId('age-range-unit-button')
Copy link
Member

Choose a reason for hiding this comment

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

You could create a constant for this test-id, like the other two

jest.useRealTimers()
})

it("should call 'onFocus' and 'onBlur' when start input gets focus and it loses focus", async () => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
it("should call 'onFocus' and 'onBlur' when start input gets focus and it loses focus", async () => {
it("should call 'onFocus' and 'onBlur' when start input gets focus and then loses it", async () => {

@wesleydecezere wesleydecezere removed their assignment Oct 23, 2024
@tainadacruz tainadacruz removed their assignment Oct 23, 2024
Comment on lines +1 to +5
export enum AgeRangeUnitEnum {
YEARS,
MONTHS,
DAYS,
}

Choose a reason for hiding this comment

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

will it be possible to add new units when using the component?

asking because I've seen cases where it could be used with weeks, for example

export interface AgeRangeFieldProps extends AgeRangeInputProps, UseFormControlProps {}

export function AgeRangeField(props: AgeRangeFieldProps) {
const { label, error, ...rest } = props

Choose a reason for hiding this comment

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

where are label and error getting used? is it necessary to destructure it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably to avoid propagating these props to the AgeRangeInput

@vitoriapizzutti vitoriapizzutti removed their assignment Oct 24, 2024
Comment on lines +121 to +130
let start: number = null

const startText = e.currentTarget?.value
const startParsed = parseInt(startText)

if (!isNaN(startParsed)) {
start = startParsed
} else if (!isEmpty(startText)) {
start = value?.start
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let start: number = null
const startText = e.currentTarget?.value
const startParsed = parseInt(startText)
if (!isNaN(startParsed)) {
start = startParsed
} else if (!isEmpty(startText)) {
start = value?.start
}
const start = parseInt(e.currentTarget?.value) || value?.start

Are the isNaN and isEmpty checks really necessary in this case?

Comment on lines +172 to +175
const handleClose = () => {
setOpen(false)
anchorRef.focus()
}
Copy link
Member

Choose a reason for hiding this comment

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

Would using a useCallback be beneficial here?

anchorRef.focus()
}

const avaibleUnitOptions = getAvaibleAgeRangeUnits(unitOptionsToExclude)
Copy link
Member

Choose a reason for hiding this comment

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

Would using a useMemo be beneficial here?

Comment on lines +8 to +10
switch (ageRangeUnitEnum) {
case AgeRangeUnitEnum.YEARS:
return locale.ageRange.years
Copy link
Member

Choose a reason for hiding this comment

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

Why not use a Map?

Comment on lines +133 to +135
start,
end: value?.end,
unit: value?.unit,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
start,
end: value?.end,
unit: value?.unit,
...value,
start

@christianaurichzm christianaurichzm removed their assignment Oct 24, 2024
export interface AgeRangeFieldProps extends AgeRangeInputProps, UseFormControlProps {}

export function AgeRangeField(props: AgeRangeFieldProps) {
const { label, error, ...rest } = props
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably to avoid propagating these props to the AgeRangeInput

@zDudaHang zDudaHang self-assigned this Nov 5, 2024
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.

Age Range Field
7 participants