Skip to content

Commit

Permalink
fix(code/frontend): should disable structure tab if no structure or l…
Browse files Browse the repository at this point in the history
…oad failed (#34908)
  • Loading branch information
WangQianliang authored Apr 12, 2019
1 parent 116c7f6 commit eaa578a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
13 changes: 7 additions & 6 deletions x-pack/plugins/code/public/components/main/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +35,7 @@ const Container = styled.div`
interface Props extends RouteComponentProps<MainRouteParams> {
loadingFileTree: boolean;
loadingStructureTree: boolean;
hasStructure: boolean;
}

class CodeMain extends React.Component<Props> {
Expand All @@ -56,14 +58,15 @@ class CodeMain extends React.Component<Props> {
}

public render() {
const { loadingFileTree, loadingStructureTree } = this.props;
const { loadingFileTree, loadingStructureTree, hasStructure } = this.props;
return (
<Root>
<Container>
<React.Fragment>
<SideTabs
loadingFileTree={loadingFileTree}
loadingStructureTree={loadingStructureTree}
hasStructure={hasStructure}
/>
<Content />
</React.Fragment>
Expand All @@ -77,9 +80,7 @@ class CodeMain extends React.Component<Props> {
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);
4 changes: 3 additions & 1 deletion x-pack/plugins/code/public/components/main/side_tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ enum Tabs {
interface Props extends RouteComponentProps<MainRouteParams> {
loadingFileTree: boolean;
loadingStructureTree: boolean;
hasStructure: boolean;
}

class CodeSideTabs extends React.PureComponent<Props> {
Expand Down Expand Up @@ -73,7 +74,7 @@ class CodeSideTabs extends React.PureComponent<Props> {
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',
},
];
Expand All @@ -95,6 +96,7 @@ class CodeSideTabs extends React.PureComponent<Props> {
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)}
/>
<Shortcut
keyCode="t"
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/code/public/reducers/symbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export const symbol = handleActions(
...state.symbols,
[path]: data,
};
draft.error = undefined;
}),
[String(loadStructureFailed)]: (state: SymbolState, action: Action<any>) => {
if (action.payload) {
Expand Down

0 comments on commit eaa578a

Please sign in to comment.