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

[Code] added symbol type to file types #28808

Merged
merged 1 commit into from
Jan 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions x-pack/plugins/code/model/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export enum FileTreeItemType {
File,
Directory,
Submodule,
Link,
}

export interface WorkerResult {
Expand Down
18 changes: 16 additions & 2 deletions x-pack/plugins/code/public/components/file_tree/file_tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ export class CodeFileTree extends React.Component<Props> {
public onClick = (node: Tree) => {
const { resource, org, repo, revision, path } = this.props.match.params;
if (!(path === node.path)) {
const pathType = node.type === FileTreeItemType.File ? PathTypes.blob : PathTypes.tree;
let pathType: PathTypes;
if (node.type === FileTreeItemType.Link || node.type === FileTreeItemType.File) {
pathType = PathTypes.blob;
} else {
pathType = PathTypes.tree;
}
this.props.history.push(`/${resource}/${org}/${repo}/${pathType}/${revision}/${node.path}`);
}
};
Expand Down Expand Up @@ -86,7 +91,16 @@ export class CodeFileTree extends React.Component<Props> {
case FileTreeItemType.Submodule: {
return (
<div onClick={onClick} className={className} role="button">
{node.name}
<EuiIcon type="submodule" />
<DirectoryNode>{node.name}</DirectoryNode>
</div>
);
}
case FileTreeItemType.Link: {
return (
<div onClick={onClick} className={classes(className, 'fileTreeFile')} role="button">
<EuiIcon type="symlink" />
<DirectoryNode>{node.name}</DirectoryNode>
</div>
);
}
Expand Down
27 changes: 21 additions & 6 deletions x-pack/plugins/code/server/git_operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,30 @@ async function checkExists<R>(func: () => Promise<R>, message: string): Promise<
}

function entry2Tree(entry: TreeEntry): FileTree {
let type: FileTreeItemType;
switch (entry.filemode()) {
case TreeEntry.FILEMODE.LINK:
type = FileTreeItemType.Link;
break;
case TreeEntry.FILEMODE.COMMIT:
type = FileTreeItemType.Submodule;
break;
case TreeEntry.FILEMODE.TREE:
type = FileTreeItemType.Directory;
break;
case TreeEntry.FILEMODE.BLOB:
case TreeEntry.FILEMODE.EXECUTABLE:
type = FileTreeItemType.File;
break;
default:
// @ts-ignore
throw new Error('unreadable file');
}
return {
name: entry.name(),
path: entry.path(),
sha1: entry.sha(),
type: entry.isDirectory()
? FileTreeItemType.Directory
: entry.isSubmodule()
? FileTreeItemType.Submodule
: FileTreeItemType.File,
type,
};
}

Expand All @@ -74,7 +89,7 @@ export class GitOperations {
() => commit.getEntry(path),
`file ${uri}/${path} not found `
);
if (entry.isFile()) {
if (entry.isFile() || entry.filemode() === TreeEntry.FILEMODE.LINK) {
return await entry.getBlob();
} else {
throw Boom.unsupportedMediaType(`${uri}/${path} is not a file.`);
Expand Down