-
Notifications
You must be signed in to change notification settings - Fork 231
feat(compass-collection): Output Validation Followup - Mock Data Generator LLM CLOUDP-347048 #7365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 8 commits
d9f6a23
406aa2b
0b079fb
df49911
b471586
06258a8
84ee0cf
a8b814b
e9087d4
806f5c3
e2dc601
4f65350
340234a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ import { | |
Banner, | ||
BannerVariant, | ||
Body, | ||
Code, | ||
css, | ||
Label, | ||
Option, | ||
palette, | ||
Select, | ||
|
@@ -11,6 +13,7 @@ import { | |
import React from 'react'; | ||
import { UNRECOGNIZED_FAKER_METHOD } from '../../modules/collection-tab'; | ||
import type { MongoDBFieldType } from '@mongodb-js/compass-generative-ai'; | ||
import type { FakerArg } from './script-generation-utils'; | ||
|
||
const fieldMappingSelectorsStyles = css({ | ||
width: '50%', | ||
|
@@ -24,16 +27,37 @@ const labelStyles = css({ | |
fontWeight: 600, | ||
}); | ||
|
||
const parseFakerArg = (arg: FakerArg): string => { | ||
if (typeof arg === 'object' && arg !== null && 'json' in arg) { | ||
try { | ||
return JSON.stringify(JSON.parse(arg.json)); | ||
} catch { | ||
return ''; | ||
} | ||
} | ||
return arg.toString(); | ||
|
||
}; | ||
|
||
const formatFakerFunctionCallWithArgs = ( | ||
fakerFunction: string, | ||
fakerArgs: FakerArg[] | ||
) => { | ||
const parsedFakerArgs = fakerArgs.map(parseFakerArg); | ||
return `faker.${fakerFunction}(${parsedFakerArgs.join(', ')})`; | ||
}; | ||
|
||
interface Props { | ||
activeJsonType: string; | ||
activeFakerFunction: string; | ||
onJsonTypeSelect: (jsonType: MongoDBFieldType) => void; | ||
activeFakerArgs: FakerArg[]; | ||
onFakerFunctionSelect: (fakerFunction: string) => void; | ||
} | ||
|
||
const FakerMappingSelector = ({ | ||
activeJsonType, | ||
activeFakerFunction, | ||
activeFakerArgs, | ||
onJsonTypeSelect, | ||
onFakerFunctionSelect, | ||
}: Props) => { | ||
|
@@ -66,13 +90,29 @@ const FakerMappingSelector = ({ | |
</Option> | ||
))} | ||
</Select> | ||
{activeFakerFunction === UNRECOGNIZED_FAKER_METHOD && ( | ||
{activeFakerFunction === UNRECOGNIZED_FAKER_METHOD ? ( | ||
<Banner variant={BannerVariant.Warning}> | ||
Please select a function or we will default fill this field with the | ||
string "Unrecognized" | ||
</Banner> | ||
) : ( | ||
<> | ||
<Label htmlFor="faker-function-call-preview"> | ||
Preview Faker Function Call | ||
</Label> | ||
<Code | ||
id="faker-function-call-preview" | ||
data-testid="faker-function-call-preview" | ||
language="javascript" | ||
copyable={false} | ||
> | ||
{formatFakerFunctionCallWithArgs( | ||
activeFakerFunction, | ||
activeFakerArgs | ||
)} | ||
</Code> | ||
</> | ||
)} | ||
{/* TODO(CLOUDP-344400): Render faker function parameters once we have a way to validate them. */} | ||
</div> | ||
); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: there's a
parseFakerArgs
with a different behavior. One should be renamedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find another function you mentioned, but the name still doesn't make too much sense: it seems to be the opposite of parse, takes the arguments and serializes them to string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renaming to
stringifyFakerArg