diff --git a/src/common/MenuLayout.tsx b/src/common/MenuLayout.tsx index d7166288..99e0de49 100644 --- a/src/common/MenuLayout.tsx +++ b/src/common/MenuLayout.tsx @@ -5,12 +5,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import classNames from 'classnames'; import { withSelectedServer } from '../servers/helpers/withSelectedServer'; import { useSwipeable, useToggle } from '../utils/helpers/hooks'; -import { - supportsDomainRedirects, - supportsDomainVisits, - supportsNonOrphanVisits, - supportsOrphanVisits, -} from '../utils/helpers/features'; +import { supportsDomainRedirects, supportsDomainVisits, supportsNonOrphanVisits } from '../utils/helpers/features'; import { isReachableServer } from '../servers/data'; import NotFound from './NotFound'; import { AsideMenuProps } from './AsideMenu'; @@ -51,7 +46,6 @@ const MenuLayout = ( return ; } - const addOrphanVisitsRoute = supportsOrphanVisits(selectedServer); const addNonOrphanVisitsRoute = supportsNonOrphanVisits(selectedServer); const addManageDomainsRoute = supportsDomainRedirects(selectedServer); const addDomainVisitsRoute = supportsDomainVisits(selectedServer); @@ -76,7 +70,7 @@ const MenuLayout = ( } /> } /> {addDomainVisitsRoute && } />} - {addOrphanVisitsRoute && } />} + } /> {addNonOrphanVisitsRoute && } />} } /> {addManageDomainsRoute && } />} diff --git a/src/servers/Overview.tsx b/src/servers/Overview.tsx index 9127b1ab..e9ddec8b 100644 --- a/src/servers/Overview.tsx +++ b/src/servers/Overview.tsx @@ -10,7 +10,7 @@ import { CreateShortUrlProps } from '../short-urls/CreateShortUrl'; import { VisitsOverview } from '../visits/reducers/visitsOverview'; import { Topics } from '../mercure/helpers/Topics'; import { ShlinkShortUrlsListParams } from '../api/types'; -import { supportsNonOrphanVisits, supportsOrphanVisits } from '../utils/helpers/features'; +import { supportsNonOrphanVisits } from '../utils/helpers/features'; import { getServerId, SelectedServer } from './data'; import { HighlightCard } from './helpers/HighlightCard'; import { ForServerVersionProps } from './helpers/ForServerVersion'; @@ -42,7 +42,6 @@ export const Overview = ( const { loading: loadingTags } = tagsList; const { loading: loadingVisits, visitsCount, orphanVisitsCount } = visitsOverview; const serverId = getServerId(selectedServer); - const linkToOrphanVisits = supportsOrphanVisits(selectedServer); const linkToNonOrphanVisits = supportsNonOrphanVisits(selectedServer); const navigate = useNavigate(); @@ -61,7 +60,7 @@ export const Overview = (
- + {loadingVisits ? 'Loading...' : prettify(orphanVisitsCount ?? 0)} diff --git a/src/utils/helpers/features.ts b/src/utils/helpers/features.ts index 47887fb4..8746d174 100644 --- a/src/utils/helpers/features.ts +++ b/src/utils/helpers/features.ts @@ -1,17 +1,16 @@ import { isReachableServer, SelectedServer } from '../../servers/data'; -import { versionMatch, Versions } from './version'; +import { SemVerPattern, versionMatch } from './version'; -const serverMatchesVersions = (versions: Versions) => (selectedServer: SelectedServer): boolean => - isReachableServer(selectedServer) && versionMatch(selectedServer.version, versions); +const serverMatchesMinVersion = (minVersion: SemVerPattern) => (selectedServer: SelectedServer): boolean => + isReachableServer(selectedServer) && versionMatch(selectedServer.version, { minVersion }); -export const supportsShortUrlTitle = serverMatchesVersions({ minVersion: '2.6.0' }); -export const supportsOrphanVisits = supportsShortUrlTitle; -export const supportsBotVisits = serverMatchesVersions({ minVersion: '2.7.0' }); +export const supportsShortUrlTitle = serverMatchesMinVersion('2.6.0'); +export const supportsBotVisits = serverMatchesMinVersion('2.7.0'); export const supportsCrawlableVisits = supportsBotVisits; -export const supportsQrErrorCorrection = serverMatchesVersions({ minVersion: '2.8.0' }); +export const supportsQrErrorCorrection = serverMatchesMinVersion('2.8.0'); export const supportsDomainRedirects = supportsQrErrorCorrection; -export const supportsForwardQuery = serverMatchesVersions({ minVersion: '2.9.0' }); -export const supportsDefaultDomainRedirectsEdition = serverMatchesVersions({ minVersion: '2.10.0' }); -export const supportsNonOrphanVisits = serverMatchesVersions({ minVersion: '3.0.0' }); +export const supportsForwardQuery = serverMatchesMinVersion('2.9.0'); +export const supportsDefaultDomainRedirectsEdition = serverMatchesMinVersion('2.10.0'); +export const supportsNonOrphanVisits = serverMatchesMinVersion('3.0.0'); export const supportsAllTagsFiltering = supportsNonOrphanVisits; -export const supportsDomainVisits = serverMatchesVersions({ minVersion: '3.1.0' }); +export const supportsDomainVisits = serverMatchesMinVersion('3.1.0'); diff --git a/test/common/MenuLayout.test.tsx b/test/common/MenuLayout.test.tsx index 2cf03f78..425a242c 100644 --- a/test/common/MenuLayout.test.tsx +++ b/test/common/MenuLayout.test.tsx @@ -53,7 +53,6 @@ describe('', () => { }); it.each([ - ['2.5.0' as SemVer, 9], ['2.6.0' as SemVer, 10], ['2.7.0' as SemVer, 10], ['2.8.0' as SemVer, 11], diff --git a/test/servers/Overview.test.tsx b/test/servers/Overview.test.tsx index 1dbc7bcf..28008507 100644 --- a/test/servers/Overview.test.tsx +++ b/test/servers/Overview.test.tsx @@ -77,10 +77,11 @@ describe('', () => { const wrapper = createWrapper(); const links = wrapper.find(Link); - expect(links).toHaveLength(4); - expect(links.at(0).prop('to')).toEqual(`/server/${serverId}/list-short-urls/1`); - expect(links.at(1).prop('to')).toEqual(`/server/${serverId}/manage-tags`); - expect(links.at(2).prop('to')).toEqual(`/server/${serverId}/create-short-url`); - expect(links.at(3).prop('to')).toEqual(`/server/${serverId}/list-short-urls/1`); + expect(links).toHaveLength(5); + expect(links.at(0).prop('to')).toEqual(`/server/${serverId}/orphan-visits`); + expect(links.at(1).prop('to')).toEqual(`/server/${serverId}/list-short-urls/1`); + expect(links.at(2).prop('to')).toEqual(`/server/${serverId}/manage-tags`); + expect(links.at(3).prop('to')).toEqual(`/server/${serverId}/create-short-url`); + expect(links.at(4).prop('to')).toEqual(`/server/${serverId}/list-short-urls/1`); }); });