fix(code/frontend): fix file tree issues (#28218)

This commit is contained in:
WangQianliang 2019-01-10 20:50:10 +08:00 committed by GitHub
parent e46c9eddf6
commit 65844a559a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 134 additions and 118 deletions

View file

@ -76,78 +76,16 @@ exports[`render correctly 1`] = `
>
<div
className="fileNode"
onClick={[Function]}
role="button"
>
<span
className="sc-bdVaJa fsxEnI"
onClick={[Function]}
/>
<svg
className="euiIcon euiIcon--medium"
focusable="false"
height="16"
style={null}
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M1 9.5l.826-3.717A1 1 0 0 1 2.802 5H13V3.5H7.125A1.125 1.125 0 0 1 6 2.375V2H1v7.5zm.247 3.5h11.95l1.556-7H2.803l-1.556 7zM13 14H1a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.25a.75.75 0 0 1 .75.75v.625c0 .069.056.125.125.125H13a1 1 0 0 1 1 1V5h.753a1 1 0 0 1 .977 1.217l-1.556 7a1 1 0 0 1-.976.783H13z"
/>
</svg>
<span
className="sc-htpNat hyFNl"
>
android/
</span>
</div>
</div>
<div
className="euiSideNavItem euiSideNavItem--trunk"
>
<div
className="fileNode"
onClick={[Function]}
role="button"
>
<span
className="sc-bdVaJa fsxEnI"
/>
<svg
className="euiIcon euiIcon--medium"
focusable="false"
height="16"
style={null}
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M1 9.5l.826-3.717A1 1 0 0 1 2.802 5H13V3.5H7.125A1.125 1.125 0 0 1 6 2.375V2H1v7.5zm.247 3.5h11.95l1.556-7H2.803l-1.556 7zM13 14H1a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.25a.75.75 0 0 1 .75.75v.625c0 .069.056.125.125.125H13a1 1 0 0 1 1 1V5h.753a1 1 0 0 1 .977 1.217l-1.556 7a1 1 0 0 1-.976.783H13z"
/>
</svg>
<span
className="sc-htpNat hyFNl"
>
futures/
</span>
</div>
</div>
<div
className="euiSideNavItem euiSideNavItem--trunk euiSideNavItem--hasChildItems"
>
<div
className="fileNode"
onClick={[Function]}
role="button"
>
<span
className="sc-bwzfXH kVxRUe sc-bdVaJa fsxEnI"
/>
<svg
className="euiIcon euiIcon--medium"
focusable="false"
height="16"
onClick={[Function]}
style={null}
viewBox="0 0 16 16"
width="16"
@ -159,6 +97,71 @@ exports[`render correctly 1`] = `
</svg>
<span
className="sc-htpNat hyFNl"
onClick={[Function]}
>
android/
</span>
</div>
</div>
<div
className="euiSideNavItem euiSideNavItem--trunk"
>
<div
className="fileNode"
>
<span
className="sc-bdVaJa fsxEnI"
onClick={[Function]}
/>
<svg
className="euiIcon euiIcon--medium"
focusable="false"
height="16"
onClick={[Function]}
style={null}
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M6 2H1v11h14V3.5H7.125A1.125 1.125 0 0 1 6 2.375V2zm.25-1a.75.75 0 0 1 .75.75v.625c0 .069.056.125.125.125H15a1 1 0 0 1 1 1V13a1 1 0 0 1-1 1H1a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.25z"
/>
</svg>
<span
className="sc-htpNat hyFNl"
onClick={[Function]}
>
futures/
</span>
</div>
</div>
<div
className="euiSideNavItem euiSideNavItem--trunk euiSideNavItem--hasChildItems"
>
<div
className="fileNode"
>
<span
className="sc-bwzfXH kVxRUe sc-bdVaJa fsxEnI"
onClick={[Function]}
/>
<svg
className="euiIcon euiIcon--medium"
focusable="false"
height="16"
onClick={[Function]}
style={null}
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M1 9.5l.826-3.717A1 1 0 0 1 2.802 5H13V3.5H7.125A1.125 1.125 0 0 1 6 2.375V2H1v7.5zm.247 3.5h11.95l1.556-7H2.803l-1.556 7zM13 14H1a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.25a.75.75 0 0 1 .75.75v.625c0 .069.056.125.125.125H13a1 1 0 0 1 1 1V5h.753a1 1 0 0 1 .977 1.217l-1.556 7a1 1 0 0 1-.976.783H13z"
/>
</svg>
<span
className="sc-htpNat hyFNl"
onClick={[Function]}
>
guava/
</span>
@ -171,27 +174,28 @@ exports[`render correctly 1`] = `
>
<div
className="fileNode"
onClick={[Function]}
role="button"
>
<span
className="sc-bdVaJa fsxEnI"
onClick={[Function]}
/>
<svg
className="euiIcon euiIcon--medium"
focusable="false"
height="16"
onClick={[Function]}
style={null}
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M1 9.5l.826-3.717A1 1 0 0 1 2.802 5H13V3.5H7.125A1.125 1.125 0 0 1 6 2.375V2H1v7.5zm.247 3.5h11.95l1.556-7H2.803l-1.556 7zM13 14H1a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.25a.75.75 0 0 1 .75.75v.625c0 .069.056.125.125.125H13a1 1 0 0 1 1 1V5h.753a1 1 0 0 1 .977 1.217l-1.556 7a1 1 0 0 1-.976.783H13z"
d="M6 2H1v11h14V3.5H7.125A1.125 1.125 0 0 1 6 2.375V2zm.25-1a.75.75 0 0 1 .75.75v.625c0 .069.056.125.125.125H15a1 1 0 0 1 1 1V13a1 1 0 0 1-1 1H1a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.25z"
/>
</svg>
<span
className="sc-htpNat hyFNl"
onClick={[Function]}
>
javadoc-link/
</span>
@ -237,27 +241,28 @@ exports[`render correctly 1`] = `
>
<div
className="activeFileNode"
onClick={[Function]}
role="button"
>
<span
className="sc-bwzfXH kVxRUe sc-bdVaJa fsxEnI"
onClick={[Function]}
/>
<svg
className="euiIcon euiIcon--medium"
focusable="false"
height="16"
onClick={[Function]}
style={null}
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M6 2H1v11h14V3.5H7.125A1.125 1.125 0 0 1 6 2.375V2zm.25-1a.75.75 0 0 1 .75.75v.625c0 .069.056.125.125.125H15a1 1 0 0 1 1 1V13a1 1 0 0 1-1 1H1a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.25z"
d="M1 9.5l.826-3.717A1 1 0 0 1 2.802 5H13V3.5H7.125A1.125 1.125 0 0 1 6 2.375V2H1v7.5zm.247 3.5h11.95l1.556-7H2.803l-1.556 7zM13 14H1a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.25a.75.75 0 0 1 .75.75v.625c0 .069.056.125.125.125H13a1 1 0 0 1 1 1V5h.753a1 1 0 0 1 .977 1.217l-1.556 7a1 1 0 0 1-.976.783H13z"
/>
</svg>
<span
className="sc-htpNat hyFNl"
onClick={[Function]}
>
src/com/google/
</span>
@ -270,27 +275,28 @@ exports[`render correctly 1`] = `
>
<div
className="fileNode"
onClick={[Function]}
role="button"
>
<span
className="sc-bdVaJa fsxEnI"
onClick={[Function]}
/>
<svg
className="euiIcon euiIcon--medium"
focusable="false"
height="16"
onClick={[Function]}
style={null}
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M1 9.5l.826-3.717A1 1 0 0 1 2.802 5H13V3.5H7.125A1.125 1.125 0 0 1 6 2.375V2H1v7.5zm.247 3.5h11.95l1.556-7H2.803l-1.556 7zM13 14H1a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.25a.75.75 0 0 1 .75.75v.625c0 .069.056.125.125.125H13a1 1 0 0 1 1 1V5h.753a1 1 0 0 1 .977 1.217l-1.556 7a1 1 0 0 1-.976.783H13z"
d="M6 2H1v11h14V3.5H7.125A1.125 1.125 0 0 1 6 2.375V2zm.25-1a.75.75 0 0 1 .75.75v.625c0 .069.056.125.125.125H15a1 1 0 0 1 1 1V13a1 1 0 0 1-1 1H1a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.25z"
/>
</svg>
<span
className="sc-htpNat hyFNl"
onClick={[Function]}
>
common/
</span>
@ -301,27 +307,28 @@ exports[`render correctly 1`] = `
>
<div
className="fileNode"
onClick={[Function]}
role="button"
>
<span
className="sc-bdVaJa fsxEnI"
onClick={[Function]}
/>
<svg
className="euiIcon euiIcon--medium"
focusable="false"
height="16"
onClick={[Function]}
style={null}
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M1 9.5l.826-3.717A1 1 0 0 1 2.802 5H13V3.5H7.125A1.125 1.125 0 0 1 6 2.375V2H1v7.5zm.247 3.5h11.95l1.556-7H2.803l-1.556 7zM13 14H1a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.25a.75.75 0 0 1 .75.75v.625c0 .069.056.125.125.125H13a1 1 0 0 1 1 1V5h.753a1 1 0 0 1 .977 1.217l-1.556 7a1 1 0 0 1-.976.783H13z"
d="M6 2H1v11h14V3.5H7.125A1.125 1.125 0 0 1 6 2.375V2zm.25-1a.75.75 0 0 1 .75.75v.625c0 .069.056.125.125.125H15a1 1 0 0 1 1 1V13a1 1 0 0 1-1 1H1a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.25z"
/>
</svg>
<span
className="sc-htpNat hyFNl"
onClick={[Function]}
>
thirdparty/publicsuffix/
</span>
@ -335,34 +342,31 @@ exports[`render correctly 1`] = `
className="euiSideNavItem euiSideNavItem--trunk"
>
<div
className="fileNode fileTreeFile"
onClick={[Function]}
role="button"
className="fileNode"
>
<span
className="sc-bdVaJa fsxEnI"
onClick={[Function]}
/>
<svg
className="euiIcon euiIcon--medium"
focusable="false"
height="16"
onClick={[Function]}
style={null}
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
xmlnsXlink="http://www.w3.org/1999/xlink"
>
<defs>
<path
d="M10.8 0H2a1 1 0 0 0-1 1v14a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V4.429c0-.256-.098-.503-.274-.689l-3.2-3.428A1.002 1.002 0 0 0 10.8 0M14 5v10H2V1h8v3.5a.5.5 0 0 0 .5.5H14z"
id="document-a"
/>
</defs>
<use
xlinkHref="#document-a"
<path
d="M6 2H1v11h14V3.5H7.125A1.125 1.125 0 0 1 6 2.375V2zm.25-1a.75.75 0 0 1 .75.75v.625c0 .069.056.125.125.125H15a1 1 0 0 1 1 1V13a1 1 0 0 1-1 1H1a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.25z"
/>
</svg>
<span
className="sc-htpNat hyFNl"
onClick={[Function]}
>
guava-bom/pom.xml
guava-bom/
</span>
</div>
</div>
@ -371,27 +375,28 @@ exports[`render correctly 1`] = `
>
<div
className="fileNode"
onClick={[Function]}
role="button"
>
<span
className="sc-bdVaJa fsxEnI"
onClick={[Function]}
/>
<svg
className="euiIcon euiIcon--medium"
focusable="false"
height="16"
onClick={[Function]}
style={null}
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M1 9.5l.826-3.717A1 1 0 0 1 2.802 5H13V3.5H7.125A1.125 1.125 0 0 1 6 2.375V2H1v7.5zm.247 3.5h11.95l1.556-7H2.803l-1.556 7zM13 14H1a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.25a.75.75 0 0 1 .75.75v.625c0 .069.056.125.125.125H13a1 1 0 0 1 1 1V5h.753a1 1 0 0 1 .977 1.217l-1.556 7a1 1 0 0 1-.976.783H13z"
d="M6 2H1v11h14V3.5H7.125A1.125 1.125 0 0 1 6 2.375V2zm.25-1a.75.75 0 0 1 .75.75v.625c0 .069.056.125.125.125H15a1 1 0 0 1 1 1V13a1 1 0 0 1-1 1H1a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.25z"
/>
</svg>
<span
className="sc-htpNat hyFNl"
onClick={[Function]}
>
guava-gwt/
</span>
@ -402,27 +407,28 @@ exports[`render correctly 1`] = `
>
<div
className="fileNode"
onClick={[Function]}
role="button"
>
<span
className="sc-bdVaJa fsxEnI"
onClick={[Function]}
/>
<svg
className="euiIcon euiIcon--medium"
focusable="false"
height="16"
onClick={[Function]}
style={null}
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M1 9.5l.826-3.717A1 1 0 0 1 2.802 5H13V3.5H7.125A1.125 1.125 0 0 1 6 2.375V2H1v7.5zm.247 3.5h11.95l1.556-7H2.803l-1.556 7zM13 14H1a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.25a.75.75 0 0 1 .75.75v.625c0 .069.056.125.125.125H13a1 1 0 0 1 1 1V5h.753a1 1 0 0 1 .977 1.217l-1.556 7a1 1 0 0 1-.976.783H13z"
d="M6 2H1v11h14V3.5H7.125A1.125 1.125 0 0 1 6 2.375V2zm.25-1a.75.75 0 0 1 .75.75v.625c0 .069.056.125.125.125H15a1 1 0 0 1 1 1V13a1 1 0 0 1-1 1H1a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.25z"
/>
</svg>
<span
className="sc-htpNat hyFNl"
onClick={[Function]}
>
guava-testlib/
</span>
@ -433,27 +439,28 @@ exports[`render correctly 1`] = `
>
<div
className="fileNode"
onClick={[Function]}
role="button"
>
<span
className="sc-bdVaJa fsxEnI"
onClick={[Function]}
/>
<svg
className="euiIcon euiIcon--medium"
focusable="false"
height="16"
onClick={[Function]}
style={null}
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M1 9.5l.826-3.717A1 1 0 0 1 2.802 5H13V3.5H7.125A1.125 1.125 0 0 1 6 2.375V2H1v7.5zm.247 3.5h11.95l1.556-7H2.803l-1.556 7zM13 14H1a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.25a.75.75 0 0 1 .75.75v.625c0 .069.056.125.125.125H13a1 1 0 0 1 1 1V5h.753a1 1 0 0 1 .977 1.217l-1.556 7a1 1 0 0 1-.976.783H13z"
d="M6 2H1v11h14V3.5H7.125A1.125 1.125 0 0 1 6 2.375V2zm.25-1a.75.75 0 0 1 .75.75v.625c0 .069.056.125.125.125H15a1 1 0 0 1 1 1V13a1 1 0 0 1-1 1H1a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.25z"
/>
</svg>
<span
className="sc-htpNat hyFNl"
onClick={[Function]}
>
guava-tests/
</span>
@ -464,27 +471,28 @@ exports[`render correctly 1`] = `
>
<div
className="fileNode"
onClick={[Function]}
role="button"
>
<span
className="sc-bdVaJa fsxEnI"
onClick={[Function]}
/>
<svg
className="euiIcon euiIcon--medium"
focusable="false"
height="16"
onClick={[Function]}
style={null}
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M1 9.5l.826-3.717A1 1 0 0 1 2.802 5H13V3.5H7.125A1.125 1.125 0 0 1 6 2.375V2H1v7.5zm.247 3.5h11.95l1.556-7H2.803l-1.556 7zM13 14H1a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.25a.75.75 0 0 1 .75.75v.625c0 .069.056.125.125.125H13a1 1 0 0 1 1 1V5h.753a1 1 0 0 1 .977 1.217l-1.556 7a1 1 0 0 1-.976.783H13z"
d="M6 2H1v11h14V3.5H7.125A1.125 1.125 0 0 1 6 2.375V2zm.25-1a.75.75 0 0 1 .75.75v.625c0 .069.056.125.125.125H15a1 1 0 0 1 1 1V13a1 1 0 0 1-1 1H1a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.25z"
/>
</svg>
<span
className="sc-htpNat hyFNl"
onClick={[Function]}
>
refactorings/
</span>
@ -495,27 +503,28 @@ exports[`render correctly 1`] = `
>
<div
className="fileNode"
onClick={[Function]}
role="button"
>
<span
className="sc-bdVaJa fsxEnI"
onClick={[Function]}
/>
<svg
className="euiIcon euiIcon--medium"
focusable="false"
height="16"
onClick={[Function]}
style={null}
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M1 9.5l.826-3.717A1 1 0 0 1 2.802 5H13V3.5H7.125A1.125 1.125 0 0 1 6 2.375V2H1v7.5zm.247 3.5h11.95l1.556-7H2.803l-1.556 7zM13 14H1a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.25a.75.75 0 0 1 .75.75v.625c0 .069.056.125.125.125H13a1 1 0 0 1 1 1V5h.753a1 1 0 0 1 .977 1.217l-1.556 7a1 1 0 0 1-.976.783H13z"
d="M6 2H1v11h14V3.5H7.125A1.125 1.125 0 0 1 6 2.375V2zm.25-1a.75.75 0 0 1 .75.75v.625c0 .069.056.125.125.125H15a1 1 0 0 1 1 1V13a1 1 0 0 1-1 1H1a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.25z"
/>
</svg>
<span
className="sc-htpNat hyFNl"
onClick={[Function]}
>
util/
</span>

View file

@ -56,7 +56,7 @@ export class CodeFileTree extends React.Component<Props> {
};
public flattenDirectory: (node: Tree) => Tree[] = (node: Tree) => {
if (node.childrenCount === 1) {
if (node.childrenCount === 1 && node.children![0].type === FileTreeItemType.Directory) {
return [node, ...this.flattenDirectory(node.children![0])];
} else {
return [node];
@ -68,19 +68,18 @@ export class CodeFileTree extends React.Component<Props> {
const onClick = () => this.onClick(node);
switch (node.type) {
case FileTreeItemType.Directory: {
const onFolderClick = (e: React.MouseEvent<HTMLDivElement>) => {
const target = e.target as HTMLElement;
if (target.tagName === 'DIV') {
this.onClick(node);
} else {
this.getTreeToggler(node.path || '')();
}
const onFolderClick = () => {
this.getTreeToggler(node.path || '')();
};
return (
<div onClick={onFolderClick} className={className} role="button">
{forceOpen ? <FolderOpenTriangle /> : <FolderClosedTriangle />}
<EuiIcon type={forceOpen ? 'folderClosed' : 'folderOpen'} />
<DirectoryNode>{`${node.name}/`}</DirectoryNode>
<div className={className}>
{forceOpen ? (
<FolderOpenTriangle onClick={onFolderClick} />
) : (
<FolderClosedTriangle onClick={onFolderClick} />
)}
<EuiIcon type={forceOpen ? 'folderOpen' : 'folderClosed'} onClick={onClick} />
<DirectoryNode onClick={onClick}>{`${node.name}/`}</DirectoryNode>
</div>
);
}

View file

@ -43,12 +43,12 @@ import { repoRoutePattern } from './patterns';
function* handleFetchRepoTree(action: Action<FetchRepoTreePayload>) {
try {
const { uri, revision, path } = action.payload!;
const { uri, revision, path, parents } = action.payload!;
if (path) {
const requestedPaths: string[] = yield select(requestedPathsSelector);
const shouldFetch = !some(requestedPaths, p => p.startsWith(path));
if (shouldFetch) {
yield call(fetchPath, { uri, revision, path });
yield call(fetchPath, { uri, revision, path, parents });
}
const pathSegments = path.split('/');
let currentPath = '';

View file

@ -54,6 +54,13 @@ function entry2Tree(entry: TreeEntry): FileTree {
}
export class GitOperations {
public static sortFileTreeChildren(a: FileTree, b: FileTree) {
if (a.type !== b.type) {
return b.type - a.type;
} else {
return a.name.localeCompare(b.name);
}
}
private repoRoot: string;
constructor(repoRoot: string) {
@ -329,6 +336,7 @@ export class GitOperations {
}
}
}
fileTree.children.sort(GitOperations.sortFileTreeChildren);
}
if (path) {
const entry = await checkExists(