-
Notifications
You must be signed in to change notification settings - Fork 1
Implement for App Alert #5
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
071f30a
configure redux-thunk
AllenFang ab8e04c
add cors for express
AllenFang 2f94e0f
use cors and create new api for fetching configuration
AllenFang b97cd66
basic implementation for fetching ungit configuration on path container
AllenFang 8dbd698
enhance error handling and also handle UI staus when API is calling
AllenFang 568dce0
Refine reducers:
AllenFang 03e2edd
[refactor-1] separate actionCreators:
AllenFang f7c8b7e
[refactor-2] add some states into state tree
AllenFang ae63c56
change to calling bootstrap action for initialize data
AllenFang 1b73f13
implement pending mechanism
AllenFang 1743ba5
create config reducers
AllenFang f7530a5
implement app and alert-area
AllenFang 689e5b0
typo
AllenFang 6bc6dd0
move one pending call into ungitconfig due to there's some condition
AllenFang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { fetchUngitConfig } from './ungit-config'; | ||
import { fetchLatestVersion, fetchGitVersion } from './version'; | ||
import { pending } from './common'; | ||
|
||
export function bootstrap() { | ||
return dispatch => { | ||
dispatch(pending(4)); | ||
dispatch(fetchUngitConfig()); | ||
dispatch(fetchLatestVersion()); | ||
dispatch(fetchGitVersion()); | ||
}; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* This export common using actionCreator */ | ||
import * as types from 'constants/action-types'; | ||
|
||
export function pending(count) { | ||
return { | ||
type: types.PATH_PAGE_PENDING, | ||
payload: count || 1 | ||
}; | ||
}; | ||
|
||
export function apiError(message) { | ||
return { | ||
type: types.PATH_PAGE_API_ERR, | ||
payload: message | ||
}; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as types from 'constants/action-types'; | ||
import { fetchUserConfig } from './user-config'; | ||
import { apiError } from './common'; | ||
|
||
export function fetchUngitConfig() { | ||
return dispatch => { | ||
// consider wrap API call in separate modules | ||
// it will be easy to stub module's function when testing | ||
fetch('http://localhost:8448/ungit/config') | ||
.then(response => response.json()) | ||
.then(json => { | ||
if (!json.config.bugtracking) { | ||
dispatch(fetchUserConfig()); | ||
} | ||
dispatch(receiveUgitConfig(json)); | ||
}) | ||
.catch(e => { | ||
dispatch(apiError(e.message)); | ||
}); | ||
}; | ||
}; | ||
|
||
function receiveUgitConfig(ungitConfig) { | ||
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 think it's typo in the function name?
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. fixed |
||
return { | ||
type: types.RECEIVE_UNGIT_CONFIG, | ||
payload: ungitConfig | ||
}; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as types from 'constants/action-types'; | ||
import { apiError } from './common'; | ||
|
||
export function fetchUserConfig() { | ||
return dispatch => { | ||
// consider wrap API call in separate modules | ||
// it will be easy to stub module's function when testing | ||
fetch('http://localhost:8448/api/userconfig') | ||
.then(response => response.json()) | ||
.then(json => { | ||
dispatch(receiveUserConfig(json)); | ||
}) | ||
.catch(e => { | ||
dispatch(apiError(e.message)); | ||
}); | ||
}; | ||
}; | ||
|
||
|
||
function receiveUserConfig(userConfig) { | ||
return { | ||
type: types.RECEIVE_USER_CONFIG, | ||
payload: userConfig | ||
}; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as types from 'constants/action-types'; | ||
import { apiError } from './common'; | ||
|
||
export function fetchLatestVersion() { | ||
return dispatch => { | ||
// consider wrap API call in separate modules | ||
// it will be easy to stub module's function when testing | ||
fetch('http://localhost:8448/api/latestversion') | ||
.then(response => response.json()) | ||
.then(json => { | ||
dispatch(receiveLatestVersion(json)); | ||
}) | ||
.catch(e => { | ||
dispatch(apiError(e.message)); | ||
}); | ||
}; | ||
} | ||
|
||
export function fetchGitVersion() { | ||
return dispatch => { | ||
// consider wrap API call in separate modules | ||
// it will be easy to stub module's function when testing | ||
fetch('http://localhost:8448/api/gitversion') | ||
.then(response => response.json()) | ||
.then(json => { | ||
dispatch(receiveGitVersion(json)); | ||
}) | ||
.catch(e => { | ||
dispatch(apiError(e.message)); | ||
}); | ||
}; | ||
} | ||
|
||
function receiveGitVersion(gitVersion) { | ||
return { | ||
type: types.RECEIVE_GIT_VERSION, | ||
payload: gitVersion | ||
}; | ||
} | ||
|
||
function receiveLatestVersion(latestVersion) { | ||
return { | ||
type: types.RECEIVE_LATEST_VERSION, | ||
payload: latestVersion | ||
}; | ||
}; |
17 changes: 17 additions & 0 deletions
17
src-react/components/alert-area/bug-tracking-nag-screen.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React, { Component } from 'react'; | ||
|
||
class BugTrackingNagScreen extends Component { | ||
render() { | ||
return ( | ||
<div className="alert alert-info clearfix"> | ||
<button type="button" className="close" data-bind="click: dismissBugtrackingNagscreen">×</button> | ||
<p><strong>Help make ungit better with the press of a button!</strong></p> | ||
<button className="btn btn-primary" data-bind="click: enableBugtrackingAndStatistics">Enable automatic bug reports + anonymous usage statistics</button> | ||
<button className="btn btn-primary" data-bind="click: enableBugtracking">Enable automatic bug reports</button> | ||
<button className="btn btn-default" data-bind="click: dismissBugtrackingNagscreen">Naah, I'll skip that</button> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default BugTrackingNagScreen; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
|
||
class GitVersionError extends Component { | ||
static propTypes = { | ||
gitVersionError: PropTypes.string | ||
} | ||
|
||
render() { | ||
return ( | ||
<div class="alert alert-danger"> | ||
<span>{ this.props.gitVersionError }</span> | ||
<button type="button" className="close" data-bind="click: dismissGitVersionError">×</button> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default GitVersionError; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
|
||
import GitVersionError from './git-version-error'; | ||
import NewVersionAvailable from './new-version-available'; | ||
import BugTrackingNagScreen from './bug-tracking-nag-screen'; | ||
import NPSSurvey from './nps-survey'; | ||
|
||
class AlertArea extends Component { | ||
static propTypes = { | ||
config: PropTypes.object.isRequired, | ||
gitVersionErrorVisible: PropTypes.bool.isRequired, | ||
showNewVersionAvailable: PropTypes.bool.isRequired, | ||
showBugtrackingNagscreen: PropTypes.bool.isRequired, | ||
showNPSSurvey: PropTypes.bool.isRequired | ||
} | ||
|
||
render() { | ||
const { | ||
config: { | ||
ungitConfig: { platform }, | ||
versions: { | ||
gitVersion: { error }, | ||
latestVersion: { | ||
latestVersion | ||
} | ||
} | ||
}, | ||
gitVersionErrorVisible, | ||
showNewVersionAvailable, | ||
showBugtrackingNagscreen, | ||
showNPSSurvey | ||
} = this.props; | ||
return ( | ||
<div className="container" data-ta-container="app"> | ||
{ | ||
gitVersionErrorVisible ? ( | ||
<GitVersionError gitVersionError={ error }/> | ||
) : null | ||
} | ||
{ | ||
showNewVersionAvailable ? ( | ||
<NewVersionAvailable | ||
latestVersion={ latestVersion } | ||
platform={ platform }/> | ||
) : null | ||
} | ||
{ | ||
showBugtrackingNagscreen ? ( | ||
<BugTrackingNagScreen /> | ||
) : null | ||
} | ||
{ | ||
showNPSSurvey ? ( | ||
<NPSSurvey /> | ||
) : null | ||
} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default AlertArea; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
|
||
class NewVersionAvailable extends Component { | ||
static propTypes = { | ||
latestVersion: PropTypes.string, | ||
platform: PropTypes.string | ||
} | ||
|
||
render() { | ||
const newVersionInstallCommand = `#{this.props.platform ? '' : 'sudo -H'}npm update -g ungit`; | ||
return ( | ||
<div className="alert alert-info"> | ||
A new version of ungit (<span>{ this.props.latestVersion }</span>) is | ||
<a href="https://github.com/FredrikNoren/ungit">available</a>! Run | ||
<code>{ newVersionInstallCommand }</code> to install. | ||
See what's new in the | ||
<a href="https://github.com/FredrikNoren/ungit/blob/master/CHANGELOG.md">changelog</a>. | ||
<button type="button" className="close" data-bind="click: dismissNewVersion">×</button> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default NewVersionAvailable; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React, { Component } from 'react'; | ||
|
||
class NPSSurvey extends Component { | ||
static propTypes = { | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className="alert alert-info clearfix" data-bind="visible: showNPSSurvey"> | ||
<button type="button" className="close" data-bind="click: dismissNPSSurvey">×</button> | ||
<span className="text-dimmed">Hi! This is a one-question survey to learn more about how people use Ungit. You can dismiss it by clicking the x in the upper right corner.</span> | ||
<p><h4>Question: How likely are you to recommend Ungit to your friends and colleagues?</h4></p> | ||
<p> | ||
<div className="btn-group btn-group-justified"> | ||
<a className="btn btn-default" role="button" data-bind="click: sendNPS.bind(null, 0)">0</a> | ||
<a className="btn btn-default" role="button" data-bind="click: sendNPS.bind(null, 1)">1</a> | ||
<a className="btn btn-default" role="button" data-bind="click: sendNPS.bind(null, 2)">2</a> | ||
<a className="btn btn-default" role="button" data-bind="click: sendNPS.bind(null, 3)">3</a> | ||
<a className="btn btn-default" role="button" data-bind="click: sendNPS.bind(null, 4)">4</a> | ||
<a className="btn btn-default" role="button" data-bind="click: sendNPS.bind(null, 5)">5</a> | ||
<a className="btn btn-default" role="button" data-bind="click: sendNPS.bind(null, 6)">6</a> | ||
<a className="btn btn-default" role="button" data-bind="click: sendNPS.bind(null, 7)">7</a> | ||
<a className="btn btn-default" role="button" data-bind="click: sendNPS.bind(null, 8)">8</a> | ||
<a className="btn btn-default" role="button" data-bind="click: sendNPS.bind(null, 9)">9</a> | ||
<a className="btn btn-default" role="button" data-bind="click: sendNPS.bind(null, 10)">10</a> | ||
</div> | ||
<div className="clearfix"> | ||
Not at all likely | ||
<div className="pull-right">Extremely likely</div> | ||
</div> | ||
</p> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default NPSSurvey; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const RECEIVE_GIT_VERSION = 'RECEIVE_GIT_VERSION'; | ||
export const RECEIVE_LATEST_VERSION = 'RECEIVE_LATEST_VERSION'; | ||
export const RECEIVE_USER_CONFIG = 'RECEIVE_USER_CONFIG'; | ||
export const RECEIVE_UNGIT_CONFIG = 'RECEIVE_UNGIT_CONFIG'; | ||
export const PATH_PAGE_PENDING = 'PATH_PAGE_PENDING'; | ||
export const PATH_PAGE_API_ERR = 'PATH_PAGE_API_ERR'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just want to make my understanding much clearer.
I think the usage of
pending
is to know how many APIs don't finish yet.If my understanding is correct, according to this
bootstrap
action, there're threefetch
action, why do you use4
here?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.
Due to ungitconfig action will also fetch userconfig, but after I check the code, there's a condition to decide if fetching userconfig or not, so I think I need to move a pending call into ungitconfig
It's fixed