Skip to content

Commit 216b92d

Browse files
authored
feat(compass-collection): Add descriptions to FakerJS methods - CLOUDP-358516 (#7561)
* Add descriptions to FakerJS methods * description updates
1 parent 4086459 commit 216b92d

File tree

3 files changed

+175
-78
lines changed

3 files changed

+175
-78
lines changed

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

Lines changed: 165 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -52,85 +52,178 @@ export const MongoDBFieldTypeValues: MongoDBFieldType[] = [
5252
*/
5353
export const MONGO_TYPE_TO_FAKER_METHODS: Record<
5454
MongoDBFieldType,
55-
Array<string>
55+
Array<{ method: string; description?: string }>
5656
> = {
5757
String: [
58-
'lorem.word',
59-
'lorem.words',
60-
'lorem.sentence',
61-
'lorem.paragraph',
62-
'person.firstName',
63-
'person.lastName',
64-
'person.fullName',
65-
'person.jobTitle',
66-
'internet.displayName',
67-
'internet.email',
68-
'internet.emoji',
69-
'internet.password',
70-
'internet.url',
71-
'internet.domainName',
72-
'internet.userName',
73-
'phone.number',
74-
'location.city',
75-
'location.country',
76-
'location.streetAddress',
77-
'location.zipCode',
78-
'location.state',
79-
'company.name',
80-
'company.catchPhrase',
81-
'color.human',
82-
'commerce.productName',
83-
'commerce.department',
84-
'finance.accountName',
85-
'finance.currencyCode',
86-
'git.commitSha',
87-
'string.uuid',
88-
'string.alpha',
89-
'string.alphanumeric',
90-
'system.fileName',
91-
'system.filePath',
92-
'system.mimeType',
93-
'book.title',
94-
'music.songName',
95-
'food.dish',
96-
'animal.type',
97-
'vehicle.model',
98-
'hacker.phrase',
99-
'science.chemicalElement',
58+
{ method: 'lorem.word', description: 'Single word' },
59+
{ method: 'lorem.words', description: 'Multiple words' },
60+
{ method: 'lorem.sentence', description: 'Short sentence' },
61+
{ method: 'lorem.paragraph', description: 'Paragraph of text' },
62+
{ method: 'person.firstName' },
63+
{ method: 'person.lastName' },
64+
{ method: 'person.fullName' },
65+
{ method: 'person.jobTitle' },
66+
{
67+
method: 'internet.displayName',
68+
description: 'Username-style display name',
69+
},
70+
{ method: 'internet.email' },
71+
{ method: 'internet.emoji' },
72+
{ method: 'internet.password', description: 'Randomly generated password' },
73+
{ method: 'internet.url' },
74+
{ method: 'internet.domainName' },
75+
{ method: 'internet.userName' },
76+
{ method: 'phone.number' },
77+
{ method: 'location.city' },
78+
{ method: 'location.country' },
79+
{ method: 'location.streetAddress' },
80+
{ method: 'location.zipCode' },
81+
{ method: 'location.state' },
82+
{ method: 'company.name' },
83+
{
84+
method: 'company.catchPhrase',
85+
description: 'Corporate-style marketing slogan',
86+
},
87+
{ method: 'color.human', description: 'Human-readable color name' },
88+
{
89+
method: 'commerce.productName',
90+
description: 'Product name from a commerce catalog',
91+
},
92+
{
93+
method: 'commerce.department',
94+
description: 'Commerce category or department name',
95+
},
96+
{
97+
method: 'finance.accountName',
98+
description: 'Financial account type or name',
99+
},
100+
{
101+
method: 'finance.currencyCode',
102+
description: 'ISO 4217 currency code like USD or EUR',
103+
},
104+
{ method: 'git.commitSha', description: 'Git commit SHA hash' },
105+
{ method: 'string.uuid' },
106+
{ method: 'string.alpha', description: 'Alphabetic string' },
107+
{ method: 'string.alphanumeric', description: 'Alphanumeric string' },
108+
{
109+
method: 'system.fileName',
110+
description: 'File name with optional extension',
111+
},
112+
{ method: 'system.filePath', description: 'System-like file path' },
113+
{
114+
method: 'system.mimeType',
115+
description: 'MIME type string like image/png',
116+
},
117+
{ method: 'book.title' },
118+
{ method: 'music.songName' },
119+
{ method: 'food.dish' },
120+
{ method: 'animal.type' },
121+
{ method: 'vehicle.model' },
122+
{ method: 'hacker.phrase', description: 'Hacker-style phrase' },
123+
{
124+
method: 'science.chemicalElement',
125+
description: 'Chemical element with name and symbol',
126+
},
100127
],
128+
101129
Number: [
102-
'number.binary',
103-
'number.octal',
104-
'number.hex',
105-
'commerce.price',
106-
'date.weekday',
107-
'internet.port',
108-
'number.int',
109-
'number.float',
110-
'finance.amount',
111-
'location.latitude',
112-
'location.longitude',
130+
{ method: 'number.binary', description: 'Binary number string' },
131+
{ method: 'number.octal', description: 'Octal number string' },
132+
{ method: 'number.hex', description: 'Hexadecimal number string' },
133+
{ method: 'commerce.price', description: 'Monetary price with decimals' },
134+
{ method: 'date.weekday', description: 'Day of the week' },
135+
{ method: 'internet.port', description: 'Network port number' },
136+
{ method: 'number.int' },
137+
{ method: 'number.float' },
138+
{
139+
method: 'finance.amount',
140+
description: 'Monetary amount as number or string',
141+
},
142+
{ method: 'location.latitude' },
143+
{ method: 'location.longitude' },
144+
],
145+
146+
Int32: [
147+
{ method: 'number.int' },
148+
{ method: 'finance.amount', description: 'Monetary amount as integer' },
149+
],
150+
151+
Long: [
152+
{ method: 'number.int' },
153+
{ method: 'number.bigInt', description: 'Large integer value as bigint' },
154+
],
155+
156+
Decimal128: [
157+
{ method: 'number.float' },
158+
{ method: 'finance.amount', description: 'Decimal-style monetary amount' },
113159
],
114-
Int32: ['number.int', 'finance.amount'],
115-
Long: ['number.int', 'number.bigInt'],
116-
Decimal128: ['number.float', 'finance.amount'],
117-
Boolean: ['datatype.boolean'],
160+
161+
Boolean: [{ method: 'datatype.boolean' }],
162+
118163
Date: [
119-
'date.recent',
120-
'date.past',
121-
'date.future',
122-
'date.anytime',
123-
'date.birthdate',
164+
{ method: 'date.recent', description: 'Date within the last few days' },
165+
{ method: 'date.past', description: 'Past date relative to now' },
166+
{ method: 'date.future', description: 'Future date relative to now' },
167+
{ method: 'date.anytime', description: 'Date at any time in history' },
168+
{ method: 'date.birthdate' },
169+
],
170+
171+
Timestamp: [
172+
{ method: 'date.recent' },
173+
{ method: 'date.past' },
174+
{ method: 'date.future' },
175+
{ method: 'date.anytime' },
176+
],
177+
178+
ObjectId: [
179+
{
180+
method: 'database.mongodbObjectId',
181+
description: 'Valid MongoDB ObjectId string',
182+
},
124183
],
125-
Timestamp: ['date.recent', 'date.past', 'date.future', 'date.anytime'],
126-
ObjectId: ['database.mongodbObjectId'],
127-
Binary: ['string.hexadecimal', 'string.binary'],
128-
RegExp: ['lorem.word', 'string.alpha'],
129-
Code: ['lorem.sentence', 'lorem.paragraph', 'git.commitMessage'],
130-
MinKey: ['number.int'],
131-
MaxKey: ['number.int'],
132-
Symbol: ['lorem.word', 'string.symbol'],
133-
DBRef: ['database.mongodbObjectId'],
184+
185+
Binary: [
186+
{
187+
method: 'string.hexadecimal',
188+
description: 'Hexadecimal string representation',
189+
},
190+
{ method: 'string.binary', description: 'Binary string representation' },
191+
],
192+
193+
RegExp: [{ method: 'lorem.word' }, { method: 'string.alpha' }],
194+
195+
Code: [
196+
{
197+
method: 'lorem.sentence',
198+
description: 'Short line of code',
199+
},
200+
{ method: 'lorem.paragraph', description: 'Block of placeholder code' },
201+
{ method: 'git.commitMessage', description: 'Git-style commit message' },
202+
],
203+
204+
MinKey: [
205+
{
206+
method: 'number.int',
207+
description: 'Integer representing minimal key value',
208+
},
209+
],
210+
211+
MaxKey: [
212+
{
213+
method: 'number.int',
214+
description: 'Integer representing maximal key value',
215+
},
216+
],
217+
218+
Symbol: [
219+
{ method: 'lorem.word' },
220+
{
221+
method: 'string.symbol',
222+
description: 'Symbol character such as punctuation or currency',
223+
},
224+
],
225+
226+
DBRef: [{ method: 'database.mongodbObjectId' }],
134227
};
135228

136229
export const DEFAULT_CONNECTION_STRING_FALLBACK = '<connection-string>';

packages/compass-collection/src/components/mock-data-generator-modal/faker-mapping-selector.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('FakerMappingSelector', () => {
5353
MONGO_TYPE_TO_FAKER_METHODS
5454
)) {
5555
it(`should display faker methods for ${mongoType}`, () => {
56-
const firstMethod = methods[0];
56+
const firstMethod = methods[0].method;
5757

5858
render(
5959
<FakerMappingSelector
@@ -70,7 +70,7 @@ describe('FakerMappingSelector', () => {
7070
const fakerFunctionSelect = screen.getByLabelText('Faker Function');
7171
userEvent.click(fakerFunctionSelect);
7272

73-
methods.forEach((method) => {
73+
methods.forEach(({ method }) => {
7474
expect(screen.getByRole('option', { name: method })).to.exist;
7575
});
7676
});

packages/compass-collection/src/components/mock-data-generator-modal/faker-mapping-selector.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,14 @@ const FakerMappingSelector = ({
7575
}: Props) => {
7676
const fakerMethodOptions = useMemo(() => {
7777
const methods = MONGO_TYPE_TO_FAKER_METHODS[activeJsonType] || [];
78+
const methodNames = methods.map((m) => m.method);
7879

7980
// Include original LLM method if it's not already in the list of methods
80-
if (originalLlmFakerMethod && !methods.includes(originalLlmFakerMethod)) {
81-
return [originalLlmFakerMethod, ...methods];
81+
if (
82+
originalLlmFakerMethod &&
83+
!methodNames.includes(originalLlmFakerMethod)
84+
) {
85+
return [{ method: originalLlmFakerMethod }, ...methods];
8286
}
8387

8488
return methods;
@@ -105,8 +109,8 @@ const FakerMappingSelector = ({
105109
value={activeFakerFunction}
106110
onChange={onFakerFunctionSelect}
107111
>
108-
{fakerMethodOptions.map((method) => (
109-
<Option key={method} value={method}>
112+
{fakerMethodOptions.map(({ method, description }) => (
113+
<Option key={method} value={method} description={description}>
110114
{method}
111115
</Option>
112116
))}

0 commit comments

Comments
 (0)