mirror of
https://github.com/ansible/awx.git
synced 2026-02-02 18:18:12 -03:30
RoutedTabs is now a functional component
This commit is contained in:
@@ -1,55 +1,44 @@
|
||||
import React from 'react';
|
||||
|
||||
import {
|
||||
withRouter
|
||||
} from 'react-router-dom';
|
||||
|
||||
import {
|
||||
Tab,
|
||||
Tabs
|
||||
} from '@patternfly/react-core';
|
||||
|
||||
class RoutedTabs extends React.Component {
|
||||
constructor (props) {
|
||||
super(props);
|
||||
export default function RoutedTabs (props) {
|
||||
const { history, tabsArray } = props;
|
||||
const getActiveTabId = () => {
|
||||
if (history && history.location.pathname) {
|
||||
const matchTab = tabsArray.find(selectedTab => selectedTab.link
|
||||
=== history.location.pathname);
|
||||
return matchTab.id;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
this.handleTabSelect = this.handleTabSelect.bind(this);
|
||||
function handleTabSelect (event, eventKey) {
|
||||
if (history && history.location.pathname) {
|
||||
const tab = tabsArray.find(tabElement => tabElement.id === eventKey);
|
||||
history.push(tab.link);
|
||||
}
|
||||
}
|
||||
|
||||
getActiveTabId () {
|
||||
const { history, tabsArray } = this.props;
|
||||
const matchTab = tabsArray.find(selectedTab => selectedTab.link === history.location.pathname);
|
||||
return matchTab ? matchTab.id : 0;
|
||||
}
|
||||
|
||||
handleTabSelect (event, eventKey) {
|
||||
const { history, tabsArray } = this.props;
|
||||
|
||||
const tab = tabsArray.find(tabElement => tabElement.id === eventKey);
|
||||
history.push(tab.link);
|
||||
}
|
||||
|
||||
render () {
|
||||
const { tabsArray } = this.props;
|
||||
return (
|
||||
<Tabs
|
||||
activeKey={this.getActiveTabId()}
|
||||
onSelect={this.handleTabSelect}
|
||||
>
|
||||
{tabsArray.map(tabElement => (
|
||||
<Tab
|
||||
className={`${tabElement.name}`}
|
||||
aria-label={`${tabElement.name}`}
|
||||
eventKey={tabElement.id}
|
||||
key={tabElement.id}
|
||||
link={tabElement.link}
|
||||
title={tabElement.name}
|
||||
/>
|
||||
))}
|
||||
</Tabs>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Tabs
|
||||
activeKey={getActiveTabId()}
|
||||
onSelect={handleTabSelect}
|
||||
>
|
||||
{tabsArray.map(tabElement => (
|
||||
<Tab
|
||||
className={`${tabElement.name}`}
|
||||
aria-label={`${tabElement.name}`}
|
||||
eventKey={tabElement.id}
|
||||
key={tabElement.id}
|
||||
link={tabElement.link}
|
||||
title={tabElement.name}
|
||||
/>
|
||||
))}
|
||||
</Tabs>
|
||||
);
|
||||
}
|
||||
|
||||
export { RoutedTabs as _RoutedTabs };
|
||||
export default withRouter(RoutedTabs);
|
||||
|
||||
Reference in New Issue
Block a user