pierrejeambrun commented on code in PR #67636:
URL: https://github.com/apache/airflow/pull/67636#discussion_r3318755903


##########
airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldDateTime.tsx:
##########


Review Comment:
   get type from the destructured element here



##########
airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldDateTime.tsx:
##########
@@ -31,14 +31,18 @@ export const FieldDateTime = ({
 }: FlexibleFormElementProps & InputProps) => {
   const { disabled, paramsDict, setParamsDict } = useParamStore(namespace);
   const param = paramsDict[name] ?? paramPlaceholder;
+  const isTime = rest.type === "time";
+  const normalizeTime = (value: string) => (isTime && 
/^\d{2}:\d{2}$/u.test(value) ? `${value}:00` : value);

Review Comment:
   Why this normalization? Seems unecessary.



##########
airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldDateTime.tsx:
##########
@@ -62,6 +66,7 @@ export const FieldDateTime = ({
       onChange={(event) => handleChange(event.target.value)}
       required={rest.required}
       size="sm"
+      step={isTime ? 1 : undefined}

Review Comment:
   This should be enough.



##########
airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldDateTime.test.tsx:
##########
@@ -0,0 +1,189 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { fireEvent, render } from "@testing-library/react";
+import { describe, it, expect, beforeEach, vi } from "vitest";
+
+import { Wrapper } from "src/utils/Wrapper";
+
+import { FieldDateTime } from "./FieldDateTime";
+
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
+const mockParamsDict: Record<string, any> = {};
+const mockSetParamsDict = vi.fn();
+
+vi.mock("src/queries/useParamStore", () => ({
+  paramPlaceholder: {
+    schema: {},
+    value: null,
+  },
+  useParamStore: () => ({
+    disabled: false,
+    paramsDict: mockParamsDict,
+    setParamsDict: mockSetParamsDict,
+  }),
+}));
+
+const getInputByName = (name: string) =>
+  document.querySelector<HTMLInputElement>(`#element_${name}`) as 
HTMLInputElement;
+
+describe("FieldDateTime — time field (issue #66492)", () => {
+  beforeEach(() => {
+    mockSetParamsDict.mockClear();
+    Object.keys(mockParamsDict).forEach((key) => {
+      // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
+      delete mockParamsDict[key];
+    });
+  });
+
+  it("renders time input with step=1 so the picker exposes the seconds field", 
() => {
+    mockParamsDict.cutoff_time = {
+      schema: { format: "time", type: "string" },
+      value: null,
+    };
+
+    render(<FieldDateTime name="cutoff_time" onUpdate={vi.fn()} type="time" 
/>, {
+      wrapper: Wrapper,
+    });
+
+    const input = getInputByName("cutoff_time");
+
+    expect(input.type).toBe("time");
+    expect(input.getAttribute("step")).toBe("1");
+  });
+
+  it("does not set step on a date input", () => {
+    mockParamsDict.cutoff_date = {
+      schema: { format: "date", type: "string" },
+      value: null,
+    };
+
+    render(<FieldDateTime name="cutoff_date" onUpdate={vi.fn()} type="date" 
/>, {
+      wrapper: Wrapper,
+    });
+
+    const input = getInputByName("cutoff_date");
+
+    expect(input.type).toBe("date");
+    expect(input.getAttribute("step")).toBeNull();
+  });
+
+  it("appends ':00' when the browser emits an HH:MM value, so the API receives 
HH:MM:SS", () => {
+    // Reproduces the 400 in #66492: browsers without a seconds field emit 
"15:58",
+    // but the backend `{format: "time"}` validator requires "15:58:00".
+    mockParamsDict.cutoff_time = {
+      schema: { format: "time", type: "string" },
+      value: null,
+    };
+    const onUpdate = vi.fn();
+
+    render(<FieldDateTime name="cutoff_time" onUpdate={onUpdate} type="time" 
/>, {
+      wrapper: Wrapper,
+    });
+
+    fireEvent.change(getInputByName("cutoff_time"), { target: { value: "15:58" 
} });
+
+    // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
+    expect(mockParamsDict.cutoff_time.value).toBe("15:58:00");
+    expect(onUpdate).toHaveBeenLastCalledWith("15:58:00");
+    expect(mockSetParamsDict).toHaveBeenCalled();
+  });

Review Comment:
   I don't think that's necessary, do you have a browser / setup that can 
highlight that?



##########
airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldDateTime.test.tsx:
##########
@@ -0,0 +1,189 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { fireEvent, render } from "@testing-library/react";
+import { describe, it, expect, beforeEach, vi } from "vitest";
+
+import { Wrapper } from "src/utils/Wrapper";
+
+import { FieldDateTime } from "./FieldDateTime";
+
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
+const mockParamsDict: Record<string, any> = {};
+const mockSetParamsDict = vi.fn();
+
+vi.mock("src/queries/useParamStore", () => ({
+  paramPlaceholder: {
+    schema: {},
+    value: null,
+  },
+  useParamStore: () => ({
+    disabled: false,
+    paramsDict: mockParamsDict,
+    setParamsDict: mockSetParamsDict,
+  }),
+}));
+
+const getInputByName = (name: string) =>
+  document.querySelector<HTMLInputElement>(`#element_${name}`) as 
HTMLInputElement;
+
+describe("FieldDateTime — time field (issue #66492)", () => {
+  beforeEach(() => {
+    mockSetParamsDict.mockClear();
+    Object.keys(mockParamsDict).forEach((key) => {
+      // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
+      delete mockParamsDict[key];
+    });
+  });
+
+  it("renders time input with step=1 so the picker exposes the seconds field", 
() => {
+    mockParamsDict.cutoff_time = {
+      schema: { format: "time", type: "string" },
+      value: null,
+    };
+
+    render(<FieldDateTime name="cutoff_time" onUpdate={vi.fn()} type="time" 
/>, {
+      wrapper: Wrapper,
+    });
+
+    const input = getInputByName("cutoff_time");
+
+    expect(input.type).toBe("time");
+    expect(input.getAttribute("step")).toBe("1");
+  });
+
+  it("does not set step on a date input", () => {
+    mockParamsDict.cutoff_date = {
+      schema: { format: "date", type: "string" },
+      value: null,
+    };
+
+    render(<FieldDateTime name="cutoff_date" onUpdate={vi.fn()} type="date" 
/>, {
+      wrapper: Wrapper,
+    });
+
+    const input = getInputByName("cutoff_date");
+
+    expect(input.type).toBe("date");
+    expect(input.getAttribute("step")).toBeNull();
+  });
+
+  it("appends ':00' when the browser emits an HH:MM value, so the API receives 
HH:MM:SS", () => {
+    // Reproduces the 400 in #66492: browsers without a seconds field emit 
"15:58",
+    // but the backend `{format: "time"}` validator requires "15:58:00".
+    mockParamsDict.cutoff_time = {
+      schema: { format: "time", type: "string" },
+      value: null,
+    };
+    const onUpdate = vi.fn();
+
+    render(<FieldDateTime name="cutoff_time" onUpdate={onUpdate} type="time" 
/>, {
+      wrapper: Wrapper,
+    });
+
+    fireEvent.change(getInputByName("cutoff_time"), { target: { value: "15:58" 
} });
+
+    // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
+    expect(mockParamsDict.cutoff_time.value).toBe("15:58:00");
+    expect(onUpdate).toHaveBeenLastCalledWith("15:58:00");
+    expect(mockSetParamsDict).toHaveBeenCalled();
+  });
+
+  it("passes a fully-qualified HH:MM:SS value through unchanged", () => {
+    mockParamsDict.cutoff_time = {
+      schema: { format: "time", type: "string" },
+      value: null,
+    };
+    const onUpdate = vi.fn();
+
+    render(<FieldDateTime name="cutoff_time" onUpdate={onUpdate} type="time" 
/>, {
+      wrapper: Wrapper,
+    });
+
+    fireEvent.change(getInputByName("cutoff_time"), { target: { value: 
"15:58:42" } });
+
+    // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
+    expect(mockParamsDict.cutoff_time.value).toBe("15:58:42");
+    expect(onUpdate).toHaveBeenLastCalledWith("15:58:42");
+  });
+
+  it("clears the param to null when the time input is emptied", () => {
+    mockParamsDict.cutoff_time = {
+      schema: { format: "time", type: "string" },
+      value: "15:58:00",
+    };
+    const onUpdate = vi.fn();
+
+    render(<FieldDateTime name="cutoff_time" onUpdate={onUpdate} type="time" 
/>, {
+      wrapper: Wrapper,
+    });
+
+    fireEvent.change(getInputByName("cutoff_time"), { target: { value: "" } });
+
+    // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
+    expect(mockParamsDict.cutoff_time.value).toBeNull();
+    expect(onUpdate).toHaveBeenLastCalledWith("");
+  });
+
+  it("does not pad date inputs whose value never matches the HH:MM pattern", 
() => {
+    // Guard against the time normalizer leaking into date handling.
+    mockParamsDict.cutoff_date = {
+      schema: { format: "date", type: "string" },
+      value: null,
+    };
+    const onUpdate = vi.fn();
+
+    render(<FieldDateTime name="cutoff_date" onUpdate={onUpdate} type="date" 
/>, {
+      wrapper: Wrapper,
+    });
+
+    fireEvent.change(getInputByName("cutoff_date"), { target: { value: 
"2026-05-28" } });
+
+    // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
+    expect(mockParamsDict.cutoff_date.value).toBe("2026-05-28");
+    expect(onUpdate).toHaveBeenLastCalledWith("2026-05-28");
+  });
+
+  it("preserves a previously-stored HH:MM:SS value when re-rendering", () => {
+    mockParamsDict.cutoff_time = {
+      schema: { format: "time", type: "string" },
+      value: "09:15:30",
+    };
+
+    render(<FieldDateTime name="cutoff_time" onUpdate={vi.fn()} type="time" 
/>, {
+      wrapper: Wrapper,
+    });
+
+    expect(getInputByName("cutoff_time").value).toBe("09:15:30");
+  });
+
+  it("does not mutate the param store when the entry is missing, but still 
forwards the normalized value to onUpdate", () => {
+    // FieldDateTime guards `if (paramsDict[name])` before writing; the 
normalized
+    // value should still reach the parent via onUpdate so the form stays 
consistent.
+    const onUpdate = vi.fn();
+
+    render(<FieldDateTime name="cutoff_time" onUpdate={onUpdate} type="time" 
/>, {
+      wrapper: Wrapper,
+    });
+
+    fireEvent.change(getInputByName("cutoff_time"), { target: { value: "15:58" 
} });
+
+    expect(mockParamsDict.cutoff_time).toBeUndefined();
+    expect(onUpdate).toHaveBeenLastCalledWith("15:58:00");
+  });
+});

Review Comment:
   To remove



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to