-
Notifications
You must be signed in to change notification settings - Fork 17.4k
Allow pasting full datetime strings into date picker inputs #66251
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c15d119
Allow pasting full datetime strings into date picker inputs
junyeong0619 ab40c68
Merge branch 'main' into paste_datetime_fix
junyeong0619 4167611
Merge branch 'main' into paste_datetime_fix
junyeong0619 f3d48d0
Honor selected UI timezone for pasted datetimes and add tests
junyeong0619 47e6c21
Drop unnecessary ChangeEvent cast on paste handler
junyeong0619 9153cb5
Cancel pending debounced typing call when handling paste
junyeong0619 33a0b90
Share parseInput between typing and paste, drop duplicate setDisplayDate
junyeong0619 5014143
Apply prettier and eslint auto-fixes from UI compile-lint hook
junyeong0619 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
129 changes: 129 additions & 0 deletions
129
airflow-core/src/airflow/ui/src/components/DateTimeInput.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| /*! | ||
| * 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, screen } from "@testing-library/react"; | ||
| import dayjs from "dayjs"; | ||
| import timezone from "dayjs/plugin/timezone"; | ||
| import utc from "dayjs/plugin/utc"; | ||
| import type { ChangeEvent } from "react"; | ||
| import type { Mock } from "vitest"; | ||
| import { describe, it, expect, vi } from "vitest"; | ||
|
|
||
| import { TimezoneContext } from "src/context/timezone"; | ||
| import { Wrapper } from "src/utils/Wrapper"; | ||
|
|
||
| import { DateTimeInput } from "./DateTimeInput"; | ||
|
|
||
| dayjs.extend(utc); | ||
| dayjs.extend(timezone); | ||
|
|
||
| type ChangeHandler = (event: ChangeEvent<HTMLInputElement>) => void; | ||
|
|
||
| const renderWithTimezone = (selectedTimezone: string) => { | ||
| const onChange: Mock<ChangeHandler> = vi.fn(); | ||
|
|
||
| render( | ||
| <TimezoneContext.Provider value={{ selectedTimezone, setSelectedTimezone: vi.fn() }}> | ||
| <DateTimeInput onChange={onChange} value="" /> | ||
| </TimezoneContext.Provider>, | ||
| { wrapper: Wrapper }, | ||
| ); | ||
|
|
||
| return { input: screen.getByTestId<HTMLInputElement>("datetime-input"), onChange }; | ||
| }; | ||
|
|
||
| const paste = (input: HTMLInputElement, text: string) => | ||
| fireEvent.paste(input, { clipboardData: { getData: () => text } }); | ||
|
|
||
| const lastEmittedValue = (onChange: Mock<ChangeHandler>): string | undefined => | ||
| onChange.mock.calls.at(-1)?.[0].target.value; | ||
|
|
||
| describe("DateTimeInput onPaste timezone handling", () => { | ||
| it("renders pasted UTC instant in the selected UTC timezone", () => { | ||
| const { input, onChange } = renderWithTimezone("UTC"); | ||
|
|
||
| paste(input, "2026-01-15T10:30:00Z"); | ||
|
|
||
| expect(input.value).toBe("2026-01-15T10:30"); | ||
| expect(lastEmittedValue(onChange)).toBe("2026-01-15T10:30:00.000Z"); | ||
| }); | ||
|
|
||
| it("converts pasted UTC instant into a non-UTC selected timezone", () => { | ||
| const { input, onChange } = renderWithTimezone("Asia/Seoul"); | ||
|
|
||
| paste(input, "2026-01-15T10:30:00Z"); | ||
|
|
||
| // 10:30 UTC == 19:30 Asia/Seoul (+09:00) | ||
| expect(input.value).toBe("2026-01-15T19:30"); | ||
| expect(lastEmittedValue(onChange)).toBe("2026-01-15T10:30:00.000Z"); | ||
| }); | ||
|
|
||
| it("converts pasted offset value into the selected timezone", () => { | ||
| const { input, onChange } = renderWithTimezone("UTC"); | ||
|
|
||
| paste(input, "2026-01-15T10:30:00+09:00"); | ||
|
|
||
| // 10:30 in +09:00 == 01:30 UTC | ||
| expect(input.value).toBe("2026-01-15T01:30"); | ||
| expect(lastEmittedValue(onChange)).toBe("2026-01-15T01:30:00.000Z"); | ||
| }); | ||
|
|
||
| it("treats a bare datetime as being in the selected timezone", () => { | ||
| const { input, onChange } = renderWithTimezone("Asia/Seoul"); | ||
|
|
||
| paste(input, "2026-01-15T10:30"); | ||
|
|
||
| // bare 10:30 interpreted as Asia/Seoul (+09:00) == 01:30 UTC | ||
| expect(input.value).toBe("2026-01-15T10:30"); | ||
| expect(lastEmittedValue(onChange)).toBe("2026-01-15T01:30:00.000Z"); | ||
| }); | ||
|
|
||
| it("ignores invalid pasted strings", () => { | ||
| const { input, onChange } = renderWithTimezone("UTC"); | ||
|
|
||
| paste(input, "not a date"); | ||
|
|
||
| expect(input.value).toBe(""); | ||
| expect(onChange).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("does not fire a pending debounced typing call after a paste", () => { | ||
| vi.useFakeTimers(); | ||
| try { | ||
| const { input, onChange } = renderWithTimezone("UTC"); | ||
|
|
||
| // 1. User types — schedules debouncedOnDateChange (1s delay). | ||
| fireEvent.change(input, { target: { value: "2026-01-15T05:00" } }); | ||
| expect(onChange).not.toHaveBeenCalled(); | ||
|
|
||
| // 2. Within the debounce window, user pastes — fires onChange immediately. | ||
| vi.advanceTimersByTime(300); | ||
| paste(input, "2026-12-31T23:59:00Z"); | ||
| expect(onChange).toHaveBeenCalledTimes(1); | ||
|
|
||
| // 3. Advance past the debounce delay. The pending typed call must NOT fire, | ||
| // otherwise the parent form gets a redundant onChange (and any side effects | ||
| // attached to it run twice). | ||
| vi.advanceTimersByTime(2000); | ||
| expect(onChange).toHaveBeenCalledTimes(1); | ||
| expect(lastEmittedValue(onChange)).toBe("2026-12-31T23:59:00.000Z"); | ||
| } finally { | ||
| vi.useRealTimers(); | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.