Deleted ForServerVersion component, which is no longer used

This commit is contained in:
Alejandro Celaya 2022-05-02 19:28:07 +02:00
parent 677f1da8df
commit 337bfc47c1
6 changed files with 3 additions and 71 deletions

View file

@ -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 {

View file

@ -59,7 +59,7 @@ export const Overview = (
</div>
<div className="col-lg-6 col-xl-3 mb-3">
<HighlightCard title="Orphan visits" link={`/server/${serverId}/orphan-visits`}>
{loadingVisits ? 'Loading...' : prettify(orphanVisitsCount ?? 0)}
{loadingVisits ? 'Loading...' : prettify(orphanVisitsCount)}
</HighlightCard>
</div>
<div className="col-lg-6 col-xl-3 mb-3">

View file

@ -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<Versions>;
interface ForServerVersionConnectProps extends ForServerVersionProps {
selectedServer: SelectedServer;
}
export const ForServerVersion: FC<ForServerVersionConnectProps> = (
{ minVersion, maxVersion, selectedServer, children },
) => {
if (!isReachableServer(selectedServer)) {
return null;
}
const { version } = selectedServer;
const matchesVersion = versionMatch(version, { maxVersion, minVersion });
if (!matchesVersion) {
return null;
}
return <>{children}</>;
};

View file

@ -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']));

View file

@ -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;
}

View file

@ -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('<ForServerVersion />', () => {
const setUp = (selectedServer: SelectedServer, minVersion?: SemVerPattern, maxVersion?: SemVerPattern) => render(
<ForServerVersion minVersion={minVersion} maxVersion={maxVersion} selectedServer={selectedServer}>
<span>Hello</span>
</ForServerVersion>,
);
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<ReachableServer>({ 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<ReachableServer>({ version, printableVersion: version }), min, max);
expect(screen.queryByText('Hello')).toBeInTheDocument();
});
});