Skip to content

Commit 8129209

Browse files
author
ole
authored
Remove unnecessary libs from browser (#407)
* Removed jquery from browser * Slightly amended the dot positions of BranchGraph * reduced repeating calls on componentWillUpdate by removing LOGENTRY_ITEM_HEIGHT_CALCULATED action * Apply styles only for origin "null" * removed react-scroll as it was pretty much unused (or not properly working)
1 parent 4951e7c commit 8129209

File tree

13 files changed

+35
-257
lines changed

13 files changed

+35
-257
lines changed

browser/src/actions/results.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -255,26 +255,6 @@ function fetchAuthors(dispatch: Dispatch<any>, store: RootState) {
255255
console.error(err);
256256
});
257257
}
258-
// export const fetchLogEntries = (pageIndex: number, pageSize: number) => {
259-
// return (dispatch: Dispatch<any>, getState: () => RootState) => {
260-
// return axios.get(`/log?pageSize=${pageSize}&pageIndex=${pageIndex}`)
261-
// .then(result => {
262-
// debugger;
263-
// const x = getState();
264258

265-
// dispatch(addResults({ logEntries: result.data, pageIndex: pageIndex }));
266-
// })
267-
// .catch(err => {
268-
// debugger;
269-
// console.error('Result failed');
270-
// console.error(err);
271-
// });
272-
// };
273-
// };
259+
export const commitsRendered = createAction<number>(Actions.COMMITS_RENDERED);
274260

275-
export const logViewSizeCalculated = createAction<{ height: string; width: string }>(Actions.LOGVIEW_SIZE_CALCULATED);
276-
export const logEntryHeightCalculated = createAction<number>(Actions.LOGENTRY_ITEM_HEIGHT_CALCULATED);
277-
export const commitsRendered = createAction(Actions.COMMITS_RENDERED);
278-
// export const doSomethingWithCommit = createAction<LogEntry>(Actions.SELECT_COMMIT);
279-
// export const closeCommitView = createAction(Actions.CLOSE_COMMIT_VIEW);
280-
// export const closeCommittedFile = createAction(Actions.CLOSE_COMMIT_VIEW);

browser/src/components/LogView/BranchGraph/index.tsx

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import { RootState } from '../../../reducers';
66
type BranchGrapProps = {
77
hideGraph: boolean;
88
logEntries: LogEntry[];
9-
height?: string;
10-
width?: string;
119
itemHeight?: number;
1210
updateTick?: number;
1311
};
@@ -48,11 +46,10 @@ function drawGitGraph(svg: SVGSVGElement, content: HTMLElement, startAt: number,
4846
}
4947
svg.style.display = '';
5048
// Draw the graph
51-
const circleOffset = 0; //0.5 * logEntryHeight;
49+
const circleOffset = 0;
5250
const standardOffset = (0 + 0.5) * logEntryHeight;
5351
let currentY = (0 + 0.5) * logEntryHeight;
5452
let topMostY = (0 + 0.5) * logEntryHeight;
55-
// topMostY = (0 + 0.5) * logEntryHeight;
5653
let maxLeft = 0;
5754
let lastXOffset = 12;
5855
let maxXOffset = 12;
@@ -275,69 +272,31 @@ function drawGitGraph(svg: SVGSVGElement, content: HTMLElement, startAt: number,
275272
branch.path.setAttribute('d', branch.path.cmds + currentY);
276273
});
277274

278-
// Commented only fo debugging
279-
// circlesToAppend.forEach(svg.appendChild.bind(svg));
275+
// calculate the height
276+
if (entries.length > 0 && !isNaN(logEntryHeight)) {
277+
svg.setAttribute('height', (entries.length * logEntryHeight).toString());
278+
}
280279
}
281280

282281
class BrachGraph extends React.Component<BranchGrapProps> {
283282
componentWillReceiveProps(newProps: BranchGrapProps) {
284283
}
285284
componentWillUpdate(newProps: BranchGrapProps) {
286285
if (newProps.hideGraph) {
287-
this.grahWasHidden = true;
288286
drawGitGraph(this.svg, this.svg.nextSibling as HTMLElement, 0, newProps.itemHeight, [], true);
289287
return;
290288
}
291-
if (this.props.hideGraph && !newProps.hideGraph) {
292-
drawGitGraph(this.svg, this.svg.nextSibling as HTMLElement, 0, newProps.itemHeight, newProps.logEntries || []);
293-
}
294-
if (Array.isArray(newProps.logEntries) && newProps.logEntries.length === 0) {
295-
drawGitGraph(this.svg, this.svg.nextSibling as HTMLElement, 0, newProps.itemHeight, []);
296-
}
297-
if (!newProps.height || !newProps.width || !newProps.itemHeight || !Array.isArray(newProps.logEntries)) {
298-
return;
299-
}
300-
if (newProps.itemHeight > 0 && (!Array.isArray(newProps.logEntries) || newProps.logEntries.length === 0)) {
301-
drawGitGraph(this.svg, this.svg.nextSibling as HTMLElement, 0, newProps.itemHeight, newProps.logEntries);
302-
return;
303-
}
304-
if (newProps.itemHeight > 0 && newProps.itemHeight === this.props.itemHeight &&
305-
Array.isArray(this.props.logEntries) && this.props.logEntries.length > 0 &&
306-
newProps.updateTick === this.props.updateTick &&
307-
newProps.logEntries.length === this.props.logEntries.length &&
308-
newProps.logEntries[0].hash.full === this.props.logEntries[0].hash.full) {
309-
return;
310-
}
311289
if (newProps.updateTick === this.props.updateTick) {
312290
return;
313-
}
314-
if (!this.grahWasHidden && this.lastDrawnDetails && newProps.logEntries.length > 0 &&
315-
this.lastDrawnDetails.count === newProps.logEntries.length &&
316-
this.lastDrawnDetails.firstHash === newProps.logEntries[0].hash.full &&
317-
this.lastDrawnDetails.firstHash === newProps.logEntries[0].hash.full) {
318-
return;
319-
}
320-
321-
// Hack (dependant components).
322-
this.grahWasHidden = false;
323-
this.lastDrawnDetails = {
324-
count: newProps.logEntries.length,
325-
firstHash: newProps.logEntries.length > 0 ? newProps.logEntries[0].hash.full : '',
326-
lastHash: newProps.logEntries.length > 0 ? newProps.logEntries[newProps.logEntries.length - 1].hash.full : '',
327-
};
328-
329-
this.svg.setAttribute('height', newProps.height);
330-
this.svg.setAttribute('width', newProps.width);
291+
}
331292

332293
// Hack, first clear before rebuilding.
333294
// Remember, we will need to support apending results, as opposed to clearing page
334295
drawGitGraph(this.svg, this.svg.nextSibling as HTMLElement, 0, newProps.itemHeight, []);
335-
drawGitGraph(this.svg, this.svg.nextSibling as HTMLElement, 0, newProps.itemHeight, newProps.logEntries);
296+
drawGitGraph(this.svg, this.svg.nextSibling as HTMLElement, 0, newProps.itemHeight, newProps.logEntries);
336297
}
337-
private lastDrawnDetails: { firstHash: string, lastHash: string, count: number };
338-
private grahWasHidden: boolean;
298+
339299
private svg: SVGSVGElement;
340-
341300
render() {
342301
return (
343302
<svg className='commitGraph' ref={(ref) => this.svg = ref} xmlns='http://www.w3.org/2000/svg'></svg>
@@ -348,13 +307,12 @@ class BrachGraph extends React.Component<BranchGrapProps> {
348307
function mapStateToProps(state: RootState): BranchGrapProps {
349308
const hideGraph = (state && state.logEntries) && ((state.logEntries.searchText && state.logEntries.searchText.length > 0) ||
350309
(state.logEntries.file && state.logEntries.file.fsPath && state.logEntries.file.fsPath.length > 0) ||
351-
(state.logEntries.author && state.logEntries.author.length > 0));
310+
(state.logEntries.author && state.logEntries.author.length > 0) || state.logEntries.isLoading
311+
);
352312

353313
return {
354314
logEntries: state.logEntries.items,
355315
hideGraph,
356-
height: state.graph.height,
357-
width: state.graph.width,
358316
itemHeight: state.graph.itemHeight,
359317
updateTick: state.graph.updateTick
360318
};

browser/src/components/LogView/Commit/Author/index.tsx

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ function formatDateTime(locale: string, date?: Date) {
2929
return date.toLocaleString(undefined, dateOptions);
3030
}
3131
}
32-
// function formatDate(date: Date) {
33-
// const lang = process.env.language;
34-
// const dateOptions = { weekday: 'short', day: 'numeric', month: 'short', year: 'numeric', hour: 'numeric', minute: 'numeric' };
35-
// return date.toLocaleString(lang, dateOptions);
36-
// }
3732

3833
function mapStateToProps(state: RootState, wrapper: { result: ActionedDetails }) {
3934
return {
@@ -42,18 +37,6 @@ function mapStateToProps(state: RootState, wrapper: { result: ActionedDetails })
4237
};
4338
}
4439

45-
// function mapDispatchToProps(dispatch) {
46-
// return {
47-
// // ...bindActionCreators({ ...ResultActions }, dispatch),
48-
// // fetchData: (pageIndex: number) => dispatch(ResultActions.fetchLogEntries(pageIndex))
49-
// setSize: (size: Size) => dispatch(ResultActions.logViewSizeCalculated(size)),
50-
// setHeight: (height: number) => dispatch(ResultActions.logEntryHeightCalculated(height)),
51-
// commitsRendered: () => dispatch(ResultActions.commitsRendered()),
52-
// onViewCommit: (hash: string) => dispatch(ResultActions.viewCommit(hash)),
53-
// actionACommit: (logEntry: LogEntry) => dispatch(ResultActions.actionACommit(logEntry))
54-
// };
55-
// }
56-
5740
export default connect(
5841
mapStateToProps
5942
)(Author);

browser/src/components/LogView/Commit/Avatar/index.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,6 @@ function mapStateToProps(state: RootState, wrapper: { result: ActionedDetails })
2929
};
3030
}
3131

32-
// function mapDispatchToProps(dispatch) {
33-
// return {
34-
// // ...bindActionCreators({ ...ResultActions }, dispatch),
35-
// // fetchData: (pageIndex: number) => dispatch(ResultActions.fetchLogEntries(pageIndex))
36-
// setSize: (size: Size) => dispatch(ResultActions.logViewSizeCalculated(size)),
37-
// setHeight: (height: number) => dispatch(ResultActions.logEntryHeightCalculated(height)),
38-
// commitsRendered: () => dispatch(ResultActions.commitsRendered()),
39-
// onViewCommit: (hash: string) => dispatch(ResultActions.viewCommit(hash)),
40-
// actionACommit: (logEntry: LogEntry) => dispatch(ResultActions.actionACommit(logEntry))
41-
// };
42-
// }
43-
4432
export default connect(
4533
mapStateToProps
4634
)(Avatar);

browser/src/components/LogView/LogEntryList/index.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react';
2-
import { Element, Events, scrollSpy } from 'react-scroll';
32
import { LogEntry } from '../../../definitions';
43
import LogEntryView from '../LogEntry';
54

@@ -11,30 +10,27 @@ interface ResultProps {
1110

1211
export default class LogEntryList extends React.Component<ResultProps> {
1312
// private scrolled;
14-
private ref: HTMLDivElement;
13+
public ref: HTMLDivElement;
1514
public componentDidUpdate() {
1615

1716
}
1817
public componentDidMount() {
19-
scrollSpy.update();
18+
2019
}
2120
public componentWillUnmount() {
22-
Events.scrollEvent.remove('begin');
23-
Events.scrollEvent.remove('end');
21+
2422
}
2523
public render() {
2624
if (!Array.isArray(this.props.logEntries)) {
2725
return null;
2826
}
2927

3028
const results = this.props.logEntries.map(entry =>
31-
<Element name={entry.hash.full} className='myItem' key={entry.hash.full}>
3229
<LogEntryView
3330
key={entry.hash.full}
3431
logEntry={entry}
3532
onViewCommit={this.props.onViewCommit}
3633
onClick={this.props.onClick} />
37-
</Element>
3834
);
3935
return (
4036
// tslint:disable-next-line:react-this-binding-issue

browser/src/components/LogView/LogView/index.tsx

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as jQuery from 'jquery';
21
import * as React from 'react';
32
import { connect } from 'react-redux';
43
import * as ResultActions from '../../../actions/results';
@@ -7,11 +6,8 @@ import { RootState } from '../../../reducers';
76
import BranchGraph from '../BranchGraph';
87
import LogEntryList from '../LogEntryList';
98

10-
type Size = { height: string, width: string };
119
type LogViewProps = {
1210
logEntries: LogEntries;
13-
setSize: typeof ResultActions.logViewSizeCalculated;
14-
setHeight: typeof ResultActions.logEntryHeightCalculated;
1511
commitsRendered: typeof ResultActions.commitsRendered;
1612
onViewCommit: typeof ResultActions.selectCommit;
1713
actionACommit: typeof ResultActions.actionACommit;
@@ -26,41 +22,30 @@ class LogView extends React.Component<LogViewProps, LogViewState> {
2622
constructor(props?: LogViewProps, context?: any) {
2723
super(props, context);
2824
// this.state = { height: '', width: '', itemHeight: 0 };
25+
this.ref = React.createRef<LogEntryList>();
2926
}
30-
private calculatedHeight: string;
31-
private calculatedWidth: string;
32-
private calculatedItemHeight: number;
33-
private ref: HTMLDivElement;
27+
private ref: React.RefObject<LogEntryList>;
3428
public componentDidUpdate() {
35-
// const $ref = jQuery(this.ref);
36-
const $ref = jQuery(this.ref.children[1]);
37-
const height = $ref.outerHeight().toString();
38-
const width = $ref.outerWidth().toString();
39-
const $logEntry = jQuery('.log-entry').filter(':first');
40-
const logEntryHeight = $logEntry.outerHeight() + parseFloat($logEntry.css('marginTop'));
29+
const el = this.ref.current.ref;
4130

42-
if (!isNaN(logEntryHeight) && (!this.state || this.calculatedHeight !== height ||
43-
this.calculatedItemHeight !== logEntryHeight || this.calculatedWidth !== width)) {
44-
// this.setState({ height, width, itemHeight: logEntryHeight, commitsUpdatedTime: new Date().getTime() });
45-
this.props.setHeight(logEntryHeight);
46-
this.props.setSize({ height, width });
47-
this.props.commitsRendered();
31+
if (this.props.logEntries.selected) {
4832
return;
4933
}
5034

51-
if (!isNaN(logEntryHeight) && this.props.logEntries &&
52-
this.calculatedItemHeight > 0 &&
53-
Array.isArray(this.props.logEntries.items) && this.props.logEntries.items.length > 0) {
54-
this.props.commitsRendered();
35+
if(el.hasChildNodes() && this.props.logEntries && !this.props.logEntries.isLoading && !this.props.logEntries.isLoadingCommit && Array.isArray(this.props.logEntries.items) && this.props.logEntries.items.length > 0) {
36+
// use the total height to be more accurate in positioning the dots from BranchGraph
37+
const totalHeight = el.offsetHeight;
38+
const logEntryHeight = totalHeight / this.props.logEntries.items.length;
39+
this.props.commitsRendered(logEntryHeight);
5540
}
5641
}
5742

5843
public render() {
5944
return (
6045
// tslint:disable-next-line:react-this-binding-issue
61-
<div className='log-view' id='scrollCnt' ref={(ref) => this.ref = ref}>
62-
<BranchGraph ></BranchGraph>
63-
<LogEntryList logEntries={this.props.logEntries.items}
46+
<div className='log-view' id='scrollCnt'>
47+
<BranchGraph></BranchGraph>
48+
<LogEntryList ref={this.ref} logEntries={this.props.logEntries.items}
6449
onClick={this.onClick}
6550
onViewCommit={this.onViewCommit}></LogEntryList>
6651
</div>
@@ -79,22 +64,12 @@ function mapStateToProps(state: RootState, wrapper: { logEntries: LogEntries })
7964
logEntries: wrapper.logEntries
8065
};
8166
}
82-
// function mapStateToProps(state: RootState) {
83-
// return {
84-
// logEntries: {
85-
// items: state.logEntries.items,
86-
// count: state.logEntries.count
87-
// }
88-
// };
89-
// }
9067

9168
function mapDispatchToProps(dispatch) {
9269
return {
9370
// ...bindActionCreators({ ...ResultActions }, dispatch),
9471
// fetchData: (pageIndex: number) => dispatch(ResultActions.fetchLogEntries(pageIndex))
95-
setSize: (size: Size) => dispatch(ResultActions.logViewSizeCalculated(size)),
96-
setHeight: (height: number) => dispatch(ResultActions.logEntryHeightCalculated(height)),
97-
commitsRendered: () => dispatch(ResultActions.commitsRendered()),
72+
commitsRendered: (height: number) => dispatch(ResultActions.commitsRendered(height)),
9873
onViewCommit: (hash: string) => dispatch(ResultActions.selectCommit(hash)),
9974
actionACommit: (logEntry: LogEntry) => dispatch(ResultActions.actionACommit(logEntry))
10075
};

browser/src/constants/resultActions.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
export const CLEAR_RESULTS = 'CLEAR_RESULTS';
2-
export const LOGENTRY_ITEM_HEIGHT_CALCULATED = 'LOGENTRY_ITEM_HEIGHT_CALCULATED';
32
export const COMMITS_RENDERED = 'COMMITS_RENDERED';
43
export const SELECT_COMMITTED_FILE = 'SELECT_COMMITTED_FILE';
54
export const SELECT_COMMIT = 'SELECT_COMMIT';
6-
// export const CLOSE_COMMIT_VIEW = 'CLOSE_COMMIT_VIEW';
7-
export const LOGVIEW_SIZE_CALCULATED = 'LOGVIEW_SIZE_CALCULATED';
85
export const SET_APPEND_RESULTS = 'SET_APPEND_RESULTS';
96
export const ADD_RESULT = 'ADD_RESULT';
107
export const FETCHED_COMMITS = 'FETCHED_COMMITS';

browser/src/index.ejs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
window['configuration'] = <%- JSON.stringify(config) %>;
1212
1313
function receiveMessage(event) {
14+
if(event.origin !== "null") return;
15+
1416
console.log('Applying styles received from parent frame...');
1517
document.getElementById('_defaultStyles').innerHTML = ':root { ' + event.data + ' }';
1618
}

browser/src/main.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ div.appRoot {
171171
height:15px;
172172
width:15px;
173173
float:left;
174-
margin:0.2em 0.4em 0.2em 0;
174+
margin:0.2em 0.4em 0em 0em;
175175
}
176176

177177
.authorAndCommitInfoContainer {

browser/src/reducers/graph.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,7 @@ export interface IGraphState {
1010
const initialState: IGraphState = {};
1111

1212
export default handleActions<IGraphState, any>({
13-
// [Actions.CLEAR_RESULTS]: (state, action) => {
14-
// return { ...state, logEntries: undefined } as IGraphState;
15-
// },
16-
// [Actions.ADD_RESULTS]: (state, action: ReduxActions.Action<LogEntries>) => {
17-
// return { ...state, logEntries: action.payload } as IGraphState;
18-
// },
19-
[Actions.LOGENTRY_ITEM_HEIGHT_CALCULATED]: (state, action: ReduxActions.Action<number>) => {
20-
return { ...state, itemHeight: action.payload } as IGraphState;
13+
[Actions.COMMITS_RENDERED]: (state, action: ReduxActions.Action<number>) => {
14+
return { ...state, updateTick: new Date().getTime(), itemHeight: action.payload } as IGraphState;
2115
},
22-
[Actions.COMMITS_RENDERED]: (state, action: any) => {
23-
return { ...state, updateTick: new Date().getTime() } as IGraphState;
24-
},
25-
[Actions.LOGVIEW_SIZE_CALCULATED]: (state, action: ReduxActions.Action<{ height: string, widht: string }>) => {
26-
return { ...state, ...action.payload } as IGraphState;
27-
}
2816
}, initialState);

0 commit comments

Comments
 (0)