mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-02-27 04:06:39 +00:00
32 lines
877 B
JavaScript
32 lines
877 B
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { serverType } from '../prop-types';
|
|
import { compareVersions } from '../../utils/helpers/version';
|
|
|
|
const propTypes = {
|
|
minVersion: PropTypes.string,
|
|
maxVersion: PropTypes.string,
|
|
selectedServer: serverType,
|
|
children: PropTypes.node.isRequired,
|
|
};
|
|
|
|
const ForServerVersion = ({ minVersion, maxVersion, selectedServer, children }) => {
|
|
if (!selectedServer) {
|
|
return null;
|
|
}
|
|
|
|
const { version } = selectedServer;
|
|
const matchesMinVersion = !minVersion || compareVersions(version, '>=', minVersion);
|
|
const matchesMaxVersion = !maxVersion || compareVersions(version, '<=', maxVersion);
|
|
|
|
if (!matchesMinVersion || !matchesMaxVersion) {
|
|
return null;
|
|
}
|
|
|
|
return <React.Fragment>{children}</React.Fragment>;
|
|
};
|
|
|
|
ForServerVersion.propTypes = propTypes;
|
|
|
|
export default ForServerVersion;
|