From 3cd3b93511033d9948ddaf5b6ed8281537634994 Mon Sep 17 00:00:00 2001 From: Ildar Kamalov Date: Mon, 29 Oct 2018 13:12:04 +0300 Subject: [PATCH] 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',