()
| 19 | }; |
| 20 | |
| 21 | export default function Header() { |
| 22 | const dispatch = useAppDispatch(); |
| 23 | const currentTab = useAppSelector((state) => state.ui.tabs.current); |
| 24 | const selectedFlows = useAppSelector((state) => state.flows.selected); |
| 25 | const [wasFlowSelected, setWasFlowSelected] = useState(false); |
| 26 | |
| 27 | const entries: Tab[] = [Tab.Capture, Tab.FlowList, Tab.Options]; |
| 28 | if (selectedFlows.length > 0) { |
| 29 | entries.push(Tab.Flow); |
| 30 | } |
| 31 | |
| 32 | // Switch to "Flow" tab if we just selected a new flow. |
| 33 | useEffect(() => { |
| 34 | if (selectedFlows.length > 0 && !wasFlowSelected) { |
| 35 | // User just clicked on a flow without having previously selected one. |
| 36 | dispatch(setCurrent(Tab.Flow)); |
| 37 | setWasFlowSelected(true); |
| 38 | } else if (selectedFlows.length === 0) { |
| 39 | if (wasFlowSelected) { |
| 40 | setWasFlowSelected(false); |
| 41 | } |
| 42 | if (currentTab === Tab.Flow) { |
| 43 | dispatch(setCurrent(Tab.FlowList)); |
| 44 | } |
| 45 | } |
| 46 | }, [selectedFlows, wasFlowSelected, currentTab]); |
| 47 | |
| 48 | function handleClick(tab: Tab, e: React.MouseEvent<HTMLAnchorElement>) { |
| 49 | e.preventDefault(); |
| 50 | dispatch(setCurrent(tab)); |
| 51 | } |
| 52 | |
| 53 | const ActiveMenu = tabs[currentTab]; |
| 54 | |
| 55 | return ( |
| 56 | <header> |
| 57 | <nav className="nav-tabs nav-tabs-lg"> |
| 58 | <FileMenu /> |
| 59 | {entries.map((tab) => ( |
| 60 | <a |
| 61 | key={tab} |
| 62 | href="#" |
| 63 | className={classnames({ active: tab === currentTab })} |
| 64 | onClick={(e) => handleClick(tab, e)} |
| 65 | > |
| 66 | {tabs[tab].title} |
| 67 | </a> |
| 68 | ))} |
| 69 | <HideInStatic> |
| 70 | <ConnectionIndicator /> |
| 71 | </HideInStatic> |
| 72 | </nav> |
| 73 | <div> |
| 74 | <ActiveMenu /> |
| 75 | </div> |
| 76 | </header> |
| 77 | ); |
| 78 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…