diff --git a/browser/src/actions/results.ts b/browser/src/actions/results.ts index 0d43248d..4f365b48 100644 --- a/browser/src/actions/results.ts +++ b/browser/src/actions/results.ts @@ -89,10 +89,6 @@ export const selectCommittedFile = (logEntry: LogEntry, committedFile: Committed export const closeCommitView = () => { // tslint:disable-next-line:no-any return async (dispatch: Dispatch, getState: () => RootState) => { - const state = getState(); - const url = getQueryUrl(state, 'log/clearSelection'); - // tslint:disable-next-line:no-backbone-get-set-outside-model - await axios.post(url); await dispatch(clearCommitSelection()); }; }; @@ -103,9 +99,6 @@ export const selectCommit = (hash?: string) => { if (hash) { await fetchCommit(dispatch, state, hash); } else { - const url = getQueryUrl(state, 'log/clearSelection'); - // tslint:disable-next-line:no-backbone-get-set-outside-model - await axios.get(url); await dispatch(clearCommitSelection()); } }; @@ -144,7 +137,9 @@ export const selectBranch = (branchName: string) => { // tslint:disable-next-line:no-any return (dispatch: Dispatch, getState: () => RootState) => { const state = getState(); - return fetchCommits(dispatch, state, 0, undefined, '', true, branchName); + state.logEntries.branch = state.settings.branchName = branchName; + + return fetchCommits(dispatch, state, 0, undefined, '', true); }; }; export const selectAuthor = (authorName: string) => { @@ -158,10 +153,12 @@ export const refresh = () => { // tslint:disable-next-line:no-any return (dispatch: Dispatch, getState: () => RootState) => { const state = getState(); + // update branches + fetchBranches(dispatch, state); return fetchCommits(dispatch, state, undefined, undefined, undefined, true); }; }; -export const getCommits = (id?: string) => { +export const getCommits = () => { // tslint:disable-next-line:no-any return (dispatch: Dispatch, getState: () => RootState) => { const state = getState(); @@ -197,6 +194,12 @@ function fetchCommits(dispatch: Dispatch, store: RootState, pageIndex?: num if (typeof branchName === 'string') { queryParts.push(`branch=${encodeURIComponent(branchName)}`); } + if (store.settings.branchName) { + queryParts.push(`branch=${encodeURIComponent(store.settings.branchName)}`); + } + if (store.settings.file) { + queryParts.push(`file=${encodeURIComponent(store.settings.file)}`); + } if (typeof searchText === 'string') { queryParts.push(`searchText=${encodeURIComponent(searchText)}`); } diff --git a/browser/src/components/Dialog/index.tsx b/browser/src/components/Dialog/index.tsx index e6187ea4..04be3aba 100644 --- a/browser/src/components/Dialog/index.tsx +++ b/browser/src/components/Dialog/index.tsx @@ -93,7 +93,7 @@ export default class Dialog extends React.Component { */ private handleKeyDown(e: React.KeyboardEvent) { - if (e.key === 'Enter') { + if (e.key === 'Enter' && !(e.currentTarget instanceof HTMLButtonElement)) { const buttonEl = ReactDOM.findDOMNode(this.buttonOk) as HTMLButtonElement; buttonEl.click(); } else if (e.key === 'Escape') { diff --git a/browser/src/components/Header/index.tsx b/browser/src/components/Header/index.tsx index a84c01ec..a9985837 100644 --- a/browser/src/components/Header/index.tsx +++ b/browser/src/components/Header/index.tsx @@ -2,13 +2,17 @@ import * as React from 'react'; import { Button } from 'react-bootstrap'; import { connect } from 'react-redux'; import * as ResultActions from '../../actions/results'; -import { RootState } from '../../reducers/index'; +import { RootState, BranchesState } from '../../reducers/index'; import Author from './author'; import Branch from './branch'; +import { ISettings } from '../../types'; +import { GoMarkGithub, GoBrowser } from 'react-icons/lib/go'; interface HeaderProps { isLoading?: boolean; searchText?: string; + branches?: BranchesState; + settings?: ISettings; search(searchText: string): void; clearSearch(): void; refresh(): void; @@ -24,6 +28,11 @@ export class Header extends React.Component { super(props); this.state = { isLoading: props.isLoading, searchText: props.searchText }; } + + componentWillReceiveProps(nextProps: HeaderProps): void { + this.setState({ isLoading: nextProps.isLoading, searchText: nextProps.searchText }); + } + private onSearch = () => { if (!this.state.isLoading) { this.setState({ isLoading: true }); @@ -44,9 +53,37 @@ export class Header extends React.Component { this.props.refresh(); } } - componentWillReceiveProps(nextProps: HeaderProps): void { - this.setState({ isLoading: nextProps.isLoading, searchText: nextProps.searchText }); + + private remoteLink() { + if (this.props.branches.length === 0) { + return (); + } + + const branchIndex = this.props.branches.findIndex(v => v.name === this.props.settings.branchName); + + if (branchIndex === -1) { + return (); + } + + const selectedBranch = this.props.branches[branchIndex]; + + if (!selectedBranch.remote) { + return (); + } + + switch (selectedBranch.remoteType) { + case 2: + return (); + case 3: + let m = selectedBranch.remote.match(/:(\w+)\/(.*)/); + if (m) { + return (); + } + } + + return (); } + private handleSearchChange = (e: React.ChangeEvent) => { this.setState({ isLoading: this.state.isLoading, searchText: e.target.value }); } @@ -79,19 +116,24 @@ export class Header extends React.Component { bsSize='small' disabled={this.state.isLoading} onClick={this.onRefresh}>Refresh + + {this.remoteLink()} + ); } } -function mapStateToProps(state: RootState): HeaderState { +function mapStateToProps(state: RootState): HeaderProps { const searchText = (state && state.logEntries.searchText) ? state.logEntries.searchText : ''; const isLoading = state && state.logEntries && state.logEntries.isLoading; return { isLoading, - searchText - }; + searchText, + branches: state.branches, + settings: state.settings + } as HeaderProps; } function mapDispatchToProps(dispatch) { diff --git a/browser/src/containers/App/index.tsx b/browser/src/containers/App/index.tsx index 1b76681e..5b94dfff 100644 --- a/browser/src/containers/App/index.tsx +++ b/browser/src/containers/App/index.tsx @@ -38,7 +38,7 @@ class App extends React.Component { return (
-
+