Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filetree on left of diff view #21012

Merged
merged 29 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5ae314d
Add filelist on left of diff view
sebastian-sauer Aug 31, 2022
4f2ea0a
Hide file tree on small screens
sebastian-sauer Aug 31, 2022
1dd45c8
Use ellipsis class and overflow auto
sebastian-sauer Aug 31, 2022
6706cf8
Use vue and create a tree layout for diff files
sebastian-sauer Sep 1, 2022
fcd9d1a
Merge remote-tracking branch 'origin/main' into feature/18192_pr_tree…
sebastian-sauer Sep 2, 2022
ce0b4ec
Rework vue component and add toggle button
sebastian-sauer Sep 2, 2022
a6a0761
Only pass needed infos to vue template
sebastian-sauer Sep 2, 2022
6d53226
Fix styling and overflow
sebastian-sauer Sep 2, 2022
e1ff913
Hover styles and some padding improvements
sebastian-sauer Sep 2, 2022
2651860
Converted file list to vue component and fix show more button
sebastian-sauer Sep 4, 2022
4bdcb2d
Set initial css width of diff to 100%
sebastian-sauer Sep 4, 2022
de2f3c9
Merge remote-tracking branch 'origin/main' into feature/18192_pr_tree…
sebastian-sauer Sep 4, 2022
327fd74
Remove unused style from difffiletree
sebastian-sauer Sep 4, 2022
50ecb2f
Merge folders containing only folders
sebastian-sauer Sep 6, 2022
f5f2daa
Merge branch 'main' into feature/18192_pr_tree_view
sebastian-sauer Sep 6, 2022
5469b99
Merge remote-tracking branch 'origin/main' into feature/18192_pr_tree…
sebastian-sauer Sep 22, 2022
f0080ab
Add comments to js code
sebastian-sauer Sep 22, 2022
902a5bc
Merge remote-tracking branch 'fork/feature/18192_pr_tree_view' into f…
sebastian-sauer Sep 22, 2022
52475b6
Remove inline javascript and create click listener
sebastian-sauer Sep 22, 2022
834b592
isolate DiffFileList related code into its component
wxiaoguang Sep 26, 2022
b6748c1
use flex instead of #diff-file-tree[style*='display: block'] ~ #diff-…
wxiaoguang Sep 26, 2022
c013fcc
fine tune
wxiaoguang Sep 26, 2022
6763545
reformat
wxiaoguang Sep 26, 2022
e5ebc6d
fix lint
wxiaoguang Sep 26, 2022
a8891d2
make code more readable
wxiaoguang Sep 26, 2022
980a7d1
remove unnecessary style
wxiaoguang Sep 26, 2022
de678c8
Merge branch 'main' into feature/18192_pr_tree_view
wxiaoguang Sep 26, 2022
a14e42a
make code more readable
wxiaoguang Sep 26, 2022
19daf20
Merge branch 'main' into feature/18192_pr_tree_view
wxiaoguang Sep 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion templates/repo/commit_page.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{template "base/head" .}}
<div class="page-content repository diff">
{{template "repo/header" .}}
<div class="ui container {{if .IsSplitStyle}}fluid padded{{end}}">
<div class="ui container fluid padded">
{{$class := ""}}
{{if .Commit.Signature}}
{{$class = (printf "%s%s" $class " isSigned")}}
Expand Down
224 changes: 120 additions & 104 deletions templates/repo/diff/box.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -56,120 +56,136 @@
</li>
{{end}}
</ol>
<div id="diff-file-boxes">
{{range $i, $file := .Diff.Files}}
{{$blobBase := call $.GetBlobByPathForCommit $.BaseCommit $file.OldName}}
{{$blobHead := call $.GetBlobByPathForCommit $.HeadCommit $file.Name}}
{{$isImage := or (call $.IsBlobAnImage $blobBase) (call $.IsBlobAnImage $blobHead)}}
{{$isCsv := (call $.IsCsvFile $file)}}
{{$showFileViewToggle := or $isImage (and (not $file.IsIncomplete) $isCsv)}}
<div class="diff-file-box diff-box file-content {{TabSizeClass $.Editorconfig $file.Name}} mt-3" id="diff-{{$file.NameHash}}" data-old-filename="{{$file.OldName}}" data-new-filename="{{$file.Name}}" {{if $file.ShouldBeHidden}}data-folded="true"{{end}}>
<h4 class="diff-file-header sticky-2nd-row ui top attached normal header df ac sb">
<div class="df ac">
<a role="button" class="fold-file muted mr-2">
{{if $file.ShouldBeHidden}}
{{svg "octicon-chevron-right" 18}}
{{else}}
{{svg "octicon-chevron-down" 18}}
{{end}}
</a>
<div class="bold df ac">
{{if $file.IsBin}}
<span class="ml-1 mr-3">
{{$.locale.Tr "repo.diff.bin"}}
</span>
{{else}}
{{template "repo/diff/stats" dict "file" . "root" $}}
{{end}}
</div>
<span class="file mono"><a class="muted" href="#diff-{{$file.NameHash}}">{{if $file.IsRenamed}}{{$file.OldName}} &rarr; {{end}}{{$file.Name}}</a>{{if .IsLFSFile}} ({{$.locale.Tr "repo.stored_lfs"}}){{end}}</span>
{{if $file.IsGenerated}}
<span class="ui label ml-3">{{$.locale.Tr "repo.diff.generated"}}</span>
{{end}}
{{if $file.IsVendored}}
<span class="ui label ml-3">{{$.locale.Tr "repo.diff.vendored"}}</span>
{{end}}
</div>
<div class="diff-file-header-actions df ac">
{{if $showFileViewToggle}}
<div class="ui compact icon buttons">
<span class="ui tiny basic button tooltip file-view-toggle" data-toggle-selector="#diff-source-{{$i}}" data-content="{{$.locale.Tr "repo.file_view_source"}}" data-position="bottom center">{{svg "octicon-code"}}</span>
<span class="ui tiny basic button tooltip file-view-toggle active" data-toggle-selector="#diff-rendered-{{$i}}" data-content="{{$.locale.Tr "repo.file_view_rendered"}}" data-position="bottom center">{{svg "octicon-file"}}</span>
</div>
{{end}}
{{if $file.IsProtected}}
<span class="ui basic label">{{$.locale.Tr "repo.diff.protected"}}</span>
{{end}}
{{if not (or $file.IsIncomplete $file.IsBin $file.IsSubmodule)}}
<a class="ui basic tiny button unescape-button">{{$.locale.Tr "repo.unescape_control_characters"}}</a>
<a class="ui basic tiny button escape-button" style="display: none;">{{$.locale.Tr "repo.escape_control_characters"}}</a>
{{end}}
{{if and (not $file.IsSubmodule) (not $.PageIsWiki)}}
{{if $file.IsDeleted}}
<a class="ui basic tiny button" rel="nofollow" href="{{$.BeforeSourcePath}}/{{PathEscapeSegments .Name}}">{{$.locale.Tr "repo.diff.view_file"}}</a>
{{else}}
<a class="ui basic tiny button" rel="nofollow" href="{{$.SourcePath}}/{{PathEscapeSegments .Name}}">{{$.locale.Tr "repo.diff.view_file"}}</a>
{{end}}
{{end}}
{{if and $.IsSigned $.PageIsPullFiles (not $.IsArchived)}}
{{if $file.HasChangedSinceLastReview}}
<span class="changed-since-last-review unselectable">{{$.locale.Tr "repo.pulls.has_changed_since_last_review"}}</span>
{{end}}
<div data-link="{{$.Issue.Link}}/viewed-files" data-headcommit="{{$.PullHeadCommitID}}" class="viewed-file-form unselectable{{if $file.IsViewed}} viewed-file-checked-form{{end}}">
<input type="checkbox" name="{{$file.GetDiffFileName}}" id="viewed-file-checkbox-{{$i}}" autocomplete="off" {{if $file.IsViewed}}checked{{end}}></input>
<label for="viewed-file-checkbox-{{$i}}">{{$.locale.Tr "repo.pulls.has_viewed_file"}}</label>
</div>
{{end}}
</div>
</h4>
<div class="diff-file-body ui attached unstackable table segment" {{if $file.IsViewed}}data-folded="true"{{end}}>
<div id="diff-source-{{$i}}" class="file-body file-code unicode-escaped code-diff{{if $.IsSplitStyle}} code-diff-split{{else}} code-diff-unified{{end}}{{if $showFileViewToggle}} hide{{end}}">
{{if or $file.IsIncomplete $file.IsBin}}
<div class="diff-file-body binary" style="padding: 5px 10px;">
{{if $file.IsIncomplete}}
{{if $file.IsIncompleteLineTooLong}}
{{$.locale.Tr "repo.diff.file_suppressed_line_too_long"}}
<div id="diff-container" class="ui grid">
<div class="row">
<script>
(() => {
window.config.pageData.pullRequestFileTree = {
sebastian-sauer marked this conversation as resolved.
Show resolved Hide resolved
files: {{.Diff.Files}},
isIncomplete: {{.Diff.IsIncomplete}},
visibilityInfo: {
isVisible: false
}
};
})();
</script>
<div id="diff-file-tree-container"></div>
<div id="diff-file-boxes" class="sixteen wide column">
{{range $i, $file := .Diff.Files}}
{{$blobBase := call $.GetBlobByPathForCommit $.BaseCommit $file.OldName}}
{{$blobHead := call $.GetBlobByPathForCommit $.HeadCommit $file.Name}}
{{$isImage := or (call $.IsBlobAnImage $blobBase) (call $.IsBlobAnImage $blobHead)}}
{{$isCsv := (call $.IsCsvFile $file)}}
{{$showFileViewToggle := or $isImage (and (not $file.IsIncomplete) $isCsv)}}
<div class="diff-file-box diff-box file-content {{TabSizeClass $.Editorconfig $file.Name}} mt-3" id="diff-{{$file.NameHash}}" data-old-filename="{{$file.OldName}}" data-new-filename="{{$file.Name}}" {{if $file.ShouldBeHidden}}data-folded="true"{{end}}>
<h4 class="diff-file-header sticky-2nd-row ui top attached normal header df ac sb">
<div class="df ac">
<a role="button" class="fold-file muted mr-2">
{{if $file.ShouldBeHidden}}
{{svg "octicon-chevron-right" 18}}
{{else}}
{{$.locale.Tr "repo.diff.file_suppressed"}}
<a class="ui basic tiny button diff-show-more-button" data-href="{{$.Link}}?file-only=true&files={{$file.Name}}&files={{$file.OldName}}">{{$.locale.Tr "repo.diff.load"}}</a>
{{svg "octicon-chevron-down" 18}}
{{end}}
{{else}}
{{$.locale.Tr "repo.diff.bin_not_shown"}}
</a>
<div class="bold df ac">
{{if $file.IsBin}}
<span class="ml-1 mr-3">
{{$.locale.Tr "repo.diff.bin"}}
</span>
{{else}}
{{template "repo/diff/stats" dict "file" . "root" $}}
{{end}}
</div>
<span class="file mono"><a class="muted" href="#diff-{{$file.NameHash}}">{{if $file.IsRenamed}}{{$file.OldName}} &rarr; {{end}}{{$file.Name}}</a>{{if .IsLFSFile}} ({{$.locale.Tr "repo.stored_lfs"}}){{end}}</span>
{{if $file.IsGenerated}}
<span class="ui label ml-3">{{$.locale.Tr "repo.diff.generated"}}</span>
{{end}}
{{if $file.IsVendored}}
<span class="ui label ml-3">{{$.locale.Tr "repo.diff.vendored"}}</span>
{{end}}
</div>
{{else}}
<table class="chroma" data-new-comment-url="{{$.Issue.HTMLURL}}/files/reviews/new_comment" data-path="{{$file.Name}}">
{{if $.IsSplitStyle}}
{{template "repo/diff/section_split" dict "file" . "root" $}}
{{else}}
{{template "repo/diff/section_unified" dict "file" . "root" $}}
<div class="diff-file-header-actions df ac">
{{if $showFileViewToggle}}
<div class="ui compact icon buttons">
<span class="ui tiny basic button tooltip file-view-toggle" data-toggle-selector="#diff-source-{{$i}}" data-content="{{$.locale.Tr "repo.file_view_source"}}" data-position="bottom center">{{svg "octicon-code"}}</span>
<span class="ui tiny basic button tooltip file-view-toggle active" data-toggle-selector="#diff-rendered-{{$i}}" data-content="{{$.locale.Tr "repo.file_view_rendered"}}" data-position="bottom center">{{svg "octicon-file"}}</span>
</div>
{{end}}
</table>
{{end}}
</div>
{{if $showFileViewToggle}}
<div id="diff-rendered-{{$i}}" class="file-body file-code {{if $.IsSplitStyle}} code-diff-split{{else}} code-diff-unified{{end}}">
<table class="chroma w-100">
{{if $isImage}}
{{template "repo/diff/image_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead}}
{{if $file.IsProtected}}
<span class="ui basic label">{{$.locale.Tr "repo.diff.protected"}}</span>
{{end}}
{{if not (or $file.IsIncomplete $file.IsBin $file.IsSubmodule)}}
<a class="ui basic tiny button unescape-button">{{$.locale.Tr "repo.unescape_control_characters"}}</a>
<a class="ui basic tiny button escape-button" style="display: none;">{{$.locale.Tr "repo.escape_control_characters"}}</a>
{{end}}
{{if and (not $file.IsSubmodule) (not $.PageIsWiki)}}
{{if $file.IsDeleted}}
<a class="ui basic tiny button" rel="nofollow" href="{{$.BeforeSourcePath}}/{{PathEscapeSegments .Name}}">{{$.locale.Tr "repo.diff.view_file"}}</a>
{{else}}
<a class="ui basic tiny button" rel="nofollow" href="{{$.SourcePath}}/{{PathEscapeSegments .Name}}">{{$.locale.Tr "repo.diff.view_file"}}</a>
{{end}}
{{end}}
{{if and $.IsSigned $.PageIsPullFiles (not $.IsArchived)}}
{{if $file.HasChangedSinceLastReview}}
<span class="changed-since-last-review unselectable">{{$.locale.Tr "repo.pulls.has_changed_since_last_review"}}</span>
{{end}}
<div data-link="{{$.Issue.Link}}/viewed-files" data-headcommit="{{$.PullHeadCommitID}}" class="viewed-file-form unselectable{{if $file.IsViewed}} viewed-file-checked-form{{end}}">
<input type="checkbox" name="{{$file.GetDiffFileName}}" id="viewed-file-checkbox-{{$i}}" autocomplete="off" {{if $file.IsViewed}}checked{{end}}></input>
<label for="viewed-file-checkbox-{{$i}}">{{$.locale.Tr "repo.pulls.has_viewed_file"}}</label>
</div>
{{end}}
</div>
</h4>
<div class="diff-file-body ui attached unstackable table segment" {{if $file.IsViewed}}data-folded="true"{{end}}>
<div id="diff-source-{{$i}}" class="file-body file-code unicode-escaped code-diff{{if $.IsSplitStyle}} code-diff-split{{else}} code-diff-unified{{end}}{{if $showFileViewToggle}} hide{{end}}">
{{if or $file.IsIncomplete $file.IsBin}}
<div class="diff-file-body binary" style="padding: 5px 10px;">
{{if $file.IsIncomplete}}
{{if $file.IsIncompleteLineTooLong}}
{{$.locale.Tr "repo.diff.file_suppressed_line_too_long"}}
{{else}}
{{$.locale.Tr "repo.diff.file_suppressed"}}
<a class="ui basic tiny button diff-show-more-button" data-href="{{$.Link}}?file-only=true&files={{$file.Name}}&files={{$file.OldName}}">{{$.locale.Tr "repo.diff.load"}}</a>
{{end}}
{{else}}
{{$.locale.Tr "repo.diff.bin_not_shown"}}
{{end}}
</div>
{{else}}
{{template "repo/diff/csv_diff" dict "file" . "root" $}}
<table class="chroma" data-new-comment-url="{{$.Issue.HTMLURL}}/files/reviews/new_comment" data-path="{{$file.Name}}">
{{if $.IsSplitStyle}}
{{template "repo/diff/section_split" dict "file" . "root" $}}
{{else}}
{{template "repo/diff/section_unified" dict "file" . "root" $}}
{{end}}
</table>
{{end}}
</table>
</div>
{{if $showFileViewToggle}}
<div id="diff-rendered-{{$i}}" class="file-body file-code {{if $.IsSplitStyle}} code-diff-split{{else}} code-diff-unified{{end}}">
<table class="chroma w-100">
{{if $isImage}}
{{template "repo/diff/image_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead}}
{{else}}
{{template "repo/diff/csv_diff" dict "file" . "root" $}}
{{end}}
</table>
</div>
{{end}}
</div>
{{end}}
</div>
</div>
{{end}}
</div>
{{end}}

{{if .Diff.IsIncomplete}}
<div class="diff-file-box diff-box file-content mt-3" id="diff-incomplete">
<h4 class="ui top attached normal header df ac sb">
{{$.locale.Tr "repo.diff.too_many_files"}}
<a class="ui basic tiny button" id="diff-show-more-files" data-href="{{$.Link}}?skip-to={{.Diff.End}}&file-only=true">{{.locale.Tr "repo.diff.show_more"}}</a>
</h4>
{{if .Diff.IsIncomplete}}
<div class="diff-file-box diff-box file-content mt-3" id="diff-incomplete">
<h4 class="ui top attached normal header df ac sb">
{{$.locale.Tr "repo.diff.too_many_files"}}
<a class="ui basic tiny button" id="diff-show-more-files" data-href="{{$.Link}}?skip-to={{.Diff.End}}&file-only=true">{{.locale.Tr "repo.diff.show_more"}}</a>
</h4>
</div>
{{end}}
</div>
{{end}}
</div>
</div>

{{if not $.Repository.IsArchived}}
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/diff/compare.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{template "base/head" .}}
<div class="page-content repository diff {{if .PageIsComparePull}}compare pull{{end}}">
{{template "repo/header" .}}
<div class="ui container {{if .IsSplitStyle}}fluid padded{{end}}">
<div class="ui container fluid padded">

<h2 class="ui header">
{{if and $.PageIsComparePull $.IsSigned (not .Repository.IsArchived)}}
Expand Down
1 change: 1 addition & 0 deletions templates/repo/diff/options_dropdown.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
<a class="item" href="{{$.RepoLink}}/commit/{{PathEscape .Commit.ID.String}}.patch" download="{{ShortSha .Commit.ID.String}}.patch">{{.locale.Tr "repo.diff.download_patch"}}</a>
<a class="item" href="{{$.RepoLink}}/commit/{{PathEscape .Commit.ID.String}}.diff" download="{{ShortSha .Commit.ID.String}}.diff">{{.locale.Tr "repo.diff.download_diff"}}</a>
{{end}}
<a class="item diff-show-file-tree-button" data-target="#">Show file tree</a>
</div>
</div>
2 changes: 1 addition & 1 deletion templates/repo/pulls/files.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<div class="page-content repository view issue pull files diff">
{{template "repo/header" .}}
<div class="ui container {{if .IsSplitStyle}}fluid padded{{end}}">
<div class="ui container fluid padded">
<div class="navbar">
{{template "repo/issue/navbar" .}}
<div class="ui right">
Expand Down
121 changes: 121 additions & 0 deletions web_src/js/components/DiffFileTree.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<template>
<!-- eslint-disable -->
<div
v-show="visibilityInfo.isVisible"
id="diff-file-tree"
class="large screen only five wide column diff-detail-box sticky"
>
<div class="ui list">
<DiffFileTreeItem :children="this.fileTree"></DiffFileTreeItem>
</div>
</div>
</template>

<script>
import DiffFileTreeItem from './DiffFileTreeItem.vue';

const {pageData} = window.config;
const LOCAL_STORAGE_KEY = 'diff_file_tree_visible';

export default {
name: 'PullRequestFileTree',
components: {DiffFileTreeItem},

data: () => ({
files: pageData.pullRequestFileTree.files,
isIncomplete: pageData.pullRequestFileTree.isIncomplete,
visibilityInfo: pageData.pullRequestFileTree.visibilityInfo,
}),

computed: {
fileTree() {
const result = [];
for (const file of this.files) {
// Split file into directories
const splits = file.Name.split('/');
let index = 0;
let parent = null;
let isFile = false;
for (const split of splits) {
index += 1;
// reached the end
if (index === splits.length) {
isFile = true;
}
let newParent = {
name: split,
children: [],
isFile,
level: index,
file,
};

if (parent) {
// check if the folder already exists
const existingFolder = parent.children.find(
(x) => x.name === split
);
if (existingFolder) {
newParent = existingFolder;
} else {
parent.children.push(newParent);
}
} else {
const existingFolder = result.find((x) => x.name === split);
if (existingFolder) {
newParent = existingFolder;
} else {
result.push(newParent);
}
}
parent = newParent;
}
}
return result;
},
},

watch: {
visibilityInfo: {
handler(val) {
const fileBoxesDiv = document.querySelector('#diff-file-boxes');
if (val.isVisible === true) {
localStorage.setItem(LOCAL_STORAGE_KEY, 'true');
fileBoxesDiv.classList.value =
'sixteen wide mobile tablet eleven wide large screen column';
} else {
localStorage.setItem(LOCAL_STORAGE_KEY, 'false');
fileBoxesDiv.classList.value = 'sixteen wide column';
}
},
deep: true,
},
},

created() {
const savedVisibility = localStorage.getItem(LOCAL_STORAGE_KEY);
if (savedVisibility === 'true') {
this.visibilityInfo.isVisible = true;
}
},

mounted() {
document
.querySelector('.diff-show-file-tree-button')
.addEventListener('click', (evt) => {
evt.stopPropagation();
this.visibilityInfo.isVisible = !this.visibilityInfo.isVisible;
});
},

unmounted() {},

methods: {},
};
</script>

<style scoped>
div.list {
padding-top: 0;
}
</style>
Loading