-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Fix task instance and runs tooltips in Grid view #58359
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
9 commits
Select commit
Hold shift + click to select a range
e5c5179
refactor: replace hovertooltip with basictooltip
RoyLee1224 3a6ba7d
feat: implement basic tooltip for grid TI
RoyLee1224 06a68d9
feat: implement basic tooltip for grid run
RoyLee1224 1596e79
fix: use get duration util
RoyLee1224 cd82c2e
refactor: simplify BasicTooltip and add auto-flip for viewport overflow
RoyLee1224 fe14760
fix(i18n): add translation for tooltip states
RoyLee1224 3c52202
refactor: improve BasicTooltip positioning and remove duration
RoyLee1224 18bb2c4
fix: use Chakra semantic tokens
RoyLee1224 b38c4b6
refactor: use dynamic height for BasicTooltip positioning
RoyLee1224 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
127 changes: 127 additions & 0 deletions
127
airflow-core/src/airflow/ui/src/components/BasicTooltip.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,127 @@ | ||
| /*! | ||
| * 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 { Box, Portal } from "@chakra-ui/react"; | ||
| import type { ReactElement, ReactNode } from "react"; | ||
| import { cloneElement, useCallback, useEffect, useLayoutEffect, useRef, useState } from "react"; | ||
|
|
||
| type Props = { | ||
| readonly children: ReactElement; | ||
| readonly content: ReactNode; | ||
| }; | ||
|
|
||
| const offset = 8; | ||
|
|
||
| export const BasicTooltip = ({ children, content }: Props): ReactElement => { | ||
| const triggerRef = useRef<HTMLElement>(null); | ||
| const tooltipRef = useRef<HTMLDivElement>(null); | ||
| const [isOpen, setIsOpen] = useState(false); | ||
| const [showOnTop, setShowOnTop] = useState(false); | ||
| const timeoutRef = useRef<NodeJS.Timeout>(); | ||
|
|
||
| const handleMouseEnter = useCallback(() => { | ||
| if (timeoutRef.current) { | ||
| clearTimeout(timeoutRef.current); | ||
| } | ||
| timeoutRef.current = setTimeout(() => { | ||
| setIsOpen(true); | ||
| }, 500); | ||
| }, []); | ||
|
|
||
| const handleMouseLeave = useCallback(() => { | ||
| if (timeoutRef.current) { | ||
| clearTimeout(timeoutRef.current); | ||
| timeoutRef.current = undefined; | ||
| } | ||
| setIsOpen(false); | ||
| }, []); | ||
|
|
||
| // Calculate position based on actual tooltip height before paint | ||
| useLayoutEffect(() => { | ||
| if (isOpen && triggerRef.current && tooltipRef.current) { | ||
| const triggerRect = triggerRef.current.getBoundingClientRect(); | ||
| const tooltipHeight = tooltipRef.current.clientHeight; | ||
| const wouldOverflow = triggerRect.bottom + offset + tooltipHeight > globalThis.innerHeight; | ||
|
|
||
| setShowOnTop(wouldOverflow); | ||
| } | ||
| }, [isOpen]); | ||
|
|
||
| // Cleanup on unmount | ||
pierrejeambrun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| useEffect( | ||
| () => () => { | ||
| if (timeoutRef.current) { | ||
| clearTimeout(timeoutRef.current); | ||
| } | ||
| }, | ||
| [], | ||
| ); | ||
|
|
||
| // Clone children and attach event handlers + ref | ||
| const trigger = cloneElement(children, { | ||
| onMouseEnter: handleMouseEnter, | ||
| onMouseLeave: handleMouseLeave, | ||
| ref: triggerRef, | ||
| }); | ||
|
|
||
| if (!isOpen || !triggerRef.current) { | ||
| return trigger; | ||
| } | ||
|
|
||
| const rect = triggerRef.current.getBoundingClientRect(); | ||
| const { scrollX, scrollY } = globalThis; | ||
|
|
||
| return ( | ||
| <> | ||
| {trigger} | ||
| <Portal> | ||
| <Box | ||
| bg="bg.inverted" | ||
| borderRadius="md" | ||
| boxShadow="md" | ||
| color="fg.inverted" | ||
| fontSize="sm" | ||
| left={`${rect.left + scrollX + rect.width / 2}px`} | ||
| paddingX="3" | ||
| paddingY="2" | ||
| pointerEvents="none" | ||
| position="absolute" | ||
| ref={tooltipRef} | ||
| top={showOnTop ? `${rect.top + scrollY - offset}px` : `${rect.bottom + scrollY + offset}px`} | ||
| transform={showOnTop ? "translate(-50%, -100%)" : "translateX(-50%)"} | ||
| whiteSpace="nowrap" | ||
| zIndex="popover" | ||
| > | ||
| <Box | ||
| borderLeft="4px solid transparent" | ||
| borderRight="4px solid transparent" | ||
| height={0} | ||
| left="50%" | ||
| position="absolute" | ||
| transform="translateX(-50%)" | ||
| width={0} | ||
| {...(showOnTop | ||
| ? { borderTop: "4px solid var(--chakra-colors-bg-inverted)", bottom: "-4px" } | ||
| : { borderBottom: "4px solid var(--chakra-colors-bg-inverted)", top: "-4px" })} | ||
| /> | ||
| {content} | ||
| </Box> | ||
| </Portal> | ||
| </> | ||
| ); | ||
| }; | ||
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
63 changes: 0 additions & 63 deletions
63
airflow-core/src/airflow/ui/src/components/HoverTooltip.tsx
This file was deleted.
Oops, something went wrong.
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
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
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.