Skip to content

Commit

Permalink
Minor improvements and fixes (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavgoel29 authored Nov 11, 2024
1 parent 5ec625f commit 1e97253
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/pages/Stream/Views/Manage/Alerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ type ColumnRuleProps = {
};

const getInputComponent = (type: 'text' | 'number' | 'timestamp') => {
return type === 'text' || 'timestamp' ? TextInput : NumberInput;
return type === 'text' || type === 'timestamp' ? TextInput : NumberInput;
};

const ColumnRule = (props: ColumnRuleProps) => {
Expand Down
17 changes: 0 additions & 17 deletions src/utils/convertToReadableScale.ts

This file was deleted.

16 changes: 8 additions & 8 deletions src/utils/formatBytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ export const formatBytes = (a: number, b: number = 1) => {
if (!+a) return '0 Bytes';
const c = b < 0 ? 0 : b,
d = Math.floor(Math.log(a) / Math.log(1024));
return `${parseFloat((a / Math.pow(1024, d)).toFixed(c))} ${
['Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'][d]
}`;
return `${parseFloat((a / Math.pow(1024, d)).toFixed(c))} ${['Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'][d]
}`;
};

export const convertGibToBytes = (value: number) => {
Expand All @@ -13,23 +12,24 @@ export const convertGibToBytes = (value: number) => {
return value * Math.pow(1024, 3);
};

export function HumanizeNumber(val: number) {
export const HumanizeNumber = (val: number) => {
// Thousands, millions, billions etc..
let s = ['', ' K', ' M', ' B', ' T'];
const s = ['', ' K', ' M', ' B', ' T'];

// Dividing the value by 3.
let sNum = Math.floor(('' + val).length / 3);
const sNum = Math.floor(('' + val).length / 3);

// Calculating the precised value.
let sVal = parseFloat((sNum != 0 ? val / Math.pow(1000, sNum) : val).toPrecision(4));
const sVal = parseFloat((sNum != 0 ? val / Math.pow(1000, sNum) : val).toPrecision(4));

if (sVal % 1 != 0) {
return sVal.toFixed(1) + s[sNum];
}

// Appending the letter to precised val.
return sVal + s[sNum];
}
};


export const sanitizeEventsCount = (val: any) => {
return typeof val === 'number' ? HumanizeNumber(val) : '0';
Expand Down

0 comments on commit 1e97253

Please sign in to comment.