-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🪟 🎉 [Job logs] Make reset streams list expandable (#11502)
- Loading branch information
Showing
2 changed files
with
43 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
47 changes: 36 additions & 11 deletions
47
airbyte-webapp/src/area/connection/components/JobHistoryItem/ResetStreamDetails.tsx
This file contains 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 |
---|---|---|
@@ -1,21 +1,46 @@ | ||
import classNames from "classnames"; | ||
import React from "react"; | ||
import React, { useEffect, useRef, useState } from "react"; | ||
import { useToggle } from "react-use"; | ||
|
||
import { Button } from "components/ui/Button"; | ||
import { FlexContainer } from "components/ui/Flex"; | ||
import { Icon } from "components/ui/Icon"; | ||
import { Text } from "components/ui/Text"; | ||
|
||
import styles from "./ResetStreamDetails.module.scss"; | ||
|
||
interface ResetStreamsDetailsProps { | ||
names?: string[]; | ||
isOpen?: boolean; | ||
} | ||
|
||
export const ResetStreamsDetails: React.FC<ResetStreamsDetailsProps> = ({ names = [], isOpen }) => ( | ||
<Text size="sm" className={classNames(styles.textContainer, { [styles.open]: isOpen })}> | ||
{names.map((name, idx) => ( | ||
<span key={idx} className={styles.text}> | ||
{name} | ||
</span> | ||
))} | ||
</Text> | ||
); | ||
export const ResetStreamsDetails: React.FC<ResetStreamsDetailsProps> = ({ names = [] }) => { | ||
const textRef = useRef<HTMLParagraphElement>(null); | ||
const [isExpanded, setIsExpanded] = useToggle(false); | ||
const [isExpandButtonVisible, setIsExpandButtonVisible] = useState<boolean>(false); | ||
const onIconClick = () => setIsExpanded(); | ||
|
||
useEffect(() => { | ||
const textCurrent = textRef.current; | ||
// detect text overflow | ||
if (textCurrent) { | ||
setIsExpandButtonVisible(textCurrent.scrollWidth > textCurrent.clientWidth); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<FlexContainer direction="column" justifyContent="center" alignItems="center" gap="none"> | ||
<Text ref={textRef} size="sm" className={classNames(styles.textContainer, { [styles.expanded]: isExpanded })}> | ||
{names.map((name, idx) => ( | ||
<span key={idx} className={styles.text}> | ||
{name} | ||
</span> | ||
))} | ||
</Text> | ||
{isExpandButtonVisible && ( | ||
<Button size="xs" onClick={onIconClick} variant="clear" className={styles.expandBtn}> | ||
<Icon type={isExpanded ? "chevronUp" : "chevronDown"} /> | ||
</Button> | ||
)} | ||
</FlexContainer> | ||
); | ||
}; |