Skip to content

Commit

Permalink
Task: Persist sidebar selection (#1664)
Browse files Browse the repository at this point in the history
  • Loading branch information
Onokaev authored Apr 19, 2022
1 parent 96d3112 commit 27d917e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
13 changes: 11 additions & 2 deletions src/app/views/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ interface IAppState {
selectedVerb: string;
mobileScreen: boolean;
hideDialog: boolean;
sidebarTabSelection: string;
}

class App extends Component<IAppProps, IAppState> {
Expand All @@ -78,10 +79,17 @@ class App extends Component<IAppProps, IAppState> {
this.state = {
selectedVerb: 'GET',
mobileScreen: false,
hideDialog: true
hideDialog: true,
sidebarTabSelection: 'sample-queries'
};
}

private setSidebarTabSelection = (selectedTab : string) => {
this.setState({
sidebarTabSelection: selectedTab
});
}

public componentDidMount = async () => {
this.displayToggleButton(this.mediaQueryList);
this.mediaQueryList.addListener(this.displayToggleButton);
Expand Down Expand Up @@ -476,7 +484,8 @@ class App extends Component<IAppProps, IAppState> {
{this.displayAuthenticationSection(minimised)}
<hr className={classes.separator} />

{showSidebar && (<Sidebar />)}
{showSidebar && ( <Sidebar currentTab = { this.state.sidebarTabSelection }
setSidebarTabSelection = { this.setSidebarTabSelection } /> ) }
</Resizable>
)}
{graphExplorerMode === Mode.TryIt &&
Expand Down
27 changes: 18 additions & 9 deletions src/app/views/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,25 @@ import { translateMessage } from '../../utils/translate-messages';
import History from './history/History';
import { ResourceExplorer } from './resource-explorer';
import SampleQueries from './sample-queries/SampleQueries';
export const Sidebar = () => {

interface ISidebar {
currentTab: string;
setSidebarTabSelection: Function;
}
export const Sidebar = (props: ISidebar) => {

const onPivotItemClick = (item?: PivotItem) => {
if (!item) { return; }
const key = item.props.itemKey;
if (key) {
props.setSidebarTabSelection(key);
telemetry.trackTabClickEvent(key);
}
}

return (
<div>
<Pivot onLinkClick={onPivotItemClick} overflowBehavior='menu'>
<Pivot onLinkClick={onPivotItemClick} overflowBehavior='menu' defaultSelectedKey={props.currentTab}>
<PivotItem
headerText={translateMessage('Sample Queries')}
itemIcon='Rocket'
Expand Down Expand Up @@ -45,10 +60,4 @@ export const Sidebar = () => {
);
};

function onPivotItemClick(item?: PivotItem) {
if (!item) { return; }
const key = item.props.itemKey;
if (key) {
telemetry.trackTabClickEvent(key);
}
}

0 comments on commit 27d917e

Please sign in to comment.