Browse Source

#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>
Alexander Krivonosov 4 years ago
parent
commit
a153ce7b21

+ 1 - 0
kafka-ui-contract/src/main/resources/swagger/kafka-ui-api.yaml

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

+ 1 - 1
kafka-ui-react-app/src/components/common/BytesFormatted/BytesFormatted.tsx

@@ -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);

+ 3 - 0
kafka-ui-react-app/src/components/common/BytesFormatted/__tests__/BytesFormatted.spec.tsx

@@ -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]}`);
   });