-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from Gimnath-Perera/feat/inter-mock-connection
feat: extract & clean interfaces
- Loading branch information
Showing
10 changed files
with
1,095 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { FC, useState } from 'react'; | ||
import { Listbox, ListboxItem } from '@nextui-org/react'; | ||
import { Chip } from '@nextui-org/react'; | ||
|
||
const InterfaceSelectContent: FC = () => { | ||
const [selectedKeys, setSelectedKeys] = useState<Set<string> | any>(new Set(['text'])); | ||
|
||
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); | ||
}; | ||
|
||
return ( | ||
<div className='flex flex-col gap-2'> | ||
<Listbox | ||
aria-label='Multiple selection example' | ||
variant='flat' | ||
disallowEmptySelection | ||
selectionMode='multiple' | ||
selectedKeys={selectedKeys} | ||
onSelectionChange={setSelectedKeys} | ||
> | ||
<ListboxItem key='text'>⚡ Text</ListboxItem> | ||
<ListboxItem key='number'>⚡ Number</ListboxItem> | ||
<ListboxItem key='date'>⚡ Date</ListboxItem> | ||
<ListboxItem key='single_date'>⚡ Single Date</ListboxItem> | ||
<ListboxItem key='iteration'>⚡ Iteration</ListboxItem> | ||
</Listbox> | ||
<div className='flex flex-wrap gap-2 items-center'> | ||
<p className='text-small text-default-500'>Selected interfaces: </p> | ||
{Array.from(selectedKeys).map((selectedInterface: any, index: number) => ( | ||
<Chip | ||
size='sm' | ||
radius='full' | ||
variant='flat' | ||
key={selectedInterface} | ||
onClose={(): void => handleChipClose(selectedInterface)} | ||
classNames={{ | ||
base: backgroundColors[index % backgroundColors.length], | ||
content: 'text-white', | ||
}} | ||
> | ||
{selectedInterface} | ||
</Chip> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default InterfaceSelectContent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React, { FC } from 'react'; | ||
import { | ||
Modal, | ||
ModalContent, | ||
ModalHeader, | ||
ModalBody, | ||
ModalFooter, | ||
Button, | ||
} from '@nextui-org/react'; | ||
import InterfaceSelectContent from '@/components/interface-select-content'; | ||
|
||
interface Props { | ||
isOpen: boolean; | ||
selectedInterfaces: string[] | null; | ||
onOpenChange: () => void; | ||
} | ||
|
||
const InterfaceSelectModal: FC<Props> = ({ isOpen, onOpenChange, selectedInterfaces }) => { | ||
console.log('🚀 ~ file: index.tsx:18 ~ selectedInterfaces:', selectedInterfaces); | ||
|
||
return ( | ||
<> | ||
<Modal isOpen={isOpen} onOpenChange={onOpenChange}> | ||
<ModalContent> | ||
{(onClose): any => ( | ||
<> | ||
<ModalHeader className='flex flex-col gap-1'> | ||
Following 𝕀𝕟𝕥𝕖𝕣𝕗𝕒𝕔𝕖𝕤 Detected | ||
</ModalHeader> | ||
<ModalBody> | ||
<p>Please select the interfaces you want to generate mock data for.</p> | ||
<InterfaceSelectContent /> | ||
</ModalBody> | ||
<ModalFooter> | ||
<Button color='danger' variant='bordered' onPress={onClose}> | ||
Close | ||
</Button> | ||
<Button color='primary' onPress={onClose}> | ||
🪄 Generate | ||
</Button> | ||
</ModalFooter> | ||
</> | ||
)} | ||
</ModalContent> | ||
</Modal> | ||
</> | ||
); | ||
}; | ||
|
||
export default InterfaceSelectModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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[]; | ||
} | ||
`, | ||
}; | ||
|
||
export const RegexExp = { | ||
InterfaceName: /interface\s+(\w+)/g, | ||
Interface: /interface\s+(\w+)\s*{[^}]*}/gs, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { RegexExp } from '@/config/constants'; | ||
|
||
export const extractInterfaceNames = (code: string): string[] => { | ||
const matches = code.match(RegexExp.InterfaceName); | ||
|
||
return matches ? matches.map(match => match.split(' ')[1]) : []; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { mock } from 'intermock'; | ||
|
||
export const generateMocks = ( | ||
code: string, | ||
selectedInterfaces: string[], | ||
): string | Record<string | number, {}> => { | ||
const mockedData = mock({ | ||
language: 'typescript', | ||
files: [['docs', code]], | ||
output: 'string', | ||
interfaces: selectedInterfaces, | ||
}); | ||
|
||
return mockedData; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './extract-interface-names'; | ||
export * from './generate-mocks'; |
Oops, something went wrong.