Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a1cb095

Browse files
change render logic to use function call instead of switch statement
1 parent 8bd2612 commit a1cb095

File tree

1 file changed

+114
-111
lines changed

1 file changed

+114
-111
lines changed

lib/views/git-tab-view.js

Lines changed: 114 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,18 @@ export default class GitTabView extends React.Component {
8787
}
8888

8989
render() {
90-
let type = 'default';
90+
let renderMethod = 'renderNormal';
9191
let isEmpty = false;
9292
let isLoading = false;
9393
if (this.props.repository.isTooLarge()) {
94-
type = 'is-too-large';
94+
renderMethod = 'renderTooLarge';
9595
isEmpty = true;
9696
} else if (this.props.repository.hasDirectory() &&
9797
!isValidWorkdir(this.props.repository.getWorkingDirectoryPath())) {
98-
type = 'unsupported-dir';
98+
renderMethod = 'renderUnsupportedDir';
9999
isEmpty = true;
100100
} else if (this.props.repository.showGitTabInit()) {
101-
type = 'no-repo';
101+
renderMethod = 'renderNoRepo';
102102
isEmpty = true;
103103
} else if (this.props.isLoading || this.props.repository.showGitTabLoading()) {
104104
isLoading = true;
@@ -110,7 +110,7 @@ export default class GitTabView extends React.Component {
110110
tabIndex="-1"
111111
ref={this.props.refRoot.setter}>
112112
{this.renderHeader()}
113-
{this.renderBody(type)}
113+
{this[renderMethod]()}
114114
</div>
115115
);
116116
}
@@ -125,115 +125,118 @@ export default class GitTabView extends React.Component {
125125
);
126126
}
127127

128-
renderBody(type) {
129-
switch (type) {
130-
case 'is-too-large':
131-
return (
132-
<div className="github-Git too-many-changes">
133-
<div className="github-Git-LargeIcon icon icon-diff" />
134-
<h1>Too many changes</h1>
135-
<div className="initialize-repo-description">
136-
The repository at <strong>{this.props.workingDirectoryPath}</strong> has too many changed files
137-
to display in Atom. Ensure that you have set up an appropriate <code>.gitignore</code> file.
138-
</div>
128+
renderNormal() {
129+
return (
130+
<Fragment>
131+
<StagingView
132+
ref={this.props.refStagingView.setter}
133+
commands={this.props.commands}
134+
notificationManager={this.props.notificationManager}
135+
workspace={this.props.workspace}
136+
stagedChanges={this.props.stagedChanges}
137+
unstagedChanges={this.props.unstagedChanges}
138+
mergeConflicts={this.props.mergeConflicts}
139+
workingDirectoryPath={this.props.workingDirectoryPath}
140+
resolutionProgress={this.props.resolutionProgress}
141+
openFiles={this.props.openFiles}
142+
discardWorkDirChangesForPaths={this.props.discardWorkDirChangesForPaths}
143+
attemptFileStageOperation={this.props.attemptFileStageOperation}
144+
attemptStageAllOperation={this.props.attemptStageAllOperation}
145+
undoLastDiscard={this.props.undoLastDiscard}
146+
abortMerge={this.props.abortMerge}
147+
resolveAsOurs={this.props.resolveAsOurs}
148+
resolveAsTheirs={this.props.resolveAsTheirs}
149+
lastCommit={this.props.lastCommit}
150+
isLoading={this.props.isLoading}
151+
hasUndoHistory={this.props.hasUndoHistory}
152+
isMerging={this.props.isMerging}
153+
/>
154+
<CommitController
155+
ref={this.refCommitController.setter}
156+
tooltips={this.props.tooltips}
157+
config={this.props.config}
158+
stagedChangesExist={this.props.stagedChanges.length > 0}
159+
mergeConflictsExist={this.props.mergeConflicts.length > 0}
160+
prepareToCommit={this.props.prepareToCommit}
161+
commit={this.props.commit}
162+
abortMerge={this.props.abortMerge}
163+
currentBranch={this.props.currentBranch}
164+
workspace={this.props.workspace}
165+
commands={this.props.commands}
166+
notificationManager={this.props.notificationManager}
167+
grammars={this.props.grammars}
168+
mergeMessage={this.props.mergeMessage}
169+
isMerging={this.props.isMerging}
170+
isLoading={this.props.isLoading}
171+
lastCommit={this.props.lastCommit}
172+
repository={this.props.repository}
173+
userStore={this.props.userStore}
174+
selectedCoAuthors={this.props.selectedCoAuthors}
175+
updateSelectedCoAuthors={this.props.updateSelectedCoAuthors}
176+
/>
177+
<RecentCommitsController
178+
ref={this.refRecentCommitsController.setter}
179+
commands={this.props.commands}
180+
commits={this.props.recentCommits}
181+
isLoading={this.props.isLoading}
182+
undoLastCommit={this.props.undoLastCommit}
183+
workspace={this.props.workspace}
184+
repository={this.props.repository}
185+
/>
186+
</Fragment>
187+
);
188+
}
189+
190+
renderTooLarge() {
191+
return (
192+
<div className="github-Git too-many-changes">
193+
<div className="github-Git-LargeIcon icon icon-diff" />
194+
<h1>Too many changes</h1>
195+
<div className="initialize-repo-description">
196+
The repository at <strong>{this.props.workingDirectoryPath}</strong> has too many changed files
197+
to display in Atom. Ensure that you have set up an appropriate <code>.gitignore</code> file.
139198
</div>
140-
);
141-
case 'unsupported-dir':
142-
return (
143-
<div className="github-Git unsupported-directory">
144-
<div className="github-Git-LargeIcon icon icon-alert" />
145-
<h1>Unsupported directory</h1>
146-
<div className="initialize-repo-description">
147-
Atom does not support managing Git repositories in your home or root directories.
148-
</div>
199+
</div>
200+
);
201+
}
202+
203+
renderUnsupportedDir() {
204+
return (
205+
<div className="github-Git unsupported-directory">
206+
<div className="github-Git-LargeIcon icon icon-alert" />
207+
<h1>Unsupported directory</h1>
208+
<div className="initialize-repo-description">
209+
Atom does not support managing Git repositories in your home or root directories.
149210
</div>
150-
);
151-
case 'no-repo':
152-
return (
153-
<div className="github-Git no-repository">
154-
<div className="github-Git-LargeIcon icon icon-repo" />
155-
<h1>Create Repository</h1>
156-
<div className="initialize-repo-description">
157-
{
158-
this.props.repository.hasDirectory()
159-
?
160-
(
161-
<span>Initialize <strong>{this.props.workingDirectoryPath}</strong> with a
162-
Git repository</span>
163-
)
164-
: <span>Initialize a new project directory with a Git repository</span>
165-
}
166-
</div>
167-
<button
168-
onClick={this.initializeRepo}
169-
disabled={this.props.repository.showGitTabInitInProgress()}
170-
className="btn btn-primary">
171-
{this.props.repository.showGitTabInitInProgress()
172-
? 'Creating repository...' : 'Create repository'}
173-
</button>
211+
</div>
212+
);
213+
}
214+
215+
renderNoRepo() {
216+
return (
217+
<div className="github-Git no-repository">
218+
<div className="github-Git-LargeIcon icon icon-repo" />
219+
<h1>Create Repository</h1>
220+
<div className="initialize-repo-description">
221+
{
222+
this.props.repository.hasDirectory()
223+
?
224+
(
225+
<span>Initialize <strong>{this.props.workingDirectoryPath}</strong> with a
226+
Git repository</span>
227+
)
228+
: <span>Initialize a new project directory with a Git repository</span>
229+
}
174230
</div>
175-
);
176-
default:
177-
return (
178-
<Fragment>
179-
<StagingView
180-
ref={this.props.refStagingView.setter}
181-
commands={this.props.commands}
182-
notificationManager={this.props.notificationManager}
183-
workspace={this.props.workspace}
184-
stagedChanges={this.props.stagedChanges}
185-
unstagedChanges={this.props.unstagedChanges}
186-
mergeConflicts={this.props.mergeConflicts}
187-
workingDirectoryPath={this.props.workingDirectoryPath}
188-
resolutionProgress={this.props.resolutionProgress}
189-
openFiles={this.props.openFiles}
190-
discardWorkDirChangesForPaths={this.props.discardWorkDirChangesForPaths}
191-
attemptFileStageOperation={this.props.attemptFileStageOperation}
192-
attemptStageAllOperation={this.props.attemptStageAllOperation}
193-
undoLastDiscard={this.props.undoLastDiscard}
194-
abortMerge={this.props.abortMerge}
195-
resolveAsOurs={this.props.resolveAsOurs}
196-
resolveAsTheirs={this.props.resolveAsTheirs}
197-
lastCommit={this.props.lastCommit}
198-
isLoading={this.props.isLoading}
199-
hasUndoHistory={this.props.hasUndoHistory}
200-
isMerging={this.props.isMerging}
201-
/>
202-
<CommitController
203-
ref={this.refCommitController.setter}
204-
tooltips={this.props.tooltips}
205-
config={this.props.config}
206-
stagedChangesExist={this.props.stagedChanges.length > 0}
207-
mergeConflictsExist={this.props.mergeConflicts.length > 0}
208-
prepareToCommit={this.props.prepareToCommit}
209-
commit={this.props.commit}
210-
abortMerge={this.props.abortMerge}
211-
currentBranch={this.props.currentBranch}
212-
workspace={this.props.workspace}
213-
commands={this.props.commands}
214-
notificationManager={this.props.notificationManager}
215-
grammars={this.props.grammars}
216-
mergeMessage={this.props.mergeMessage}
217-
isMerging={this.props.isMerging}
218-
isLoading={this.props.isLoading}
219-
lastCommit={this.props.lastCommit}
220-
repository={this.props.repository}
221-
userStore={this.props.userStore}
222-
selectedCoAuthors={this.props.selectedCoAuthors}
223-
updateSelectedCoAuthors={this.props.updateSelectedCoAuthors}
224-
/>
225-
<RecentCommitsController
226-
ref={this.refRecentCommitsController.setter}
227-
commands={this.props.commands}
228-
commits={this.props.recentCommits}
229-
isLoading={this.props.isLoading}
230-
undoLastCommit={this.props.undoLastCommit}
231-
workspace={this.props.workspace}
232-
repository={this.props.repository}
233-
/>
234-
</Fragment>
235-
);
236-
}
231+
<button
232+
onClick={this.initializeRepo}
233+
disabled={this.props.repository.showGitTabInitInProgress()}
234+
className="btn btn-primary">
235+
{this.props.repository.showGitTabInitInProgress()
236+
? 'Creating repository...' : 'Create repository'}
237+
</button>
238+
</div>
239+
);
237240
}
238241

239242
componentWillUnmount() {

0 commit comments

Comments
 (0)