Skip to content

Commit

Permalink
change render logic to use function call instead of switch statement
Browse files Browse the repository at this point in the history
  • Loading branch information
wadethestealth committed Oct 24, 2019
1 parent 8bd2612 commit a1cb095
Showing 1 changed file with 114 additions and 111 deletions.
225 changes: 114 additions & 111 deletions lib/views/git-tab-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,18 @@ export default class GitTabView extends React.Component {
}

render() {
let type = 'default';
let renderMethod = 'renderNormal';
let isEmpty = false;
let isLoading = false;
if (this.props.repository.isTooLarge()) {
type = 'is-too-large';
renderMethod = 'renderTooLarge';
isEmpty = true;
} else if (this.props.repository.hasDirectory() &&
!isValidWorkdir(this.props.repository.getWorkingDirectoryPath())) {
type = 'unsupported-dir';
renderMethod = 'renderUnsupportedDir';
isEmpty = true;
} else if (this.props.repository.showGitTabInit()) {
type = 'no-repo';
renderMethod = 'renderNoRepo';
isEmpty = true;
} else if (this.props.isLoading || this.props.repository.showGitTabLoading()) {
isLoading = true;
Expand All @@ -110,7 +110,7 @@ export default class GitTabView extends React.Component {
tabIndex="-1"
ref={this.props.refRoot.setter}>
{this.renderHeader()}
{this.renderBody(type)}
{this[renderMethod]()}
</div>
);
}
Expand All @@ -125,115 +125,118 @@ export default class GitTabView extends React.Component {
);
}

renderBody(type) {
switch (type) {
case 'is-too-large':
return (
<div className="github-Git too-many-changes">
<div className="github-Git-LargeIcon icon icon-diff" />
<h1>Too many changes</h1>
<div className="initialize-repo-description">
The repository at <strong>{this.props.workingDirectoryPath}</strong> has too many changed files
to display in Atom. Ensure that you have set up an appropriate <code>.gitignore</code> file.
</div>
renderNormal() {
return (
<Fragment>
<StagingView
ref={this.props.refStagingView.setter}
commands={this.props.commands}
notificationManager={this.props.notificationManager}
workspace={this.props.workspace}
stagedChanges={this.props.stagedChanges}
unstagedChanges={this.props.unstagedChanges}
mergeConflicts={this.props.mergeConflicts}
workingDirectoryPath={this.props.workingDirectoryPath}
resolutionProgress={this.props.resolutionProgress}
openFiles={this.props.openFiles}
discardWorkDirChangesForPaths={this.props.discardWorkDirChangesForPaths}
attemptFileStageOperation={this.props.attemptFileStageOperation}
attemptStageAllOperation={this.props.attemptStageAllOperation}
undoLastDiscard={this.props.undoLastDiscard}
abortMerge={this.props.abortMerge}
resolveAsOurs={this.props.resolveAsOurs}
resolveAsTheirs={this.props.resolveAsTheirs}
lastCommit={this.props.lastCommit}
isLoading={this.props.isLoading}
hasUndoHistory={this.props.hasUndoHistory}
isMerging={this.props.isMerging}
/>
<CommitController
ref={this.refCommitController.setter}
tooltips={this.props.tooltips}
config={this.props.config}
stagedChangesExist={this.props.stagedChanges.length > 0}
mergeConflictsExist={this.props.mergeConflicts.length > 0}
prepareToCommit={this.props.prepareToCommit}
commit={this.props.commit}
abortMerge={this.props.abortMerge}
currentBranch={this.props.currentBranch}
workspace={this.props.workspace}
commands={this.props.commands}
notificationManager={this.props.notificationManager}
grammars={this.props.grammars}
mergeMessage={this.props.mergeMessage}
isMerging={this.props.isMerging}
isLoading={this.props.isLoading}
lastCommit={this.props.lastCommit}
repository={this.props.repository}
userStore={this.props.userStore}
selectedCoAuthors={this.props.selectedCoAuthors}
updateSelectedCoAuthors={this.props.updateSelectedCoAuthors}
/>
<RecentCommitsController
ref={this.refRecentCommitsController.setter}
commands={this.props.commands}
commits={this.props.recentCommits}
isLoading={this.props.isLoading}
undoLastCommit={this.props.undoLastCommit}
workspace={this.props.workspace}
repository={this.props.repository}
/>
</Fragment>
);
}

renderTooLarge() {
return (
<div className="github-Git too-many-changes">
<div className="github-Git-LargeIcon icon icon-diff" />
<h1>Too many changes</h1>
<div className="initialize-repo-description">
The repository at <strong>{this.props.workingDirectoryPath}</strong> has too many changed files
to display in Atom. Ensure that you have set up an appropriate <code>.gitignore</code> file.
</div>
);
case 'unsupported-dir':
return (
<div className="github-Git unsupported-directory">
<div className="github-Git-LargeIcon icon icon-alert" />
<h1>Unsupported directory</h1>
<div className="initialize-repo-description">
Atom does not support managing Git repositories in your home or root directories.
</div>
</div>
);
}

renderUnsupportedDir() {
return (
<div className="github-Git unsupported-directory">
<div className="github-Git-LargeIcon icon icon-alert" />
<h1>Unsupported directory</h1>
<div className="initialize-repo-description">
Atom does not support managing Git repositories in your home or root directories.
</div>
);
case 'no-repo':
return (
<div className="github-Git no-repository">
<div className="github-Git-LargeIcon icon icon-repo" />
<h1>Create Repository</h1>
<div className="initialize-repo-description">
{
this.props.repository.hasDirectory()
?
(
<span>Initialize <strong>{this.props.workingDirectoryPath}</strong> with a
Git repository</span>
)
: <span>Initialize a new project directory with a Git repository</span>
}
</div>
<button
onClick={this.initializeRepo}
disabled={this.props.repository.showGitTabInitInProgress()}
className="btn btn-primary">
{this.props.repository.showGitTabInitInProgress()
? 'Creating repository...' : 'Create repository'}
</button>
</div>
);
}

renderNoRepo() {
return (
<div className="github-Git no-repository">
<div className="github-Git-LargeIcon icon icon-repo" />
<h1>Create Repository</h1>
<div className="initialize-repo-description">
{
this.props.repository.hasDirectory()
?
(
<span>Initialize <strong>{this.props.workingDirectoryPath}</strong> with a
Git repository</span>
)
: <span>Initialize a new project directory with a Git repository</span>
}
</div>
);
default:
return (
<Fragment>
<StagingView
ref={this.props.refStagingView.setter}
commands={this.props.commands}
notificationManager={this.props.notificationManager}
workspace={this.props.workspace}
stagedChanges={this.props.stagedChanges}
unstagedChanges={this.props.unstagedChanges}
mergeConflicts={this.props.mergeConflicts}
workingDirectoryPath={this.props.workingDirectoryPath}
resolutionProgress={this.props.resolutionProgress}
openFiles={this.props.openFiles}
discardWorkDirChangesForPaths={this.props.discardWorkDirChangesForPaths}
attemptFileStageOperation={this.props.attemptFileStageOperation}
attemptStageAllOperation={this.props.attemptStageAllOperation}
undoLastDiscard={this.props.undoLastDiscard}
abortMerge={this.props.abortMerge}
resolveAsOurs={this.props.resolveAsOurs}
resolveAsTheirs={this.props.resolveAsTheirs}
lastCommit={this.props.lastCommit}
isLoading={this.props.isLoading}
hasUndoHistory={this.props.hasUndoHistory}
isMerging={this.props.isMerging}
/>
<CommitController
ref={this.refCommitController.setter}
tooltips={this.props.tooltips}
config={this.props.config}
stagedChangesExist={this.props.stagedChanges.length > 0}
mergeConflictsExist={this.props.mergeConflicts.length > 0}
prepareToCommit={this.props.prepareToCommit}
commit={this.props.commit}
abortMerge={this.props.abortMerge}
currentBranch={this.props.currentBranch}
workspace={this.props.workspace}
commands={this.props.commands}
notificationManager={this.props.notificationManager}
grammars={this.props.grammars}
mergeMessage={this.props.mergeMessage}
isMerging={this.props.isMerging}
isLoading={this.props.isLoading}
lastCommit={this.props.lastCommit}
repository={this.props.repository}
userStore={this.props.userStore}
selectedCoAuthors={this.props.selectedCoAuthors}
updateSelectedCoAuthors={this.props.updateSelectedCoAuthors}
/>
<RecentCommitsController
ref={this.refRecentCommitsController.setter}
commands={this.props.commands}
commits={this.props.recentCommits}
isLoading={this.props.isLoading}
undoLastCommit={this.props.undoLastCommit}
workspace={this.props.workspace}
repository={this.props.repository}
/>
</Fragment>
);
}
<button
onClick={this.initializeRepo}
disabled={this.props.repository.showGitTabInitInProgress()}
className="btn btn-primary">
{this.props.repository.showGitTabInitInProgress()
? 'Creating repository...' : 'Create repository'}
</button>
</div>
);
}

componentWillUnmount() {
Expand Down

0 comments on commit a1cb095

Please sign in to comment.