Commit 131a2487 authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

SuperSize: Show srcPath and Component in info cards

For structural nodes, still shows the "idPath", because our data model
does not allow mapping subpaths -> components.

Also fixes cell alignment in the infocard where titles were center
aligned over right-aligned values.

Bug: 880671
Change-Id: I5be0bb6b07aba20a9c49bffa4c14da45f8bb0599
Reviewed-on: https://chromium-review.googlesource.com/c/1313076
Commit-Queue: agrieve <agrieve@chromium.org>
Reviewed-by: default avatarSamuel Huang <huangs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604939}
parent 998565f0
...@@ -74,21 +74,32 @@ const displayInfocard = (() => { ...@@ -74,21 +74,32 @@ const displayInfocard = (() => {
} }
/** /**
* Updates the path text, which shows the idPath of the node but highlights * Updates the path text, which shows the idPath for directory nodes, and
* the symbol name portion using bold text. * srcPath / component for symbol nodes.
* @param {TreeNode} node * @param {TreeNode} node
*/ */
_updatePath(node) { _updatePaths(node) {
let pathFragment;
if (node.srcPath) {
pathFragment = dom.createFragment([
dom.textElement('span', 'Path: ', 'symbol-name-info'),
document.createTextNode(node.srcPath),
document.createElement('br'),
dom.textElement('span', 'Component: ', 'symbol-name-info'),
document.createTextNode(node.componet || '(No component)'),
]);
} else {
const path = node.idPath.slice(0, node.shortNameIndex); const path = node.idPath.slice(0, node.shortNameIndex);
const boldShortName = dom.textElement( const boldShortName = dom.textElement(
'span', 'span',
shortName(node), shortName(node),
'symbol-name-info' 'symbol-name-info'
); );
const pathFragment = dom.createFragment([ pathFragment = dom.createFragment([
document.createTextNode(path), document.createTextNode(path),
boldShortName, boldShortName,
]); ]);
}
// Update DOM // Update DOM
dom.replace(this._pathInfo, pathFragment); dom.replace(this._pathInfo, pathFragment);
...@@ -145,7 +156,7 @@ const displayInfocard = (() => { ...@@ -145,7 +156,7 @@ const displayInfocard = (() => {
// Update DOM // Update DOM
this._updateSize(node); this._updateSize(node);
this._updatePath(node); this._updatePaths(node);
if (type !== this._lastType) { if (type !== this._lastType) {
// No need to create a new icon if it is identical. // No need to create a new icon if it is identical.
const icon = getIconTemplate(type); const icon = getIconTemplate(type);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
left: 8px; left: 8px;
right: 8px; right: 8px;
margin: 0 auto; margin: 0 auto;
max-width: 512px; max-width: 720px;
max-height: 50vh; max-height: 50vh;
overflow-y: auto; overflow-y: auto;
background: white; background: white;
...@@ -94,6 +94,7 @@ ...@@ -94,6 +94,7 @@
border-top: 1px solid #dadce0; border-top: 1px solid #dadce0;
padding-top: 8px; padding-top: 8px;
clear: right; clear: right;
text-align: left;
} }
.canvas-overlay { .canvas-overlay {
position: absolute; position: absolute;
...@@ -108,9 +109,6 @@ ...@@ -108,9 +109,6 @@
min-width: 100%; min-width: 100%;
font-size: 14px; font-size: 14px;
} }
.type-breakdown-info th {
text-align: left;
}
.type-breakdown-info th[scope='row'] { .type-breakdown-info th[scope='row'] {
font-weight: normal; font-weight: normal;
} }
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
* arrays indicate this is a leaf node. * arrays indicate this is a leaf node.
* @prop {TreeNode | null} parent Parent tree node. null if this is a root node. * @prop {TreeNode | null} parent Parent tree node. null if this is a root node.
* @prop {string} idPath Full path to this node. * @prop {string} idPath Full path to this node.
* @prop {string} srcPath Path to the source containing this symbol.
* @prop {string} component OWNERS Component for this symbol.
* @prop {number} shortNameIndex The name of the node is include in the idPath. * @prop {number} shortNameIndex The name of the node is include in the idPath.
* This index indicates where to start to slice the idPath to read the name. * This index indicates where to start to slice the idPath to read the name.
* @prop {number} size Byte size of this node and its children. * @prop {number} size Byte size of this node and its children.
......
...@@ -49,6 +49,14 @@ function getSourcePath(fileEntry) { ...@@ -49,6 +49,14 @@ function getSourcePath(fileEntry) {
return fileEntry[_KEYS.SOURCE_PATH]; return fileEntry[_KEYS.SOURCE_PATH];
} }
/**
* @param {Meta} meta
* @param {FileEntry} fileEntry
*/
function getComponent(meta, fileEntry) {
return meta.components[fileEntry[_KEYS.COMPONENT_INDEX]];
}
/** /**
* Find the last index of either '/' or `sep` in the given path. * Find the last index of either '/' or `sep` in the given path.
* @param {string} path * @param {string} path
...@@ -91,6 +99,8 @@ function _compareFunc(a, b) { ...@@ -91,6 +99,8 @@ function _compareFunc(a, b) {
function createNode(options) { function createNode(options) {
const { const {
idPath, idPath,
srcPath,
component,
type, type,
shortNameIndex, shortNameIndex,
size = 0, size = 0,
...@@ -102,6 +112,8 @@ function createNode(options) { ...@@ -102,6 +112,8 @@ function createNode(options) {
children: [], children: [],
parent: null, parent: null,
idPath, idPath,
srcPath,
component,
type, type,
shortNameIndex, shortNameIndex,
size, size,
...@@ -128,13 +140,16 @@ class TreeBuilder { ...@@ -128,13 +140,16 @@ class TreeBuilder {
* @param {(symbolNode: TreeNode) => boolean} options.highlightTest Called to * @param {(symbolNode: TreeNode) => boolean} options.highlightTest Called to
* see if a symbol should be highlighted. * see if a symbol should be highlighted.
* @param {string} options.sep Path seperator used to find parent names. * @param {string} options.sep Path seperator used to find parent names.
* @param {Meta} options.meta Metadata associated with this tree.
*/ */
constructor(options) { constructor(options) {
this._getPath = options.getPath; this._getPath = options.getPath;
this._filterTest = options.filterTest; this._filterTest = options.filterTest;
this._highlightTest = options.highlightTest; this._highlightTest = options.highlightTest;
this._sep = options.sep || _PATH_SEP; this._sep = options.sep || _PATH_SEP;
this._meta = options.meta;
// srcPath and component don't make sense for the root node.
this.rootNode = createNode({ this.rootNode = createNode({
idPath: this._sep, idPath: this._sep,
shortNameIndex: 0, shortNameIndex: 0,
...@@ -234,6 +249,8 @@ class TreeBuilder { ...@@ -234,6 +249,8 @@ class TreeBuilder {
if (classNode == null) { if (classNode == null) {
classNode = createNode({ classNode = createNode({
idPath: classIdPath, idPath: classIdPath,
srcPath: node.srcPath,
component: node.component,
shortNameIndex: childNode.shortNameIndex, shortNameIndex: childNode.shortNameIndex,
type: _CONTAINER_TYPES.JAVA_CLASS, type: _CONTAINER_TYPES.JAVA_CLASS,
}); });
...@@ -341,6 +358,9 @@ class TreeBuilder { ...@@ -341,6 +358,9 @@ class TreeBuilder {
// get parent from cache if it exists, otherwise create it // get parent from cache if it exists, otherwise create it
parentNode = this._parents.get(parentPath); parentNode = this._parents.get(parentPath);
if (parentNode == null) { if (parentNode == null) {
// srcPath and component are not available for parent nodes, since they
// are stored alongside FileEntry. We could extract srcPath from idPath,
// but it doesn't really add enough value to warrent doing so.
parentNode = createNode({ parentNode = createNode({
idPath: parentPath, idPath: parentPath,
shortNameIndex: lastIndexOf(parentPath, this._sep) + 1, shortNameIndex: lastIndexOf(parentPath, this._sep) + 1,
...@@ -365,9 +385,13 @@ class TreeBuilder { ...@@ -365,9 +385,13 @@ class TreeBuilder {
*/ */
addFileEntry(fileEntry, diffMode) { addFileEntry(fileEntry, diffMode) {
const idPath = this._getPath(fileEntry); const idPath = this._getPath(fileEntry);
const srcPath = getSourcePath(fileEntry);
const component = getComponent(this._meta, fileEntry);
// make node for this // make node for this
const fileNode = createNode({ const fileNode = createNode({
idPath, idPath,
srcPath,
component,
shortNameIndex: lastIndexOf(idPath, this._sep) + 1, shortNameIndex: lastIndexOf(idPath, this._sep) + 1,
type: _CONTAINER_TYPES.FILE, type: _CONTAINER_TYPES.FILE,
}); });
...@@ -384,6 +408,8 @@ class TreeBuilder { ...@@ -384,6 +408,8 @@ class TreeBuilder {
const symbolNode = createNode({ const symbolNode = createNode({
// Join file path to symbol name with a ":" // Join file path to symbol name with a ":"
idPath: `${idPath}:${symbol[_KEYS.SYMBOL_NAME]}`, idPath: `${idPath}:${symbol[_KEYS.SYMBOL_NAME]}`,
srcPath,
component,
shortNameIndex: idPath.length + 1, shortNameIndex: idPath.length + 1,
size, size,
type, type,
...@@ -707,20 +733,13 @@ async function buildTree(groupBy, filterTest, highlightTest, onProgress) { ...@@ -707,20 +733,13 @@ async function buildTree(groupBy, filterTest, highlightTest, onProgress) {
/** @type {{ [gropyBy: string]: (fileEntry: FileEntry) => string }} */ /** @type {{ [gropyBy: string]: (fileEntry: FileEntry) => string }} */
const getPathMap = { const getPathMap = {
component(fileEntry) { component(fileEntry) {
const component = meta.components[fileEntry[_KEYS.COMPONENT_INDEX]]; const component = getComponent(meta, fileEntry);
const path = getSourcePath(fileEntry); const path = getSourcePath(fileEntry);
return `${component || '(No component)'}>${path}`; return `${component || '(No component)'}>${path}`;
}, },
source_path: getSourcePath, source_path: getSourcePath,
}; };
builder = new TreeBuilder({
sep: groupBy === 'component' ? '>' : _PATH_SEP,
getPath: getPathMap[groupBy],
filterTest,
highlightTest,
});
/** /**
* Creates data to post to the UI thread. Defaults will be used for the root * Creates data to post to the UI thread. Defaults will be used for the root
* and percent values if not specified. * and percent values if not specified.
...@@ -767,6 +786,15 @@ async function buildTree(groupBy, filterTest, highlightTest, onProgress) { ...@@ -767,6 +786,15 @@ async function buildTree(groupBy, filterTest, highlightTest, onProgress) {
// First line of data is used to store meta information. // First line of data is used to store meta information.
meta = /** @type {Meta} */ (dataObj); meta = /** @type {Meta} */ (dataObj);
diffMode = meta.diff_mode; diffMode = meta.diff_mode;
builder = new TreeBuilder({
getPath: getPathMap[groupBy],
filterTest,
highlightTest,
sep: groupBy === 'component' ? '>' : _PATH_SEP,
meta,
});
postToUi(); postToUi();
} else { } else {
builder.addFileEntry(/** @type {FileEntry} */ (dataObj), diffMode); builder.addFileEntry(/** @type {FileEntry} */ (dataObj), diffMode);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment