diff --git a/src/settings/Settings.tsx b/src/settings/Settings.tsx index 751af4a1..8415763b 100644 --- a/src/settings/Settings.tsx +++ b/src/settings/Settings.tsx @@ -1,7 +1,7 @@ import { FC, ReactNode } from 'react'; import { Navigate, Routes, Route } from 'react-router-dom'; import { NoMenuLayout } from '../common/NoMenuLayout'; -import { NavPills } from '../utils/NavPills'; +import { NavPillItem, NavPills } from '../utils/NavPills'; const SettingsSections: FC<{ items: ReactNode[] }> = ({ items }) => ( <> @@ -18,13 +18,11 @@ const Settings = ( Tags: FC, ) => () => ( - + + App + Short URLs + Others + , ]} />} /> diff --git a/src/utils/NavPills.tsx b/src/utils/NavPills.tsx index c65d9b89..e00000c7 100644 --- a/src/utils/NavPills.tsx +++ b/src/utils/NavPills.tsx @@ -1,17 +1,29 @@ -import { FC, ReactNode } from 'react'; +import { FC, Children, isValidElement } from 'react'; import { Card, Nav, NavLink } from 'reactstrap'; import { NavLink as RouterNavLink } from 'react-router-dom'; import './NavPills.scss'; -interface NavPillsProps { - items: { children: ReactNode; to: string; replace?: boolean }[]; +interface NavPillProps { + to: string; + replace?: boolean; } -export const NavPills: FC = ({ items }) => ( +export const NavPillItem: FC = ({ children, ...rest }) => ( + + {children} + +); + +export const NavPills: FC = ({ children }) => ( ); diff --git a/src/visits/VisitsStats.tsx b/src/visits/VisitsStats.tsx index 3a11e779..9c740a5d 100644 --- a/src/visits/VisitsStats.tsx +++ b/src/visits/VisitsStats.tsx @@ -15,7 +15,7 @@ import { Settings } from '../settings/reducers/settings'; import { SelectedServer } from '../servers/data'; import { supportsBotVisits } from '../utils/helpers/features'; import { prettify } from '../utils/helpers/numbers'; -import { NavPills } from '../utils/NavPills'; +import { NavPillItem, NavPills } from '../utils/NavPills'; import LineChartCard from './charts/LineChartCard'; import VisitsTable from './VisitsTable'; import { NormalizedOrphanVisit, NormalizedVisit, VisitsFilter, VisitsInfo, VisitsParams } from './types'; @@ -143,18 +143,14 @@ const VisitsStats: FC = ({ return ( <> - ({ - replace: true, - to: buildSectionUrl(subPath), - children: ( - <> - - {title} - - ), - }))} - /> + + {Object.values(sections).map(({ title, icon, subPath }, index) => ( + + + {title} + + ))} + ', () => { + it.each([ + [ 'Foo' ], + [ Hi! ], + [[ , Hi! ]], + ])('throws error when any of the children is not a NavPillItem', (children) => { + expect.assertions(1); + + try { + shallow({children}); + } catch (e: any) { + expect(e.message).toEqual('Only NavPillItem children are allowed inside NavPills.'); + } + }); + + it('renders provided items', () => { + const wrapper = shallow( + + 1 + 2 + 3 + , + ); + const card = wrapper.find(Card); + const nav = wrapper.find(Nav); + + expect(card).toHaveLength(1); + expect(card.prop('body')).toEqual(true); + expect(nav).toHaveLength(1); + expect(nav.prop('pills')).toEqual(true); + expect(nav.prop('fill')).toEqual(true); + }); +});