Skip to content

Commit

Permalink
Replace git command with git extension api (1/2) (#410)
Browse files Browse the repository at this point in the history
* Very first try to get rid of the iframe
* Resolve redirects to properly match server url
* Other improvements
* removeTag command and use it in TagRef component
* recovered selection
* Replaced several git commands with git extension API
* Updated CHANGELOG.md
* Version 0.5.0
* corrected the use of createGitService
* Slightly amended repo index
* provide repository picker for first use
* Provide a default style when debugging in external browser
* Removed workspace StateStore while applying more git extension features
* getGitRoots is no longer needed in IGitService
* Corrected removeTag command
* Fixed doAction to match new gitServiceFactory
* getCommit does not require id as argument
* Moved ISettings to server source (selectedBranchName => branchName)
* Fixed Git History command does nothing when reopening
* Corrected ISettings property branchName
* Include upstream url and type when calling getBranches
* Display external link to bitbucket or github when upstream is defined for branch
* Fixed dialog button fired twice when pressing enter key
* Slightly amended ui and debug logging
  • Loading branch information
ole authored Feb 8, 2020
1 parent 0e19aaf commit e8becc4
Show file tree
Hide file tree
Showing 40 changed files with 353 additions and 666 deletions.
21 changes: 12 additions & 9 deletions browser/src/actions/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ export const selectCommittedFile = (logEntry: LogEntry, committedFile: Committed
export const closeCommitView = () => {
// tslint:disable-next-line:no-any
return async (dispatch: Dispatch<any>, 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());
};
};
Expand All @@ -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());
}
};
Expand Down Expand Up @@ -144,7 +137,9 @@ export const selectBranch = (branchName: string) => {
// tslint:disable-next-line:no-any
return (dispatch: Dispatch<any>, 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) => {
Expand All @@ -158,10 +153,12 @@ export const refresh = () => {
// tslint:disable-next-line:no-any
return (dispatch: Dispatch<any>, 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<any>, getState: () => RootState) => {
const state = getState();
Expand Down Expand Up @@ -197,6 +194,12 @@ function fetchCommits(dispatch: Dispatch<any>, 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)}`);
}
Expand Down
2 changes: 1 addition & 1 deletion browser/src/components/Dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default class Dialog extends React.Component<DialogProps, DialogState> {
*/
private handleKeyDown(e: React.KeyboardEvent<any>)
{
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') {
Expand Down
54 changes: 48 additions & 6 deletions browser/src/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,6 +28,11 @@ export class Header extends React.Component<HeaderProps, HeaderState> {
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 });
Expand All @@ -44,9 +53,37 @@ export class Header extends React.Component<HeaderProps, HeaderState> {
this.props.refresh();
}
}
componentWillReceiveProps(nextProps: HeaderProps): void {
this.setState({ isLoading: nextProps.isLoading, searchText: nextProps.searchText });

private remoteLink() {
if (this.props.branches.length === 0) {
return (<span></span>);
}

const branchIndex = this.props.branches.findIndex(v => v.name === this.props.settings.branchName);

if (branchIndex === -1) {
return (<span></span>);
}

const selectedBranch = this.props.branches[branchIndex];

if (!selectedBranch.remote) {
return (<span></span>);
}

switch (selectedBranch.remoteType) {
case 2:
return (<a className='hint--right hint--rounded hint--bounce' aria-label='Open repository on Github' href={selectedBranch.remote.replace(/\.git$/, '') + '/tree/' + encodeURI(selectedBranch.name)}><GoMarkGithub /></a>);
case 3:
let m = selectedBranch.remote.match(/:(\w+)\/(.*)/);
if (m) {
return (<a className='hint--right hint--rounded hint--bounce' aria-label='Open repository on Bitbucket' href={'https://bitbucket.org/' + m[1] + '/' + m[2] + '/src/' + encodeURI(selectedBranch.name) }><GoBrowser /></a>);
}
}

return (<span></span>);
}

private handleSearchChange = (e: React.ChangeEvent<HTMLInputElement>) => {
this.setState({ isLoading: this.state.isLoading, searchText: e.target.value });
}
Expand Down Expand Up @@ -79,19 +116,24 @@ export class Header extends React.Component<HeaderProps, HeaderState> {
bsSize='small'
disabled={this.state.isLoading}
onClick={this.onRefresh}>Refresh</Button>
<span style={{display: 'inline-block', marginLeft: '1em', fontSize: '130%', verticalAlign: 'middle'}}>
{this.remoteLink()}
</span>
</header>);
}
}

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) {
Expand Down
2 changes: 1 addition & 1 deletion browser/src/containers/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class App extends React.Component<AppProps, AppState> {
return (
<div className='appRootParent'>
<div className='appRoot'>
<Header></Header >
<Header></Header>
<LogView logEntries={ this.props.logEntries }></LogView>
<Footer
canGoBack={ this.props.logEntries.pageIndex > 0 }
Expand Down
103 changes: 0 additions & 103 deletions browser/src/definitions.ts
Original file line number Diff line number Diff line change
@@ -1,104 +1 @@
export * from '../src/types';
import { BranchSelection } from '../src/types';
// export interface IUri {
// /**
// * Path is the `/some/path` part of `http://www.msft.com/some/path?query#fragment`.
// */
// readonly path: string;

// /**
// * The string representing the corresponding file system path of this Uri.
// *
// * Will handle UNC paths and normalize windows drive letters to lower-case. Also
// * uses the platform specific path separator. Will *not* validate the path for
// * invalid characters and semantics. Will *not* look at the scheme of this Uri.
// */
// readonly fsPath: string;
// }

// export enum RefType {
// Head,
// RemoteHead,
// Tag
// }
// export interface Ref {
// type: RefType;
// name?: string;
// }
// export interface Remote {
// name: string;
// url: string;
// }

// export interface BranchType extends Ref {
// upstream?: string;
// ahead?: number;
// behind?: number;
// }

// export interface CommittedFile {
// uri: IUri;
// oldUri?: IUri;
// oldRelativePath?: string;
// relativePath: string;
// status: Status;
// additions?: number;
// deletions?: number;
// }

// /////////////////////////////////////////////////////////
// export interface ActionedDetails {
// name: string;
// email: string;
// date: Date;
// localisedDate: string;
// }
// export interface LogEntries {
// items: LogEntry[];
// count: number;
// }
// export interface LogEntry {
// author?: ActionedDetails;
// committer?: ActionedDetails;
// parents: Hash[];
// hash: Hash;
// tree: Hash;
// refs: Ref[];
// subject: string;
// body: string;
// notes: string;
// committedFiles?: CommittedFile[];
// isLastCommit?: boolean;
// isThisLastCommitMerged?: boolean;
// }

// export interface CherryPickEntry {
// branch: string;
// hash: string;
// }

// export interface Hash {
// full: string;
// short: string;
// }

// export enum Status {
// Modified,
// Added,
// Deleted,
// Renamed,
// Copied
// }

// export enum Branch {
// All = 1,
// Current = 2
// }
export interface ISettings {
selectedBranchType?: BranchSelection;
selectedBranchName?: string;
pageIndex?: number;
searchText?: string;
file?: string;
id?: string;
}
2 changes: 1 addition & 1 deletion browser/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ ReactDOM.render(
document.getElementById('root')
);

store.dispatch(ResultActions.getCommits(defaultSettings.id));
store.dispatch(ResultActions.getCommits());
store.dispatch(ResultActions.getBranches());
store.dispatch(ResultActions.getAuthors());
2 changes: 1 addition & 1 deletion browser/src/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ header input, header button {

div.details-view-cnt {
position: fixed !important;
background: var(--vscode-editor-background);
background-color: var(--vscode-editor-background);
border-top-width: 1px;
border-top-style: solid;
border-top-color: var(--vscode-editorGroup-border);
Expand Down
2 changes: 1 addition & 1 deletion browser/src/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type LogEntriesState = LogEntriesResponse & {
isLoadingCommit: boolean;
};

export type BranchesState = { name: string; current: boolean }[];
export type BranchesState = { name: string; current: boolean, remote: string, remoteType: number }[];
export type AuthorsState = ActionedUser[];
export type AvatarsState = Avatar[];
export type RootState = {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "githistory",
"displayName": "Git History",
"description": "View git log, file history, compare branches or commits",
"version": "0.4.17",
"version": "0.5.0",
"publisher": "donjayamanne",
"author": {
"name": "Don Jayamanne",
Expand Down Expand Up @@ -353,7 +353,7 @@
},
"gitHistory.logLevel": {
"type": "string",
"default": "None",
"default": "Info",
"enum": [
"None",
"Info",
Expand Down
2 changes: 0 additions & 2 deletions src/adapter/parsers/refs/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ export * from './types';
import { injectable, multiInject } from 'inversify';
import { ILogService } from '../../../common/types';
import { Ref } from '../../../types';
// import { TYPES } from '../constants';
// import * as TYPES from '../types';
import { IRefsParser } from '../types';
import { IRefParser } from './types';

Expand Down
Loading

0 comments on commit e8becc4

Please sign in to comment.