Merge pull request #290 from MartinH0/patch-1

Added Links to Version Info
This commit is contained in:
Alejandro Celaya 2020-07-09 17:42:39 +02:00 committed by GitHub
commit 6f6ba9e34d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 9 deletions

View file

@ -2,10 +2,12 @@ import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import classNames from 'classnames'; import classNames from 'classnames';
import { pipe } from 'ramda'; import { pipe } from 'ramda';
import { ExternalLink } from 'react-external-link';
import { serverType } from '../servers/prop-types'; import { serverType } from '../servers/prop-types';
import { versionToPrintable, versionToSemVer } from '../utils/helpers/version'; import { versionToPrintable, versionToSemVer } from '../utils/helpers/version';
const SHLINK_WEB_CLIENT_VERSION = '%_VERSION_%'; const SHLINK_WEB_CLIENT_VERSION = '%_VERSION_%';
const normalizeVersion = pipe(versionToSemVer(), versionToPrintable);
const propTypes = { const propTypes = {
selectedServer: serverType, selectedServer: serverType,
@ -13,13 +15,27 @@ const propTypes = {
clientVersion: PropTypes.string, clientVersion: PropTypes.string,
}; };
const versionLinkPropTypes = {
project: PropTypes.oneOf([ 'shlink', 'shlink-web-client' ]).isRequired,
version: PropTypes.string.isRequired,
};
const VersionLink = ({ project, version }) => (
<ExternalLink href={`https://github.com/shlinkio/${project}/releases/${version}`} className="text-muted">
<b>{version}</b>
</ExternalLink>
);
VersionLink.propTypes = versionLinkPropTypes;
const ShlinkVersions = ({ selectedServer, className, clientVersion = SHLINK_WEB_CLIENT_VERSION }) => { const ShlinkVersions = ({ selectedServer, className, clientVersion = SHLINK_WEB_CLIENT_VERSION }) => {
const { printableVersion: serverVersion } = selectedServer; const { printableVersion: serverVersion } = selectedServer;
const normalizedClientVersion = pipe(versionToSemVer(), versionToPrintable)(clientVersion); const normalizedClientVersion = normalizeVersion(clientVersion);
return ( return (
<small className={classNames('text-muted', className)}> <small className={classNames('text-muted', className)}>
Client: <b>{normalizedClientVersion}</b> - Server: <b>{serverVersion}</b> Client: <VersionLink project="shlink-web-client" version={normalizedClientVersion} /> -
Server: <VersionLink project="shlink" version={serverVersion} />
</small> </small>
); );
}; };

View file

@ -13,14 +13,20 @@ describe('<ShlinkVersions />', () => {
afterEach(() => wrapper && wrapper.unmount()); afterEach(() => wrapper && wrapper.unmount());
it.each([ it.each([
[ '1.2.3', 'foo', 'Client: v1.2.3 - Server: foo' ], [ '1.2.3', 'foo', 'v1.2.3', 'foo' ],
[ 'foo', '1.2.3', 'Client: latest - Server: 1.2.3' ], [ 'foo', '1.2.3', 'latest', '1.2.3' ],
[ 'latest', 'latest', 'Client: latest - Server: latest' ], [ 'latest', 'latest', 'latest', 'latest' ],
[ '5.5.0', '0.2.8', 'Client: v5.5.0 - Server: 0.2.8' ], [ '5.5.0', '0.2.8', 'v5.5.0', '0.2.8' ],
[ 'not-semver', 'something', 'Client: latest - Server: something' ], [ 'not-semver', 'something', 'latest', 'something' ],
])('displays expected versions', (clientVersion, printableVersion, expected) => { ])('displays expected versions', (clientVersion, printableVersion, expectedClientVersion, expectedServerVersion) => {
const wrapper = createWrapper({ clientVersion, selectedServer: { printableVersion } }); const wrapper = createWrapper({ clientVersion, selectedServer: { printableVersion } });
const links = wrapper.find('VersionLink');
const clientLink = links.at(0);
const serverLink = links.at(1);
expect(wrapper.text()).toEqual(expected); expect(clientLink.prop('project')).toEqual('shlink-web-client');
expect(clientLink.prop('version')).toEqual(expectedClientVersion);
expect(serverLink.prop('project')).toEqual('shlink');
expect(serverLink.prop('version')).toEqual(expectedServerVersion);
}); });
}); });