diff --git a/src/short-urls/CreateShortUrl.js b/src/short-urls/CreateShortUrl.js index 9119bc7b..57d604af 100644 --- a/src/short-urls/CreateShortUrl.js +++ b/src/short-urls/CreateShortUrl.js @@ -4,11 +4,11 @@ import { assoc, dissoc, isEmpty, isNil, pipe, replace, trim } from 'ramda'; import React from 'react'; import { Collapse } from 'reactstrap'; import * as PropTypes from 'prop-types'; -import { compare } from 'compare-versions'; import DateInput from '../utils/DateInput'; import Checkbox from '../utils/Checkbox'; import ForVersion from '../utils/ForVersion'; import { serverType } from '../servers/prop-types'; +import { compareVersions } from '../utils/utils'; import { createShortUrlResultType } from './reducers/shortUrlCreation'; import UseExistingIfFoundInfoIcon from './UseExistingIfFoundInfoIcon'; @@ -71,8 +71,8 @@ const CreateShortUrl = (TagsSelector, CreateShortUrlResult) => class CreateShort assoc('validUntil', formatDate(this.state.validUntil)) )(this.state)); }; - const currentServerVersion = this.props.selectedServer ? this.props.selectedServer.version : '9999'; - const disableDomain = compare('1.19.0-beta.1', currentServerVersion, '>'); + const currentServerVersion = this.props.selectedServer ? this.props.selectedServer.version : ''; + const disableDomain = isEmpty(currentServerVersion) || compareVersions(currentServerVersion, '<', '1.19.0-beta.1'); return (
diff --git a/src/utils/ForVersion.js b/src/utils/ForVersion.js index 10f9befa..7ed39890 100644 --- a/src/utils/ForVersion.js +++ b/src/utils/ForVersion.js @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { compare } from 'compare-versions'; import { isEmpty } from 'ramda'; +import { compareVersions } from './utils'; const propTypes = { minVersion: PropTypes.string.isRequired, @@ -10,7 +10,7 @@ const propTypes = { }; const ForVersion = ({ minVersion, currentServerVersion, children }) => - isEmpty(currentServerVersion) || compare(minVersion, currentServerVersion, '>') + isEmpty(currentServerVersion) || compareVersions(currentServerVersion, '<', minVersion) ? null : {children}; diff --git a/src/utils/utils.js b/src/utils/utils.js index b1daf53b..3edcb7fb 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -4,6 +4,7 @@ import marker from 'leaflet/dist/images/marker-icon.png'; import markerShadow from 'leaflet/dist/images/marker-shadow.png'; import { range } from 'ramda'; import { useState } from 'react'; +import { compare } from 'compare-versions'; const TEN_ROUNDING_NUMBER = 10; 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 compareVersions = (firstVersion, operator, secondVersion) => compare( + firstVersion, + secondVersion, + operator +);