Skip to content

Commit eaa578a

Browse files
fix(code/frontend): should disable structure tab if no structure or load failed (#34908)
1 parent 116c7f6 commit eaa578a

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

x-pack/plugins/code/public/components/main/main.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import styled from 'styled-components';
1111

1212
import chrome from 'ui/chrome';
1313
import { MainRouteParams } from '../../common/types';
14-
import { RootState } from '../../reducers';
1514
import { ShortcutsProvider } from '../shortcuts';
1615
import { Content } from './content';
1716
import { SideTabs } from './side_tabs';
17+
import { structureSelector } from '../../selectors';
18+
import { RootState } from '../../reducers';
1819

1920
const Root = styled.div`
2021
position: absolute;
@@ -34,6 +35,7 @@ const Container = styled.div`
3435
interface Props extends RouteComponentProps<MainRouteParams> {
3536
loadingFileTree: boolean;
3637
loadingStructureTree: boolean;
38+
hasStructure: boolean;
3739
}
3840

3941
class CodeMain extends React.Component<Props> {
@@ -56,14 +58,15 @@ class CodeMain extends React.Component<Props> {
5658
}
5759

5860
public render() {
59-
const { loadingFileTree, loadingStructureTree } = this.props;
61+
const { loadingFileTree, loadingStructureTree, hasStructure } = this.props;
6062
return (
6163
<Root>
6264
<Container>
6365
<React.Fragment>
6466
<SideTabs
6567
loadingFileTree={loadingFileTree}
6668
loadingStructureTree={loadingStructureTree}
69+
hasStructure={hasStructure}
6770
/>
6871
<Content />
6972
</React.Fragment>
@@ -77,9 +80,7 @@ class CodeMain extends React.Component<Props> {
7780
const mapStateToProps = (state: RootState) => ({
7881
loadingFileTree: state.file.loading,
7982
loadingStructureTree: state.symbol.loading,
83+
hasStructure: structureSelector(state).length > 0 && !state.symbol.error,
8084
});
8185

82-
export const Main = connect(
83-
mapStateToProps
84-
// @ts-ignore
85-
)(CodeMain);
86+
export const Main = connect(mapStateToProps)(CodeMain);

x-pack/plugins/code/public/components/main/side_tabs.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ enum Tabs {
2222
interface Props extends RouteComponentProps<MainRouteParams> {
2323
loadingFileTree: boolean;
2424
loadingStructureTree: boolean;
25+
hasStructure: boolean;
2526
}
2627

2728
class CodeSideTabs extends React.PureComponent<Props> {
@@ -73,7 +74,7 @@ class CodeSideTabs extends React.PureComponent<Props> {
7374
name: 'Structure',
7475
content: structureTabContent,
7576
isSelected: Tabs.structure === this.sideTab,
76-
disabled: this.props.match.params.pathType === PathTypes.tree,
77+
disabled: this.props.match.params.pathType === PathTypes.tree || !this.props.hasStructure,
7778
'data-test-subj': 'codeStructureTreeTab',
7879
},
7980
];
@@ -95,6 +96,7 @@ class CodeSideTabs extends React.PureComponent<Props> {
9596
initialSelectedTab={this.tabs.find(t => t.id === this.sideTab)}
9697
onTabClick={tab => this.switchTab(tab.id as Tabs)}
9798
expand={true}
99+
selectedTab={this.tabs.find(t => t.id === this.sideTab)}
98100
/>
99101
<Shortcut
100102
keyCode="t"

x-pack/plugins/code/public/reducers/symbol.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export const symbol = handleActions(
131131
...state.symbols,
132132
[path]: data,
133133
};
134+
draft.error = undefined;
134135
}),
135136
[String(loadStructureFailed)]: (state: SymbolState, action: Action<any>) => {
136137
if (action.payload) {

0 commit comments

Comments
 (0)