From f7cec3c62fdb1c9491c73be7cc7c639aca78c9bf Mon Sep 17 00:00:00 2001 From: Gimnath-Perera Date: Mon, 11 Sep 2023 09:46:20 +0530 Subject: [PATCH 1/2] feat: interface-select-content UI & landing UI changes added --- app/page.tsx | 19 +---- components/header/index.tsx | 38 +-------- components/interface-select-content/index.tsx | 85 ++++++++++--------- components/interface-select-modal/index.tsx | 8 +- config/constants.ts | 4 + utils/generate-mocks/index.ts | 4 +- 6 files changed, 62 insertions(+), 96 deletions(-) diff --git a/app/page.tsx b/app/page.tsx index b2daa4e..eaa75c7 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -11,32 +11,21 @@ import InterfaceSelectModal from '@/components/interface-select-modal'; const Home: FC = () => { const { isOpen, onOpen, onOpenChange } = useDisclosure(); const [code, setCode] = useState(Initials.DefaultInterface); - const [numberOfRows, setNumberOfRows] = useState(new Set(['1'])); - - const selectedInterfaces = useRef(null); + const detectedInterfaces = useRef(null); const handleOnGenerate = (): void => { const interfaceNamesToMock = extractInterfaceNames(code); - selectedInterfaces.current = interfaceNamesToMock; + detectedInterfaces.current = interfaceNamesToMock; onOpen(); }; - // TODO: fix any type here - const handleOnRowCountChange = (newRowCount: any): void => { - setNumberOfRows(newRowCount); - }; - const handleOnCodeChange = (newCode: string): void => { setCode(newCode); }; return (
-
+
@@ -45,7 +34,7 @@ const Home: FC = () => {
); diff --git a/components/header/index.tsx b/components/header/index.tsx index 5eecca9..d2daf66 100644 --- a/components/header/index.tsx +++ b/components/header/index.tsx @@ -1,51 +1,17 @@ import React, { FC } from 'react'; -import { - Dropdown, - DropdownTrigger, - DropdownMenu, - DropdownItem, - Button, - Selection, -} from '@nextui-org/react'; +import { Button } from '@nextui-org/react'; type Props = { onGenerate: () => void; - onRowCountChange: (rowCount: Selection) => void; - numberOfRows: any; }; -const Header: FC = ({ onGenerate, onRowCountChange, numberOfRows }) => { - const selectedValue = React.useMemo( - () => Array.from(numberOfRows).join(', ').replaceAll('_', ' '), - [numberOfRows], - ); - +const Header: FC = ({ onGenerate }) => { return (

Generate 𝔽𝕒𝕜𝕖 Data

- - - - - - 1 - 10 - 50 - - - diff --git a/components/interface-select-content/index.tsx b/components/interface-select-content/index.tsx index 5500ef1..9c50c4d 100644 --- a/components/interface-select-content/index.tsx +++ b/components/interface-select-content/index.tsx @@ -1,23 +1,19 @@ import React, { FC, useState } from 'react'; -import { Listbox, ListboxItem } from '@nextui-org/react'; import { Chip } from '@nextui-org/react'; +import { Colors } from '@/config/constants'; +import { Listbox, ListboxItem, Radio, RadioGroup } from '@nextui-org/react'; -const InterfaceSelectContent: FC = () => { - const [selectedKeys, setSelectedKeys] = useState | any>(new Set(['text'])); +interface Props { + detectedInterfaces: string[]; +} + +const InterfaceSelectContent: FC = ({ detectedInterfaces }) => { + const [interfaces, setInterfaces] = useState | any>(new Set(detectedInterfaces)); - const backgroundColors: string[] = [ - 'bg-primary', - 'bg-secondary', - 'bg-warning', - 'bg-danger', - 'bg-default', - ]; const handleChipClose = (closedInterface: string): void => { - if (selectedKeys.size === 1) return; - const newSelectedKeys = new Set( - Array.from(selectedKeys).filter(key => key !== closedInterface), - ); - setSelectedKeys(newSelectedKeys); + if (interfaces.size === 1) return; + const newSelectedKeys = new Set(Array.from(interfaces).filter(key => key !== closedInterface)); + setInterfaces(newSelectedKeys); }; return ( @@ -27,33 +23,44 @@ const InterfaceSelectContent: FC = () => { variant='flat' disallowEmptySelection selectionMode='multiple' - selectedKeys={selectedKeys} - onSelectionChange={setSelectedKeys} + selectedKeys={interfaces} + onSelectionChange={setInterfaces} > - ⚡ Text - ⚡ Number - ⚡ Date - ⚡ Single Date - ⚡ Iteration + {detectedInterfaces?.map((interfaceName: any) => ( + {`⚡ ${interfaceName}`} + )) || null} -
-

Selected interfaces:

- {Array.from(selectedKeys).map((selectedInterface: any, index: number) => ( - handleChipClose(selectedInterface)} - classNames={{ - base: backgroundColors[index % backgroundColors.length], - content: 'text-white', - }} - > - {selectedInterface} - - ))} + +
+

Selected interfaces

+
+ {Array.from(interfaces).map((interfaceName: any, index: number) => ( + handleChipClose(interfaceName)} + classNames={{ + base: Colors.ChipClors[index % Colors.ChipClors.length], + content: 'text-white', + }} + > + {interfaceName} + + ))} +
+ {interfaces.size === 1 ? ( + Scale number of rows

} + orientation='horizontal' + > + 1 Row + 10 Rows + 50 Rows +
+ ) : null}
); }; diff --git a/components/interface-select-modal/index.tsx b/components/interface-select-modal/index.tsx index 9603e05..c1e5c0d 100644 --- a/components/interface-select-modal/index.tsx +++ b/components/interface-select-modal/index.tsx @@ -11,12 +11,12 @@ import InterfaceSelectContent from '@/components/interface-select-content'; interface Props { isOpen: boolean; - selectedInterfaces: string[] | null; + detectedInterfaces: string[] | null; onOpenChange: () => void; } -const InterfaceSelectModal: FC = ({ isOpen, onOpenChange, selectedInterfaces }) => { - console.log('🚀 ~ file: index.tsx:18 ~ selectedInterfaces:', selectedInterfaces); +const InterfaceSelectModal: FC = ({ isOpen, onOpenChange, detectedInterfaces }) => { + console.log('🚀 ~ file: index.tsx:18 ~ detectedInterfaces:', detectedInterfaces); return ( <> @@ -29,7 +29,7 @@ const InterfaceSelectModal: FC = ({ isOpen, onOpenChange, selectedInterfa

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';