@@ -11,10 +11,13 @@ import type {FieldConfig} from './types';
1111import { Icon } from 'isl-components/Icon' ;
1212import { extractTokens , TokensList } from 'isl-components/Tokens' ;
1313import { DOCUMENTATION_DELAY , Tooltip } from 'isl-components/Tooltip' ;
14+ import { useAtomValue } from 'jotai' ;
1415import { Fragment } from 'react' ;
1516import { tracker } from '../analytics' ;
1617import { Copyable } from '../Copyable' ;
1718import { T } from '../i18n' ;
19+ import { copyFromParentCommit , parentCommitContextAtom } from './CommitInfoState' ;
20+ import { isFieldNonEmpty } from './CommitMessageFields' ;
1821import { RenderMarkup } from './RenderMarkup' ;
1922import { SeeMoreContainer } from './SeeMoreContainer' ;
2023import { CommitInfoTextArea } from './TextArea' ;
@@ -29,7 +32,6 @@ export function CommitInfoField({
2932 editedField,
3033 startEditingField,
3134 setEditedField,
32- copyFromParent,
3335 extra,
3436 autofocus,
3537} : {
@@ -40,10 +42,12 @@ export function CommitInfoField({
4042 content ?: string | Array < string > ;
4143 editedField : string | Array < string > | undefined ;
4244 setEditedField : ( value : string ) => unknown ;
43- copyFromParent ?: ( ) => void ;
4445 extra ?: JSX . Element ;
4546 autofocus ?: boolean ;
4647} ) : JSX . Element | null {
48+ const parentFields = useAtomValue ( parentCommitContextAtom ) ?. parentFields ;
49+ const showCopyFromParent =
50+ ! readonly && parentFields != null && isFieldNonEmpty ( parentFields [ field . key ] ) ;
4751 const editedFieldContent =
4852 editedField == null ? '' : Array . isArray ( editedField ) ? editedField . join ( ', ' ) : editedField ;
4953 if ( field . type === 'title' ) {
@@ -73,9 +77,9 @@ export function CommitInfoField({
7377 </ ClickToEditField >
7478 < div className = "commit-info-field-buttons" >
7579 { readonly ? null : < EditFieldButton onClick = { startEditingField } /> }
76- { readonly || copyFromParent == null ? null : (
77- < CopyFromParentButton onClick = { copyFromParent } />
78- ) }
80+ { showCopyFromParent ? (
81+ < CopyFromParentButton onClick = { ( ) => copyFromParentCommit ( field . key ) } />
82+ ) : null }
7983 </ div >
8084 </ div >
8185 ) }
@@ -129,7 +133,6 @@ export function CommitInfoField({
129133 autoFocus = { autofocus ?? false }
130134 editedMessage = { editedFieldContent }
131135 setEditedField = { setEditedField }
132- copyFromParent = { copyFromParent }
133136 />
134137 ) }
135138 { extra }
@@ -187,9 +190,9 @@ export function CommitInfoField({
187190 < T > { field . key } </ T >
188191 < div className = "commit-info-field-buttons" >
189192 { readonly ? null : < EditFieldButton onClick = { startEditingField } /> }
190- { readonly || copyFromParent == null ? null : (
191- < CopyFromParentButton onClick = { copyFromParent } />
192- ) }
193+ { showCopyFromParent ? (
194+ < CopyFromParentButton onClick = { ( ) => copyFromParentCommit ( field . key ) } />
195+ ) : null }
193196 </ div >
194197 </ SmallCapsTitle >
195198 < ClickToEditField
0 commit comments