From 337bfc47c19282f11e7b9abe0d6c72510db275f8 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 2 May 2022 19:28:07 +0200 Subject: [PATCH] Deleted ForServerVersion component, which is no longer used --- src/api/types/index.ts | 2 +- src/servers/Overview.tsx | 2 +- src/servers/helpers/ForServerVersion.tsx | 26 ------------- src/servers/services/provideServices.ts | 4 -- src/visits/reducers/visitsOverview.ts | 2 +- .../servers/helpers/ForServerVersion.test.tsx | 38 ------------------- 6 files changed, 3 insertions(+), 71 deletions(-) delete mode 100644 src/servers/helpers/ForServerVersion.tsx delete mode 100644 test/servers/helpers/ForServerVersion.test.tsx diff --git a/src/api/types/index.ts b/src/api/types/index.ts index ce94d65d..126750bd 100644 --- a/src/api/types/index.ts +++ b/src/api/types/index.ts @@ -46,7 +46,7 @@ export interface ShlinkVisits { export interface ShlinkVisitsOverview { visitsCount: number; - orphanVisitsCount?: number; // Optional only for versions older than 2.6.0 + orphanVisitsCount: number; } export interface ShlinkVisitsParams { diff --git a/src/servers/Overview.tsx b/src/servers/Overview.tsx index 6b22a17c..8903709d 100644 --- a/src/servers/Overview.tsx +++ b/src/servers/Overview.tsx @@ -59,7 +59,7 @@ export const Overview = (
- {loadingVisits ? 'Loading...' : prettify(orphanVisitsCount ?? 0)} + {loadingVisits ? 'Loading...' : prettify(orphanVisitsCount)}
diff --git a/src/servers/helpers/ForServerVersion.tsx b/src/servers/helpers/ForServerVersion.tsx deleted file mode 100644 index f7c8534c..00000000 --- a/src/servers/helpers/ForServerVersion.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import { FC, PropsWithChildren } from 'react'; -import { versionMatch, Versions } from '../../utils/helpers/version'; -import { isReachableServer, SelectedServer } from '../data'; - -export type ForServerVersionProps = PropsWithChildren; - -interface ForServerVersionConnectProps extends ForServerVersionProps { - selectedServer: SelectedServer; -} - -export const ForServerVersion: FC = ( - { minVersion, maxVersion, selectedServer, children }, -) => { - if (!isReachableServer(selectedServer)) { - return null; - } - - const { version } = selectedServer; - const matchesVersion = versionMatch(version, { maxVersion, minVersion }); - - if (!matchesVersion) { - return null; - } - - return <>{children}; -}; diff --git a/src/servers/services/provideServices.ts b/src/servers/services/provideServices.ts index 61c37cb1..fcb04a46 100644 --- a/src/servers/services/provideServices.ts +++ b/src/servers/services/provideServices.ts @@ -8,7 +8,6 @@ import ImportServersBtn from '../helpers/ImportServersBtn'; import { resetSelectedServer, selectServer } from '../reducers/selectedServer'; import { createServer, createServers, deleteServer, editServer, setAutoConnect } from '../reducers/servers'; import { fetchServers } from '../reducers/remoteServers'; -import { ForServerVersion } from '../helpers/ForServerVersion'; import { ServerError } from '../helpers/ServerError'; import { ConnectDecorator } from '../../container/types'; import { withoutSelectedServer } from '../helpers/withoutSelectedServer'; @@ -55,9 +54,6 @@ const provideServices = (bottle: Bottle, connect: ConnectDecorator) => { bottle.serviceFactory('ImportServersBtn', ImportServersBtn, 'ServersImporter'); bottle.decorator('ImportServersBtn', connect(['servers'], ['createServers'])); - bottle.serviceFactory('ForServerVersion', () => ForServerVersion); - bottle.decorator('ForServerVersion', connect(['selectedServer'])); - bottle.serviceFactory('ServerError', ServerError, 'DeleteServerButton'); bottle.decorator('ServerError', connect(['servers', 'selectedServer'])); diff --git a/src/visits/reducers/visitsOverview.ts b/src/visits/reducers/visitsOverview.ts index 9c1609b7..ec5d8fec 100644 --- a/src/visits/reducers/visitsOverview.ts +++ b/src/visits/reducers/visitsOverview.ts @@ -12,7 +12,7 @@ export const GET_OVERVIEW = 'shlink/visitsOverview/GET_OVERVIEW'; export interface VisitsOverview { visitsCount: number; - orphanVisitsCount?: number; + orphanVisitsCount: number; loading: boolean; error: boolean; } diff --git a/test/servers/helpers/ForServerVersion.test.tsx b/test/servers/helpers/ForServerVersion.test.tsx deleted file mode 100644 index d8865544..00000000 --- a/test/servers/helpers/ForServerVersion.test.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import { render, screen } from '@testing-library/react'; -import { Mock } from 'ts-mockery'; -import { ForServerVersion } from '../../../src/servers/helpers/ForServerVersion'; -import { ReachableServer, SelectedServer } from '../../../src/servers/data'; -import { SemVer, SemVerPattern } from '../../../src/utils/helpers/version'; - -describe('', () => { - const setUp = (selectedServer: SelectedServer, minVersion?: SemVerPattern, maxVersion?: SemVerPattern) => render( - - Hello - , - ); - - it('does not render children when current server is empty', () => { - setUp(null, '1.*.*'); - expect(screen.queryByText('Hello')).not.toBeInTheDocument(); - }); - - it.each([ - ['2.0.0' as SemVerPattern, undefined, '1.8.3' as SemVer], - [undefined, '1.8.0' as SemVerPattern, '1.8.3' as SemVer], - ['1.7.0' as SemVerPattern, '1.8.0' as SemVerPattern, '1.8.3' as SemVer], - ])('does not render children when current version does not match requirements', (min, max, version) => { - setUp(Mock.of({ version, printableVersion: version }), min, max); - expect(screen.queryByText('Hello')).not.toBeInTheDocument(); - }); - - it.each([ - ['2.0.0' as SemVerPattern, undefined, '2.8.3' as SemVer], - ['2.0.0' as SemVerPattern, undefined, '2.0.0' as SemVer], - [undefined, '1.8.0' as SemVerPattern, '1.8.0' as SemVer], - [undefined, '1.8.0' as SemVerPattern, '1.7.1' as SemVer], - ['1.7.0' as SemVerPattern, '1.8.0' as SemVerPattern, '1.7.3' as SemVer], - ])('renders children when current version matches requirements', (min, max, version) => { - setUp(Mock.of({ version, printableVersion: version }), min, max); - expect(screen.queryByText('Hello')).toBeInTheDocument(); - }); -});