addons/isl/src/CommitTitle.tsxblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import type {Placement} from 'isl-components/Tooltip';
b69ab319
b69ab3110import {Tooltip} from 'isl-components/Tooltip';
b69ab3111import {t} from './i18n';
b69ab3112
b69ab3113type CommitTitleProps = React.HTMLAttributes<HTMLDivElement> & {
b69ab3114 commitMessage: string;
b69ab3115 tooltipPlacement?: Placement;
b69ab3116};
b69ab3117
b69ab3118/** One line commit message with tooltip about full message. */
b69ab3119export function CommitTitle(props: CommitTitleProps) {
b69ab3120 const {commitMessage, tooltipPlacement, ...restProps} = props;
b69ab3121 const title = commitMessage.split('\n')[0];
b69ab3122 const trimmed = commitMessage.trim();
b69ab3123 if (trimmed === '') {
b69ab3124 return null;
b69ab3125 }
b69ab3126
b69ab3127 const divElement = <div {...restProps}>{title}</div>;
b69ab3128 if (title === trimmed) {
b69ab3129 // No need to use a tooltip.
b69ab3130 return divElement;
b69ab3131 } else {
b69ab3132 return (
b69ab3133 <Tooltip placement={tooltipPlacement} title={title}>
b69ab3134 {divElement}
b69ab3135 </Tooltip>
b69ab3136 );
b69ab3137 }
b69ab3138}
b69ab3139
b69ab3140export function temporaryCommitTitle() {
b69ab3141 return t('Temporary Commit at $time', {replace: {$time: new Date().toLocaleString()}});
b69ab3142}