Skip to content

Commit 301cd2b

Browse files
committed
Rename CommitGraphViewMode -> CommitHistoryViewMode, change default to "List"
1 parent 428826b commit 301cd2b

2 files changed

Lines changed: 32 additions & 36 deletions

File tree

app/src/lib/stores/commit-graph-state.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,31 @@ const commitGraph_CollapsedBranchGroupsKeyPrefix =
88
'commitGraph-collapsed-branch-groups'
99
const commitGraph_ViewModeKey = 'commitGraph-view-mode'
1010
const commitGraph_DefaultCollapsedBranchGroups = ['origin', 'upstream', 'tags']
11-
const commitGraph_DefaultViewMode: CommitGraphViewModePreference = 'tree'
11+
12+
export enum CommitHistoryViewMode {
13+
List = 'list',
14+
Graph = 'graph',
15+
}
16+
17+
const DEFAULT_COMMIT_GRAPH_VIEW_MODE = CommitHistoryViewMode.List
1218

1319
export const commitGraph_DefaultBranchListWidth = 180
1420
export const commitGraph_BranchListWidthConfigKey =
1521
'commitGraph-branch-list-width'
1622

17-
export type CommitGraphViewModePreference = 'list' | 'tree'
18-
19-
export function commitGraph_getStoredViewMode(): CommitGraphViewModePreference {
23+
export function commitGraph_getStoredViewMode(): CommitHistoryViewMode {
2024
const value = localStorage.getItem(commitGraph_ViewModeKey)
21-
22-
return value === 'list' || value === 'tree'
23-
? value
24-
: commitGraph_DefaultViewMode
25+
switch (value) {
26+
case CommitHistoryViewMode.List:
27+
return CommitHistoryViewMode.List
28+
case CommitHistoryViewMode.Graph:
29+
return CommitHistoryViewMode.Graph
30+
default:
31+
return DEFAULT_COMMIT_GRAPH_VIEW_MODE
32+
}
2533
}
2634

27-
export function commitGraph_setStoredViewMode(
28-
viewMode: CommitGraphViewModePreference
29-
) {
35+
export function commitGraph_setStoredViewMode(viewMode: CommitHistoryViewMode) {
3036
localStorage.setItem(commitGraph_ViewModeKey, viewMode)
3137
}
3238

app/src/ui/history/commit-graph-sidebar.tsx

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ICompareState, IConstrainedValue } from '../../lib/app-state'
55
import {
66
commitGraph_getStoredViewMode,
77
commitGraph_setStoredViewMode,
8+
CommitHistoryViewMode,
89
} from '../../lib/stores/commit-graph-state'
910
import { Repository } from '../../models/repository'
1011
import { Branch, BranchType } from '../../models/branch'
@@ -37,17 +38,6 @@ import {
3738
} from './commit-graph-model'
3839
import { CommitGraphCommitListItem } from './commit-graph-commit-list-item'
3940

40-
enum CommitGraphViewMode {
41-
List = 'list',
42-
Tree = 'tree',
43-
}
44-
45-
function commitGraph_getInitialViewMode() {
46-
return commitGraph_getStoredViewMode() === 'list'
47-
? CommitGraphViewMode.List
48-
: CommitGraphViewMode.Tree
49-
}
50-
5141
type CommitGraphBranchGroup =
5242
| 'local'
5343
| 'origin'
@@ -90,7 +80,7 @@ interface ICommitGraphSidebarProps {
9080
interface ICommitGraphSidebarState {
9181
readonly keyboardReorderData?: KeyboardInsertionData
9282
readonly isSearching: boolean
93-
readonly commitGraphViewMode: CommitGraphViewMode
83+
readonly commitGraphViewMode: CommitHistoryViewMode
9484
readonly commitGraphSelectedBranchRef: string | null
9585
}
9686

@@ -527,7 +517,7 @@ export class CommitGraphSidebar extends React.Component<
527517

528518
this.state = {
529519
isSearching: false,
530-
commitGraphViewMode: commitGraph_getInitialViewMode(),
520+
commitGraphViewMode: commitGraph_getStoredViewMode(),
531521
commitGraphSelectedBranchRef: null,
532522
}
533523
}
@@ -568,7 +558,7 @@ export class CommitGraphSidebar extends React.Component<
568558
{this.commitGraph_renderViewModeSwitch()}
569559
</div>
570560

571-
{this.state.commitGraphViewMode === CommitGraphViewMode.Tree
561+
{this.state.commitGraphViewMode === CommitHistoryViewMode.Graph
572562
? this.commitGraph_renderView()
573563
: this.renderCommitList(false)}
574564
</div>
@@ -582,10 +572,10 @@ export class CommitGraphSidebar extends React.Component<
582572
size="small"
583573
className={classNames('button-group-item', {
584574
selected:
585-
this.state.commitGraphViewMode === CommitGraphViewMode.List,
575+
this.state.commitGraphViewMode === CommitHistoryViewMode.List,
586576
})}
587577
ariaPressed={
588-
this.state.commitGraphViewMode === CommitGraphViewMode.List
578+
this.state.commitGraphViewMode === CommitHistoryViewMode.List
589579
}
590580
ariaLabel="List view"
591581
tooltip="List view"
@@ -597,10 +587,10 @@ export class CommitGraphSidebar extends React.Component<
597587
size="small"
598588
className={classNames('button-group-item', {
599589
selected:
600-
this.state.commitGraphViewMode === CommitGraphViewMode.Tree,
590+
this.state.commitGraphViewMode === CommitHistoryViewMode.Graph,
601591
})}
602592
ariaPressed={
603-
this.state.commitGraphViewMode === CommitGraphViewMode.Tree
593+
this.state.commitGraphViewMode === CommitHistoryViewMode.Graph
604594
}
605595
ariaLabel="Graph view"
606596
tooltip="Graph view"
@@ -1166,24 +1156,24 @@ export class CommitGraphSidebar extends React.Component<
11661156
}
11671157

11681158
private commitGraph_onListModeClicked = () => {
1169-
commitGraph_setStoredViewMode('list')
1170-
this.setState({ commitGraphViewMode: CommitGraphViewMode.List })
1159+
commitGraph_setStoredViewMode(CommitHistoryViewMode.List)
1160+
this.setState({ commitGraphViewMode: CommitHistoryViewMode.List })
11711161
void this.props.dispatcher.setCommitSearchQuery(
11721162
this.props.repository,
11731163
this.props.compareState.commitSearchQuery
11741164
)
11751165
}
11761166

11771167
private commitGraph_onTreeModeClicked = () => {
1178-
commitGraph_setStoredViewMode('tree')
1179-
this.setState({ commitGraphViewMode: CommitGraphViewMode.Tree }, () =>
1168+
commitGraph_setStoredViewMode(CommitHistoryViewMode.Graph)
1169+
this.setState({ commitGraphViewMode: CommitHistoryViewMode.Graph }, () =>
11801170
this.commitGraph_ensureLoaded()
11811171
)
11821172
}
11831173

11841174
private commitGraph_ensureLoaded() {
11851175
if (
1186-
this.state.commitGraphViewMode !== CommitGraphViewMode.Tree ||
1176+
this.state.commitGraphViewMode !== CommitHistoryViewMode.Graph ||
11871177
this.commitGraph_getHiddenBranchRefs() === null
11881178
) {
11891179
return
@@ -1278,7 +1268,7 @@ export class CommitGraphSidebar extends React.Component<
12781268

12791269
private onScroll = (start: number, end: number) => {
12801270
const commitGraphIsTreeMode =
1281-
this.state.commitGraphViewMode === CommitGraphViewMode.Tree
1271+
this.state.commitGraphViewMode === CommitHistoryViewMode.Graph
12821272
const commits = commitGraphIsTreeMode
12831273
? this.commitGraph_getFilteredCommitSHAs()
12841274
: this.props.compareState.filteredHistoryCommitSHAs
@@ -1324,7 +1314,7 @@ export class CommitGraphSidebar extends React.Component<
13241314
}
13251315

13261316
private onCommitSearchQueryChanged = async (text: string) => {
1327-
if (this.state.commitGraphViewMode === CommitGraphViewMode.Tree) {
1317+
if (this.state.commitGraphViewMode === CommitHistoryViewMode.Graph) {
13281318
this.props.dispatcher.updateCompareForm(this.props.repository, {
13291319
commitSearchQuery: text,
13301320
})

0 commit comments

Comments
 (0)