import React from 'react'; import { shape, string, number, arrayOf } from 'prop-types'; import { Tab, Tabs } from '@patternfly/react-core'; import { withRouter } from 'react-router-dom'; function RoutedTabs (props) { const { history, tabsArray } = props; const getActiveTabId = () => { const match = tabsArray.find(tab => tab.link === history.location.pathname); if (match) { return match.id; } return 0; }; function handleTabSelect (event, eventKey) { const match = tabsArray.find(tab => tab.id === eventKey); if (match) { history.push(match.link); } } return ( {tabsArray.map(tab => ( ))} ); } RoutedTabs.propTypes = { history: shape({ location: shape({ pathname: string.isRequired }).isRequired, }).isRequired, tabsArray: arrayOf(shape({ id: number.isRequired, link: string.isRequired, name: string.isRequired, })).isRequired, }; export { RoutedTabs as _RoutedTabs }; export default withRouter(RoutedTabs);