From a90e53dcb0b52ba8ea997f16256b7c38ec07c996 Mon Sep 17 00:00:00 2001 From: Yang Zhen Date: Mon, 31 Oct 2016 17:34:14 +0800 Subject: [PATCH 1/4] Add git stash, unstash and reset. --- app/api/gitAPI.js | 28 ++++ app/commands/commandBindings/git.js | 23 +++- app/components/Git/actions.js | 148 ++++++++++++++++++++- app/components/Git/index.jsx | 6 +- app/components/Git/modals/reset.jsx | 119 +++++++++++++++++ app/components/Git/modals/stash.jsx | 65 +++++++++ app/components/Git/modals/unstash.jsx | 177 +++++++++++++++++++++++++ app/components/Git/reducer.js | 58 +++++++- app/components/MenuBar/menuBarItems.js | 15 +++ app/components/Modal/index.jsx | 14 +- app/components/Modal/modals/index.js | 7 +- app/components/Notification/actions.js | 25 ++++ app/styles/components/Git.styl | 45 +++++++ app/styles/components/Modal.styl | 11 +- app/styles/components/PaneView.styl | 1 + app/styles/main.styl | 1 + 16 files changed, 729 insertions(+), 14 deletions(-) create mode 100644 app/components/Git/modals/reset.jsx create mode 100644 app/components/Git/modals/stash.jsx create mode 100644 app/components/Git/modals/unstash.jsx diff --git a/app/api/gitAPI.js b/app/api/gitAPI.js index 32c5cb65..89a00fb4 100644 --- a/app/api/gitAPI.js +++ b/app/api/gitAPI.js @@ -30,3 +30,31 @@ export function gitPushAll () { if (!res.ok) return false }) } + +export function gitCurrentBranch (){ + return request.get(`/git/${config.spaceKey}/branch`) +} + +export function gitCreateStash (message){ + return request.post(`/git/${config.spaceKey}/stash`, {message: message}) +} + +export function gitStashList (){ + return request.get(`/git/${config.spaceKey}/stash`) +} + +export function gitDropStash (stashRef, all=false){ + return request.delete(`/git/${config.spaceKey}/stash`, {stashRef, all}) +} + +export function gitApplyStash ({stashRef, pop, applyIndex}){ + return request.post(`/git/${config.spaceKey}/stash/apply`, {stashRef, pop, applyIndex}) +} + +export function gitCheckoutStash ({stashRef, branch}){ + return request.post(`/git/${config.spaceKey}/stash/checkout`, {stashRef, branch}) +} + +export function gitResetHead ({ref, resetType}) { + return request.post(`/git/${config.spaceKey}/reset`, {ref, resetType}) +} \ No newline at end of file diff --git a/app/commands/commandBindings/git.js b/app/commands/commandBindings/git.js index c24eb4bb..233bc063 100644 --- a/app/commands/commandBindings/git.js +++ b/app/commands/commandBindings/git.js @@ -14,16 +14,31 @@ export default { }, 'git:pull': c => $d(Git.pull()), - 'git:push': c => $d(Git.push()) + 'git:push': c => $d(Git.push()), // 'git:commit_and_push': // 'git:branch': // 'git:tag': // 'git:merge': // 'git:resolve_conflicts': - // 'git:stash': - // 'git:unstash'<:> - // 'git:reset_head': + 'git:stash': c => { + $d(Git.getCurrentBranch()).then(() => + $d(Modal.showModal('GitStash')) + ) + }, + 'git:unstash': c => { + $d(Git.getCurrentBranch()).then(() => { + $d(Git.getStashList()) + .then(() => + $d(Modal.showModal('GitUnstash')) + ) + }) + }, + 'git:reset_head': c => { + $d(Git.getCurrentBranch()).then(() => + $d(Modal.showModal('GitResetHead')) + ) + }, // 'git:rebase:start': // 'git:rebase:abort': // 'git:rebase:continue': diff --git a/app/components/Git/actions.js b/app/components/Git/actions.js index 7988c423..bf168fd3 100644 --- a/app/components/Git/actions.js +++ b/app/components/Git/actions.js @@ -1,7 +1,7 @@ /* @flow weak */ import api from '../../api' -import { notify } from '../Notification/actions' -import { dismissModal } from '../Modal/actions' +import { notify, error } from '../Notification/actions' +import { showModal, dismissModal } from '../Modal/actions' export const GIT_STATUS = 'GIT_STATUS' export function updateStatus ({files, isClean}) { @@ -94,3 +94,147 @@ export function push () { }) } } + +export const GIT_CURRENT_BRANCH = 'GIT_CURRENT_BRANCH' +export function updateCurrentBranch ({ name }) { + return { + type: GIT_CURRENT_BRANCH, + branch: name, + } +} + +export const GIT_UPDATE_STASH_MESSAGE = 'GIT_UPDATE_STASH_MESSAGE' +export function updateStashMessage (stashMessage) { + return { + type: GIT_UPDATE_STASH_MESSAGE, + stashMessage, + } +} + +export function createStash (message) { + return dispatch => api.gitCreateStash(message).then(res => { + dispatch(notify({ + message: 'Git stash success.', + })) + dispatch(dismissModal()) + }).catch(res => { + dispatch(error({ + className: 'error', + message: res.msg, + })) + dispatch(dismissModal()) + }) +} + +export const GIT_UPDATE_STASH_LIST = 'GIT_UPDATE_STASH_LIST' +export function updateStashList (stashList) { + return { + type: GIT_UPDATE_STASH_LIST, + stashList: stashList + } +} + +export const GIT_UPDATE_UNSTASH_IS_POP = 'GIT_UPDATE_UNSTASH_IS_POP' +export function updateUnstashIsPop (isPop) { + return { + type: GIT_UPDATE_UNSTASH_IS_POP, + isPop + } +} + +export const GIT_UPDATE_UNSTASH_IS_REINSTATE= 'GIT_UPDATE_UNSTASH_IS_REINSTATE' +export function updateUnstashIsReinstate (isReinstate) { + return { + type: GIT_UPDATE_UNSTASH_IS_REINSTATE, + isReinstate + } +} + +export const GIT_UPDATE_UNSTASH_BRANCH_NAME= 'GIT_UPDATE_UNSTASH_BRANCH_NAME' +export function updateUnstashBranchName (newBranchName) { + return { + type: GIT_UPDATE_UNSTASH_BRANCH_NAME, + newBranchName + } +} + +export function getStashList () { + return (dispatch) => api.gitStashList().then(({ stashes }) => { + dispatch(updateStashList(stashes)) + }) +} + +export const GIT_SELECT_STASH = 'GIT_SELECT_STASH' +export function selectStash (selectedStash) { + return { + type: GIT_SELECT_STASH, + selectedStash: selectedStash + } +} + +export function dropStash (stashRef, all) { + return dispatch => api.gitDropStash(stashRef, all).then(res => { + dispatch(notify({ + message: 'Drop stash success.', + })) + getStashList()(dispatch) + }).catch(res => { + dispatch(error({ + className: 'error', + message: 'Drop stash error.', + })) + }) +} + +export function applyStash ({stashRef, pop, applyIndex}) { + return dispatch => api.gitApplyStash({stashRef, pop, applyIndex}).then(res => { + dispatch(notify({ + message: 'Apply stash success.', + })) + dispatch(dismissModal()) + }).catch(res => { + dispatch(error({ + className: 'error', + message: 'Apply stash error.', + })) + }) +} + +export function checkoutStash ({stashRef, branch}) { + return dispatch => api.gitCheckoutStash({stashRef, branch}).then(res => { + dispatch(notify({ + message: 'Checkout stash success.', + })) + dispatch(dismissModal()) + }).catch(res => { + dispatch(error({ + className: 'error', + message: 'Checkout stash error.', + })) + }) +} + +export function getCurrentBranch () { + return dispatch => api.gitCurrentBranch().then(({ name }) => { + dispatch(updateCurrentBranch({name})) + }).catch(res => { + dispatch(error({ + className: 'error', + message: 'Get current branch error.', + })) + }) +} + +export function resetHead ({ref, resetType}) { + return dispatch => api.gitResetHead({ref, resetType}).then(res => { + dispatch(notify({ + message: 'Reset success.', + })) + dispatch(dismissModal()) + }).catch(res => { + dispatch(error({ + className: 'error', + message: 'Reset error.', + })) + }) +} diff --git a/app/components/Git/index.jsx b/app/components/Git/index.jsx index 8639d30f..5524c19a 100644 --- a/app/components/Git/index.jsx +++ b/app/components/Git/index.jsx @@ -38,7 +38,7 @@ var GitCommitView = ({workingDir, stagingArea, ...actionProps}) => { onChange={e => updateCommitMessage(e.target.value)} />
-
+
@@ -59,6 +59,10 @@ class _GitBranchWidget extends Component { } } + componentWillMount () { + this.props.getCurrentBranch() + } + render () { const {current: currentBranch, local: localBranches, remote: remoteBranches} = this.props return ( diff --git a/app/components/Git/modals/reset.jsx b/app/components/Git/modals/reset.jsx new file mode 100644 index 00000000..3d70a435 --- /dev/null +++ b/app/components/Git/modals/reset.jsx @@ -0,0 +1,119 @@ +/* @flow weak */ +import React, { Component, PropTypes } from 'react' +import { bindActionCreators } from 'redux' +import { dispatchCommand } from '../../../commands' +import cx from 'classnames' +import { connect } from 'react-redux' + +import * as GitActions from '../actions' + +const actionOptions = [ + 'SOFT', + 'MIXED', + 'HARD', +] + +class GitResetView extends Component { + constructor (props) { + super(props) + this.state = { + resetType: 'MIXED', + commit: 'HEAD', + } + this.handleChangeOption = this.handleChangeOption.bind(this) + this.handleCommitChange = this.handleCommitChange.bind(this) + this.handleConfirm = this.handleConfirm.bind(this) + } + render () { + const { branches } = this.props + const { current: currentBranch} = branches + return ( +
+
+

+ Reset Head +

+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+ ) + } + + renderOptions () { + return ( + + ) + } + + handleChangeOption (e) { + console.log('handleChangeOption') + this.setState({resetType: e.target.value}) + e.stopPropagation() + e.nativeEvent.stopImmediatePropagation() + } + + handleCommitChange (e) { + this.setState({commit: e.target.value}) + e.stopPropagation() + e.nativeEvent.stopImmediatePropagation() + } + + handleConfirm (e) { + console.log('handleConfirm') + this.props.resetHead({ + ref: this.state.commit, + resetType: this.state.resetType, + }) + e.stopPropagation() + e.nativeEvent.stopImmediatePropagation() + } +} + +export default GitResetView = connect( + state => state.GitState, + dispatch => bindActionCreators(GitActions, dispatch) +)(GitResetView) diff --git a/app/components/Git/modals/stash.jsx b/app/components/Git/modals/stash.jsx new file mode 100644 index 00000000..13d64bab --- /dev/null +++ b/app/components/Git/modals/stash.jsx @@ -0,0 +1,65 @@ +/* @flow weak */ +import React, { Component, PropTypes } from 'react' +import { bindActionCreators } from 'redux' +import { dispatchCommand } from '../../../commands' +import cx from 'classnames' +import { connect } from 'react-redux' + +import * as GitActions from '../actions' + +class GitStashView extends Component { + constructor (props) { + super(props) + this.state = { + } + } + + render () { + const { branches, updateStashMessage, createStash } = this.props + const { current: currentBranch} = branches + const { stashMessage } = this.props.stash + return ( +
+
+

+ Stash Changes +

+
+
+
+ + +
+
+ +
+ { + updateStashMessage(e.target.value); + e.preventDefault() + e.stopPropagation() + }} + /> +
+
+
+
+
+ + +
+
+
+ ) + } +} + +export default GitStashView = connect( + state => state.GitState, + dispatch => bindActionCreators(GitActions, dispatch) +)(GitStashView) diff --git a/app/components/Git/modals/unstash.jsx b/app/components/Git/modals/unstash.jsx new file mode 100644 index 00000000..53e2824a --- /dev/null +++ b/app/components/Git/modals/unstash.jsx @@ -0,0 +1,177 @@ +/* @flow weak */ +import React, { Component, PropTypes } from 'react' +import { bindActionCreators } from 'redux' +import { dispatchCommand } from '../../../commands' +import cx from 'classnames' +import { connect } from 'react-redux' + +import * as GitActions from '../actions' + +class GitUntashView extends Component { + constructor (props) { + super(props) + this.state = { + } + this.handleDrop = this.handleDrop.bind(this) + this.handleClear = this.handleClear.bind(this) + this.handleApply = this.handleApply.bind(this) + this.handleBranchName = this.handleBranchName.bind(this) + } + + render () { + const { branches, unstash, selectStash, dropStash, applyStash, + updateUnstashIsPop, updateUnstashIsReinstate } = this.props + const { current: currentBranch} = branches + var { stashList, selectedStash, isPop, isReinstate, newBranchName } = unstash + // if (!selectedStash && stashList.length > 0) { + // selectedStash = stashList[0] + // } + // console.log(selectedStash) + let confirmBtn = null + if (newBranchName) + confirmBtn = 'Branch' + else + confirmBtn = 'Apply' + + return ( +
+
+

+ Unstash Changes +

+
+
+
+ + +
+
+ +
+ {this.renderStashList(stashList, selectStash, selectedStash)} +
+
+ {/**/} + + +
+
+
+ +
+
+ +
+
+ +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ ) + } + + renderStashList(stashList, selectStash, selectedStash) { + return ( +
+
    + { + stashList.map( (item, itemIdx) => { + return (
  • selectStash(item)} + key={itemIdx}> + {`${item.name}:${item.message}`} +
  • ) + }) + } +
+
+ ) + } + + handleDrop(e) { + this.props.dropStash(this.props.unstash.selectedStash.name) + e.stopPropagation() + e.nativeEvent.stopImmediatePropagation() + } + + handleClear(e) { + this.props.dropStash(null, true) + e.stopPropagation() + e.nativeEvent.stopImmediatePropagation() + } + + handleBranchName(e) { + this.props.updateUnstashBranchName(e.target.value) + e.stopPropagation() + e.nativeEvent.stopImmediatePropagation() + } + + handleApply(e) { + if (this.props.unstash.newBranchName) { + this.props.checkoutStash({ + stashRef: this.props.unstash.selectedStash.name, + branch: this.props.unstash.newBranchName + }) + } else { + this.props.applyStash({ + stashRef: this.props.unstash.selectedStash.name, + pop: this.props.unstash.isPop, + applyIndex: this.props.unstash.isReinstate, + }) + } + e.stopPropagation() + e.nativeEvent.stopImmediatePropagation() + } +} + +export default GitUntashView = connect( + state => state.GitState, + dispatch => bindActionCreators(GitActions, dispatch) +)(GitUntashView) diff --git a/app/components/Git/reducer.js b/app/components/Git/reducer.js index 7fbcdbc0..f3942fc5 100644 --- a/app/components/Git/reducer.js +++ b/app/components/Git/reducer.js @@ -7,7 +7,14 @@ import { GIT_CHECKOUT, GIT_STAGE_FILE, GIT_UNSTAGE_FILE, - GIT_UPDATE_COMMIT_MESSAGE + GIT_UPDATE_COMMIT_MESSAGE, + GIT_CURRENT_BRANCH, + GIT_UPDATE_STASH_MESSAGE, + GIT_UPDATE_STASH_LIST, + GIT_SELECT_STASH, + GIT_UPDATE_UNSTASH_IS_POP, + GIT_UPDATE_UNSTASH_IS_REINSTATE, + GIT_UPDATE_UNSTASH_BRANCH_NAME, } from './actions' const _state = { @@ -21,7 +28,17 @@ const _state = { }, branches: { current: 'master' - } + }, + stash: { + stashMessage: '', + }, + unstash: { + stashList: [], + selectedStash: null, + isPop: false, + isReinstate: false, + newBranchName: '', + }, } export default function GitReducer (state = _state, action) { @@ -56,6 +73,43 @@ export default function GitReducer (state = _state, action) { state.branches.current = action.branch return state + case GIT_CURRENT_BRANCH: + state.branches.current = action.branch + return state + + case GIT_UPDATE_STASH_MESSAGE: + state.stash.stashMessage = action.stashMessage + return state + + case GIT_UPDATE_UNSTASH_IS_POP: + state.unstash.isPop = action.isPop + return state + + case GIT_UPDATE_UNSTASH_IS_POP: + state.unstash.isPop = action.isPop + return state + + case GIT_UPDATE_UNSTASH_IS_REINSTATE: + state.unstash.isReinstate = action.isReinstate + return state + + case GIT_UPDATE_UNSTASH_BRANCH_NAME: + state.unstash.newBranchName = action.newBranchName + return state + + case GIT_UPDATE_STASH_LIST: + state.unstash.stashList = action.stashList + if (action.stashList.length == 0) { + state.unstash.selectedStash = null + } else if(!state.unstash.selectedStash) { + state.unstash.selectedStash = action.stashList[0] + } + return state + + case GIT_SELECT_STASH: + state.unstash.selectedStash = action.selectedStash + return state + default: return state } diff --git a/app/components/MenuBar/menuBarItems.js b/app/components/MenuBar/menuBarItems.js index 65dfb5e8..4d3f71df 100644 --- a/app/components/MenuBar/menuBarItems.js +++ b/app/components/MenuBar/menuBarItems.js @@ -43,6 +43,21 @@ var menuBarItems = [ name: 'Push', icon: 'octicon octicon-repo-push', command: 'git:push' + }, dividItem, + { + name: 'Stash Changes...', + icon: 'fa', + command: 'git:stash' + }, + { + name: 'Unstash Changes...', + icon: 'fa', + command: 'git:unstash' + }, + { + name: 'Reset HEAD...', + icon: 'fa', + command: 'git:reset_head' } ] }, { diff --git a/app/components/Modal/index.jsx b/app/components/Modal/index.jsx index 669121fd..c7a5c293 100644 --- a/app/components/Modal/index.jsx +++ b/app/components/Modal/index.jsx @@ -6,7 +6,10 @@ import { Prompt, Confirm, CommandPalette, - GitCommitView + GitCommitView, + GitStashView, + GitUnstashView, + GitResetView, } from './modals' var ModalContainer = (props) => { @@ -41,6 +44,15 @@ class Modal extends Component { case 'GitCommit': return + case 'GitStash': + return + + case 'GitUnstash': + return + + case 'GitResetHead': + return + case 'Prompt': return diff --git a/app/components/Modal/modals/index.js b/app/components/Modal/modals/index.js index 325604f0..1118b41b 100644 --- a/app/components/Modal/modals/index.js +++ b/app/components/Modal/modals/index.js @@ -1,5 +1,8 @@ /* @flow weak */ -export Prompt from './Prompt' -export Confirm from './Confirm' +export Prompt from './Prompt'; +export Confirm from './Confirm'; export {GitCommitView} from '../../Git'; export {CommandPalette} from '../../../commands'; +export GitStashView from '../../Git/modals/stash'; +export GitUnstashView from '../../Git/modals/unstash'; +export GitResetView from '../../Git/modals/reset'; diff --git a/app/components/Notification/actions.js b/app/components/Notification/actions.js index ea9ca6bb..a52f005c 100644 --- a/app/components/Notification/actions.js +++ b/app/components/Notification/actions.js @@ -23,6 +23,31 @@ export function addNotification (_notification) { export const notify = addNotification +export function addErrorNotification (_notification) { + return dispatch => { + var notification, defaultNotification + + defaultNotification = { + message: '', + action: 'Dismiss', + key: Date.now(), + dismissAfter: 6000, + barStyle: {backgroundColor:'red'}, + actionStyle: {color:'white'}, + onClick: () => dispatch({type: NOTIFICATION_REMOVE, notification}) + } + + notification = {...defaultNotification, ..._notification} + + dispatch({ + type: NOTIFICATION_ADD, + notification + }) + } +} + +export const error = addErrorNotification + export const NOTIFICATION_REMOVE = 'NOTIFICATION_REMOVE' export function removeNotification (notification) { return { diff --git a/app/styles/components/Git.styl b/app/styles/components/Git.styl index becff725..03d85f89 100644 --- a/app/styles/components/Git.styl +++ b/app/styles/components/Git.styl @@ -21,3 +21,48 @@ max-width: 100%; } } + +.git-unstash-container { + .btn-list { + .btn-default { + width: 100%; + margin-bottom: 6px; + &:last-child { + margin-bottom: 0; + } + } + } + .stash-list { + min-height: 114px; + max-height: 200px; + overflow: auto; + border: 1px solid gray(85%); + ul { + margin: 0; + padding: 0; + li { + padding: 2px 10px; + cursor: pointer; + } + li:nth-child(odd) { + background: $gray-lighter; + } + li.isSelected { + background: $component-active-bg; + color: $component-active-color; + } + } + } + + .checkbox { + float: left; + padding-top: 0; + label { + padding-right: 20px; + } + input[type="checkbox"] { + margin: 4px 0 0 -20px; + } + } +} + diff --git a/app/styles/components/Modal.styl b/app/styles/components/Modal.styl index d4e57f98..09eb302a 100644 --- a/app/styles/components/Modal.styl +++ b/app/styles/components/Modal.styl @@ -32,7 +32,7 @@ } } -.modal { +.modal min-width: 600px; min-height: 20px; padding: 0.75em; @@ -40,7 +40,14 @@ border-radius: 4px; background-color: #FFF; box-shadow: 0 4px 20px 1px rgba(0, 0, 0, .3); -} + + h1 + font-size: 14px; + + .modal-ops + text-align: right + .btn + margin-left: 10px .modal-content { .message { margin-bottom: 0.4em; } diff --git a/app/styles/components/PaneView.styl b/app/styles/components/PaneView.styl index 13d52661..f2a33b60 100644 --- a/app/styles/components/PaneView.styl +++ b/app/styles/components/PaneView.styl @@ -27,6 +27,7 @@ border-top: 0; border-bottom: 0; border-left: 0; + margin: 0; } &.column { border-top: 0; diff --git a/app/styles/main.styl b/app/styles/main.styl index 623fc4b6..38898502 100644 --- a/app/styles/main.styl +++ b/app/styles/main.styl @@ -3,6 +3,7 @@ @import 'bootstrap/mixins'; @import 'bootstrap/scaffolding'; +@import 'bootstrap/grid'; @import 'bootstrap/buttons'; @import 'bootstrap/forms'; From cc72a75b308520db028759c6f5feb649b2780cef Mon Sep 17 00:00:00 2001 From: Yang Zhen Date: Mon, 31 Oct 2016 18:02:33 +0800 Subject: [PATCH 2/4] Fix code style and remove console.log --- app/components/Git/actions.js | 4 ++-- app/components/Git/modals/reset.jsx | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/components/Git/actions.js b/app/components/Git/actions.js index bf168fd3..c610d781 100644 --- a/app/components/Git/actions.js +++ b/app/components/Git/actions.js @@ -142,7 +142,7 @@ export function updateUnstashIsPop (isPop) { } } -export const GIT_UPDATE_UNSTASH_IS_REINSTATE= 'GIT_UPDATE_UNSTASH_IS_REINSTATE' +export const GIT_UPDATE_UNSTASH_IS_REINSTATE = 'GIT_UPDATE_UNSTASH_IS_REINSTATE' export function updateUnstashIsReinstate (isReinstate) { return { type: GIT_UPDATE_UNSTASH_IS_REINSTATE, @@ -150,7 +150,7 @@ export function updateUnstashIsReinstate (isReinstate) { } } -export const GIT_UPDATE_UNSTASH_BRANCH_NAME= 'GIT_UPDATE_UNSTASH_BRANCH_NAME' +export const GIT_UPDATE_UNSTASH_BRANCH_NAME = 'GIT_UPDATE_UNSTASH_BRANCH_NAME' export function updateUnstashBranchName (newBranchName) { return { type: GIT_UPDATE_UNSTASH_BRANCH_NAME, diff --git a/app/components/Git/modals/reset.jsx b/app/components/Git/modals/reset.jsx index 3d70a435..36a7e2dd 100644 --- a/app/components/Git/modals/reset.jsx +++ b/app/components/Git/modals/reset.jsx @@ -90,7 +90,6 @@ class GitResetView extends Component { } handleChangeOption (e) { - console.log('handleChangeOption') this.setState({resetType: e.target.value}) e.stopPropagation() e.nativeEvent.stopImmediatePropagation() @@ -103,7 +102,6 @@ class GitResetView extends Component { } handleConfirm (e) { - console.log('handleConfirm') this.props.resetHead({ ref: this.state.commit, resetType: this.state.resetType, From 8a4a9338e3bc474b0e2e19af7be3784190a2bce5 Mon Sep 17 00:00:00 2001 From: Yang Zhen Date: Tue, 1 Nov 2016 16:40:16 +0800 Subject: [PATCH 3/4] Fix css style. --- app/styles/components/Modal.styl | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/styles/components/Modal.styl b/app/styles/components/Modal.styl index 09eb302a..097f02e3 100644 --- a/app/styles/components/Modal.styl +++ b/app/styles/components/Modal.styl @@ -32,7 +32,7 @@ } } -.modal +.modal { min-width: 600px; min-height: 20px; padding: 0.75em; @@ -41,13 +41,17 @@ background-color: #FFF; box-shadow: 0 4px 20px 1px rgba(0, 0, 0, .3); - h1 + h1 { font-size: 14px; + } - .modal-ops - text-align: right - .btn - margin-left: 10px + .modal-ops { + text-align: right; + .btn { + margin-left: 10px; + } + } +} .modal-content { .message { margin-bottom: 0.4em; } From 9f35ca6e3f7b4120b96f39728b9775ea69918052 Mon Sep 17 00:00:00 2001 From: Yang Zhen Date: Wed, 2 Nov 2016 10:37:14 +0800 Subject: [PATCH 4/4] Change notify --- app/components/Git/actions.js | 26 ++++++++++---------- app/components/Notification/actions.js | 34 +++++++++----------------- 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/app/components/Git/actions.js b/app/components/Git/actions.js index c610d781..80bad5d9 100644 --- a/app/components/Git/actions.js +++ b/app/components/Git/actions.js @@ -1,6 +1,6 @@ /* @flow weak */ import api from '../../api' -import { notify, error } from '../Notification/actions' +import { notify, NOTIFY_TYPE } from '../Notification/actions' import { showModal, dismissModal } from '../Modal/actions' export const GIT_STATUS = 'GIT_STATUS' @@ -118,8 +118,8 @@ export function createStash (message) { })) dispatch(dismissModal()) }).catch(res => { - dispatch(error({ - className: 'error', + dispatch(notify({ + notifyType: NOTIFY_TYPE.ERROR, message: res.msg, })) dispatch(dismissModal()) @@ -179,8 +179,8 @@ export function dropStash (stashRef, all) { })) getStashList()(dispatch) }).catch(res => { - dispatch(error({ - className: 'error', + dispatch(notify({ + notifyType: NOTIFY_TYPE.ERROR, message: 'Drop stash error.', })) }) @@ -193,8 +193,8 @@ export function applyStash ({stashRef, pop, applyIndex}) { })) dispatch(dismissModal()) }).catch(res => { - dispatch(error({ - className: 'error', + dispatch(notify({ + notifyType: NOTIFY_TYPE.ERROR, message: 'Apply stash error.', })) }) @@ -207,8 +207,8 @@ export function checkoutStash ({stashRef, branch}) { })) dispatch(dismissModal()) }).catch(res => { - dispatch(error({ - className: 'error', + dispatch(notify({ + notifyType: NOTIFY_TYPE.ERROR, message: 'Checkout stash error.', })) }) @@ -218,8 +218,8 @@ export function getCurrentBranch () { return dispatch => api.gitCurrentBranch().then(({ name }) => { dispatch(updateCurrentBranch({name})) }).catch(res => { - dispatch(error({ - className: 'error', + dispatch(notify({ + notifyType: NOTIFY_TYPE.ERROR, message: 'Get current branch error.', })) }) @@ -232,8 +232,8 @@ export function resetHead ({ref, resetType}) { })) dispatch(dismissModal()) }).catch(res => { - dispatch(error({ - className: 'error', + dispatch(notify({ + notifyType: NOTIFY_TYPE.ERROR, message: 'Reset error.', })) }) diff --git a/app/components/Notification/actions.js b/app/components/Notification/actions.js index a52f005c..b2e02089 100644 --- a/app/components/Notification/actions.js +++ b/app/components/Notification/actions.js @@ -12,6 +12,14 @@ export function addNotification (_notification) { onClick: () => dispatch({type: NOTIFICATION_REMOVE, notification}) } + let { notifyType } = _notification + if (notifyType === NOTIFY_TYPE.ERROR) { + defaultNotification = {...defaultNotification, ...{ + barStyle: { backgroundColor:'red' }, + actionStyle: { color:'white' } + }} + } + notification = {...defaultNotification, ..._notification} dispatch({ @@ -23,31 +31,11 @@ export function addNotification (_notification) { export const notify = addNotification -export function addErrorNotification (_notification) { - return dispatch => { - var notification, defaultNotification - - defaultNotification = { - message: '', - action: 'Dismiss', - key: Date.now(), - dismissAfter: 6000, - barStyle: {backgroundColor:'red'}, - actionStyle: {color:'white'}, - onClick: () => dispatch({type: NOTIFICATION_REMOVE, notification}) - } - - notification = {...defaultNotification, ..._notification} - - dispatch({ - type: NOTIFICATION_ADD, - notification - }) - } +export const NOTIFY_TYPE = { + ERROR: 'error', + INFO: 'info', } -export const error = addErrorNotification - export const NOTIFICATION_REMOVE = 'NOTIFICATION_REMOVE' export function removeNotification (notification) { return {