diff --git a/client/package-lock.json b/client/package-lock.json index 1e9b0f5d..a4170f6e 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -6551,7 +6551,7 @@ }, "html-webpack-plugin": { "version": "3.2.0", - "resolved": "https://registry.npmjs.org/html-webpack-plugin/-/html-webpack-plugin-3.2.0.tgz", + "resolved": "http://registry.npmjs.org/html-webpack-plugin/-/html-webpack-plugin-3.2.0.tgz", "integrity": "sha1-sBq71yOsqqeze2r0SS69oD2d03s=", "dev": true, "requires": { @@ -6601,7 +6601,7 @@ }, "readable-stream": { "version": "1.0.34", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz", "integrity": "sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw=", "dev": true, "requires": { @@ -14930,7 +14930,7 @@ }, "through": { "version": "2.3.8", - "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", + "resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz", "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", "dev": true }, @@ -14965,11 +14965,6 @@ "setimmediate": "^1.0.4" } }, - "tiny-version-compare": { - "version": "0.9.1", - "resolved": "https://registry.npmjs.org/tiny-version-compare/-/tiny-version-compare-0.9.1.tgz", - "integrity": "sha512-kYim94l7ptSmj9rqxUMkrcMCJ448CS+hwqjA7OFcRi0ISdi0zjgdSUklQ4velVVECCjCo5frU3tNZ3oSgIKzsA==" - }, "tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", diff --git a/client/package.json b/client/package.json index 38e18a30..9e3a16e8 100644 --- a/client/package.json +++ b/client/package.json @@ -30,7 +30,6 @@ "redux-actions": "^2.4.0", "redux-thunk": "^2.3.0", "svg-url-loader": "^2.3.2", - "tiny-version-compare": "^0.9.1", "whatwg-fetch": "2.0.3" }, "devDependencies": { diff --git a/client/src/components/Dashboard/BlockedDomains.js b/client/src/components/Dashboard/BlockedDomains.js index 707007a7..d2a81029 100644 --- a/client/src/components/Dashboard/BlockedDomains.js +++ b/client/src/components/Dashboard/BlockedDomains.js @@ -20,8 +20,8 @@ class BlockedDomains extends Component { const trackerData = getTrackerData(value); return ( -
-
+
+
{value}
{trackerData && } diff --git a/client/src/components/Dashboard/Clients.js b/client/src/components/Dashboard/Clients.js index 633ef08b..a9fa4792 100644 --- a/client/src/components/Dashboard/Clients.js +++ b/client/src/components/Dashboard/Clients.js @@ -23,6 +23,7 @@ class Clients extends Component { Header: 'IP', accessor: 'ip', Cell: ({ value }) => (
{value}
), + sortMethod: (a, b) => parseInt(a.replace(/\./g, ''), 10) - parseInt(b.replace(/\./g, ''), 10), }, { Header: 'Requests count', accessor: 'count', diff --git a/client/src/components/Dashboard/QueriedDomains.js b/client/src/components/Dashboard/QueriedDomains.js index 045ceb6c..7ffc2555 100644 --- a/client/src/components/Dashboard/QueriedDomains.js +++ b/client/src/components/Dashboard/QueriedDomains.js @@ -29,8 +29,8 @@ class QueriedDomains extends Component { const trackerData = getTrackerData(value); return ( -
-
+
+
{value}
{trackerData && } diff --git a/client/src/helpers/versionCompare.js b/client/src/helpers/versionCompare.js new file mode 100644 index 00000000..47302d6f --- /dev/null +++ b/client/src/helpers/versionCompare.js @@ -0,0 +1,63 @@ +/* +* Project: tiny-version-compare https://github.com/bfred-it/tiny-version-compare +* License (MIT) https://github.com/bfred-it/tiny-version-compare/blob/master/LICENSE +*/ +const split = v => String(v).replace(/^[vr]/, '') // Drop initial 'v' or 'r' + .replace(/([a-z]+)/gi, '.$1.') // Sort each word separately + .replace(/[-.]+/g, '.') // Consider dashes as separators (+ trim multiple separators) + .split('.'); + +// Development versions are considered "negative", +// but localeCompare doesn't handle negative numbers. +// This offset is applied to reset the lowest development version to 0 +const offset = (part) => { + // Not numeric, return as is + if (Number.isNaN(part)) { + return part; + } + return 5 + Number(part); +}; + +const parsePart = (part) => { + // Missing, consider it zero + if (typeof part === 'undefined') { + return 0; + } + // Sort development versions + switch (part.toLowerCase()) { + case 'dev': + return -5; + case 'alpha': + return -4; + case 'beta': + return -3; + case 'rc': + return -2; + case 'pre': + return -1; + default: + } + // Return as is, it’s either a plain number or text that will be sorted alphabetically + return part; +}; + +const versionCompare = (prev, next) => { + const a = split(prev); + const b = split(next); + for (let i = 0; i < a.length || i < b.length; i += 1) { + const ai = offset(parsePart(a[i])); + const bi = offset(parsePart(b[i])); + const sort = String(ai).localeCompare(bi, 'en', { + numeric: true, + }); + // Once the difference is found, + // stop comparing the rest of the parts + if (sort !== 0) { + return sort; + } + } + // No difference found + return 0; +}; + +export default versionCompare; diff --git a/client/src/reducers/index.js b/client/src/reducers/index.js index 9fbd8f73..2e32be98 100644 --- a/client/src/reducers/index.js +++ b/client/src/reducers/index.js @@ -1,8 +1,8 @@ import { combineReducers } from 'redux'; import { handleActions } from 'redux-actions'; import { loadingBarReducer } from 'react-redux-loading-bar'; -import versionCompare from 'tiny-version-compare'; import nanoid from 'nanoid'; +import versionCompare from '../helpers/versionCompare'; import * as actions from '../actions';