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

Separate date and datetime components #9161

Merged
merged 2 commits into from
Dec 20, 2024

Conversation

martmull
Copy link
Contributor

Add a 2 components solution for FormDate and FormDateTime

@martmull martmull marked this pull request as ready for review December 20, 2024 09:58
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR separates the date and datetime form field components into distinct files, improving component organization and API clarity while maintaining existing functionality.

  • Added new FormDateFieldInput component in /packages/twenty-front/src/modules/object-record/record-field/form-types/components/FormDateFieldInput.tsx that wraps FormDateTimeFieldInput with dateOnly prop
  • Replaced FormDateTimeFieldInputBase with FormDateTimeFieldInput in /packages/twenty-front/src/modules/object-record/record-field/form-types/components/FormDateTimeFieldInput.tsx, simplifying API by removing mode prop
  • Added comprehensive test coverage in new story files /packages/twenty-front/src/modules/object-record/record-field/form-types/components/__stories__/FormDateFieldInput.stories.tsx and FormDateTimeFieldInput.stories.tsx
  • Updated FormFieldInput component to use separate date/datetime components instead of base component with mode

6 file(s) reviewed, 9 comment(s)
Edit PR Review Bot Settings | Greptile


type FormDateFieldInputProps = {
label?: string;
defaultValue: string | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider making defaultValue nullable (string | undefined | null) to match onPersist's return type

Comment on lines +113 to 118
<FormDateFieldInput
label={field.label}
defaultValue={defaultValue as string | undefined}
onPersist={onPersist}
VariablePicker={VariablePicker}
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

style: FormDateFieldInput wraps FormDateTimeFieldInput with dateOnly=true. Consider passing the onPersist type as (value: string | null) => void to match the child component's type signature.

Comment on lines +106 to +108
expect(args.onPersist).toHaveBeenCalledWith(
expect.stringMatching(/^2024-12-07/),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: this regex pattern is too loose - could match invalid dates like '2024-12-07999'. Use exact ISO string match instead

Comment on lines +197 to +199
await Promise.all([
userEvent.type(input, '02/02/1500{Enter}'),

Copy link
Contributor

Choose a reason for hiding this comment

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

style: consider testing multiple invalid date formats to ensure robust validation

Comment on lines +343 to +347
const defaultValueAsDisplayString = parseDateToString({
date: new Date(args.defaultValue!),
isDateTimeInput: false,
userTimezone: undefined,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: parseDateToString called with undefined userTimezone - could cause inconsistent behavior across different timezones

const variableTag = await canvas.findByText('test');
expect(variableTag).toBeVisible();

const removeVariableButton = canvas.getByTestId(/^remove-icon/);
Copy link
Contributor

Choose a reason for hiding this comment

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

style: using regex for test ID matching could be fragile if IDs change

Comment on lines +70 to +75
await userEvent.type(input, '12/08/2024 12:10{enter}');

await waitFor(() => {
expect(args.onPersist).toHaveBeenCalledWith(
expect.stringMatching(/2024-12-08T\d{2}:10:00.000Z/),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: timezone mismatch potential - the regex pattern allows any hour value, which could cause flaky tests across different timezones

@@ -143,6 +142,8 @@ export const FormDateTimeFieldInputBase = ({
const displayDatePicker =
draftValue.type === 'static' && draftValue.mode === 'edit';

const placeholder = dateOnly ? 'mm/dd/yyyy' : 'mm/dd/yyyy hh:mm';

useListenClickOutside({
refs: [datePickerWrapperRef],
listenerId: 'FormDateTimeFieldInputBase',
Copy link
Contributor

Choose a reason for hiding this comment

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

style: listenerId still references old component name 'FormDateTimeFieldInputBase'

label?: string;
placeholder?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

style: placeholder prop is defined but never used since placeholder is defined internally on line 145

Copy link
Contributor

@Devessier Devessier left a comment

Choose a reason for hiding this comment

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

I agree with the changes! We can merge.

@martmull martmull enabled auto-merge (squash) December 20, 2024 10:44
@martmull martmull merged commit 0d2bfad into main Dec 20, 2024
22 checks passed
@martmull martmull deleted the separate-date-and-datetimecomponents branch December 20, 2024 10:50
mdrazak2001 pushed a commit to mdrazak2001/twenty that referenced this pull request Dec 20, 2024
Add a 2 components solution for FormDate and FormDateTime
samyakpiya pushed a commit to samyakpiya/twenty that referenced this pull request Dec 28, 2024
Add a 2 components solution for FormDate and FormDateTime
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