shlink-web-client/src/common/ShlinkVersions.js

46 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-03-05 12:18:33 +03:00
import React from 'react';
2020-03-05 13:11:26 +03:00
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { pipe } from 'ramda';
import { ExternalLink } from 'react-external-link';
2020-03-05 12:18:33 +03:00
import { serverType } from '../servers/prop-types';
import { versionToPrintable, versionToSemVer } from '../utils/helpers/version';
const SHLINK_WEB_CLIENT_VERSION = '%_VERSION_%';
const normalizeVersion = pipe(versionToSemVer(), versionToPrintable);
2020-03-05 12:18:33 +03:00
const propTypes = {
selectedServer: serverType,
2020-03-05 13:11:26 +03:00
className: PropTypes.string,
clientVersion: PropTypes.string,
2020-03-05 12:18:33 +03:00
};
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 { printableVersion: serverVersion } = selectedServer;
const normalizedClientVersion = normalizeVersion(clientVersion);
2020-03-05 12:18:33 +03:00
return (
<small className={classNames('text-muted', className)}>
Client: <VersionLink project="shlink-web-client" version={normalizedClientVersion} /> -
Server: <VersionLink project="shlink" version={serverVersion} />
</small>
);
2020-03-05 12:18:33 +03:00
};
ShlinkVersions.propTypes = propTypes;
export default ShlinkVersions;