From e782f45d6e00456064502a0ace8de63f27929bf7 Mon Sep 17 00:00:00 2001 From: Ryan Stillings Date: Mon, 11 Sep 2023 18:34:26 -0400 Subject: [PATCH] fix showCommitLengthWarning property access --- app/src/ui/app.tsx | 2 ++ .../autocompletion/autocompleting-text-input.tsx | 2 ++ app/src/ui/changes/changes-list.tsx | 7 +++++++ app/src/ui/changes/commit-message.tsx | 15 ++++++++------- app/src/ui/changes/sidebar.tsx | 3 +++ .../ui/commit-message/commit-message-dialog.tsx | 9 +++++++++ app/src/ui/repository.tsx | 2 ++ 7 files changed, 33 insertions(+), 7 deletions(-) diff --git a/app/src/ui/app.tsx b/app/src/ui/app.tsx index 57035be214..6ac81a7b2b 100644 --- a/app/src/ui/app.tsx +++ b/app/src/ui/app.tsx @@ -2173,6 +2173,7 @@ export class App extends React.Component { commitAuthor={repositoryState.commitAuthor} commitMessage={popup.commitMessage} commitSpellcheckEnabled={this.state.commitSpellcheckEnabled} + showCommitLengthWarning={this.state.showCommitLengthWarning} dialogButtonText={popup.dialogButtonText} dialogTitle={popup.dialogTitle} dispatcher={this.props.dispatcher} @@ -3268,6 +3269,7 @@ export class App extends React.Component { isShowingFoldout={this.state.currentFoldout !== null} aheadBehindStore={this.props.aheadBehindStore} commitSpellcheckEnabled={this.state.commitSpellcheckEnabled} + showCommitLengthWarning={this.state.showCommitLengthWarning} onCherryPick={this.startCherryPickWithoutBranch} pullRequestSuggestedNextAction={state.pullRequestSuggestedNextAction} /> diff --git a/app/src/ui/autocompletion/autocompleting-text-input.tsx b/app/src/ui/autocompletion/autocompleting-text-input.tsx index 2fc0569fe8..e5616d4cd5 100644 --- a/app/src/ui/autocompletion/autocompleting-text-input.tsx +++ b/app/src/ui/autocompletion/autocompleting-text-input.tsx @@ -51,6 +51,8 @@ interface IAutocompletingTextInputProps { /** Indicates if input field applies spellcheck */ readonly spellcheck?: boolean + readonly showCommitLengthWarning?: boolean + /** Indicates if it should always try to autocomplete. Optional (defaults to false) */ readonly alwaysAutocomplete?: boolean diff --git a/app/src/ui/changes/changes-list.tsx b/app/src/ui/changes/changes-list.tsx index a6fd200a8c..044152f75b 100644 --- a/app/src/ui/changes/changes-list.tsx +++ b/app/src/ui/changes/changes-list.tsx @@ -219,6 +219,8 @@ interface IChangesListProps { readonly shouldNudgeToCommit: boolean readonly commitSpellcheckEnabled: boolean + + readonly showCommitLengthWarning: boolean } interface IChangesState { @@ -818,6 +820,7 @@ export class ChangesList extends React.Component< showNoWriteAccess={fileCount > 0 && !hasWritePermissionForRepository} shouldNudge={this.props.shouldNudgeToCommit} commitSpellcheckEnabled={this.props.commitSpellcheckEnabled} + showCommitLengthWarning={this.props.showCommitLengthWarning} onCoAuthorsUpdated={this.onCoAuthorsUpdated} onShowCoAuthoredByChanged={this.onShowCoAuthoredByChanged} onConfirmCommitWithUnknownCoAuthors={ @@ -829,6 +832,7 @@ export class ChangesList extends React.Component< onShowPopup={this.onShowPopup} onShowFoldout={this.onShowFoldout} onCommitSpellcheckEnabledChanged={this.onCommitSpellcheckEnabledChanged} + onShowCommitLengthWarningChanged={this.onShowCommitLengthWarningChanged} onStopAmending={this.onStopAmending} onShowCreateForkDialog={this.onShowCreateForkDialog} /> @@ -866,6 +870,9 @@ export class ChangesList extends React.Component< private onCommitSpellcheckEnabledChanged = (enabled: boolean) => this.props.dispatcher.setCommitSpellcheckEnabled(enabled) + private onShowCommitLengthWarningChanged = (enabled: boolean) => + this.props.dispatcher.setShowCommitLengthWarning(enabled) + private onStopAmending = () => this.props.dispatcher.stopAmendingRepository(this.props.repository) diff --git a/app/src/ui/changes/commit-message.tsx b/app/src/ui/changes/commit-message.tsx index 5dcc8b377e..28f4d40d60 100644 --- a/app/src/ui/changes/commit-message.tsx +++ b/app/src/ui/changes/commit-message.tsx @@ -117,6 +117,9 @@ interface ICommitMessageProps { readonly commitSpellcheckEnabled: boolean + readonly showCommitLengthWarning: boolean + + /** Optional text to override default commit button text */ readonly commitButtonText?: string @@ -153,6 +156,7 @@ interface ICommitMessageProps { readonly onShowPopup: (popup: Popup) => void readonly onShowFoldout: (foldout: Foldout) => void readonly onCommitSpellcheckEnabledChanged: (enabled: boolean) => void + readonly onShowCommitLengthWarningChanged: (enabled: boolean) => void readonly onStopAmending: () => void readonly onShowCreateForkDialog: () => void } @@ -179,8 +183,6 @@ interface ICommitMessageState { readonly isRuleFailurePopoverOpen: boolean - readonly showCommitLengthWarning: boolean - readonly repoRuleCommitMessageFailures: RepoRulesMetadataFailures readonly repoRuleCommitAuthorFailures: RepoRulesMetadataFailures readonly repoRuleBranchNameFailures: RepoRulesMetadataFailures @@ -237,9 +239,6 @@ export class CommitMessage extends React.Component< isCommittingStatusMessage: '', repoRulesEnabled: false, isRuleFailurePopoverOpen: false, - // TODO: do a proper retrieval rather than pinging localStorage (use AppState?) - // (current solution requires a tab switch to hot reload) - showCommitLengthWarning: localStorage.getItem("showCommitLengthWarning") === "1", repoRuleCommitMessageFailures: new RepoRulesMetadataFailures(), repoRuleCommitAuthorFailures: new RepoRulesMetadataFailures(), repoRuleBranchNameFailures: new RepoRulesMetadataFailures(), @@ -1349,7 +1348,7 @@ export class CommitMessage extends React.Component< this.state.repoRuleCommitMessageFailures.status !== 'pass' const showSummaryLengthHint = - this.state.showCommitLengthWarning && + this.props.showCommitLengthWarning && !showRepoRuleCommitMessageFailureHint && this.state.summary.length > IdealSummaryLength @@ -1365,7 +1364,7 @@ export class CommitMessage extends React.Component< ? this.COMMIT_MSG_ERROR_BTN_ID : undefined - const { placeholder, isCommitting, commitSpellcheckEnabled } = this.props + const { placeholder, isCommitting, commitSpellcheckEnabled, showCommitLengthWarning } = this.props return ( // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions @@ -1394,6 +1393,7 @@ export class CommitMessage extends React.Component< onContextMenu={this.onAutocompletingInputContextMenu} readOnly={isCommitting === true} spellcheck={commitSpellcheckEnabled} + showCommitLengthWarning={showCommitLengthWarning} /> {showRepoRuleCommitMessageFailureHint && this.renderRepoRuleCommitMessageFailureHint()} @@ -1421,6 +1421,7 @@ export class CommitMessage extends React.Component< onContextMenu={this.onAutocompletingInputContextMenu} readOnly={isCommitting === true} spellcheck={commitSpellcheckEnabled} + showCommitLengthWarning={showCommitLengthWarning} /> {this.renderActionBar()} diff --git a/app/src/ui/changes/sidebar.tsx b/app/src/ui/changes/sidebar.tsx index 03c2687fd9..586de02cd2 100644 --- a/app/src/ui/changes/sidebar.tsx +++ b/app/src/ui/changes/sidebar.tsx @@ -78,6 +78,8 @@ interface IChangesSidebarProps { readonly shouldNudgeToCommit: boolean readonly commitSpellcheckEnabled: boolean + + readonly showCommitLengthWarning: boolean } export class ChangesSidebar extends React.Component { @@ -432,6 +434,7 @@ export class ChangesSidebar extends React.Component { currentBranchProtected={currentBranchProtected} shouldNudgeToCommit={this.props.shouldNudgeToCommit} commitSpellcheckEnabled={this.props.commitSpellcheckEnabled} + showCommitLengthWarning={this.props.showCommitLengthWarning} currentRepoRulesInfo={currentRepoRulesInfo} aheadBehind={this.props.aheadBehind} /> diff --git a/app/src/ui/commit-message/commit-message-dialog.tsx b/app/src/ui/commit-message/commit-message-dialog.tsx index ee9b77431d..657382dc27 100644 --- a/app/src/ui/commit-message/commit-message-dialog.tsx +++ b/app/src/ui/commit-message/commit-message-dialog.tsx @@ -54,6 +54,8 @@ interface ICommitMessageDialogProps { */ readonly commitSpellcheckEnabled: boolean + readonly showCommitLengthWarning: boolean + /** Text for the ok button */ readonly dialogButtonText: string @@ -140,6 +142,7 @@ export class CommitMessageDialog extends React.Component< aheadBehind={this.props.aheadBehind} showNoWriteAccess={this.props.showNoWriteAccess} commitSpellcheckEnabled={this.props.commitSpellcheckEnabled} + showCommitLengthWarning={this.props.showCommitLengthWarning} onCoAuthorsUpdated={this.onCoAuthorsUpdated} onShowCoAuthoredByChanged={this.onShowCoAuthorsChanged} onConfirmCommitWithUnknownCoAuthors={ @@ -155,6 +158,9 @@ export class CommitMessageDialog extends React.Component< onCommitSpellcheckEnabledChanged={ this.onCommitSpellcheckEnabledChanged } + onShowCommitLengthWarningChanged={ + this.onShowCommitLengthWarningChanged + } repositoryAccount={this.props.repositoryAccount} onStopAmending={this.onStopAmending} onShowCreateForkDialog={this.onShowCreateForkDialog} @@ -187,6 +193,9 @@ export class CommitMessageDialog extends React.Component< private onCommitSpellcheckEnabledChanged = (enabled: boolean) => this.props.dispatcher.setCommitSpellcheckEnabled(enabled) + private onShowCommitLengthWarningChanged = (enabled: boolean) => + this.props.dispatcher.setShowCommitLengthWarning(enabled) + private onStopAmending = () => this.props.dispatcher.stopAmendingRepository(this.props.repository) diff --git a/app/src/ui/repository.tsx b/app/src/ui/repository.tsx index 01e75ded95..ea25eaabd6 100644 --- a/app/src/ui/repository.tsx +++ b/app/src/ui/repository.tsx @@ -54,6 +54,7 @@ interface IRepositoryViewProps { readonly askForConfirmationOnCheckoutCommit: boolean readonly focusCommitMessage: boolean readonly commitSpellcheckEnabled: boolean + readonly showCommitLengthWarning: boolean readonly accounts: ReadonlyArray /** @@ -250,6 +251,7 @@ export class RepositoryView extends React.Component< this.props.currentTutorialStep === TutorialStep.MakeCommit } commitSpellcheckEnabled={this.props.commitSpellcheckEnabled} + showCommitLengthWarning={this.props.showCommitLengthWarning} /> ) }