| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| b69ab31 | | | 3 | * |
| b69ab31 | | | 4 | * This source code is licensed under the MIT license found in the |
| b69ab31 | | | 5 | * LICENSE file in the root directory of this source tree. |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | import type {Placement} from 'isl-components/Tooltip'; |
| b69ab31 | | | 9 | |
| b69ab31 | | | 10 | import {Tooltip} from 'isl-components/Tooltip'; |
| b69ab31 | | | 11 | import {t} from './i18n'; |
| b69ab31 | | | 12 | |
| b69ab31 | | | 13 | type CommitTitleProps = React.HTMLAttributes<HTMLDivElement> & { |
| b69ab31 | | | 14 | commitMessage: string; |
| b69ab31 | | | 15 | tooltipPlacement?: Placement; |
| b69ab31 | | | 16 | }; |
| b69ab31 | | | 17 | |
| b69ab31 | | | 18 | /** One line commit message with tooltip about full message. */ |
| b69ab31 | | | 19 | export function CommitTitle(props: CommitTitleProps) { |
| b69ab31 | | | 20 | const {commitMessage, tooltipPlacement, ...restProps} = props; |
| b69ab31 | | | 21 | const title = commitMessage.split('\n')[0]; |
| b69ab31 | | | 22 | const trimmed = commitMessage.trim(); |
| b69ab31 | | | 23 | if (trimmed === '') { |
| b69ab31 | | | 24 | return null; |
| b69ab31 | | | 25 | } |
| b69ab31 | | | 26 | |
| b69ab31 | | | 27 | const divElement = <div {...restProps}>{title}</div>; |
| b69ab31 | | | 28 | if (title === trimmed) { |
| b69ab31 | | | 29 | // No need to use a tooltip. |
| b69ab31 | | | 30 | return divElement; |
| b69ab31 | | | 31 | } else { |
| b69ab31 | | | 32 | return ( |
| b69ab31 | | | 33 | <Tooltip placement={tooltipPlacement} title={title}> |
| b69ab31 | | | 34 | {divElement} |
| b69ab31 | | | 35 | </Tooltip> |
| b69ab31 | | | 36 | ); |
| b69ab31 | | | 37 | } |
| b69ab31 | | | 38 | } |
| b69ab31 | | | 39 | |
| b69ab31 | | | 40 | export function temporaryCommitTitle() { |
| b69ab31 | | | 41 | return t('Temporary Commit at $time', {replace: {$time: new Date().toLocaleString()}}); |
| b69ab31 | | | 42 | } |