Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

set default time in create event modal (#63046)

Ryan Lauriefd168103b8fa
diff --git a/e2e/test/scenarios/organization/timelines-collection.cy.spec.js b/e2e/test/scenarios/organization/timelines-collection.cy.spec.js
index 0b5415bc5ea..ab481a4d1ca 100644
--- a/e2e/test/scenarios/organization/timelines-collection.cy.spec.js
+++ b/e2e/test/scenarios/organization/timelines-collection.cy.spec.js
@@ -121,9 +121,11 @@ describe("scenarios > organization > timelines > collection", () => {
cy.findByLabelText("Event name").type("RC1");
cy.findByTestId("event-form").within(() => {
- cy.findByLabelText("Date").clear().type("10/20/2026");
+ // adding the time first reproduces metabase#62999
cy.button("Add time").click();
cy.findByLabelText("Time").type("10:20");
+
+ cy.findByLabelText("Date").clear().type("10/20/2026");
cy.findByText("Create").click();
cy.wait("@createEvent");
});
diff --git a/frontend/src/metabase/forms/components/FormDateInput/FormDateInput.tsx b/frontend/src/metabase/forms/components/FormDateInput/FormDateInput.tsx
index 6395e227057..d4d362d84a7 100644
--- a/frontend/src/metabase/forms/components/FormDateInput/FormDateInput.tsx
+++ b/frontend/src/metabase/forms/components/FormDateInput/FormDateInput.tsx
@@ -50,6 +50,7 @@ export const FormDateInput = forwardRef(function FormDateInput(
return (
<DateInput
fw="bold"
+ onChange={handleChange}
{...props}
id={id}
ref={ref}
@@ -57,7 +58,6 @@ export const FormDateInput = forwardRef(function FormDateInput(
name={name}
value={dayjs(date).toDate()}
error={touched && error != null}
- onChange={handleChange}
onBlur={onBlur}
/>
);
diff --git a/frontend/src/metabase/timelines/common/components/EventForm/EventForm.tsx b/frontend/src/metabase/timelines/common/components/EventForm/EventForm.tsx
index 735322c0af0..6c417a2be96 100644
--- a/frontend/src/metabase/timelines/common/components/EventForm/EventForm.tsx
+++ b/frontend/src/metabase/timelines/common/components/EventForm/EventForm.tsx
@@ -80,7 +80,10 @@ const EventForm = ({
return (
<FormProvider
- initialValues={initialValues}
+ initialValues={{
+ ...initialValues,
+ timestamp: initialValues.timestamp || dayjs().utc(true).toISOString(),
+ }}
validationSchema={EVENT_SCHEMA}
onSubmit={onSubmit}
>
@@ -99,6 +102,19 @@ const EventForm = ({
title={t`Date`}
flex={1}
valueFormat={dateSettings?.date_style}
+ onChange={(date) => {
+ if (values.time_matters) {
+ // if time matters, preserve the time part of the timestamp
+ // when changing the date part
+ const timePart = dayjs.tz(values.timestamp);
+ const newDate = parseTimestamp(date)
+ .set("hour", timePart.hour())
+ .set("minute", timePart.minute());
+ setFieldValue("timestamp", newDate.toISOString());
+ } else {
+ setFieldValue("timestamp", dayjs(date).toISOString());
+ }
+ }}
/>
{values.time_matters ? (
<Flex gap="xs" align="end">