From 1e9a1c6275735fe04bcde65bfa85230488c05cf9 Mon Sep 17 00:00:00 2001 From: spacedragon Date: Wed, 16 Jan 2019 11:28:19 +0800 Subject: [PATCH] [Code] added symbol type to file types --- x-pack/plugins/code/model/repository.ts | 1 + .../public/components/file_tree/file_tree.tsx | 18 +++++++++++-- x-pack/plugins/code/server/git_operations.ts | 27 ++++++++++++++----- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/code/model/repository.ts b/x-pack/plugins/code/model/repository.ts index 10ddf7594e988..57456d401a788 100644 --- a/x-pack/plugins/code/model/repository.ts +++ b/x-pack/plugins/code/model/repository.ts @@ -53,6 +53,7 @@ export enum FileTreeItemType { File, Directory, Submodule, + Link, } export interface WorkerResult { diff --git a/x-pack/plugins/code/public/components/file_tree/file_tree.tsx b/x-pack/plugins/code/public/components/file_tree/file_tree.tsx index 91ee416a3ff82..8dad96334395a 100644 --- a/x-pack/plugins/code/public/components/file_tree/file_tree.tsx +++ b/x-pack/plugins/code/public/components/file_tree/file_tree.tsx @@ -42,7 +42,12 @@ export class CodeFileTree extends React.Component { 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}`); } }; @@ -86,7 +91,16 @@ export class CodeFileTree extends React.Component { case FileTreeItemType.Submodule: { return (
- {node.name} + + {node.name} +
+ ); + } + case FileTreeItemType.Link: { + return ( +
+ + {node.name}
); } diff --git a/x-pack/plugins/code/server/git_operations.ts b/x-pack/plugins/code/server/git_operations.ts index f20a0748838da..33804db8b8086 100644 --- a/x-pack/plugins/code/server/git_operations.ts +++ b/x-pack/plugins/code/server/git_operations.ts @@ -41,15 +41,30 @@ async function checkExists(func: () => Promise, 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, }; } @@ -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.`);