1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-22 12:41:19 +01:00

When a directory has a single directory child, collapse them into a single "a/b/" path entry

Summary:
Ref T13516. Instead of rendering trees like this:

  - a/
    - b/
      - c.txt

...render:

  - a/b/
    - c.txt

Test Plan: {F7374205}

Maniphest Tasks: T13516

Differential Revision: https://secure.phabricator.com/D21155
This commit is contained in:
epriestley 2020-04-21 15:52:35 -07:00
parent 12eddb18fb
commit 9550ae6984
4 changed files with 137 additions and 20 deletions

View file

@ -59,7 +59,7 @@ return array(
'rsrc/css/application/countdown/timer.css' => 'bff8012f',
'rsrc/css/application/daemon/bulk-job.css' => '73af99f5',
'rsrc/css/application/dashboard/dashboard.css' => '5a205b9d',
'rsrc/css/application/diff/diff-tree-view.css' => '8f487a99',
'rsrc/css/application/diff/diff-tree-view.css' => 'bd83417c',
'rsrc/css/application/diff/inline-comment-summary.css' => '81eb368d',
'rsrc/css/application/differential/add-comment.css' => '7e5900d9',
'rsrc/css/application/differential/changeset-view.css' => '489b6995',
@ -381,8 +381,8 @@ return array(
'rsrc/js/application/diff/DiffChangeset.js' => '2a3101b1',
'rsrc/js/application/diff/DiffChangesetList.js' => '57035863',
'rsrc/js/application/diff/DiffInline.js' => '16e97ebc',
'rsrc/js/application/diff/DiffPathView.js' => 'c0ed32ce',
'rsrc/js/application/diff/DiffTreeView.js' => 'a5823e4d',
'rsrc/js/application/diff/DiffPathView.js' => '5f70ad12',
'rsrc/js/application/diff/DiffTreeView.js' => 'ccf691f3',
'rsrc/js/application/diff/behavior-preview-link.js' => 'f51e9c17',
'rsrc/js/application/differential/behavior-diff-radios.js' => '925fe8cd',
'rsrc/js/application/differential/behavior-populate.js' => 'b86ef6c2',
@ -558,7 +558,7 @@ return array(
'conpherence-thread-manager' => 'aec8e38c',
'conpherence-transaction-css' => '3a3f5e7e',
'd3' => '9d068042',
'diff-tree-view-css' => '8f487a99',
'diff-tree-view-css' => 'bd83417c',
'differential-changeset-view-css' => '489b6995',
'differential-core-view-css' => '7300a73e',
'differential-revision-add-comment-css' => '7e5900d9',
@ -778,8 +778,8 @@ return array(
'phabricator-diff-changeset' => '2a3101b1',
'phabricator-diff-changeset-list' => '57035863',
'phabricator-diff-inline' => '16e97ebc',
'phabricator-diff-path-view' => 'c0ed32ce',
'phabricator-diff-tree-view' => 'a5823e4d',
'phabricator-diff-path-view' => '5f70ad12',
'phabricator-diff-tree-view' => 'ccf691f3',
'phabricator-drag-and-drop-file-upload' => '4370900d',
'phabricator-draggable-list' => '0169e425',
'phabricator-fatal-config-template-css' => '20babf50',
@ -1517,6 +1517,9 @@ return array(
'javelin-dom',
'phuix-dropdown-menu',
),
'5f70ad12' => array(
'javelin-dom',
),
'5faf27b9' => array(
'phuix-form-control-view',
),
@ -1869,9 +1872,6 @@ return array(
'javelin-install',
'javelin-dom',
),
'a5823e4d' => array(
'javelin-dom',
),
'a9942052' => array(
'javelin-behavior',
'javelin-dom',
@ -2035,9 +2035,6 @@ return array(
'c03f2fb4' => array(
'javelin-install',
),
'c0ed32ce' => array(
'javelin-dom',
),
'c2c500a7' => array(
'javelin-install',
'javelin-dom',
@ -2082,6 +2079,9 @@ return array(
'phuix-icon-view',
'phabricator-busy',
),
'ccf691f3' => array(
'javelin-dom',
),
'cef53b3e' => array(
'javelin-install',
'javelin-dom',

View file

@ -8,8 +8,8 @@
.diff-tree-path {
height: 20px;
color: {$greytext};
line-height: 20px;
color: {$greytext};
}
.diff-tree-path-indent {
@ -23,8 +23,12 @@
text-align: center;
}
.diff-tree-path-icon .phui-icon-view {
color: {$greytext};
}
.diff-tree-path-name {
margin-left: 24px;
margin-left: 22px;
margin-right: 44px;
white-space: nowrap;
overflow: hidden;

View file

@ -21,6 +21,8 @@ JX.install('DiffPathView', {
_pathNode: null,
_changeset: null,
_inlineNode: null,
_isDirectory: false,
_displayPath: null,
getNode: function() {
if (!this._node) {
@ -45,10 +47,19 @@ JX.install('DiffPathView', {
setPath: function(path) {
this._path = path;
this._redrawPath();
return this;
},
var display = this._path[this._path.length - 1];
JX.DOM.setContent(this._getPathNode(), display);
setDisplayPath: function(path) {
this._displayPath = path;
this._redrawPath();
return this;
},
setIsDirectory: function(is_directory) {
this._isDirectory = is_directory;
this._redrawPath();
return this;
},
@ -69,10 +80,23 @@ JX.install('DiffPathView', {
return this._path;
},
setHidden: function(hidden) {
this._hidden = hidden;
var node = this.getNode();
if (this._hidden) {
JX.DOM.hide(node);
} else {
JX.DOM.show(node);
}
return this;
},
setDepth: function(depth) {
this._depth = depth;
this._getIndentNode().style.marginLeft = (6 * this._depth) + 'px';
this._getIndentNode().style.marginLeft = (8 * this._depth) + 'px';
return this;
},
@ -154,6 +178,23 @@ JX.install('DiffPathView', {
this._inlineNode = JX.$N('div', attrs, '-');
}
return this._inlineNode;
},
_redrawPath: function() {
var display;
if (this._displayPath) {
display = this._displayPath;
} else {
display = this._path[this._path.length - 1];
}
var is_directory = this._isDirectory;
if (is_directory) {
display = display + '/';
}
JX.DOM.setContent(this._getPathNode(), display);
}
}

View file

@ -94,11 +94,12 @@ JX.install('DiffTreeView', {
// For nodes which don't have a path object yet, build one.
var tree;
var path;
var trees = [];
for (ii = 0; ii < this._keys.length; ii++) {
var key = this._keys[ii];
tree = this._nodes[key];
var path = tree.pathObject;
path = tree.pathObject;
if (!path) {
path = new JX.DiffPathView()
@ -113,16 +114,87 @@ JX.install('DiffTreeView', {
trees.push(tree);
}
for (ii = 0; ii < trees.length; ii++) {
tree = trees[ii];
tree.displayRoot = null;
tree.displayPath = null;
tree.displayHide = false;
}
var child;
for (ii = 0; ii < trees.length; ii++) {
tree = trees[ii];
if (tree.childCount !== 1) {
continue;
}
for (var k in tree.children) {
if (tree.children.hasOwnProperty(k)) {
child = tree.children[k];
break;
}
}
if (child.pathObject.getChangeset()) {
continue;
}
child.displayRoot = tree.displayRoot || tree;
}
for (ii = 0; ii < trees.length; ii++) {
tree = trees[ii];
if (!tree.displayRoot) {
continue;
}
if (!tree.displayRoot.displayPath) {
tree.displayRoot.displayPath = [
tree.displayRoot.parts[tree.displayRoot.parts.length - 1]
];
}
tree.displayRoot.displayPath.push(tree.parts[tree.parts.length - 1]);
tree.displayHide = true;
}
for (ii = 0; ii < trees.length; ii++) {
tree = trees[ii];
path = tree.pathObject;
path.setHidden(!!tree.displayHide);
if (tree.displayPath) {
path.setDisplayPath(tree.displayPath.join('/'));
} else {
path.setDisplayPath(null);
}
}
for (ii = 0; ii < trees.length; ii++) {
tree = trees[ii];
if (!tree.parent) {
tree.depth = 0;
} else {
tree.depth = tree.parent.depth + 1;
// If this node was collapsed into the parent node, don't increase
// the tree depth.
if (tree.displayHide) {
tree.depth = tree.parent.depth;
} else {
tree.depth = tree.parent.depth + 1;
}
}
tree.pathObject.setDepth((tree.depth - 1));
path = tree.pathObject;
if (tree.childCount > 0) {
path.setIsDirectory(true);
}
path.setDepth((tree.depth - 1));
}
var nodes = [];