Skip to content

Commit

Permalink
mhutchie#462 Removed CI/CD column
Browse files Browse the repository at this point in the history
  • Loading branch information
keydepth committed Apr 30, 2021
1 parent 60c9477 commit 8657451
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 89 deletions.
7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -497,17 +497,12 @@
"Commit": {
"type": "boolean",
"title": "Visibility of the Commit column"
},
"CICD": {
"type": "boolean",
"title": "Visibility of the CI/CD Status column"
}
},
"default": {
"Date": true,
"Author": true,
"Commit": true,
"CICD": false
"Commit": true
},
"description": "An object specifying the default visibility of the Date, Author & Commit columns. Example: {\"Date\": true, \"Author\": true, \"Commit\": true}"
},
Expand Down
6 changes: 3 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ class Config {
*/
get defaultColumnVisibility(): DefaultColumnVisibility {
let obj: any = this.config.get('defaultColumnVisibility', {});
if (typeof obj === 'object' && obj !== null && typeof obj['Date'] === 'boolean' && typeof obj['Author'] === 'boolean' && typeof obj['Commit'] === 'boolean' && typeof obj['CICD'] === 'boolean') {
return { author: obj['Author'], commit: obj['Commit'], date: obj['Date'], cicd: obj['CICD'] };
if (typeof obj === 'object' && obj !== null && typeof obj['Date'] === 'boolean' && typeof obj['Author'] === 'boolean' && typeof obj['Commit'] === 'boolean') {
return { author: obj['Author'], commit: obj['Commit'], date: obj['Date'] };
} else {
return { author: true, commit: true, date: true, cicd: false };
return { author: true, commit: true, date: true };
}
}

Expand Down
1 change: 1 addition & 0 deletions src/extensionState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ export class ExtensionState extends Disposable {
* Add a new cicd to the cache of cicds known to Git Graph.
* @param repo The repository that the cicd is used in.
* @param hash The hash identifying the cicd commit.
* @param id The identifying that the cicd job.
* @param cicdDataSave The CICDDataSave.
*/
public saveCICD(repo: string, hash: string, id: string, cicdDataSave: CICDDataSave) {
Expand Down
1 change: 0 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ export interface DefaultColumnVisibility {
readonly date: boolean;
readonly author: boolean;
readonly commit: boolean;
readonly cicd: boolean;
}

export interface DialogDefaults {
Expand Down
34 changes: 11 additions & 23 deletions tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,50 +726,38 @@ describe('Config', () => {
describe('defaultColumnVisibility', () => {
it('Should successfully parse the configuration value (Date column disabled)', () => {
// Setup
vscode.mockExtensionSettingReturnValue('defaultColumnVisibility', { Date: false, Author: true, Commit: true, CICD: true });
vscode.mockExtensionSettingReturnValue('defaultColumnVisibility', { Date: false, Author: true, Commit: true });

// Run
const value = config.defaultColumnVisibility;

// Assert
expect(workspaceConfiguration.get).toBeCalledWith('defaultColumnVisibility', {});
expect(value).toStrictEqual({ date: false, author: true, commit: true, cicd: true });
expect(value).toStrictEqual({ date: false, author: true, commit: true });
});

it('Should successfully parse the configuration value (Author column disabled)', () => {
// Setup
vscode.mockExtensionSettingReturnValue('defaultColumnVisibility', { Date: true, Author: false, Commit: true, CICD: true });
vscode.mockExtensionSettingReturnValue('defaultColumnVisibility', { Date: true, Author: false, Commit: true });

// Run
const value = config.defaultColumnVisibility;

// Assert
expect(workspaceConfiguration.get).toBeCalledWith('defaultColumnVisibility', {});
expect(value).toStrictEqual({ date: true, author: false, commit: true, cicd: true });
expect(value).toStrictEqual({ date: true, author: false, commit: true });
});

it('Should successfully parse the configuration value (Commit column disabled)', () => {
// Setup
vscode.mockExtensionSettingReturnValue('defaultColumnVisibility', { Date: true, Author: true, Commit: false, CICD: true });
vscode.mockExtensionSettingReturnValue('defaultColumnVisibility', { Date: true, Author: true, Commit: false });

// Run
const value = config.defaultColumnVisibility;

// Assert
expect(workspaceConfiguration.get).toBeCalledWith('defaultColumnVisibility', {});
expect(value).toStrictEqual({ date: true, author: true, commit: false, cicd: true });
});

it('Should successfully parse the configuration value (CI/CD Status column disabled)', () => {
// Setup
vscode.mockExtensionSettingReturnValue('defaultColumnVisibility', { Date: true, Author: true, Commit: true, CICD: false });

// Run
const value = config.defaultColumnVisibility;

// Assert
expect(workspaceConfiguration.get).toBeCalledWith('defaultColumnVisibility', {});
expect(value).toStrictEqual({ date: true, author: true, commit: true, cicd: false });
expect(value).toStrictEqual({ date: true, author: true, commit: false });
});

it('Should return the default value when the configuration value is invalid (not an object)', () => {
Expand All @@ -781,7 +769,7 @@ describe('Config', () => {

// Assert
expect(workspaceConfiguration.get).toBeCalledWith('defaultColumnVisibility', {});
expect(value).toStrictEqual({ date: true, author: true, commit: true, cicd: false });
expect(value).toStrictEqual({ date: true, author: true, commit: true });
});

it('Should return the default value when the configuration value is invalid (NULL)', () => {
Expand All @@ -793,19 +781,19 @@ describe('Config', () => {

// Assert
expect(workspaceConfiguration.get).toBeCalledWith('defaultColumnVisibility', {});
expect(value).toStrictEqual({ date: true, author: true, commit: true, cicd: false });
expect(value).toStrictEqual({ date: true, author: true, commit: true });
});

it('Should return the default value when the configuration value is invalid (column value is not a boolean)', () => {
// Setup
vscode.mockExtensionSettingReturnValue('defaultColumnVisibility', { Date: true, Author: true, Commit: 5, CICD: true });
vscode.mockExtensionSettingReturnValue('defaultColumnVisibility', { Date: true, Author: true, Commit: 5 });

// Run
const value = config.defaultColumnVisibility;

// Assert
expect(workspaceConfiguration.get).toBeCalledWith('defaultColumnVisibility', {});
expect(value).toStrictEqual({ date: true, author: true, commit: true, cicd: false });
expect(value).toStrictEqual({ date: true, author: true, commit: true });
});

it('Should return the default value when the configuration value is not set', () => {
Expand All @@ -814,7 +802,7 @@ describe('Config', () => {

// Assert
expect(workspaceConfiguration.get).toBeCalledWith('defaultColumnVisibility', {});
expect(value).toStrictEqual({ date: true, author: true, commit: true, cicd: false });
expect(value).toStrictEqual({ date: true, author: true, commit: true });
});
});

Expand Down
54 changes: 7 additions & 47 deletions web/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ class GitGraphView {

this.finaliseLoadCommits();
this.requestAvatars(avatarsNeeded);
this.requestCICDs();
}

private finaliseLoadCommits() {
Expand Down Expand Up @@ -526,12 +525,6 @@ class GitGraphView {
}
this.cicdDatas[repo][hash] = cicdDataSaves;
this.saveState();
let cicdElems = <HTMLCollectionOf<HTMLElement>>document.getElementsByClassName('cicd');
for (let i = 0; i < cicdElems.length; i++) {
if (cicdElems[i].dataset.hash === hash) {
cicdElems[i].innerHTML = this.getCicdHtml(cicdDataSaves);
}
}
let cicdDetailElems = <HTMLCollectionOf<HTMLElement>>document.getElementsByClassName('cicdDetail');
for (let i = 0; i < cicdDetailElems.length; i++) {
if (cicdDetailElems[i].dataset.hash === hash) {
Expand Down Expand Up @@ -744,16 +737,6 @@ class GitGraphView {
}
}

private requestCICDs() {
if (typeof this.currentRepo === 'string' && typeof this.gitRepos[this.currentRepo] !== 'undefined') {
let cicdConfigs = this.gitRepos[this.currentRepo].cicdConfigs;
if (cicdConfigs !== null && cicdConfigs.length >= 1) {
this.commits.forEach(commit => {
sendMessage({ command: 'fetchCICD', repo: this.currentRepo, hash: commit.hash });
});
}
}
}

/* State */

Expand Down Expand Up @@ -801,7 +784,7 @@ class GitGraphView {
}

private saveColumnWidths(columnWidths: GG.ColumnWidth[]) {
this.gitRepos[this.currentRepo].columnWidths = [columnWidths[0], columnWidths[2], columnWidths[3], columnWidths[4], columnWidths[5]];
this.gitRepos[this.currentRepo].columnWidths = [columnWidths[0], columnWidths[2], columnWidths[3], columnWidths[4]];
this.saveRepoState();
}

Expand Down Expand Up @@ -886,7 +869,6 @@ class GitGraphView {
(colVisibility.date ? '<th class="tableColHeader dateCol" data-col="2">Date</th>' : '') +
(colVisibility.author ? '<th class="tableColHeader authorCol" data-col="3">Author</th>' : '') +
(colVisibility.commit ? '<th class="tableColHeader" data-col="4">Commit</th>' : '') +
(colVisibility.cicd ? '<th class="tableColHeader" data-col="5">CI/CD</th>' : '') +
'</tr>';

for (let i = 0; i < this.commits.length; i++) {
Expand Down Expand Up @@ -935,9 +917,6 @@ class GitGraphView {
(colVisibility.date ? '<td class="dateCol text" title="' + date.title + '">' + date.formatted + '</td>' : '') +
(colVisibility.author ? '<td class="authorCol text" title="' + escapeHtml(commit.author + ' <' + commit.email + '>') + '">' + (this.config.fetchAvatars ? '<span class="avatar" data-email="' + escapeHtml(commit.email) + '">' + (typeof this.avatars[commit.email] === 'string' ? '<img class="avatarImg" src="' + this.avatars[commit.email] + '">' : '') + '</span>' : '') + escapeHtml(commit.author) + '</td>' : '') +
(colVisibility.commit ? '<td class="text" title="' + escapeHtml(commit.hash) + '">' + abbrevCommit(commit.hash) + '</td>' : '') +
(colVisibility.cicd ? '<td class="cicdCol">' + '<span class="cicd" data-hash="' + escapeHtml(commit.hash) + '">' +
((typeof this.cicdDatas[this.currentRepo] === 'object' && typeof this.cicdDatas[this.currentRepo][commit.hash] === 'object') ? this.getCicdHtml(this.cicdDatas[this.currentRepo][commit.hash]) : '*') +
'</span>' + '</td>' : '') +
'</tr>';
}
this.tableElem.innerHTML = '<table>' + html + '</table>';
Expand Down Expand Up @@ -995,8 +974,7 @@ class GitGraphView {
document.getElementById('uncommittedChanges')!.innerHTML = '<td></td><td><b>' + escapeHtml(this.commits[0].message) + '</b></td>' +
(colVisibility.date ? '<td class="dateCol text" title="' + date.title + '">' + date.formatted + '</td>' : '') +
(colVisibility.author ? '<td class="authorCol text" title="* <>">*</td>' : '') +
(colVisibility.commit ? '<td class="text" title="*">*</td>' : '') +
(colVisibility.cicd ? '<td class="text" title="*">*</td>' : '');
(colVisibility.commit ? '<td class="text" title="*">*</td>' : '');
}

private renderFetchButton() {
Expand Down Expand Up @@ -1765,10 +1743,10 @@ class GitGraphView {
let cWidths = this.gitRepos[this.currentRepo].columnWidths;
if (cWidths === null) { // Initialise auto column layout if it is the first time viewing the repo.
let defaults = this.config.defaultColumnVisibility;
columnWidths = [COLUMN_AUTO, COLUMN_AUTO, defaults.date ? COLUMN_AUTO : COLUMN_HIDDEN, defaults.author ? COLUMN_AUTO : COLUMN_HIDDEN, defaults.commit ? COLUMN_AUTO : COLUMN_HIDDEN, defaults.cicd ? COLUMN_AUTO : COLUMN_HIDDEN];
columnWidths = [COLUMN_AUTO, COLUMN_AUTO, defaults.date ? COLUMN_AUTO : COLUMN_HIDDEN, defaults.author ? COLUMN_AUTO : COLUMN_HIDDEN, defaults.commit ? COLUMN_AUTO : COLUMN_HIDDEN];
this.saveColumnWidths(columnWidths);
} else {
columnWidths = [cWidths[0], COLUMN_AUTO, cWidths[1], cWidths[2], cWidths[3], cWidths[4]];
columnWidths = [cWidths[0], COLUMN_AUTO, cWidths[1], cWidths[2], cWidths[3]];
}

if (columnWidths[0] !== COLUMN_AUTO) {
Expand Down Expand Up @@ -1883,12 +1861,6 @@ class GitGraphView {
visible: true,
checked: columnWidths[4] !== COLUMN_HIDDEN,
onClick: () => toggleColumnState(4, 80)
},
{
title: 'CI/CD Status',
visible: true,
checked: columnWidths[5] !== COLUMN_HIDDEN,
onClick: () => toggleColumnState(5, 80)
}
],
[
Expand All @@ -1915,31 +1887,19 @@ class GitGraphView {
});
}

public setColumnVisibility(column: number, columnWidth: number) {
let colWidths = this.gitRepos[this.currentRepo].columnWidths;
if (colWidths !== null) {
if (column < colWidths.length) {
colWidths[column] = columnWidth === COLUMN_HIDDEN ? COLUMN_HIDDEN : (colWidths[0] === COLUMN_AUTO ? COLUMN_AUTO : columnWidth - COLUMN_LEFT_RIGHT_PADDING);
let columnWidths = [colWidths[0], COLUMN_AUTO, colWidths[1], colWidths[2], colWidths[3], colWidths[4]];
this.saveColumnWidths(columnWidths);
this.render();
}
}
}

public getColumnVisibility() {
let colWidths = this.gitRepos[this.currentRepo].columnWidths;
if (colWidths !== null) {
return { date: colWidths[1] !== COLUMN_HIDDEN, author: colWidths[2] !== COLUMN_HIDDEN, commit: colWidths[3] !== COLUMN_HIDDEN, cicd: colWidths[4] !== COLUMN_HIDDEN };
return { date: colWidths[1] !== COLUMN_HIDDEN, author: colWidths[2] !== COLUMN_HIDDEN, commit: colWidths[3] !== COLUMN_HIDDEN };
} else {
let defaults = this.config.defaultColumnVisibility;
return { date: defaults.date, author: defaults.author, commit: defaults.commit, cicd: defaults.cicd };
return { date: defaults.date, author: defaults.author, commit: defaults.commit };
}
}

private getNumColumns() {
let colVisibility = this.getColumnVisibility();
return 2 + (colVisibility.date ? 1 : 0) + (colVisibility.author ? 1 : 0) + (colVisibility.commit ? 1 : 0) + (colVisibility.cicd ? 1 : 0);
return 2 + (colVisibility.date ? 1 : 0) + (colVisibility.author ? 1 : 0) + (colVisibility.commit ? 1 : 0);
}

/**
Expand Down
5 changes: 0 additions & 5 deletions web/settingsWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,11 +680,6 @@ class SettingsWidget {
if (this.currentRepo === null) return;
this.view.saveRepoStateValue(this.currentRepo, 'cicdConfigs', config);
this.render();
if (config?.length !== 0) {
this.view.setColumnVisibility(4, 80);
} else {
this.view.setColumnVisibility(4, COLUMN_HIDDEN);
}
}

/**
Expand Down
5 changes: 1 addition & 4 deletions web/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,7 @@ code{
#commitTable tr.commit td{
cursor:pointer;
}
#commitTable tr.commit td.cicdCol{
cursor:pointer;
overflow: visible;
}

#commitTable tr.commit.current span.description .text{
font-weight:bold;
}
Expand Down

0 comments on commit 8657451

Please sign in to comment.