diff --git a/app/page.tsx b/app/page.tsx
index eaa75c7..248a089 100644
--- a/app/page.tsx
+++ b/app/page.tsx
@@ -4,18 +4,31 @@ import { useDisclosure } from '@nextui-org/react';
import CodeEditor from '@/components/code-editor';
import Header from '@/components/header';
import Result from '@/components/result';
-import { extractInterfaceNames } from '@/utils';
+import { extractInterfaceNames, generateMocks } from '@/utils';
import { Initials } from '@/config/constants';
import InterfaceSelectModal from '@/components/interface-select-modal';
+import { RowNumber } from '@/types';
const Home: FC = () => {
const { isOpen, onOpen, onOpenChange } = useDisclosure();
- const [code, setCode] = useState(Initials.DefaultInterface);
const detectedInterfaces = useRef(null);
+ const mockResult = useRef(JSON.stringify(Initials.DefaultMockResult));
+ const [code, setCode] = useState(Initials.DefaultInterface);
+ const [numberOfRows, setNumberOfRows] = useState('1');
+ const [interfaces, setInterfaces] = useState | any>(
+ new Set(detectedInterfaces?.current),
+ );
+
+ const handleChipClose = (closedInterface: string): void => {
+ if (interfaces.size === 1) return;
+ const newSelectedKeys = new Set(Array.from(interfaces)?.filter(key => key !== closedInterface));
+ setInterfaces(newSelectedKeys);
+ };
const handleOnGenerate = (): void => {
const interfaceNamesToMock = extractInterfaceNames(code);
detectedInterfaces.current = interfaceNamesToMock;
+ setInterfaces(new Set(interfaceNamesToMock));
onOpen();
};
@@ -23,18 +36,31 @@ const Home: FC = () => {
setCode(newCode);
};
+ const handleOnMockGenerate = (): void => {
+ const generatedMocks = generateMocks(code, Array.from(interfaces));
+ mockResult.current = JSON.stringify(generatedMocks, null, 2);
+
+ onOpenChange();
+ };
+
return (
);
diff --git a/components/interface-select-content/index.tsx b/components/interface-select-content/index.tsx
index 9c50c4d..fd28b95 100644
--- a/components/interface-select-content/index.tsx
+++ b/components/interface-select-content/index.tsx
@@ -1,19 +1,33 @@
-import React, { FC, useState } from 'react';
+import React, { FC, Key } from 'react';
import { Chip } from '@nextui-org/react';
import { Colors } from '@/config/constants';
import { Listbox, ListboxItem, Radio, RadioGroup } from '@nextui-org/react';
+import { RowNumber } from '@/types';
interface Props {
detectedInterfaces: string[];
+ interfaces: Set;
+ numberOfRows: RowNumber;
+ setInterfaces: (keys: Set) => void;
+ handleChipClose: (closedInterface: string) => void;
+ setNumberOfRows: (numberOfRows: RowNumber) => void;
}
-const InterfaceSelectContent: FC = ({ detectedInterfaces }) => {
- const [interfaces, setInterfaces] = useState | any>(new Set(detectedInterfaces));
+const InterfaceSelectContent: FC = ({
+ detectedInterfaces,
+ numberOfRows,
+ setNumberOfRows,
+ interfaces,
+ setInterfaces,
+ handleChipClose,
+}) => {
+ const handleNumberOfRowsChange = (value: string): void => {
+ setNumberOfRows(value as RowNumber);
+ };
- const handleChipClose = (closedInterface: string): void => {
- if (interfaces.size === 1) return;
- const newSelectedKeys = new Set(Array.from(interfaces).filter(key => key !== closedInterface));
- setInterfaces(newSelectedKeys);
+ const handleInterfaceChange = (selectedInterfaces: Set): void => {
+ if (selectedInterfaces?.size > 1) setNumberOfRows('1');
+ setInterfaces(selectedInterfaces);
};
return (
@@ -24,7 +38,7 @@ const InterfaceSelectContent: FC = ({ detectedInterfaces }) => {
disallowEmptySelection
selectionMode='multiple'
selectedKeys={interfaces}
- onSelectionChange={setInterfaces}
+ onSelectionChange={(keys): void => handleInterfaceChange(new Set(keys))}
>
{detectedInterfaces?.map((interfaceName: any) => (
{`⚡ ${interfaceName}`}
@@ -55,6 +69,8 @@ const InterfaceSelectContent: FC = ({ detectedInterfaces }) => {
Scale number of rows
}
orientation='horizontal'
+ value={numberOfRows}
+ onValueChange={handleNumberOfRowsChange}
>
1 Row
10 Rows
diff --git a/components/interface-select-modal/index.tsx b/components/interface-select-modal/index.tsx
index c1e5c0d..6fa8723 100644
--- a/components/interface-select-modal/index.tsx
+++ b/components/interface-select-modal/index.tsx
@@ -1,4 +1,4 @@
-import React, { FC } from 'react';
+import React, { FC, Key } from 'react';
import {
Modal,
ModalContent,
@@ -8,16 +8,31 @@ import {
Button,
} from '@nextui-org/react';
import InterfaceSelectContent from '@/components/interface-select-content';
+import { RowNumber } from '@/types';
interface Props {
isOpen: boolean;
detectedInterfaces: string[] | null;
+ numberOfRows: RowNumber;
+ interfaces: Set;
onOpenChange: () => void;
+ setNumberOfRows: (numberOfRows: RowNumber) => void;
+ setInterfaces: (keys: Set) => void;
+ handleChipClose: (closedInterface: string) => void;
+ onMockGenerate: () => void;
}
-const InterfaceSelectModal: FC = ({ isOpen, onOpenChange, detectedInterfaces }) => {
- console.log('🚀 ~ file: index.tsx:18 ~ detectedInterfaces:', detectedInterfaces);
-
+const InterfaceSelectModal: FC = ({
+ isOpen,
+ detectedInterfaces,
+ numberOfRows,
+ interfaces,
+ setNumberOfRows,
+ onOpenChange,
+ setInterfaces,
+ handleChipClose,
+ onMockGenerate,
+}) => {
return (
<>
@@ -29,13 +44,20 @@ const InterfaceSelectModal: FC = ({ isOpen, onOpenChange, detectedInterfa
Please select the interfaces you want to generate mock data for.
-
+
-
diff --git a/components/result/index.tsx b/components/result/index.tsx
index 673ecc3..200d3e6 100644
--- a/components/result/index.tsx
+++ b/components/result/index.tsx
@@ -2,82 +2,19 @@
import { FC } from 'react';
import { Button } from '@nextui-org/react';
-const Result: FC = () => {
- const str = `
- [
- {
- subject: 'admin_users',
- label: 'Admin Users',
- group: 'Admin Management',
- },
- {
- subject: 'admin_users',
- label: 'Admin Users',
- group: 'Admin Management',
- },
- {
- subject: 'admin_users',
- label: 'Admin Users',
- group: 'Admin Management',
- },
- {
- subject: 'admin_users',
- label: 'Admin Users',
- group: 'Admin Management',
- },{
- subject: 'admin_users',
- label: 'Admin Users',
- group: 'Admin Management',
- },
- {
- subject: 'admin_users',
- label: 'Admin Users',
- group: 'Admin Management',
- },{
- subject: 'admin_users',
- label: 'Admin Users',
- group: 'Admin Management',
- },
- {
- subject: 'admin_users',
- label: 'Admin Users',
- group: 'Admin Management',
- },{
- subject: 'admin_users',
- label: 'Admin Users',
- group: 'Admin Management',
- },
- {
- subject: 'admin_users',
- label: 'Admin Users',
- group: 'Admin Management',
- },{
- subject: 'admin_users',
- label: 'Admin Users',
- group: 'Admin Management',
- },
- {
- subject: 'admin_users',
- label: 'Admin Users',
- group: 'Admin Management',
- },{
- subject: 'admin_users',
- label: 'Admin Users',
- group: 'Admin Management',
- },
- {
- subject: 'admin_users',
- label: 'Admin Users',
- group: 'Admin Management',
- },
- ]
- `;
+interface Props {
+ mockResult: string;
+}
+const Result: FC = ({ mockResult }) => {
return (
+ {/*
{JSON.parse(mockResult)}
*/}
- {str}
+
+ {JSON.parse(mockResult)}
+
diff --git a/config/constants.ts b/config/constants.ts
index 51bca4b..b965be9 100644
--- a/config/constants.ts
+++ b/config/constants.ts
@@ -1,32 +1,22 @@
export const Initials = {
DefaultInterface: `// You can use typescript interfaces like following;
- interface Admin extends User {
- adminRecord: AdminRecord;
- }
-
- interface Student extends User {
- schoolRecord: SchoolRecord;
- }
-
interface User {
firstName: string;
lastName: string;
username: string;
emailAddress: string;
}
-
- interface AdminRecord {
- studentsPassedEachYear: number[];
- }
-
- interface SchoolRecord {
- startDate: string;
- endDate: string;
- isActive: boolean;
- grades: number[];
- }
`,
+
+ DefaultMockResult: `{
+ User: {
+ firstName: "Kenny",
+ lastName: "Goodwin",
+ username: "Jessie97",
+ emailAddress: "Agustina92@yahoo.com"
+ }
+ }`,
};
export const RegexExp = {
diff --git a/types/index.ts b/types/index.ts
index e7735f0..4a6029f 100644
--- a/types/index.ts
+++ b/types/index.ts
@@ -3,3 +3,5 @@ import { SVGProps } from 'react';
export type IconSvgProps = SVGProps & {
size?: number;
};
+
+export type RowNumber = '1' | '10' | '50';