Skip to content

Commit

Permalink
feat(ui): show size in bytes in the /topic page #616 (#709)
Browse files Browse the repository at this point in the history
Implements a function to show bytes size with a round way.
With this commit now its possible se values likce 1.256 GB

close #616
  • Loading branch information
ThiagoTeodoro authored Jun 10, 2021
1 parent 00473d3 commit aaf0e9f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion client/src/containers/Topic/TopicList/TopicList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class TopicList extends Root {
name: topic.name,
count: topic.size,
lastWrite: undefined,
size: showBytes(topic.logDirSize, 0),
size: showBytes(topic.logDirSize),
partitionsTotal: topic.partitions.length,
replicationFactor: topic.replicaCount,
replicationInSync: topic.inSyncReplicaCount,
Expand Down
23 changes: 19 additions & 4 deletions client/src/utils/converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,25 @@ export function showTime(milliseconds) {
return `${valueToSHow} ${decimalPartToShow}`;
}

export function showBytes(bytes, dPlaces = 2) {
if (!bytes) return '0 B';
const value = handleConvert(bytes, 'B');
return `${parseFloat(value.val.toFixed(dPlaces))} ${value.unit}`;
/**
* This function is responsible for showing the bytes in a
* friendly way to the user, making the leases for upper
* measures such as MB, GB, TB etc.
*
* @param {*} bytes value in bytes to show
* @param {*} decimals decimal size place
* @returns
*/
export function showBytes(bytes, decimals = 3) {
if (bytes === 0) return '0 B';

const kbytes = 1024;
const decimalCheck = decimals < 0 ? 0 : decimals;
const measures = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];

const identification = Math.floor(Math.log(bytes) / Math.log(kbytes));

return parseFloat((bytes / Math.pow(kbytes, identification)).toFixed(decimalCheck)) + ' ' + measures[identification];
}

function insertRole(roles, roleType, role) {
Expand Down

0 comments on commit aaf0e9f

Please sign in to comment.