#289: Negative segment size (#295)

* Fix the negative segment size problem

* Fixed contract topic size bug

Co-authored-by: German Osin <german.osin@gmail.com>
This commit is contained in:
Alexander Krivonosov 2021-03-24 12:08:54 +03:00 committed by GitHub
parent e78284aa5b
commit a153ce7b21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 1 deletions

View file

@ -1215,6 +1215,7 @@ components:
type: integer
segmentSize:
type: integer
format: int64
segmentCount:
type: integer
underReplicatedPartitions:

View file

@ -11,7 +11,7 @@ const BytesFormatted: React.FC<Props> = ({ value, precision = 0 }) => {
const formatedValue = React.useMemo((): string => {
try {
const bytes = typeof value === 'string' ? parseInt(value, 10) : value;
if (Number.isNaN(bytes)) return `-Bytes`;
if (Number.isNaN(bytes) || (bytes && bytes < 0)) return `-Bytes`;
if (!bytes || bytes < 1024) return `${Math.ceil(bytes || 0)}${sizes[0]}`;
const pow = Math.floor(Math.log2(bytes) / 10);
const multiplier = 10 ** (precision < 0 ? 0 : precision);

View file

@ -32,6 +32,9 @@ describe('BytesFormatted', () => {
component = shallow(<BytesFormatted value="some string" />);
expect(component.text()).toEqual(`-${sizes[0]}`);
component = shallow(<BytesFormatted value={-100000} />);
expect(component.text()).toEqual(`-${sizes[0]}`);
component = shallow(<BytesFormatted value={undefined} />);
expect(component.text()).toEqual(`0${sizes[0]}`);
});