From 3cd3b93511033d9948ddaf5b6ed8281537634994 Mon Sep 17 00:00:00 2001 From: Ildar Kamalov Date: Mon, 29 Oct 2018 13:12:04 +0300 Subject: [PATCH 1/4] Fix IP address sorting Closes #437 --- client/src/components/Dashboard/Clients.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/client/src/components/Dashboard/Clients.js b/client/src/components/Dashboard/Clients.js index 633ef08b..57d97e7f 100644 --- a/client/src/components/Dashboard/Clients.js +++ b/client/src/components/Dashboard/Clients.js @@ -23,6 +23,22 @@ class Clients extends Component { Header: 'IP', accessor: 'ip', Cell: ({ value }) => (
{value}
), + sortMethod: (a, b) => { + const nextValue = a.split('.'); + const prevValue = b.split('.'); + + for (let i = 0; i < nextValue.length; i += 1) { + const nextNumber = parseInt(nextValue[i], 10); + const prevNumber = parseInt(prevValue[i], 10); + + if (nextNumber < prevNumber) { + return -1; + } else if (nextNumber > prevNumber) { + return 1; + } + } + return 0; + }, }, { Header: 'Requests count', accessor: 'count', From c427034e27e888dab33e635926e6f828b752e265 Mon Sep 17 00:00:00 2001 From: Ildar Kamalov Date: Mon, 29 Oct 2018 13:13:32 +0300 Subject: [PATCH 2/4] Fix tooltips over-lapping Closes #439 --- client/src/components/Dashboard/BlockedDomains.js | 4 ++-- client/src/components/Dashboard/QueriedDomains.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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/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 && } From 9173b0ee7a94527870e9b35478e03d6030c26846 Mon Sep 17 00:00:00 2001 From: Ildar Kamalov Date: Mon, 29 Oct 2018 14:38:01 +0300 Subject: [PATCH 3/4] Move tiny-version-compare module to helpers --- client/package-lock.json | 11 ++--- client/package.json | 1 - client/src/helpers/versionCompare.js | 63 ++++++++++++++++++++++++++++ client/src/reducers/index.js | 2 +- 4 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 client/src/helpers/versionCompare.js 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/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'; From c39831abbcc3942bc7af9f8fd6c816b96770ee3e Mon Sep 17 00:00:00 2001 From: Ildar Kamalov Date: Mon, 29 Oct 2018 15:24:35 +0300 Subject: [PATCH 4/4] Fix sorting method --- client/src/components/Dashboard/Clients.js | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/client/src/components/Dashboard/Clients.js b/client/src/components/Dashboard/Clients.js index 57d97e7f..a9fa4792 100644 --- a/client/src/components/Dashboard/Clients.js +++ b/client/src/components/Dashboard/Clients.js @@ -23,22 +23,7 @@ class Clients extends Component { Header: 'IP', accessor: 'ip', Cell: ({ value }) => (
{value}
), - sortMethod: (a, b) => { - const nextValue = a.split('.'); - const prevValue = b.split('.'); - - for (let i = 0; i < nextValue.length; i += 1) { - const nextNumber = parseInt(nextValue[i], 10); - const prevNumber = parseInt(prevValue[i], 10); - - if (nextNumber < prevNumber) { - return -1; - } else if (nextNumber > prevNumber) { - return 1; - } - } - return 0; - }, + sortMethod: (a, b) => parseInt(a.replace(/\./g, ''), 10) - parseInt(b.replace(/\./g, ''), 10), }, { Header: 'Requests count', accessor: 'count',