From 34433b89e512dd019a165a70cb3f19fe1178f096 Mon Sep 17 00:00:00 2001 From: wangqianliang Date: Thu, 11 Apr 2019 14:34:54 +0800 Subject: [PATCH] fix(code/frontend): should disable structure tab if no structure or load failed --- x-pack/plugins/code/public/components/main/main.tsx | 13 +++++++------ .../code/public/components/main/side_tabs.tsx | 4 +++- x-pack/plugins/code/public/reducers/symbol.ts | 1 + 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/code/public/components/main/main.tsx b/x-pack/plugins/code/public/components/main/main.tsx index 39db12e441823d..47106975e36234 100644 --- a/x-pack/plugins/code/public/components/main/main.tsx +++ b/x-pack/plugins/code/public/components/main/main.tsx @@ -11,10 +11,11 @@ import styled from 'styled-components'; import chrome from 'ui/chrome'; import { MainRouteParams } from '../../common/types'; -import { RootState } from '../../reducers'; import { ShortcutsProvider } from '../shortcuts'; import { Content } from './content'; import { SideTabs } from './side_tabs'; +import { structureSelector } from '../../selectors'; +import { RootState } from '../../reducers'; const Root = styled.div` position: absolute; @@ -34,6 +35,7 @@ const Container = styled.div` interface Props extends RouteComponentProps { loadingFileTree: boolean; loadingStructureTree: boolean; + hasStructure: boolean; } class CodeMain extends React.Component { @@ -56,7 +58,7 @@ class CodeMain extends React.Component { } public render() { - const { loadingFileTree, loadingStructureTree } = this.props; + const { loadingFileTree, loadingStructureTree, hasStructure } = this.props; return ( @@ -64,6 +66,7 @@ class CodeMain extends React.Component { @@ -77,9 +80,7 @@ class CodeMain extends React.Component { const mapStateToProps = (state: RootState) => ({ loadingFileTree: state.file.loading, loadingStructureTree: state.symbol.loading, + hasStructure: structureSelector(state).length > 0 && !state.symbol.error, }); -export const Main = connect( - mapStateToProps - // @ts-ignore -)(CodeMain); +export const Main = connect(mapStateToProps)(CodeMain); diff --git a/x-pack/plugins/code/public/components/main/side_tabs.tsx b/x-pack/plugins/code/public/components/main/side_tabs.tsx index ea9f705d184d3e..ef04f0a38c409c 100644 --- a/x-pack/plugins/code/public/components/main/side_tabs.tsx +++ b/x-pack/plugins/code/public/components/main/side_tabs.tsx @@ -22,6 +22,7 @@ enum Tabs { interface Props extends RouteComponentProps { loadingFileTree: boolean; loadingStructureTree: boolean; + hasStructure: boolean; } class CodeSideTabs extends React.PureComponent { @@ -73,7 +74,7 @@ class CodeSideTabs extends React.PureComponent { name: 'Structure', content: structureTabContent, isSelected: Tabs.structure === this.sideTab, - disabled: this.props.match.params.pathType === PathTypes.tree, + disabled: this.props.match.params.pathType === PathTypes.tree || !this.props.hasStructure, 'data-test-subj': 'codeStructureTreeTab', }, ]; @@ -95,6 +96,7 @@ class CodeSideTabs extends React.PureComponent { initialSelectedTab={this.tabs.find(t => t.id === this.sideTab)} onTabClick={tab => this.switchTab(tab.id as Tabs)} expand={true} + selectedTab={this.tabs.find(t => t.id === this.sideTab)} /> ) => { if (action.payload) {