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 018fd2d83e745..f55e5d153ac53 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 = {