2020-03-05 12:18:33 +03:00
|
|
|
import React from 'react';
|
2020-03-05 13:11:26 +03:00
|
|
|
import classNames from 'classnames';
|
2020-03-05 14:53:32 +03:00
|
|
|
import { pipe } from 'ramda';
|
2020-07-09 18:17:19 +03:00
|
|
|
import { ExternalLink } from 'react-external-link';
|
2020-03-28 19:33:23 +03:00
|
|
|
import { versionToPrintable, versionToSemVer } from '../utils/helpers/version';
|
2020-08-28 21:05:01 +03:00
|
|
|
import { isReachableServer, SelectedServer } from '../servers/data';
|
2020-03-05 14:53:32 +03:00
|
|
|
|
|
|
|
const SHLINK_WEB_CLIENT_VERSION = '%_VERSION_%';
|
2020-07-09 18:17:19 +03:00
|
|
|
const normalizeVersion = pipe(versionToSemVer(), versionToPrintable);
|
2020-03-05 12:18:33 +03:00
|
|
|
|
2020-08-28 21:05:01 +03:00
|
|
|
export interface ShlinkVersionsProps {
|
|
|
|
selectedServer: SelectedServer;
|
|
|
|
clientVersion?: string;
|
|
|
|
className?: string;
|
|
|
|
}
|
2020-03-05 12:18:33 +03:00
|
|
|
|
2020-08-28 21:05:01 +03:00
|
|
|
interface VersionLinkProps {
|
|
|
|
project: 'shlink' | 'shlink-web-client';
|
|
|
|
version: string;
|
|
|
|
}
|
2020-07-09 18:17:19 +03:00
|
|
|
|
2020-08-28 21:05:01 +03:00
|
|
|
const VersionLink = ({ project, version }: VersionLinkProps) => (
|
2020-07-09 18:17:19 +03:00
|
|
|
<ExternalLink href={`https://github.com/shlinkio/${project}/releases/${version}`} className="text-muted">
|
|
|
|
<b>{version}</b>
|
|
|
|
</ExternalLink>
|
|
|
|
);
|
|
|
|
|
2020-08-28 21:05:01 +03:00
|
|
|
const ShlinkVersions = (
|
|
|
|
{ selectedServer, className, clientVersion = SHLINK_WEB_CLIENT_VERSION }: ShlinkVersionsProps,
|
|
|
|
) => {
|
2020-07-09 18:17:19 +03:00
|
|
|
const normalizedClientVersion = normalizeVersion(clientVersion);
|
2020-03-05 12:18:33 +03:00
|
|
|
|
2020-03-05 14:53:32 +03:00
|
|
|
return (
|
|
|
|
<small className={classNames('text-muted', className)}>
|
2020-08-28 21:05:01 +03:00
|
|
|
{isReachableServer(selectedServer) &&
|
|
|
|
<React.Fragment>Server: <VersionLink project="shlink" version={selectedServer.printableVersion} /> - </React.Fragment>
|
|
|
|
}
|
|
|
|
Client: <VersionLink project="shlink-web-client" version={normalizedClientVersion} />
|
2020-03-05 14:53:32 +03:00
|
|
|
</small>
|
|
|
|
);
|
2020-03-05 12:18:33 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
export default ShlinkVersions;
|