|
| 1 | +import React, { useState } from 'react'; |
| 2 | + |
| 3 | +import { css } from '@mongodb-js/compass-components'; |
| 4 | + |
| 5 | +import { |
| 6 | + Button, |
| 7 | + Modal, |
| 8 | + ModalHeader, |
| 9 | + ModalBody, |
| 10 | + ModalFooter, |
| 11 | + ButtonVariant, |
| 12 | +} from '@mongodb-js/compass-components'; |
| 13 | +import { MockDataGeneratorSteps } from './types'; |
| 14 | +import { DEFAULT_OUTPUT_DOCS_COUNT } from './constants'; |
| 15 | + |
| 16 | +const footerStyles = css` |
| 17 | + flex-direction: row; |
| 18 | + justify-content: space-between; |
| 19 | +`; |
| 20 | + |
| 21 | +const rightButtonsStyles = css` |
| 22 | + display: flex; |
| 23 | + gap: 8px; |
| 24 | + flex-direction: row; |
| 25 | +`; |
| 26 | + |
| 27 | +interface Props { |
| 28 | + isOpen: boolean; |
| 29 | + setIsOpen: (isOpen: boolean) => void; |
| 30 | +} |
| 31 | + |
| 32 | +const MockDataGeneratorModal = ({ isOpen, setIsOpen }: Props) => { |
| 33 | + const [currentStep, setCurrentStep] = useState<MockDataGeneratorSteps>( |
| 34 | + MockDataGeneratorSteps.AI_DISCLAIMER |
| 35 | + ); |
| 36 | + const [rawSchema, setRawSchema] = useState<string | null>(null); |
| 37 | + const [fakerSchema, setFakerSchema] = useState<string | null>(null); |
| 38 | + const [outputDocsCount, setOutputDocsCount] = useState<number>( |
| 39 | + DEFAULT_OUTPUT_DOCS_COUNT |
| 40 | + ); |
| 41 | + const [validationRules, setValidationRules] = useState<string | null>(null); |
| 42 | + const [sampleDoc, setSampleDoc] = useState<string | null>(null); |
| 43 | + |
| 44 | + const resetState = () => { |
| 45 | + setCurrentStep(MockDataGeneratorSteps.AI_DISCLAIMER); |
| 46 | + setRawSchema(null); |
| 47 | + setFakerSchema(null); |
| 48 | + setOutputDocsCount(DEFAULT_OUTPUT_DOCS_COUNT); |
| 49 | + setValidationRules(null); |
| 50 | + setSampleDoc(null); |
| 51 | + }; |
| 52 | + |
| 53 | + const onNext = () => { |
| 54 | + if (currentStep < MockDataGeneratorSteps.GENERATE_DATA) { |
| 55 | + setCurrentStep(currentStep + 1); |
| 56 | + } else { |
| 57 | + // Final step, close the modal |
| 58 | + setIsOpen(false); |
| 59 | + resetState(); |
| 60 | + } |
| 61 | + }; |
| 62 | + |
| 63 | + const onBack = () => { |
| 64 | + if (currentStep > MockDataGeneratorSteps.AI_DISCLAIMER) { |
| 65 | + setCurrentStep(currentStep - 1); |
| 66 | + } |
| 67 | + }; |
| 68 | + |
| 69 | + const onCancel = () => { |
| 70 | + setIsOpen(false); |
| 71 | + }; |
| 72 | + |
| 73 | + return ( |
| 74 | + <Modal |
| 75 | + open={isOpen} |
| 76 | + setOpen={() => setIsOpen(false)} |
| 77 | + data-testid="generate-mock-data-modal" |
| 78 | + > |
| 79 | + <ModalHeader title="Generate Mock Data" /> |
| 80 | + <ModalBody> |
| 81 | + {currentStep === MockDataGeneratorSteps.AI_DISCLAIMER && <div></div>} |
| 82 | + {currentStep === MockDataGeneratorSteps.SCHEMA_CONFIRMATION && ( |
| 83 | + <div></div> |
| 84 | + )} |
| 85 | + {currentStep === MockDataGeneratorSteps.SCHEMA_EDITOR && <div></div>} |
| 86 | + {currentStep === MockDataGeneratorSteps.DOCUMENT_COUNT && <div></div>} |
| 87 | + {currentStep === MockDataGeneratorSteps.PREVIEW_DATA && <div></div>} |
| 88 | + {currentStep === MockDataGeneratorSteps.GENERATE_DATA && <div></div>} |
| 89 | + </ModalBody> |
| 90 | + |
| 91 | + <ModalFooter className={footerStyles}> |
| 92 | + <Button onClick={onBack}>Back</Button> |
| 93 | + <div className={rightButtonsStyles}> |
| 94 | + <Button onClick={onCancel}>Cancel</Button> |
| 95 | + <Button variant={ButtonVariant.Primary} onClick={onNext}> |
| 96 | + Next |
| 97 | + </Button> |
| 98 | + </div> |
| 99 | + </ModalFooter> |
| 100 | + </Modal> |
| 101 | + ); |
| 102 | +}; |
| 103 | + |
| 104 | +export default MockDataGeneratorModal; |
0 commit comments