Skip to content

Commit

Permalink
#132 Add sticky header option
Browse files Browse the repository at this point in the history
  • Loading branch information
bendera committed Oct 12, 2020
1 parent f10111f commit 362f65d
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 4 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@
},
"description": "An object specifying the default visibility of the Date, Author & Commit columns. Example: {\"Date\": true, \"Author\": true, \"Commit\": true}"
},
"git-graph.stickyHeader": {
"type": "boolean",
"default": true,
"description": "Keeps the header visible when the view is scrolled"
},
"git-graph.dialog.addTag.pushToRemote": {
"type": "boolean",
"default": false,
Expand Down
7 changes: 7 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,13 @@ class Config {
return !!this.config.get('showStatusBarItem', true);
}

/**
* Get the value of the `git-graph.stickyHeader` Extension Setting.
*/
get stickyHeader() {
return !!this.config.get('stickyHeader', true);
}

/**
* Get the value of the `git-graph.tabIconColourTheme` Extension Setting.
*/
Expand Down
4 changes: 3 additions & 1 deletion src/gitGraphView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ export class GitGraphView extends Disposable {
customPullRequestProviders: config.customPullRequestProviders,
dateFormat: config.dateFormat,
defaultColumnVisibility: config.defaultColumnVisibility,
stickyHeader: config.stickyHeader,
dialogDefaults: config.dialogDefaults,
enhancedAccessibility: config.enhancedAccessibility,
fetchAndPrune: config.fetchAndPrune,
Expand Down Expand Up @@ -628,9 +629,10 @@ export class GitGraphView extends Disposable {
<p class="unableToLoadMessage">${UNABLE_TO_FIND_GIT_MSG}</p>
</body>`;
} else if (numRepos > 0) {
const stickyClassAttr = initialState.config.stickyHeader ? ' class="sticky"' : '';
body = `<body>
<div id="view" tabindex="-1">
<div id="controls">
<div id="controls"${stickyClassAttr}>
<span id="repoControl"><span class="unselectable">Repo: </span><div id="repoDropdown" class="dropdown"></div></span>
<span id="branchControl"><span class="unselectable">Branches: </span><div id="branchDropdown" class="dropdown"></div></span>
<label id="showRemoteBranchesControl"><input type="checkbox" id="showRemoteBranchesCheckbox" tabindex="-1"><span class="customCheckbox"></span>Show Remote Branches</label>
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export interface GitGraphViewConfig {
readonly repoDropdownOrder: RepoDropdownOrder;
readonly showRemoteBranches: boolean;
readonly showTags: boolean;
readonly stickyHeader: boolean;
}

export interface GitGraphViewGlobalState {
Expand Down
62 changes: 62 additions & 0 deletions tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3878,4 +3878,66 @@ describe('Config', () => {
expect(value).toBe(false);
});
});

describe('stickyHeader', () => {
it('Should return TRUE when the configuration value is TRUE', () => {
// Setup
workspaceConfiguration.get.mockReturnValueOnce(true);

// Run
const value = config.stickyHeader;

// Assert
expect(workspaceConfiguration.get).toBeCalledWith('stickyHeader', true);
expect(value).toBe(true);
});

it('Should return FALSE when the configuration value is FALSE', () => {
// Setup
workspaceConfiguration.get.mockReturnValueOnce(false);

// Run
const value = config.stickyHeader;

// Assert
expect(workspaceConfiguration.get).toBeCalledWith('stickyHeader', true);
expect(value).toBe(false);
});

it('Should return TRUE when the configuration value is truthy', () => {
// Setup
workspaceConfiguration.get.mockReturnValueOnce(5);

// Run
const value = config.stickyHeader;

// Assert
expect(workspaceConfiguration.get).toBeCalledWith('stickyHeader', true);
expect(value).toBe(true);
});

it('Should return FALSE when the configuration value is falsy', () => {
// Setup
workspaceConfiguration.get.mockReturnValueOnce(0);

// Run
const value = config.stickyHeader;

// Assert
expect(workspaceConfiguration.get).toBeCalledWith('stickyHeader', true);
expect(value).toBe(false);
});

it('Should return the default value (TRUE) when the configuration value is not set', () => {
// Setup
workspaceConfiguration.get.mockImplementationOnce((_, defaultValue) => defaultValue);

// Run
const value = config.stickyHeader;

// Assert
expect(workspaceConfiguration.get).toBeCalledWith('stickyHeader', true);
expect(value).toBe(true);
});
});
});
3 changes: 2 additions & 1 deletion web/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,8 @@ class GitGraphView {
markdown: this.config.markdown
});

let html = '<tr id="tableColHeaders"><th id="tableHeaderGraphCol" class="tableColHeader" data-col="0">Graph</th><th class="tableColHeader" data-col="1">Description</th>' +
const stickyClassAttr = this.config.stickyHeader ? ' class="sticky"' : '';
let html = '<tr id="tableColHeaders"' + stickyClassAttr + '><th id="tableHeaderGraphCol" class="tableColHeader" data-col="0">Graph</th><th class="tableColHeader" data-col="1">Description</th>' +
(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>' : '') +
Expand Down
17 changes: 15 additions & 2 deletions web/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ body.selection-background-color-exists ::selection{
padding:0 4px;
}
#commitTable th{
border-bottom:1px solid rgba(128,128,128,0.5);
border-bottom:1px solid transparent;
box-shadow: 0 1px 0 rgba(128,128,128,0.5);
line-height:18px;
padding:6px 12px;
}
Expand Down Expand Up @@ -273,6 +274,12 @@ body.selection-background-color-exists ::selection{
.tableColHeader{
position:relative;
}
#tableColHeaders.sticky .tableColHeader {
position: sticky;
top: 41px;
z-index: 3;
background-color: var(--vscode-editor-background);
}
.resizeCol{
position:absolute;
top:0;
Expand Down Expand Up @@ -759,11 +766,12 @@ body.tagLabelsRightAligned .gitRef.tag{

#controls{
display:block;
position:relative;
position: relative;
left:0;
right:0;
top:0;
padding:4px 132px 4px 0;
background-color: var(--vscode-editor-background);
border-bottom:1px solid rgba(128,128,128,0.5);
line-height:32px;
text-align:center;
Expand All @@ -773,6 +781,11 @@ body.tagLabelsRightAligned .gitRef.tag{
user-select:none;
}

#controls.sticky {
position:sticky;
z-index: 4;
}

#repoControl, #branchControl, #showRemoteBranchesControl{
display:inline-block;
white-space:nowrap;
Expand Down

0 comments on commit 362f65d

Please sign in to comment.