Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Code] disable structure tab when necessary #34908

Merged
merged 1 commit into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the change of SideTabs with hasStructure in this PR though?

/>
<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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'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)}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mw-ding Code intelligence doesn't carry over tab in the url, but we have to control the selectedTab here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean by code intelligence? We want to make sure if the tab=structure param will be carried over to a new page by jumpping to reference/definition.

/>
<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