From bd945311d78f5d81ccaabed7b0dfddd8d48d4259 Mon Sep 17 00:00:00 2001 From: Yulong Date: Fri, 8 Mar 2019 11:11:45 +0800 Subject: [PATCH] [Code] fix tree loading when jumping between different repos (#32650) --- .../code/public/components/file_tree/file_tree.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 018fd2d83e74..f55e5d153ac5 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 @@ -33,9 +33,20 @@ interface Props extends RouteComponentProps { openTreePath: (paths: string) => void; fetchRepoTree: (p: FetchRepoTreePayload) => void; openedPaths: string[]; + treeLoading?: boolean; } export class CodeFileTree extends React.Component { + public componentDidUpdate(prevProps: Readonly): void { + const { openedPaths, match, treeLoading } = this.props; + const path = match.params.path; + if (prevProps.match.params.path !== path || prevProps.treeLoading !== treeLoading) { + if (!openedPaths.includes(path)) { + this.props.openTreePath(path); + } + } + } + public componentDidMount(): void { const { path } = this.props.match.params; if (path) { @@ -242,6 +253,7 @@ export class CodeFileTree extends React.Component { const mapStateToProps = (state: RootState) => ({ node: state.file.tree, openedPaths: state.file.openedPaths, + treeLoading: state.file.loading, }); const mapDispatchToProps = {