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

fix: Datetimepicker typecheck #244

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,13 @@ export const RolloutAndTiming: React.FC<{
onChange={(t) => {
onChange({
...value,
startTime: t.toDate(
Intl.DateTimeFormat().resolvedOptions()
.timeZone,
),
startTime:
t != null
? t.toDate(
Intl.DateTimeFormat().resolvedOptions()
.timeZone,
)
: new Date(),
Comment on lines +151 to +157
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Reconsider the default fallback for null dates

While the null check is good, defaulting to the current date when t is null might mask errors or create unexpected behavior. Consider either:

  1. Preserving the existing date value instead of defaulting to current date
  2. Implementing proper form validation to handle null dates
-                                startTime:
-                                  t != null
-                                    ? t.toDate(
-                                        Intl.DateTimeFormat().resolvedOptions()
-                                          .timeZone,
-                                      )
-                                    : new Date(),
+                                startTime: t?.toDate(
+                                  Intl.DateTimeFormat().resolvedOptions()
+                                    .timeZone,
+                                ) ?? value.startTime,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
startTime:
t != null
? t.toDate(
Intl.DateTimeFormat().resolvedOptions()
.timeZone,
)
: new Date(),
startTime: t?.toDate(
Intl.DateTimeFormat().resolvedOptions()
.timeZone,
) ?? value.startTime,

});
}}
/>{" "}
Expand All @@ -161,10 +164,13 @@ export const RolloutAndTiming: React.FC<{
onChange={(t) => {
onChange({
...value,
endTime: t.toDate(
Intl.DateTimeFormat().resolvedOptions()
.timeZone,
),
endTime:
t != null
? t.toDate(
Intl.DateTimeFormat().resolvedOptions()
.timeZone,
)
: new Date(),
Comment on lines +167 to +173
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Apply consistent handling for endTime

Apply the same improvement as suggested for startTime to maintain consistency.

-                                endTime:
-                                  t != null
-                                    ? t.toDate(
-                                        Intl.DateTimeFormat().resolvedOptions()
-                                          .timeZone,
-                                      )
-                                    : new Date(),
+                                endTime: t?.toDate(
+                                  Intl.DateTimeFormat().resolvedOptions()
+                                    .timeZone,
+                                ) ?? value.endTime,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
endTime:
t != null
? t.toDate(
Intl.DateTimeFormat().resolvedOptions()
.timeZone,
)
: new Date(),
endTime: t?.toDate(
Intl.DateTimeFormat().resolvedOptions()
.timeZone,
) ?? value.endTime,

});
}}
aria-label="End Time"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const DateConditionRender: React.FC<DateConditionRenderProps> = ({
<div className="col-span-7">
<DateTimePicker
value={toZonedDateTime(new Date(value))}
onChange={setDate}
onChange={(value) => value != null && setDate(value)}
aria-label={type}
variant="filter"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export const JobHistoryChart: React.FC<{
animationDuration={animationDuration}
fill={color}
onClick={(e) => {
const start = new Date(e.date);
const start = new Date((e as any).date);
const end = addDays(start, 1);

const afterStartCondition: JobCondition = {
Expand Down
3 changes: 1 addition & 2 deletions packages/ui/src/date-time-picker/date-time-picker.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/unbound-method */
"use client";

import type { DateValue } from "react-aria";
Expand Down Expand Up @@ -71,7 +70,7 @@ const DateTimePicker = React.forwardRef<
<TimeField
aria-label="time-field"
value={state.timeValue}
onChange={state.setTimeValue}
onChange={(value) => value != null && state.setTimeValue(value)}
/>
)}
</div>
Expand Down
Loading