Skip to content

Commit 75fd4cd

Browse files
Copilotniik
andcommitted
Refactor commit options button: remove isCommitOptionsButtonEnabled, show button unconditionally, conditionalize Bypass Commit Hooks menu item on hooks environment and hasCommitHooks
Co-authored-by: niik <[email protected]>
1 parent e1e5225 commit 75fd4cd

1 file changed

Lines changed: 23 additions & 40 deletions

File tree

‎app/src/ui/changes/commit-message.tsx‎

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,10 +1020,6 @@ export class CommitMessage extends React.Component<
10201020
}
10211021

10221022
private renderCommitOptionsButton() {
1023-
if (!this.isCommitOptionsButtonEnabled) {
1024-
return null
1025-
}
1026-
10271023
const ariaLabel = 'Configure commit options'
10281024

10291025
return (
@@ -1050,8 +1046,11 @@ export class CommitMessage extends React.Component<
10501046
e: React.MouseEvent<HTMLButtonElement>
10511047
) => {
10521048
e.preventDefault()
1053-
showContextualMenu([
1054-
{
1049+
1050+
const items: IMenuItem[] = []
1051+
1052+
if (enableHooksEnvironment() && this.props.hasCommitHooks) {
1053+
items.push({
10551054
type: 'checkbox',
10561055
checked: this.props.skipCommitHooks,
10571056
label: __DARWIN__ ? 'Bypass Commit Hooks' : 'Bypass Commit hooks',
@@ -1061,21 +1060,24 @@ export class CommitMessage extends React.Component<
10611060
signOffCommits: this.props.signOffCommits,
10621061
})
10631062
},
1063+
})
1064+
}
1065+
1066+
items.push({
1067+
type: 'checkbox',
1068+
checked: this.props.signOffCommits,
1069+
label: __DARWIN__
1070+
? 'Add Signed-off-by Trailer'
1071+
: 'Add Signed-off-by trailer',
1072+
action: () => {
1073+
this.props.onUpdateCommitOptions(this.props.repository, {
1074+
skipCommitHooks: this.props.skipCommitHooks,
1075+
signOffCommits: !this.props.signOffCommits,
1076+
})
10641077
},
1065-
{
1066-
type: 'checkbox',
1067-
checked: this.props.signOffCommits,
1068-
label: __DARWIN__
1069-
? 'Add Signed-off-by Trailer'
1070-
: 'Add Signed-off-by trailer',
1071-
action: () => {
1072-
this.props.onUpdateCommitOptions(this.props.repository, {
1073-
skipCommitHooks: this.props.skipCommitHooks,
1074-
signOffCommits: !this.props.signOffCommits,
1075-
})
1076-
},
1077-
},
1078-
])
1078+
})
1079+
1080+
showContextualMenu(items)
10791081
}
10801082

10811083
private renderCoAuthorToggleButton() {
@@ -1166,26 +1168,7 @@ export class CommitMessage extends React.Component<
11661168
)
11671169
}
11681170

1169-
private get isCommitOptionsButtonEnabled() {
1170-
return enableHooksEnvironment()
1171-
}
1172-
1173-
/**
1174-
* Whether or not there's anything to render in the action bar
1175-
*/
1176-
private get isActionBarEnabled() {
1177-
return (
1178-
this.isCoAuthorInputEnabled ||
1179-
this.isCopilotButtonEnabled ||
1180-
this.isCommitOptionsButtonEnabled
1181-
)
1182-
}
1183-
11841171
private renderActionBar() {
1185-
if (!this.isActionBarEnabled) {
1186-
return null
1187-
}
1188-
11891172
const { isCommitting, isGeneratingCommitMessage } = this.props
11901173

11911174
const className = classNames('action-bar', {
@@ -1681,7 +1664,7 @@ export class CommitMessage extends React.Component<
16811664

16821665
public render() {
16831666
const className = classNames('commit-message-component', {
1684-
'with-action-bar': this.isActionBarEnabled,
1667+
'with-action-bar': true,
16851668
'with-co-authors': this.isCoAuthorInputVisible,
16861669
})
16871670

0 commit comments

Comments
 (0)