Skip to content

Commit 81ba6dd

Browse files
committed
Allow hiding the "Compare" tab
Closes #98
1 parent 9894a1e commit 81ba6dd

7 files changed

Lines changed: 90 additions & 14 deletions

File tree

app/src/lib/app-state.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ export interface IAppState {
320320
/** Whether or not the worktrees dropdown should be shown in the toolbar */
321321
readonly showWorktrees: boolean
322322

323+
/** Whether or not the Compare tab should be shown in the repository view */
324+
readonly showCompareTab: boolean
325+
323326
/**
324327
* A map keyed on a user account (GitHub.com or GitHub Enterprise)
325328
* containing an object with repositories that the authenticated

app/src/lib/stores/app-store.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ const shellKey = 'shell'
467467

468468
const showRecentRepositoriesKey = 'show-recent-repositories'
469469
const showWorktreesKey = 'show-worktrees'
470+
const showCompareTabKey = 'show-compare-tab'
471+
const showCompareTabDefault = true
470472
const repositoryIndicatorsEnabledKey = 'enable-repository-indicators'
471473

472474
// background fetching should occur hourly when Desktop is active, but this
@@ -634,6 +636,7 @@ export class AppStore extends TypedBaseStore<IAppState> {
634636
private titleBarStyle: TitleBarStyle = 'native'
635637
private showRecentRepositories: boolean = true
636638
private showWorktrees: boolean = false
639+
private showCompareTab: boolean = showCompareTabDefault
637640
private hideWindowOnQuit: boolean = __DARWIN__
638641

639642
private useWindowsOpenSSH: boolean = false
@@ -751,6 +754,7 @@ export class AppStore extends TypedBaseStore<IAppState> {
751754

752755
this.showRecentRepositories = getBoolean(showRecentRepositoriesKey) ?? true
753756
this.showWorktrees = getBoolean(showWorktreesKey) ?? false
757+
this.showCompareTab = getBoolean(showCompareTabKey, showCompareTabDefault)
754758

755759
this.repositoryIndicatorUpdater = new RepositoryIndicatorUpdater(
756760
this.getRepositoriesForIndicatorRefresh,
@@ -1203,6 +1207,7 @@ export class AppStore extends TypedBaseStore<IAppState> {
12031207
titleBarStyle: this.titleBarStyle,
12041208
showRecentRepositories: this.showRecentRepositories,
12051209
showWorktrees: this.showWorktrees,
1210+
showCompareTab: this.showCompareTab,
12061211
apiRepositories: this.apiRepositoriesStore.getState(),
12071212
useWindowsOpenSSH: this.useWindowsOpenSSH,
12081213
showCommitLengthWarning: this.showCommitLengthWarning,
@@ -4177,6 +4182,25 @@ export class AppStore extends TypedBaseStore<IAppState> {
41774182
this.emitUpdate()
41784183
}
41794184

4185+
public _setShowCompareTab(showCompareTab: boolean) {
4186+
if (this.showCompareTab === showCompareTab) {
4187+
return
4188+
}
4189+
setBoolean(showCompareTabKey, showCompareTab)
4190+
this.showCompareTab = showCompareTab
4191+
if (!showCompareTab) {
4192+
for (const repository of this.repositories) {
4193+
const state = this.repositoryStateCache.get(repository)
4194+
if (state.selectedSection === RepositorySectionTab.Compare) {
4195+
this.repositoryStateCache.update(repository, () => ({
4196+
selectedSection: RepositorySectionTab.History,
4197+
}))
4198+
}
4199+
}
4200+
}
4201+
this.emitUpdate()
4202+
}
4203+
41804204
public _setCommitSpellcheckEnabled(commitSpellcheckEnabled: boolean) {
41814205
if (this.commitSpellcheckEnabled === commitSpellcheckEnabled) {
41824206
return

app/src/ui/app.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,6 +1680,7 @@ export class App extends React.Component<IAppProps, IAppState> {
16801680
titleBarStyle={this.state.titleBarStyle}
16811681
showRecentRepositories={this.state.showRecentRepositories}
16821682
showWorktrees={this.state.showWorktrees}
1683+
showCompareTab={this.state.showCompareTab}
16831684
repositoryIndicatorsEnabled={this.state.repositoryIndicatorsEnabled}
16841685
hideWindowOnQuit={this.state.hideWindowOnQuit}
16851686
onEditGlobalGitConfig={this.editGlobalGitConfig}
@@ -3717,6 +3718,7 @@ export class App extends React.Component<IAppProps, IAppState> {
37173718
onCherryPick={this.startCherryPickWithoutBranch}
37183719
pullRequestSuggestedNextAction={state.pullRequestSuggestedNextAction}
37193720
showChangesFilter={state.showChangesFilter}
3721+
showCompareTab={this.state.showCompareTab}
37203722
shouldShowGenerateCommitMessageCallOut={
37213723
!this.state.commitMessageGenerationButtonClicked
37223724
}

app/src/ui/dispatcher/dispatcher.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2928,6 +2928,10 @@ export class Dispatcher {
29282928
this.appStore._setShowWorktrees(showWorktrees)
29292929
}
29302930

2931+
public setShowCompareTab(showCompareTab: boolean) {
2932+
this.appStore._setShowCompareTab(showCompareTab)
2933+
}
2934+
29312935
public setHideWindowOnQuit(hideWindowOnQuit: boolean) {
29322936
this.appStore._setHideWindowOnQuit(hideWindowOnQuit)
29332937
}

app/src/ui/preferences/appearance.tsx

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ interface IAppearanceProps {
2929
readonly onShowRecentRepositoriesChanged: (show: boolean) => void
3030
readonly showWorktrees: boolean
3131
readonly onShowWorktreesChanged: (show: boolean) => void
32+
readonly showCompareTab: boolean
33+
readonly onShowCompareTabChanged: (show: boolean) => void
3234
readonly showBranchNameInRepoList: ShowBranchNameInRepoListSetting
3335
readonly onShowBranchNameInRepoListChanged: (
3436
value: ShowBranchNameInRepoListSetting
@@ -45,6 +47,7 @@ interface IAppearanceState {
4547
readonly titleBarStyle: TitleBarStyle
4648
readonly showRecentRepositories: boolean
4749
readonly showWorktrees: boolean
50+
readonly showCompareTab: boolean
4851
}
4952

5053
function getTitleBarStyleDescription(titleBarStyle: TitleBarStyle): string {
@@ -73,6 +76,7 @@ export class Appearance extends React.Component<
7376
titleBarStyle: props.titleBarStyle,
7477
showRecentRepositories: props.showRecentRepositories,
7578
showWorktrees: props.showWorktrees,
79+
showCompareTab: props.showCompareTab,
7680
}
7781

7882
if (!usePropTheme) {
@@ -124,6 +128,14 @@ export class Appearance extends React.Component<
124128
this.props.onShowWorktreesChanged(show)
125129
}
126130

131+
private onShowCompareTabChanged = (
132+
event: React.FormEvent<HTMLInputElement>
133+
) => {
134+
const show = event.currentTarget.checked
135+
this.setState({ showCompareTab: show })
136+
this.props.onShowCompareTabChanged(show)
137+
}
138+
127139
private onSelectedTabSizeChanged = (
128140
event: React.FormEvent<HTMLSelectElement>
129141
) => {
@@ -340,17 +352,30 @@ export class Appearance extends React.Component<
340352

341353
private renderWorktreeVisibility() {
342354
return (
343-
<div className="advanced-section">
344-
<h2 id="worktree-heading">{'Worktrees'}</h2>
345-
346-
<Checkbox
347-
label="Show worktrees dropdown in toolbar"
348-
value={
349-
this.state.showWorktrees ? CheckboxValue.On : CheckboxValue.Off
350-
}
351-
onChange={this.onShowWorktreesChanged}
352-
/>
353-
</div>
355+
<>
356+
<div className="advanced-section">
357+
<h2 id="worktree-heading">{'Worktrees'}</h2>
358+
359+
<Checkbox
360+
label="Show worktrees dropdown in toolbar"
361+
value={
362+
this.state.showWorktrees ? CheckboxValue.On : CheckboxValue.Off
363+
}
364+
onChange={this.onShowWorktreesChanged}
365+
/>
366+
</div>
367+
<div className="advanced-section">
368+
<h2>{'Commit list'}</h2>
369+
370+
<Checkbox
371+
label="Show Compare tab"
372+
value={
373+
this.state.showCompareTab ? CheckboxValue.On : CheckboxValue.Off
374+
}
375+
onChange={this.onShowCompareTabChanged}
376+
/>
377+
</div>
378+
</>
354379
)
355380
}
356381

app/src/ui/preferences/preferences.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ interface IPreferencesProps {
9595
readonly titleBarStyle: TitleBarStyle
9696
readonly showRecentRepositories: boolean
9797
readonly showWorktrees: boolean
98+
readonly showCompareTab: boolean
9899
readonly repositoryIndicatorsEnabled: boolean
99100
readonly showBranchNameInRepoList: ShowBranchNameInRepoListSetting
100101
readonly branchSortOrder: BranchSortOrder
@@ -141,6 +142,7 @@ interface IPreferencesState {
141142
readonly titleBarStyle: TitleBarStyle
142143
readonly showRecentRepositories: boolean
143144
readonly showWorktrees: boolean
145+
readonly showCompareTab: boolean
144146
/**
145147
* If unable to save Git configuration values (name, email)
146148
* due to an existing configuration lock file this property
@@ -227,6 +229,7 @@ export class Preferences extends React.Component<
227229
titleBarStyle: this.props.titleBarStyle,
228230
showRecentRepositories: this.props.showRecentRepositories,
229231
showWorktrees: this.props.showWorktrees,
232+
showCompareTab: this.props.showCompareTab,
230233
repositoryIndicatorsEnabled: this.props.repositoryIndicatorsEnabled,
231234
showBranchNameInRepoList: this.props.showBranchNameInRepoList,
232235
branchSortOrder: this.props.branchSortOrder,
@@ -564,6 +567,8 @@ export class Preferences extends React.Component<
564567
}
565568
showWorktrees={this.state.showWorktrees}
566569
onShowWorktreesChanged={this.onShowWorktreesChanged}
570+
showCompareTab={this.state.showCompareTab}
571+
onShowCompareTabChanged={this.onShowCompareTabChanged}
567572
showBranchNameInRepoList={this.state.showBranchNameInRepoList}
568573
onShowBranchNameInRepoListChanged={
569574
this.onShowBranchNameInRepoListChanged
@@ -851,6 +856,10 @@ export class Preferences extends React.Component<
851856
this.setState({ showWorktrees })
852857
}
853858

859+
private onShowCompareTabChanged = (showCompareTab: boolean) => {
860+
this.setState({ showCompareTab })
861+
}
862+
854863
private renderFooter() {
855864
const hasDisabledError = this.state.disallowedCharactersMessage != null
856865

@@ -917,6 +926,10 @@ export class Preferences extends React.Component<
917926
dispatcher.setShowWorktrees(this.state.showWorktrees)
918927
}
919928

929+
if (this.state.showCompareTab !== this.props.showCompareTab) {
930+
dispatcher.setShowCompareTab(this.state.showCompareTab)
931+
}
932+
920933
if (this.state.hideWindowOnQuit !== this.props.hideWindowOnQuit) {
921934
dispatcher.setHideWindowOnQuit(this.state.hideWindowOnQuit)
922935
}

app/src/ui/repository.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ interface IRepositoryViewProps {
125125
/** Whether or not to show the changes filter */
126126
readonly showChangesFilter: boolean
127127

128+
/** Whether or not to show the Compare tab */
129+
readonly showCompareTab: boolean
130+
128131
/**
129132
* Whether there are any hooks in the repository that could be
130133
* skipped during commit with the --no-verify flag
@@ -248,9 +251,11 @@ export class RepositoryView extends React.Component<
248251
<span>History</span>
249252
</div>
250253

251-
<div className="with-indicator" id="compare-tab">
252-
<span>Compare</span>
253-
</div>
254+
{this.props.showCompareTab && (
255+
<div className="with-indicator" id="compare-tab">
256+
<span>Compare</span>
257+
</div>
258+
)}
254259
</TabBar>
255260
)
256261
}

0 commit comments

Comments
 (0)