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

Add date time form field #9133

Merged
merged 4 commits into from
Dec 19, 2024
Merged

Add date time form field #9133

merged 4 commits into from
Dec 19, 2024

Conversation

Devessier
Copy link
Contributor

@Devessier Devessier commented Dec 18, 2024

  • Create a really simple abstraction to unify the date and date time fields. We might dissociate them sooner than expected.
  • The relative setting is ignored

@Devessier Devessier marked this pull request as ready for review December 18, 2024 17:32
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 introduces a new FormDateTimeFieldInput component and refactors date handling by extracting shared functionality into FormDateishFieldInputBase, enabling unified handling of both date and datetime fields.

  • Incomplete Escape key handling in FormDateishFieldInputBase needs fixing (noted in code comment)
  • InternalDatePicker's isDateTimeInput prop is hardcoded to false in FormDateishFieldInputBase, potentially affecting datetime functionality
  • No error state handling for invalid date inputs in FormDateishFieldInputBase
  • Timezone handling in FormDateTimeFieldInput.stories.tsx may need additional test coverage
  • The relative setting is intentionally ignored as noted in PR description, which could affect date display functionality

5 file(s) reviewed, 8 comment(s)
Edit PR Review Bot Settings | Greptile

return (
<FormDateishFieldInputBase
mode="datetime"
placeholder="mm/dd/yyyy hh:mm"
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 format 'mm/dd/yyyy hh:mm' doesn't match ISO-8601 format used in defaultValue ('2024-12-09T13:20:19.631Z'). Consider documenting the format conversion or using consistent formats.

) : isFieldDateTime(field) ? (
<FormDateTimeFieldInput
label={field.label}
defaultValue={defaultValue as 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 handling timezone conversion here since datetime values often need timezone awareness

Comment on lines 18 to 22
<FormDateishFieldInputBase
mode="date"
placeholder="mm/dd/yyyy"
{...{ label, defaultValue, onPersist, 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: Props spreading could hide future prop changes in FormDateishFieldInputBase. Consider explicitly passing each prop.

<OverlayContainer>
<InternalDatePicker
date={pickerDate ?? new Date()}
isDateTimeInput={false}
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: isDateTimeInput is hardcoded to false but mode prop indicates this component handles both date and datetime

persistDate(newDate);
};

const handlePickerEnter = () => {};
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: empty handlePickerEnter function could lead to unexpected behavior when user presses Enter key in picker

Comment on lines 269 to 271
if (!isDefined(parsedInputDateTime)) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: no feedback to user when invalid date is entered

setDraftValue({
type: 'static',
mode: 'edit',
value: newDate?.toDateString() ?? null,
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: using toDateString() loses time information for datetime mode

Comment on lines 72 to 75
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: The regex pattern \d{2}:10:00.000Z may be too specific and could fail in different timezones. Consider using a more flexible pattern that accounts for timezone variations.

Copy link
Contributor

@martmull martmull left a comment

Choose a reason for hiding this comment

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

Hey nice code. I think the components logic can be simplified. Delete FormDateFieldInput.tsx and FormDateTimeFieldInput.tsx then rename FormDateishFieldInputBase.tsx into FormDateTimeFieldInput.tsx
In FormFieldInput.tsx use <FormDateTimeFieldInput mode='datetime' ...> and <FormDateTimeFieldInput mode='date' ...>

<FormDateishFieldInputBase
mode="date"
placeholder="mm/dd/yyyy"
{...{ label, defaultValue, onPersist, VariablePicker }}
Copy link
Contributor

Choose a reason for hiding this comment

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

no props spreading in project

) : null}
</FormFieldInputRowContainer>
</FormFieldInputContainer>
<FormDateishFieldInputBase
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we don't need that component

VariablePicker?: VariablePickerComponent;
};

export const FormDateTimeFieldInput = ({
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we don't need that component

VariablePicker?: VariablePickerComponent;
};

export const FormDateishFieldInputBase = ({
Copy link
Contributor

Choose a reason for hiding this comment

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

This naming is not very clear. See my global comment

Suggested change
export const FormDateishFieldInputBase = ({
export const FormDateTimeFieldInput = ({

@thomtrp
Copy link
Contributor

thomtrp commented Dec 19, 2024

Hey nice code. I think the components logic can be simplified. Delete FormDateFieldInput.tsx and FormDateTimeFieldInput.tsx then rename FormDateishFieldInputBase.tsx into FormDateTimeFieldInput.tsx In FormFieldInput.tsx use <FormDateTimeFieldInput mode='datetime' ...> and <FormDateTimeFieldInput mode='date' ...>

+1 on this

Copy link
Contributor

@martmull martmull left a comment

Choose a reason for hiding this comment

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

LGTM thanks

@Devessier Devessier enabled auto-merge (squash) December 19, 2024 10:42
@Devessier Devessier merged commit 65586a0 into main Dec 19, 2024
22 checks passed
@Devessier Devessier deleted the add-date-time-form-field branch December 19, 2024 10:46
Copy link

Fails
🚫

node failed.

Log

�[31mError: �[39m RequestError [HttpError]: You have exceeded a secondary rate limit. Please wait a few minutes before you try again. If you reach out to GitHub Support for help, please include the request ID 7A40:320300:117C3E0:22CC7F6:6763F9AF.
    at /home/runner/work/twenty/twenty/node_modules/�[4m@octokit�[24m/request/dist-node/index.js:86:21
�[90m    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)�[39m {
  status: �[33m403�[39m,
  response: {
    url: �[32m'https://api.github.com/search/issues?q=is%3Apr%20author%3ADevessier%20is%3Aclosed%20repo%3Atwentyhq%2Ftwenty&per_page=2&page=1'�[39m,
    status: �[33m403�[39m,
    headers: {
      �[32m'access-control-allow-origin'�[39m: �[32m'*'�[39m,
      �[32m'access-control-expose-headers'�[39m: �[32m'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset'�[39m,
      connection: �[32m'close'�[39m,
      �[32m'content-encoding'�[39m: �[32m'gzip'�[39m,
      �[32m'content-security-policy'�[39m: �[32m"default-src 'none'"�[39m,
      �[32m'content-type'�[39m: �[32m'application/json; charset=utf-8'�[39m,
      date: �[32m'Thu, 19 Dec 2024 10:47:11 GMT'�[39m,
      �[32m'referrer-policy'�[39m: �[32m'origin-when-cross-origin, strict-origin-when-cross-origin'�[39m,
      server: �[32m'github.com'�[39m,
      �[32m'strict-transport-security'�[39m: �[32m'max-age=31536000; includeSubdomains; preload'�[39m,
      �[32m'transfer-encoding'�[39m: �[32m'chunked'�[39m,
      vary: �[32m'Accept-Encoding, Accept, X-Requested-With'�[39m,
      �[32m'x-content-type-options'�[39m: �[32m'nosniff'�[39m,
      �[32m'x-frame-options'�[39m: �[32m'deny'�[39m,
      �[32m'x-github-api-version-selected'�[39m: �[32m'2022-11-28'�[39m,
      �[32m'x-github-media-type'�[39m: �[32m'github.v3; format=json'�[39m,
      �[32m'x-github-request-id'�[39m: �[32m'7A40:320300:117C3E0:22CC7F6:6763F9AF'�[39m,
      �[32m'x-ratelimit-limit'�[39m: �[32m'30'�[39m,
      �[32m'x-ratelimit-remaining'�[39m: �[32m'30'�[39m,
      �[32m'x-ratelimit-reset'�[39m: �[32m'1734605291'�[39m,
      �[32m'x-ratelimit-resource'�[39m: �[32m'search'�[39m,
      �[32m'x-ratelimit-used'�[39m: �[32m'1'�[39m,
      �[32m'x-xss-protection'�[39m: �[32m'0'�[39m
    },
    data: {
      documentation_url: �[32m'https://docs.github.com/free-pro-team@latest/rest/overview/rate-limits-for-the-rest-api#about-secondary-rate-limits'�[39m,
      message: �[32m'You have exceeded a secondary rate limit. Please wait a few minutes before you try again. If you reach out to GitHub Support for help, please include the request ID 7A40:320300:117C3E0:22CC7F6:6763F9AF.'�[39m
    }
  },
  request: {
    method: �[32m'GET'�[39m,
    url: �[32m'https://api.github.com/search/issues?q=is%3Apr%20author%3ADevessier%20is%3Aclosed%20repo%3Atwentyhq%2Ftwenty&per_page=2&page=1'�[39m,
    headers: {
      accept: �[32m'application/vnd.github.v3+json'�[39m,
      �[32m'user-agent'�[39m: �[32m'octokit-rest.js/18.12.0 octokit-core.js/3.6.0 Node.js/18.20.5 (linux; x64)'�[39m,
      authorization: �[32m'token [REDACTED]'�[39m
    },
    request: { hook: �[36m[Function: bound bound register]�[39m }
  }
}
danger-results://tmp/danger-results-4680d19a.json

Generated by 🚫 dangerJS against 0ee0331

@martmull martmull restored the add-date-time-form-field branch December 20, 2024 09:20
@martmull martmull deleted the add-date-time-form-field branch December 20, 2024 09:38
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.

4 participants