-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preferences redesign #8813
Preferences redesign #8813
Changes from 25 commits
27532d8
b9be775
feddfad
be54b99
222b8b8
a397784
54eb1c9
74a6408
fe54a35
b89ecbd
a9b202b
a83f84a
e37b78b
77af3a4
ca3d5ba
211f5a0
14fd997
13e7516
ff7cd2c
c97f005
3c72edd
76afcf6
eeb0589
bc7c047
a60d295
4c5ac1d
a5454b0
d7bed4e
4cd70f2
7e50c7d
5bbc79d
3acdd9a
48d3a65
1a56994
77354a6
fe21309
f2aeb50
09e954c
8cee164
6d70d14
564be7f
79dc0d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,6 +234,8 @@ import { | |
import { | ||
UncommittedChangesStrategy, | ||
UncommittedChangesStrategyKind, | ||
uncommittedChangesStrategyKindDefault, | ||
getUncommittedChangesStrategy, | ||
askToStash, | ||
} from '../../models/uncommitted-changes-strategy' | ||
import { IStashEntry, StashedChangesLoadStates } from '../../models/stash-entry' | ||
|
@@ -281,6 +283,9 @@ const confirmRepoRemovalKey: string = 'confirmRepoRemoval' | |
const confirmDiscardChangesKey: string = 'confirmDiscardChanges' | ||
const confirmForcePushKey: string = 'confirmForcePush' | ||
|
||
const uncommittedChangesStrategyKindKey: string = | ||
'uncommittedChangesStrategyKind' | ||
|
||
const externalEditorKey: string = 'externalEditor' | ||
|
||
const imageDiffTypeDefault = ImageDiffType.TwoUp | ||
|
@@ -364,6 +369,8 @@ export class AppStore extends TypedBaseStore<IAppState> { | |
private imageDiffType: ImageDiffType = imageDiffTypeDefault | ||
private hideWhitespaceInDiff: boolean = hideWhitespaceInDiffDefault | ||
|
||
private uncommittedChangesStrategyKind: UncommittedChangesStrategyKind = uncommittedChangesStrategyKindDefault | ||
|
||
private selectedExternalEditor: ExternalEditor | null = null | ||
|
||
private resolvedExternalEditor: ExternalEditor | null = null | ||
|
@@ -705,6 +712,7 @@ export class AppStore extends TypedBaseStore<IAppState> { | |
.askForConfirmationOnRepositoryRemoval, | ||
askForConfirmationOnDiscardChanges: this.confirmDiscardChanges, | ||
askForConfirmationOnForcePush: this.askForConfirmationOnForcePush, | ||
uncommittedChangesStrategyKind: this.uncommittedChangesStrategyKind, | ||
selectedExternalEditor: this.selectedExternalEditor, | ||
imageDiffType: this.imageDiffType, | ||
hideWhitespaceInDiff: this.hideWhitespaceInDiff, | ||
|
@@ -1793,6 +1801,12 @@ export class AppStore extends TypedBaseStore<IAppState> { | |
askForConfirmationOnForcePushDefault | ||
) | ||
|
||
const strategy = localStorage.getItem( | ||
uncommittedChangesStrategyKindKey | ||
) as UncommittedChangesStrategyKind | ||
this.uncommittedChangesStrategyKind = | ||
strategy || uncommittedChangesStrategyKindDefault | ||
|
||
this.updateSelectedExternalEditor( | ||
await this.lookupSelectedExternalEditor() | ||
).catch(e => log.error('Failed resolving current editor at startup', e)) | ||
|
@@ -2968,7 +2982,9 @@ export class AppStore extends TypedBaseStore<IAppState> { | |
repository: Repository, | ||
name: string, | ||
startPoint: string | null, | ||
uncommittedChangesStrategy: UncommittedChangesStrategy = askToStash | ||
uncommittedChangesStrategy: UncommittedChangesStrategy = getUncommittedChangesStrategy( | ||
this.uncommittedChangesStrategyKind | ||
) | ||
): Promise<Repository> { | ||
const gitStore = this.gitStoreCache.get(repository) | ||
const branch = await gitStore.performFailableOperation(() => | ||
|
@@ -3038,7 +3054,9 @@ export class AppStore extends TypedBaseStore<IAppState> { | |
public async _checkoutBranch( | ||
repository: Repository, | ||
branch: Branch | string, | ||
uncommittedChangesStrategy: UncommittedChangesStrategy = askToStash | ||
uncommittedChangesStrategy: UncommittedChangesStrategy = getUncommittedChangesStrategy( | ||
this.uncommittedChangesStrategyKind | ||
) | ||
): Promise<Repository> { | ||
const gitStore = this.gitStoreCache.get(repository) | ||
const kind = 'checkout' | ||
|
@@ -3058,20 +3076,22 @@ export class AppStore extends TypedBaseStore<IAppState> { | |
let stashToPop: IStashEntry | null = null | ||
if (enableStashing()) { | ||
const hasChanges = changesState.workingDirectory.files.length > 0 | ||
if (hasChanges && uncommittedChangesStrategy.kind === askToStash.kind) { | ||
this._showPopup({ | ||
type: PopupType.StashAndSwitchBranch, | ||
branchToCheckout: foundBranch, | ||
if (hasChanges) { | ||
if (uncommittedChangesStrategy.kind === askToStash.kind) { | ||
this._showPopup({ | ||
type: PopupType.StashAndSwitchBranch, | ||
branchToCheckout: foundBranch, | ||
repository, | ||
}) | ||
return repository | ||
} | ||
Comment on lines
+3056
to
+3064
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😋 |
||
|
||
stashToPop = await this.stashToPopAfterBranchCheckout( | ||
repository, | ||
}) | ||
return repository | ||
foundBranch, | ||
uncommittedChangesStrategy | ||
) | ||
} | ||
|
||
stashToPop = await this.stashToPopAfterBranchCheckout( | ||
repository, | ||
foundBranch, | ||
uncommittedChangesStrategy | ||
) | ||
} | ||
|
||
const checkoutSucceeded = | ||
|
@@ -3161,7 +3181,9 @@ export class AppStore extends TypedBaseStore<IAppState> { | |
private async stashToPopAfterBranchCheckout( | ||
repository: Repository, | ||
branch: Branch, | ||
uncommittedChangesStrategy: UncommittedChangesStrategy = askToStash | ||
uncommittedChangesStrategy: UncommittedChangesStrategy = getUncommittedChangesStrategy( | ||
this.uncommittedChangesStrategyKind | ||
) | ||
): Promise<IStashEntry | null> { | ||
const { | ||
changesState, | ||
|
@@ -4446,6 +4468,20 @@ export class AppStore extends TypedBaseStore<IAppState> { | |
return Promise.resolve() | ||
} | ||
|
||
public _setUncommittedChangesStrategyKindSetting( | ||
value: UncommittedChangesStrategyKind | ||
): Promise<void> { | ||
this.uncommittedChangesStrategyKind = value | ||
|
||
localStorage.setItem(uncommittedChangesStrategyKindKey, value) | ||
|
||
// Do we need to do this? | ||
// this.updateMenuLabelsForSelectedRepository() | ||
|
||
this.emitUpdate() | ||
return Promise.resolve() | ||
} | ||
|
||
public _setExternalEditor(selectedEditor: ExternalEditor) { | ||
const promise = this.updateSelectedExternalEditor(selectedEditor) | ||
localStorage.setItem(externalEditorKey, selectedEditor) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
export enum PreferencesTab { | ||
Accounts = 0, | ||
Git = 1, | ||
Appearance = 2, | ||
Advanced = 3, | ||
Integrations = 1, | ||
Git = 2, | ||
Appearance = 3, | ||
Advanced = 4, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import { IStashEntry } from './stash-entry' | ||
import { assertNever } from '../lib/fatal-error' | ||
|
||
export enum UncommittedChangesStrategyKind { | ||
AskForConfirmation = 'AskForConfirmation', | ||
StashOnCurrentBranch = 'StashOnCurrentBranch', | ||
MoveToNewBranch = 'MoveToNewBranch', | ||
} | ||
|
||
export const uncommittedChangesStrategyKindDefault: UncommittedChangesStrategyKind = | ||
UncommittedChangesStrategyKind.AskForConfirmation | ||
|
||
export type UncommittedChangesStrategy = | ||
| { kind: UncommittedChangesStrategyKind.AskForConfirmation } | ||
| { kind: UncommittedChangesStrategyKind.StashOnCurrentBranch } | ||
|
@@ -20,3 +24,25 @@ export const askToStash: UncommittedChangesStrategy = { | |
export const stashOnCurrentBranch: UncommittedChangesStrategy = { | ||
kind: UncommittedChangesStrategyKind.StashOnCurrentBranch, | ||
} | ||
export const moveToNewBranch: UncommittedChangesStrategy = { | ||
kind: UncommittedChangesStrategyKind.MoveToNewBranch, | ||
transientStashEntry: null, | ||
} | ||
|
||
export function getUncommittedChangesStrategy( | ||
kind: UncommittedChangesStrategyKind | ||
) { | ||
switch (kind) { | ||
case UncommittedChangesStrategyKind.AskForConfirmation: | ||
return askToStash | ||
case UncommittedChangesStrategyKind.MoveToNewBranch: | ||
return moveToNewBranch | ||
case UncommittedChangesStrategyKind.StashOnCurrentBranch: | ||
return stashOnCurrentBranch | ||
default: | ||
return assertNever( | ||
kind, | ||
`Unknown UncommittedChangesStrategyKind: ${kind}` | ||
) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have some concerns about this function, but I think the core of my concern is that it took me a while to figure out what it was doing. Perhaps documenting this to clarify that its primary purpose is to map a kind to an actual It feels to me like there's a simpler version of this overall approach, but I'm not sure what it is yet...Is the main reason this exists so that we can store an |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -25,7 +25,7 @@ import { startTimer } from '../lib/timing' | |||||
import { | ||||||
UncommittedChangesStrategyKind, | ||||||
UncommittedChangesStrategy, | ||||||
askToStash, | ||||||
stashOnCurrentBranch, | ||||||
} from '../../models/uncommitted-changes-strategy' | ||||||
|
||||||
interface IBranchesContainerProps { | ||||||
|
@@ -45,6 +45,10 @@ interface IBranchesContainerProps { | |||||
readonly isLoadingPullRequests: boolean | ||||||
|
||||||
readonly currentBranchProtected: boolean | ||||||
|
||||||
readonly selectedUncommittedChangesStrategy: UncommittedChangesStrategy | ||||||
|
||||||
readonly hasChangesAndStash: boolean | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. non-blocking idea for a maybe more legible name:
Suggested change
|
||||||
} | ||||||
|
||||||
interface IBranchesContainerState { | ||||||
|
@@ -241,9 +245,29 @@ export class BranchesContainer extends React.Component< | |||||
private onBranchItemClick = (branch: Branch) => { | ||||||
this.props.dispatcher.closeFoldout(FoldoutType.Branch) | ||||||
|
||||||
const { currentBranch, repository, currentBranchProtected } = this.props | ||||||
const { | ||||||
currentBranch, | ||||||
repository, | ||||||
currentBranchProtected, | ||||||
dispatcher, | ||||||
hasChangesAndStash, | ||||||
} = this.props | ||||||
|
||||||
if (currentBranch == null || currentBranch.name !== branch.name) { | ||||||
if ( | ||||||
!currentBranchProtected && | ||||||
this.props.selectedUncommittedChangesStrategy.kind === | ||||||
stashOnCurrentBranch.kind && | ||||||
hasChangesAndStash | ||||||
) { | ||||||
dispatcher.showPopup({ | ||||||
type: PopupType.ConfirmOverwriteStash, | ||||||
repository, | ||||||
branchToCheckout: branch, | ||||||
}) | ||||||
return | ||||||
} | ||||||
|
||||||
const timer = startTimer('checkout branch from list', repository) | ||||||
|
||||||
// Never prompt to stash changes if someone is switching away from a protected branch | ||||||
|
@@ -252,7 +276,7 @@ export class BranchesContainer extends React.Component< | |||||
kind: UncommittedChangesStrategyKind.MoveToNewBranch, | ||||||
transientStashEntry: null, | ||||||
} | ||||||
: askToStash | ||||||
: this.props.selectedUncommittedChangesStrategy | ||||||
|
||||||
this.props.dispatcher | ||||||
.checkoutBranch(repository, branch, strategy) | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd really like to avoid using
as
here, though I'm not sure of a good alternative approach yet.localStorage.getItem
can returnundefined
if the given key doesn't exist, and this implementation tells the compiler that 'undefined' is a validUncommittedChangesStrategyKind
, which will result in runtime errors.