Skip to content

Commit 2569548

Browse files
committed
improve byte formatting and document count handling
1 parent a9b7f37 commit 2569548

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/compass-collection/src/components/mock-data-generator-modal/document-count-screen.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import type { SchemaAnalysisState } from '../../schema-analysis-types';
1212
import numeral from 'numeral';
1313
import { DEFAULT_DOCUMENT_COUNT, MAX_DOCUMENT_COUNT } from './constants';
1414

15+
const BYTE_PRECISION_THRESHOLD = 1000;
16+
1517
const titleStyles = css({
1618
fontWeight: 600,
1719
});
@@ -38,7 +40,7 @@ const boldStyles = css({
3840
});
3941

4042
const formatBytes = (bytes: number) => {
41-
const precision = bytes <= 1000 ? '0' : '0.0';
43+
const precision = bytes <= BYTE_PRECISION_THRESHOLD ? '0' : '0.0';
4244
return numeral(bytes).format(precision + 'b');
4345
};
4446

@@ -90,6 +92,15 @@ const DocumentCountScreen = ({
9092
};
9193
}, [isOutOfRange]);
9294

95+
const handleDocumentCountChange = (
96+
event: React.ChangeEvent<HTMLInputElement>
97+
) => {
98+
const value = parseInt(event.target.value, 10);
99+
if (!isNaN(value)) {
100+
onDocumentCountChange(value);
101+
}
102+
};
103+
93104
return schemaAnalysisState.status === 'complete' ? (
94105
<div>
95106
<Body className={titleStyles}>
@@ -105,7 +116,7 @@ const DocumentCountScreen = ({
105116
label="Documents to generate in current collection"
106117
type="number"
107118
value={documentCount.toString()}
108-
onChange={(e) => onDocumentCountChange(Number(e.target.value))}
119+
onChange={handleDocumentCountChange}
109120
min={1}
110121
max={MAX_DOCUMENT_COUNT}
111122
state={errorState.state}

0 commit comments

Comments
 (0)