Defined custom function to compare versions which defines the operator in the middle

This commit is contained in:
Alejandro Celaya 2019-10-05 11:03:17 +02:00
parent 354d19af1b
commit ce9ecd7b93
3 changed files with 12 additions and 5 deletions

View file

@ -4,11 +4,11 @@ import { assoc, dissoc, isEmpty, isNil, pipe, replace, trim } from 'ramda';
import React from 'react'; import React from 'react';
import { Collapse } from 'reactstrap'; import { Collapse } from 'reactstrap';
import * as PropTypes from 'prop-types'; import * as PropTypes from 'prop-types';
import { compare } from 'compare-versions';
import DateInput from '../utils/DateInput'; import DateInput from '../utils/DateInput';
import Checkbox from '../utils/Checkbox'; import Checkbox from '../utils/Checkbox';
import ForVersion from '../utils/ForVersion'; import ForVersion from '../utils/ForVersion';
import { serverType } from '../servers/prop-types'; import { serverType } from '../servers/prop-types';
import { compareVersions } from '../utils/utils';
import { createShortUrlResultType } from './reducers/shortUrlCreation'; import { createShortUrlResultType } from './reducers/shortUrlCreation';
import UseExistingIfFoundInfoIcon from './UseExistingIfFoundInfoIcon'; import UseExistingIfFoundInfoIcon from './UseExistingIfFoundInfoIcon';
@ -71,8 +71,8 @@ const CreateShortUrl = (TagsSelector, CreateShortUrlResult) => class CreateShort
assoc('validUntil', formatDate(this.state.validUntil)) assoc('validUntil', formatDate(this.state.validUntil))
)(this.state)); )(this.state));
}; };
const currentServerVersion = this.props.selectedServer ? this.props.selectedServer.version : '9999'; const currentServerVersion = this.props.selectedServer ? this.props.selectedServer.version : '';
const disableDomain = compare('1.19.0-beta.1', currentServerVersion, '>'); const disableDomain = isEmpty(currentServerVersion) || compareVersions(currentServerVersion, '<', '1.19.0-beta.1');
return ( return (
<div className="shlink-container"> <div className="shlink-container">

View file

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { compare } from 'compare-versions';
import { isEmpty } from 'ramda'; import { isEmpty } from 'ramda';
import { compareVersions } from './utils';
const propTypes = { const propTypes = {
minVersion: PropTypes.string.isRequired, minVersion: PropTypes.string.isRequired,
@ -10,7 +10,7 @@ const propTypes = {
}; };
const ForVersion = ({ minVersion, currentServerVersion, children }) => const ForVersion = ({ minVersion, currentServerVersion, children }) =>
isEmpty(currentServerVersion) || compare(minVersion, currentServerVersion, '>') isEmpty(currentServerVersion) || compareVersions(currentServerVersion, '<', minVersion)
? null ? null
: <React.Fragment>{children}</React.Fragment>; : <React.Fragment>{children}</React.Fragment>;

View file

@ -4,6 +4,7 @@ import marker from 'leaflet/dist/images/marker-icon.png';
import markerShadow from 'leaflet/dist/images/marker-shadow.png'; import markerShadow from 'leaflet/dist/images/marker-shadow.png';
import { range } from 'ramda'; import { range } from 'ramda';
import { useState } from 'react'; import { useState } from 'react';
import { compare } from 'compare-versions';
const TEN_ROUNDING_NUMBER = 10; const TEN_ROUNDING_NUMBER = 10;
const DEFAULT_TIMEOUT_DELAY = 2000; const DEFAULT_TIMEOUT_DELAY = 2000;
@ -53,3 +54,9 @@ export const useToggle = (initialValue = false) => {
}; };
export const wait = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds)); export const wait = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
export const compareVersions = (firstVersion, operator, secondVersion) => compare(
firstVersion,
secondVersion,
operator
);