-
Notifications
You must be signed in to change notification settings - Fork 246
feat(Add mock data generator modal container) (CLOUD-333848) #7155
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
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const DEFAULT_OUTPUT_DOCS_COUNT = 1000; |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,104 @@ | ||||||||||
| import React, { useState } from 'react'; | ||||||||||
|
|
||||||||||
| import { css } from '@mongodb-js/compass-components'; | ||||||||||
|
|
||||||||||
| import { | ||||||||||
| Button, | ||||||||||
| Modal, | ||||||||||
| ModalHeader, | ||||||||||
| ModalBody, | ||||||||||
| ModalFooter, | ||||||||||
| ButtonVariant, | ||||||||||
| } from '@mongodb-js/compass-components'; | ||||||||||
| import { MockDataGeneratorSteps } from './types'; | ||||||||||
| import { DEFAULT_OUTPUT_DOCS_COUNT } from './constants'; | ||||||||||
|
|
||||||||||
| const footerStyles = css` | ||||||||||
| flex-direction: row; | ||||||||||
| justify-content: space-between; | ||||||||||
| `; | ||||||||||
|
|
||||||||||
| const rightButtonsStyles = css` | ||||||||||
| display: flex; | ||||||||||
| gap: 8px; | ||||||||||
| flex-direction: row; | ||||||||||
| `; | ||||||||||
|
|
||||||||||
| interface Props { | ||||||||||
| isOpen: boolean; | ||||||||||
| setIsOpen: (isOpen: boolean) => void; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| const MockDataGeneratorModal = ({ isOpen, setIsOpen }: Props) => { | ||||||||||
| const [currentStep, setCurrentStep] = useState<MockDataGeneratorSteps>( | ||||||||||
| MockDataGeneratorSteps.AI_DISCLAIMER | ||||||||||
| ); | ||||||||||
| const [rawSchema, setRawSchema] = useState<string | null>(null); | ||||||||||
| const [fakerSchema, setFakerSchema] = useState<string | null>(null); | ||||||||||
| const [outputDocsCount, setOutputDocsCount] = useState<number>( | ||||||||||
| DEFAULT_OUTPUT_DOCS_COUNT | ||||||||||
| ); | ||||||||||
| const [validationRules, setValidationRules] = useState<string | null>(null); | ||||||||||
| const [sampleDoc, setSampleDoc] = useState<string | null>(null); | ||||||||||
|
|
||||||||||
| const resetState = () => { | ||||||||||
| setCurrentStep(MockDataGeneratorSteps.AI_DISCLAIMER); | ||||||||||
| setRawSchema(null); | ||||||||||
| setFakerSchema(null); | ||||||||||
| setOutputDocsCount(DEFAULT_OUTPUT_DOCS_COUNT); | ||||||||||
| setValidationRules(null); | ||||||||||
| setSampleDoc(null); | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| const onNext = () => { | ||||||||||
| if (currentStep < MockDataGeneratorSteps.GENERATE_DATA) { | ||||||||||
| setCurrentStep(currentStep + 1); | ||||||||||
| } else { | ||||||||||
| // Final step, close the modal | ||||||||||
| setIsOpen(false); | ||||||||||
| resetState(); | ||||||||||
| } | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| const onBack = () => { | ||||||||||
| if (currentStep > MockDataGeneratorSteps.AI_DISCLAIMER) { | ||||||||||
| setCurrentStep(currentStep - 1); | ||||||||||
| } | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| const onCancel = () => { | ||||||||||
| setIsOpen(false); | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| return ( | ||||||||||
| <Modal | ||||||||||
| open={isOpen} | ||||||||||
| setOpen={() => setIsOpen(false)} | ||||||||||
| data-testid="generate-mock-data-modal" | ||||||||||
| > | ||||||||||
| <ModalHeader title="Generate Mock Data" /> | ||||||||||
| <ModalBody> | ||||||||||
| {currentStep === MockDataGeneratorSteps.AI_DISCLAIMER && <div></div>} | ||||||||||
| {currentStep === MockDataGeneratorSteps.SCHEMA_CONFIRMATION && ( | ||||||||||
| <div></div> | ||||||||||
| )} | ||||||||||
| {currentStep === MockDataGeneratorSteps.SCHEMA_EDITOR && <div></div>} | ||||||||||
| {currentStep === MockDataGeneratorSteps.DOCUMENT_COUNT && <div></div>} | ||||||||||
| {currentStep === MockDataGeneratorSteps.PREVIEW_DATA && <div></div>} | ||||||||||
| {currentStep === MockDataGeneratorSteps.GENERATE_DATA && <div></div>} | ||||||||||
| </ModalBody> | ||||||||||
|
|
||||||||||
| <ModalFooter className={footerStyles}> | ||||||||||
| <Button onClick={onBack}>Back</Button> | ||||||||||
|
||||||||||
| <Button onClick={onBack}>Back</Button> | |
| <Button onClick={onBack} disabled={currentStep === MockDataGeneratorSteps.AI_DISCLAIMER}> | |
| Back | |
| </Button> |
Copilot
AI
Jul 30, 2025
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.
The Next button text should change to 'Generate' or 'Finish' on the final step (GENERATE_DATA) to better indicate the action being performed.
| Next | |
| {currentStep === MockDataGeneratorSteps.GENERATE_DATA ? 'Generate' : 'Next'} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| export enum MockDataGeneratorSteps { | ||
| AI_DISCLAIMER = 1, | ||
| SCHEMA_CONFIRMATION = 2, | ||
| SCHEMA_EDITOR = 3, | ||
| DOCUMENT_COUNT = 4, | ||
| PREVIEW_DATA = 5, | ||
| GENERATE_DATA = 6, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import React, { createContext, useContext, useMemo } from 'react'; | ||
|
|
||
| interface ExperimentAssignmentData { | ||
| variant: string | null; | ||
| isInSample: boolean; | ||
| } | ||
|
|
||
| interface ExperimentData { | ||
| assignmentDate: Date; | ||
| entityId: string; | ||
| entityType: string; | ||
| id: string; | ||
| tag: string; | ||
| testGroupDatabaseId: string; | ||
| testGroupId: string; | ||
| testId: string; | ||
| testName: string; | ||
| } | ||
|
|
||
| interface SDKAssignment { | ||
| assignmentData: ExperimentAssignmentData; | ||
| experimentData: ExperimentData | null; | ||
| } | ||
|
|
||
| interface UseAssignmentResponse { | ||
| assignment: SDKAssignment | null; | ||
| asyncStatus: 'LOADING' | 'SUCCESS' | 'ERROR'; | ||
| error?: Error; | ||
| } | ||
|
|
||
| interface BasicAPICallingFunctionOptions { | ||
| timeoutMs?: number; | ||
| team?: string; | ||
| } | ||
|
|
||
| type UseAssignmentHookFn = ( | ||
| experimentName: string, | ||
| trackIsInSample: boolean, | ||
| options?: BasicAPICallingFunctionOptions | ||
| ) => UseAssignmentResponse; | ||
|
|
||
| type AssignExperimentFn = ( | ||
| experimentName: string, | ||
| options?: BasicAPICallingFunctionOptions | ||
| ) => Promise<'SUCCESS' | 'ERROR' | null>; | ||
|
|
||
| interface CompassExperimentationProviderContextValue { | ||
| useAssignment: UseAssignmentHookFn; | ||
| assignExperiment: AssignExperimentFn; | ||
| } | ||
|
|
||
| const ExperimentationContext = | ||
| createContext<CompassExperimentationProviderContextValue>({ | ||
| useAssignment() { | ||
| return { | ||
| assignment: null, | ||
| asyncStatus: 'SUCCESS' as const, | ||
| }; | ||
| }, | ||
| assignExperiment() { | ||
| return Promise.resolve(null); | ||
| }, | ||
| }); | ||
|
|
||
| // Provider component that accepts MMS experiment utils as props | ||
| export const CompassExperimentationProvider: React.FC<{ | ||
| children: React.ReactNode; | ||
| useAssignment: UseAssignmentHookFn; | ||
| assignExperiment: AssignExperimentFn; | ||
| }> = ({ children, useAssignment, assignExperiment }) => { | ||
| const contextValue = useMemo( | ||
| () => ({ useAssignment, assignExperiment }), | ||
| [useAssignment, assignExperiment] | ||
| ); | ||
|
|
||
| return ( | ||
| <ExperimentationContext.Provider value={contextValue}> | ||
| {children} | ||
| </ExperimentationContext.Provider> | ||
| ); | ||
| }; | ||
|
|
||
| // Hook for components to access experiment assignment | ||
| export const useAssignment = (...args: Parameters<UseAssignmentHookFn>) => { | ||
| return useContext(ExperimentationContext).useAssignment(...args); | ||
| }; |
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.
Multiple state variables are defined but never used in the current implementation. Consider removing unused state variables (rawSchema, fakerSchema, validationRules, sampleDoc) or add TODO comments indicating their planned usage.