Skip to content

Commit a0ebd38

Browse files
committed
Merge
1 parent a0366d5 commit a0ebd38

File tree

26 files changed

+487
-152
lines changed

26 files changed

+487
-152
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,4 @@ Leo Generali <leo.d.generali@gmail.com>
116116
Ivan Medina <medinadiazivan@gmail.com>
117117
Nick Larew <nick.larew@10gen.com>
118118
Shun Miyazawa <34241526+miya@users.noreply.github.com>
119+
Kyle Lai <122811196+kylelai1@users.noreply.github.com>

package-lock.json

Lines changed: 2 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-collection/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
"mongodb-collection-model": "^5.35.3",
6969
"mongodb-ns": "^3.0.1",
7070
"mongodb-schema": "^12.6.3",
71-
"numeral": "^2.0.6",
7271
"react": "^17.0.2",
7372
"react-redux": "^8.1.3",
7473
"redux": "^4.2.1",

packages/compass-collection/src/components/mock-data-generator-modal/constants.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { MongoDBFieldType } from '@mongodb-js/compass-generative-ai';
12
import { MockDataGeneratorStep } from './types';
23

34
export const StepButtonLabelMap = {
@@ -10,3 +11,91 @@ export const StepButtonLabelMap = {
1011

1112
export const DEFAULT_DOCUMENT_COUNT = 1000;
1213
export const MAX_DOCUMENT_COUNT = 100000;
14+
15+
/**
16+
* Map of MongoDB types to available Faker v9 methods.
17+
* Not all Faker methods are included here.
18+
* More can be found in the Faker.js API: https://v9.fakerjs.dev/api/
19+
*/
20+
export const MONGO_TYPE_TO_FAKER_METHODS: Record<
21+
MongoDBFieldType,
22+
Array<string>
23+
> = {
24+
String: [
25+
'lorem.word',
26+
'lorem.words',
27+
'lorem.sentence',
28+
'lorem.paragraph',
29+
'person.firstName',
30+
'person.lastName',
31+
'person.fullName',
32+
'person.jobTitle',
33+
'internet.displayName',
34+
'internet.email',
35+
'internet.emoji',
36+
'internet.password',
37+
'internet.url',
38+
'internet.domainName',
39+
'internet.userName',
40+
'phone.number',
41+
'location.city',
42+
'location.country',
43+
'location.streetAddress',
44+
'location.zipCode',
45+
'location.state',
46+
'company.name',
47+
'company.catchPhrase',
48+
'color.human',
49+
'commerce.productName',
50+
'commerce.department',
51+
'finance.accountName',
52+
'finance.currencyCode',
53+
'git.commitSha',
54+
'string.uuid',
55+
'string.alpha',
56+
'string.alphanumeric',
57+
'system.fileName',
58+
'system.filePath',
59+
'system.mimeType',
60+
'book.title',
61+
'music.songName',
62+
'food.dish',
63+
'animal.type',
64+
'vehicle.model',
65+
'hacker.phrase',
66+
'science.chemicalElement',
67+
],
68+
Number: [
69+
'number.binary',
70+
'number.octal',
71+
'number.hex',
72+
'commerce.price',
73+
'date.weekday',
74+
'internet.port',
75+
'number.int',
76+
'number.float',
77+
'finance.amount',
78+
'location.latitude',
79+
'location.longitude',
80+
],
81+
Int32: ['number.int', 'finance.amount'],
82+
Long: ['number.int', 'number.bigInt'],
83+
Decimal128: ['number.float', 'finance.amount'],
84+
Boolean: ['datatype.boolean'],
85+
Date: [
86+
'date.recent',
87+
'date.past',
88+
'date.future',
89+
'date.anytime',
90+
'date.birthdate',
91+
],
92+
Timestamp: ['date.recent', 'date.past', 'date.future', 'date.anytime'],
93+
ObjectId: ['database.mongodbObjectId'],
94+
Binary: ['string.hexadecimal', 'string.binary'],
95+
RegExp: ['lorem.word', 'string.alpha'],
96+
Code: ['lorem.sentence', 'lorem.paragraph', 'git.commitMessage'],
97+
MinKey: ['number.int'],
98+
MaxKey: ['number.int'],
99+
Symbol: ['lorem.word', 'string.symbol'],
100+
DBRef: ['database.mongodbObjectId'],
101+
};

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
Body,
3+
compactBytes,
34
css,
45
palette,
56
spacing,
@@ -9,7 +10,6 @@ import React, { useMemo } from 'react';
910
import { connect } from 'react-redux';
1011
import type { CollectionState } from '../../modules/collection-tab';
1112
import type { SchemaAnalysisState } from '../../schema-analysis-types';
12-
import numeral from 'numeral';
1313
import { DEFAULT_DOCUMENT_COUNT, MAX_DOCUMENT_COUNT } from './constants';
1414

1515
const BYTE_PRECISION_THRESHOLD = 1000;
@@ -40,8 +40,8 @@ const boldStyles = css({
4040
});
4141

4242
const formatBytes = (bytes: number) => {
43-
const precision = bytes <= BYTE_PRECISION_THRESHOLD ? '0' : '0.0';
44-
return numeral(bytes).format(precision + 'b');
43+
const decimals = bytes <= BYTE_PRECISION_THRESHOLD ? 0 : 1;
44+
return compactBytes(bytes, true, decimals);
4545
};
4646

4747
type ErrorState =
@@ -101,7 +101,7 @@ const DocumentCountScreen = ({
101101
}
102102
};
103103

104-
return schemaAnalysisState.status === 'complete' ? (
104+
return (
105105
<div>
106106
<Body className={titleStyles}>
107107
Specify Number of Documents to Generate
@@ -130,9 +130,6 @@ const DocumentCountScreen = ({
130130
</div>
131131
</div>
132132
</div>
133-
) : (
134-
// Not reachable since schema analysis must be finished before the modal can be opened
135-
<div>We are analyzing your collection.</div>
136133
);
137134
};
138135

0 commit comments

Comments
 (0)