@@ -16,7 +16,10 @@ import type { AtlasAiService } from '@mongodb-js/compass-generative-ai/provider'
1616import type { experimentationServiceLocator } from '@mongodb-js/compass-telemetry/provider' ;
1717import { type Logger , mongoLogId } from '@mongodb-js/compass-logging/provider' ;
1818import { type PreferencesAccess } from 'compass-preferences-model/provider' ;
19- import type { MockDataSchemaRequest } from '@mongodb-js/compass-generative-ai' ;
19+ import type {
20+ MockDataSchemaRequest ,
21+ MongoDBFieldType ,
22+ } from '@mongodb-js/compass-generative-ai' ;
2023import { isInternalFieldPath } from 'hadron-document' ;
2124import toNS from 'mongodb-ns' ;
2225import {
@@ -127,7 +130,8 @@ export enum CollectionActions {
127130 FakerMappingGenerationStarted = 'compass-collection/FakerMappingGenerationStarted' ,
128131 FakerMappingGenerationCompleted = 'compass-collection/FakerMappingGenerationCompleted' ,
129132 FakerMappingGenerationFailed = 'compass-collection/FakerMappingGenerationFailed' ,
130- FakerSchemaEdited = 'compass-collection/FakerSchemaEdited' ,
133+ FakerFieldTypeChanged = 'compass-collection/FakerFieldTypeChanged' ,
134+ FakerFieldMethodChanged = 'compass-collection/FakerFieldMethodChanged' ,
131135}
132136
133137interface CollectionMetadataFetchedAction {
@@ -197,9 +201,16 @@ export interface FakerMappingGenerationFailedAction {
197201 requestId : string ;
198202}
199203
200- export interface FakerSchemaEditedAction {
201- type : CollectionActions . FakerSchemaEdited ;
202- editedFakerSchema : FakerSchema ;
204+ export interface FakerFieldTypeChangedAction {
205+ type : CollectionActions . FakerFieldTypeChanged ;
206+ fieldPath : string ;
207+ mongoType : MongoDBFieldType ;
208+ }
209+
210+ export interface FakerFieldMethodChangedAction {
211+ type : CollectionActions . FakerFieldMethodChanged ;
212+ fieldPath : string ;
213+ fakerMethod : string ;
203214}
204215
205216const reducer : Reducer < CollectionState , Action > = (
@@ -495,20 +506,67 @@ const reducer: Reducer<CollectionState, Action> = (
495506 }
496507
497508 if (
498- isAction < FakerSchemaEditedAction > (
509+ isAction < FakerFieldTypeChangedAction > (
499510 action ,
500- CollectionActions . FakerSchemaEdited
511+ CollectionActions . FakerFieldTypeChanged
501512 )
502513 ) {
503514 if ( state . fakerSchemaGeneration . status !== 'completed' ) {
504515 return state ;
505516 }
506517
518+ const { fieldPath, mongoType } = action ;
519+ const currentMapping =
520+ state . fakerSchemaGeneration . editedFakerSchema [ fieldPath ] ;
521+
522+ if ( ! currentMapping ) {
523+ return state ;
524+ }
525+
507526 return {
508527 ...state ,
509528 fakerSchemaGeneration : {
510529 ...state . fakerSchemaGeneration ,
511- editedFakerSchema : action . editedFakerSchema ,
530+ editedFakerSchema : {
531+ ...state . fakerSchemaGeneration . editedFakerSchema ,
532+ [ fieldPath ] : {
533+ ...currentMapping ,
534+ mongoType,
535+ } ,
536+ } ,
537+ } ,
538+ } ;
539+ }
540+
541+ if (
542+ isAction < FakerFieldMethodChangedAction > (
543+ action ,
544+ CollectionActions . FakerFieldMethodChanged
545+ )
546+ ) {
547+ if ( state . fakerSchemaGeneration . status !== 'completed' ) {
548+ return state ;
549+ }
550+
551+ const { fieldPath, fakerMethod } = action ;
552+ const currentMapping =
553+ state . fakerSchemaGeneration . editedFakerSchema [ fieldPath ] ;
554+
555+ if ( ! currentMapping ) {
556+ return state ;
557+ }
558+
559+ return {
560+ ...state ,
561+ fakerSchemaGeneration : {
562+ ...state . fakerSchemaGeneration ,
563+ editedFakerSchema : {
564+ ...state . fakerSchemaGeneration . editedFakerSchema ,
565+ [ fieldPath ] : {
566+ ...currentMapping ,
567+ fakerMethod,
568+ } ,
569+ } ,
512570 } ,
513571 } ;
514572 }
@@ -554,10 +612,26 @@ export const mockDataGeneratorPreviousButtonClicked = (): CollectionThunkAction<
554612 } ;
555613} ;
556614
557- export const updateEditedFakerSchema = (
558- editedFakerSchema : FakerSchema
559- ) : FakerSchemaEditedAction => {
560- return { type : CollectionActions . FakerSchemaEdited , editedFakerSchema } ;
615+ export const fakerFieldTypeChanged = (
616+ fieldPath : string ,
617+ mongoType : MongoDBFieldType
618+ ) : FakerFieldTypeChangedAction => {
619+ return {
620+ type : CollectionActions . FakerFieldTypeChanged ,
621+ fieldPath,
622+ mongoType,
623+ } ;
624+ } ;
625+
626+ export const fakerFieldMethodChanged = (
627+ fieldPath : string ,
628+ fakerMethod : string
629+ ) : FakerFieldMethodChangedAction => {
630+ return {
631+ type : CollectionActions . FakerFieldMethodChanged ,
632+ fieldPath,
633+ fakerMethod,
634+ } ;
561635} ;
562636
563637export const selectTab = (
0 commit comments