diff --git a/__tests__/componentBuilder.test.tsx b/__tests__/componentBuilder.test.tsx new file mode 100644 index 00000000..d1a192ac --- /dev/null +++ b/__tests__/componentBuilder.test.tsx @@ -0,0 +1,130 @@ +import { describe, it, expect, vi } from 'vitest'; +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import componentBuilder from '../app/src/helperFunctions/componentBuilder'; +import { ChildElement, MUIComponent } from '../app/src/interfaces/Interfaces'; + +// Mock MUITypes data +const MUITypes = [ + { + tag: 'Button', + componentData: { + name: 'button', + props: { children: 'Click me' } + } + } +]; +vi.mock('../redux/MUITypes', () => MUITypes); + +describe('componentBuilder', () => { + it('renders a simple input component', () => { + const elements: Array = [ + { + type: 'HTML Element', + typeId: 1, + name: 'input', + childId: 1, + style: {}, + attributes: { cssClasses: 'test-class' }, + events: {}, + stateProps: [], + passedInProps: [], + children: [] + } + ]; + const result = componentBuilder(elements, 1); + render(<>{result}); + expect(screen.getByRole('textbox')).toBeInTheDocument(); + }); + + it('handles MUI components', () => { + const elements: Array = [ + { + type: 'MUI Component', + typeId: 2, + name: 'Button', + childId: 2, + style: {}, + attributes: {}, + events: {}, + stateProps: [], + passedInProps: [], + children: [] + } + ]; + const result = componentBuilder(elements, 2); + render(<>{result}); + expect(screen.getByText('Click me')).toBeInTheDocument(); // Assuming 'Click me' is rendered text for Button + }); + + it('skips separators and continues rendering', () => { + const elements: Array = [ + { + type: 'HTML Element', + typeId: 1, + name: 'separator', + childId: 1, + style: {}, + attributes: {}, + events: {}, + stateProps: [], + passedInProps: [], + children: [] + }, + { + type: 'HTML Element', + typeId: 1, + name: 'img', + childId: 2, + style: {}, + attributes: { compLink: 'http://example.com/image.png' }, + events: {}, + stateProps: [], + passedInProps: [], + children: [] + } + ]; + const result = componentBuilder(elements, 3); + render(<>{result}); + expect(screen.getByRole('img')).toHaveAttribute( + 'src', + 'http://example.com/image.png' + ); + }); + + it('renders nested components', () => { + const elements: Array = [ + { + type: 'HTML Element', + typeId: 1, + name: 'div', + childId: 3, + style: {}, + attributes: { cssClasses: 'container' }, + events: {}, + stateProps: [], + passedInProps: [], + children: [ + { + type: 'HTML Element', + typeId: 1, + name: 'p', + childId: 4, + style: {}, + attributes: { compText: 'Hello, world!' }, + events: {}, + stateProps: [], + passedInProps: [], + children: [] + } + ] + } + ]; + const result = componentBuilder(elements, 4); + render(<>{result}); + expect(screen.getByText('Hello, world!')).toBeInTheDocument(); + expect(screen.getByText('Hello, world!').parentNode).toHaveClass( + 'container' + ); + }); +}); diff --git a/__tests__/generateCode.test.ts b/__tests__/generateCode.test.ts new file mode 100644 index 00000000..1abfffbd --- /dev/null +++ b/__tests__/generateCode.test.ts @@ -0,0 +1,375 @@ +import { describe, it, expect } from 'vitest'; +import generateCode from '../app/src/helperFunctions/generateCode'; +import { + muiGenerator, + handleRouteLink, + insertNestedJsxBeforeClosingTag, + modifyAndIndentJsx, + insertAttribute, + writeStateProps, + createRender, + indentLinesExceptFirst, + createContextImport, + createEventHandler, + generateUnformattedCode, + getEnrichedChildren, + formatStyles, + elementTagDetails, + writeNestedElements, + generateMUIImportStatements, + generateStateAndEventHandlerCode, + tabSpacer, + levelSpacer, + elementGenerator, + collectMUIImports, + collectStateAndEventHandlers, + formatCode +} from '../app/src/helperFunctions/generateCode'; +import { Component, HTMLType, MUIType } from '../app/src/interfaces/Interfaces'; + +const MUITypes: MUIType[] = [ + { + id: 1, + tag: 'button', + name: 'Button', + style: {}, // Assuming style is an object, provide specific styles as needed + placeHolderShort: 'Button placeholder', + placeHolderLong: 'This is a button used for submitting forms.', + icon: null, // If icon is optional and not used, set it to null or appropriate default + framework: 'React', + nestable: false, + stateAndEventHandlers: ['onClick'], + imports: ['import React from "react";'], + propOptions: ['type', 'onClick'], + defaultProps: ['type="button"'], + jsx: [''], + componentData: { type: 'button', props: { children: 'Click me' } }, + children: [], // If no nested MUI types, use an empty array + attributes: {} // If no specific attributes are needed, use an empty object + } +]; +// vi.mock('../redux/MUITypes', () => MUITypes); + +const componentsMock: Component[] = [ + { + id: 1, + name: 'Button', + style: {}, + events: {}, + code: 'return ;', + children: [], + isPage: false, + past: [], + future: [], + stateProps: [], + useStateCodes: [], + passedInProps: [], + type: 'MUI Component' + } +]; + +// Correctly mocked HTMLTypes data based on the HTMLType interface +const HTMLTypes: HTMLType[] = [ + { + id: 1, + tag: 'div', + name: 'Division', + style: {}, + placeHolderShort: 'Short placeholder text or JSX', + placeHolderLong: 'Longer placeholder text', + icon: null, + framework: 'React', + nestable: true + } +]; +const rootComponents = [1]; +const contextParam = {}; + +describe('generateCode', () => { + it('should return formatted code for Classic React', () => { + const result = generateCode( + componentsMock, + 1, + [1], + 'Classic React', + HTMLTypes, + MUITypes, + false, + {} + ); + expect(result).toContain('import React'); // Example assertion, adjust based on actual output + expect(result).toContain('function Button'); // Check for function definition + }); + + it('should handle Next.js projects', () => { + const result = generateCode( + componentsMock, + 1, + [1], + 'Next.js', + HTMLTypes, + MUITypes, + false, + {} + ); + expect(result).toContain('import Head from "next/head"'); + }); +}); + +describe('muiGenerator', () => { + it('returns correct JSX for MUI components', () => { + const childElement = { + name: 'Button', + passedInProps: [], + childId: '1', + children: [] + }; + const result = muiGenerator(childElement); + expect(result).toContain(''); // Example, adjust to actual logic + }); + + it('returns empty string when MUI component is not found', () => { + const childElement = { + name: 'NotFoundComponent', + passedInProps: [], + childId: '1', + children: [] + }; + const result = muiGenerator(childElement); + expect(result).toBe(''); + }); +}); + +describe('handleRouteLink', () => { + it('generates correct JSX for Next.js route links', () => { + const child = { name: 'home', displayName: 'Home' }; + const result = handleRouteLink(child, 0, 'Next.js'); + expect(result).toContain('Home'); + }); + + it('generates correct JSX for Gatsby route links', () => { + const child = { name: 'home', displayName: 'Home' }; + const result = handleRouteLink(child, 0, 'Gatsby.js'); + expect(result).toContain('Home'); + }); +}); + +describe('insertNestedJsxBeforeClosingTag', () => { + it('correctly inserts JSX before the closing tag', () => { + const parentJsx = '
\n
'; + const nestedJsx = ['Content']; + const result = insertNestedJsxBeforeClosingTag(parentJsx, nestedJsx, 1); + expect(result).toContain('
\n Content\n
'); + }); +}); + +describe('modifyAndIndentJsx', () => { + it('correctly modifies and indents JSX with new props and id', () => { + const jsxAry = ['']; + const newProps = 'disabled'; + const childId = 'btn1'; + const name = 'Button'; + const key = 'btn1'; + const result = modifyAndIndentJsx(jsxAry, newProps, childId, name, key); + expect(result).toContain(''); + }); +}); + +describe('insertAttribute', () => { + it('correctly inserts an attribute into JSX', () => { + const line = ''; + const attribute = 'disabled'; + const index = line.indexOf('>'); + const result = insertAttribute(line, index, attribute); + expect(result).toContain(''); + }); +}); + +describe('writeStateProps', () => { + it('correctly formats state props into component', () => { + const stateArray = ['const [count, setCount] = useState(0)']; + const result = writeStateProps(stateArray); + expect(result).toContain('const [count, setCount] = useState(0);'); + }); +}); + +describe('createRender', () => { + // Assuming createRender is adapted to be testable, potentially needing dependency injection for context + it('creates render function with nested elements', () => { + const result = createRender(); // This needs to be adapted based on actual usage and possible inputs + expect(result).toContain('return ('); + }); +}); + +describe('indentLinesExceptFirst', () => { + it('indents all lines except the first one', () => { + const text = 'Line1\nLine2\nLine3'; + const result = indentLinesExceptFirst(text, 1); + expect(result).toBe('Line1\n Line2\n Line3'); + }); +}); + +describe('createContextImport', () => { + it('generates import statements for contexts', () => { + const result = createContextImport(); // Assuming it's adapted to be testable + expect(result).toContain('import'); + }); +}); + +describe('createEventHandler', () => { + it('creates event handler functions from child elements', () => { + const children = [ + { type: 'HTML Element', events: { onClick: 'handleClick' }, children: [] } + ]; + const result = createEventHandler(children); + expect(result).toContain('const handleClick = () => {};'); + }); +}); + +describe('generateUnformattedCode', () => { + it('returns correct JSX for a given project type', () => { + const result = generateUnformattedCode( + componentsMock, + 1, + rootComponents, + 'Classic React', + HTMLTypes, + MUITypes, + false, + contextParam + ); + expect(result).toContain('Button'); // Example assertion, adjust based on actual output + }); +}); + +describe('getEnrichedChildren', () => { + it('enriches child components correctly', () => { + const result = getEnrichedChildren(componentsMock[0]); + expect(result).toBeTypeOf('array'); // Check for correct data structure + expect(result).toHaveLength(0); // No children to enrich in this case + }); +}); + +describe('formatStyles', () => { + it('formats style object into inline styles correctly', () => { + const styles = { color: 'red', fontSize: '12px' }; + const result = formatStyles(styles); + expect(result).toContain("color: 'red'"); // Checks inline style formatting + expect(result).toContain("fontSize: '12px'"); + }); +}); + +describe('elementTagDetails', () => { + it('generates correct details for an HTML element', () => { + const childElement = { + childId: '1', + attributes: { cssClasses: 'btn' }, + style: {}, + events: {} + }; + const result = elementTagDetails(childElement); + expect(result).toContain('id="1"'); + expect(result).toContain('className="btn"'); + }); +}); + +describe('writeNestedElements', () => { + it('handles nested components correctly', () => { + const enrichedChildren = [{ ...componentsMock[0], type: 'Component' }]; + const result = writeNestedElements(enrichedChildren, 0); + expect(result).toContain('`], + jsx: [``], componentData: { type: 'Button', props: { @@ -252,8 +252,8 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: true, imports: [ - "import Button from '@mui/material/Button", - "import ButtonGroup from '@mui/material/ButtonGroup'" + "import Button from '@mui/material/Button';", + "import ButtonGroup from '@mui/material/ButtonGroup';" ], stateAndEventHandlers: [], defaultProps: ['variant="contained"'], @@ -304,7 +304,7 @@ const MUITypes: MUIType[] = [ icon: 'CheckBoxOutlineBlank', framework: 'reactClassic', nestable: false, - imports: ["import Checkbox from '@mui/material/Checkbox'"], + imports: ["import Checkbox from '@mui/material/Checkbox';"], stateAndEventHandlers: [], defaultProps: ['defaultChecked'], propOptions: [ @@ -329,7 +329,7 @@ const MUITypes: MUIType[] = [ ], jsx: [ `
`, - ` `, + ` `, `
` ], componentData: { @@ -358,9 +358,9 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: true, imports: [ - "import Box from '@mui/material/Box'", - "import Fab from '@mui/material/Fab'", - "import AddIcon from '@mui/icons-material/Add'" + "import Box from '@mui/material/Box';", + "import Fab from '@mui/material/Fab';", + "import AddIcon from '@mui/icons-material/Add';" ], stateAndEventHandlers: [], defaultProps: ['color="primary" variant="circular"'], @@ -414,11 +414,11 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import Radio from '@mui/material/Radio'", - "import RadioGroup from '@mui/material/RadioGroup'", - "import FormControlLabel from '@mui/material/FormControlLabel'", - "import FormControl from '@mui/material/FormControl'", - "import FormLabel from '@mui/material/FormLabel'" + "import Radio from '@mui/material/Radio';", + "import RadioGroup from '@mui/material/RadioGroup';", + "import FormControlLabel from '@mui/material/FormControlLabel';", + "import FormControl from '@mui/material/FormControl';", + "import FormLabel from '@mui/material/FormLabel';" ], stateAndEventHandlers: [], defaultProps: ['defaultValue="female" name="radio-buttons-group"'], @@ -493,14 +493,16 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import Box from '@mui/material/Box'", - "import Rating from '@mui/material/Rating'", - "import Typography from '@mui/material/Typography'" + "import Box from '@mui/material/Box';", + "import Rating from '@mui/material/Rating';", + "import Typography from '@mui/material/Typography';" ], stateAndEventHandlers: [ - 'const [ratingValue, setRatingValue] = React.useState(2);' + 'const [ratingValue, setRatingValue] = React.useState(2);\n' + ], + defaultProps: [ + 'name="simple-controlled" value={ratingValue} onChange={(event, newValue) => { setRatingValue(newValue); }}' ], - defaultProps: ['value={value}'], propOptions: [ 'defaultValue', 'disabled', @@ -523,7 +525,7 @@ const MUITypes: MUIType[] = [ jsx: [ ` legend': { mt: 2 } }}>`, ` Controlled`, - ` { setRatingValue(newValue); }} />`, + ` `, `` ], componentData: { @@ -562,11 +564,11 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import Box from '@mui/material/Box'", - "import InputLabel from '@mui/material/InputLabel'", - "import MenuItem from '@mui/material/MenuItem'", - "import FormControl from '@mui/material/FormControl'", - "import Select from '@mui/material/Select'" + "import Box from '@mui/material/Box';", + "import InputLabel from '@mui/material/InputLabel';", + "import MenuItem from '@mui/material/MenuItem';", + "import FormControl from '@mui/material/FormControl';", + "import Select from '@mui/material/Select';" ], stateAndEventHandlers: [], defaultProps: [], @@ -677,8 +679,8 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import Box from '@mui/material/Box'", - "import Slider from '@mui/material/Slider'", + "import Box from '@mui/material/Box';", + "import Slider from '@mui/material/Slider';", '\nconst initialSliderValue = 30;' ], stateAndEventHandlers: [ @@ -750,7 +752,7 @@ const MUITypes: MUIType[] = [ icon: 'ToggleOn', framework: 'reactClassic', nestable: false, - imports: ["import Switch from '@mui/material/Switch'"], + imports: ["import Switch from '@mui/material/Switch';"], stateAndEventHandlers: [], defaultProps: [ "inputProps={{ 'aria-label': 'Switch demo' }} defaultChecked" @@ -799,8 +801,8 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import Box from '@mui/material/Box'", - "import TextField from '@mui/material/TextField'" + "import Box from '@mui/material/Box';", + "import TextField from '@mui/material/TextField';" ], stateAndEventHandlers: [], defaultProps: ['variant="outlined"'], @@ -867,8 +869,8 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import ToggleButton from '@mui/material/ToggleButton'", - "import ToggleButtonGroup from '@mui/material/ToggleButtonGroup'" + "import ToggleButton from '@mui/material/ToggleButton';", + "import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';" ], stateAndEventHandlers: [ 'const [alignment, setAlignment] = React.useState("web");\n' @@ -937,14 +939,14 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import Grid from '@mui/material/Grid'", - "import List from '@mui/material/List'", - "import ListItemButton from '@mui/material/ListItemButton'", - "import ListItemIcon from '@mui/material/ListItemIcon'", - "import ListItemText from '@mui/material/ListItemText'", - "import Checkbox from '@mui/material/Checkbox'", - "import Button from '@mui/material/Button'", - "import Paper from '@mui/material/Paper'", + "import Grid from '@mui/material/Grid';", + "import List from '@mui/material/List';", + "import ListItemButton from '@mui/material/ListItemButton';", + "import ListItemIcon from '@mui/material/ListItemIcon';", + "import ListItemText from '@mui/material/ListItemText';", + "import Checkbox from '@mui/material/Checkbox';", + "import Button from '@mui/material/Button';", + "import Paper from '@mui/material/Paper';", '\nfunction not(a, b) {', ' return a.filter((value) => b.indexOf(value) === -1);\n};', '\nfunction intersection(a, b) {', @@ -982,20 +984,21 @@ const MUITypes: MUIType[] = [ ' setRight([]);\n};', '\nconst customList = (items) => (', ' ', - ' ', - ' {items.map((value) => {', - ' const labelId = `transfer-list-item-${value}-label`;', - ' return (', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' );', - ' })}', - ' ', - ' \n);' + ' ', + ' {items.map((value) => {', + ' const labelId = `transfer-list-item-${value}-label`;', + ' return (', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' );', + ' })}', + ' ', + ' ', + ');\n' ], defaultProps: ['sx={{ width: 200, height: 230, overflow: "auto" }}'], propOptions: [ @@ -1075,7 +1078,7 @@ const MUITypes: MUIType[] = [ 'aria-label': 'move selected right', role: 'right' }, - children: '>' // Moves selected items from left to right + children: '>' // Moves selected items from left to right }, { type: 'Button', @@ -1089,7 +1092,7 @@ const MUITypes: MUIType[] = [ 'aria-label': 'move selected left', role: 'left' }, - children: '<' // Moves selected items from right to left + children: '<' // Moves selected items from right to left }, { type: 'Button', @@ -1130,10 +1133,7 @@ const MUITypes: MUIType[] = [ icon: 'Person', framework: 'reactClassic', nestable: false, - imports: [ - "import Avatar from '@mui/material/Avatar'", - "import Stack from '@mui/material/Stack'" - ], + imports: ["import Avatar from '@mui/material/Avatar';"], stateAndEventHandlers: [], defaultProps: [ 'src={imageUrl} alt="User Profile" sx={{ width: 56, height: 56 }}' @@ -1605,7 +1605,9 @@ const MUITypes: MUIType[] = [ "import TableHead from '@mui/material/TableHead';", "import TableRow from '@mui/material/TableRow';", "import Paper from '@mui/material/Paper';", - '\nfunction createData(name, calories, fat, carbs, protein) { return { name, calories, fat, carbs, protein }; }', + '\nfunction createData(name, calories, fat, carbs, protein) {', + 'return { name, calories, fat, carbs, protein };', + '};', '\nconst rows = [', " createData('Frozen yoghurt', 159, 6.0, 24, 4.0),", " createData('Ice cream sandwich', 237, 9.0, 37, 4.3),", @@ -1878,8 +1880,8 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import Button from '@mui/material/Button'", - "import Tooltip from '@mui/material/Tooltip'" + "import Button from '@mui/material/Button';", + "import Tooltip from '@mui/material/Tooltip';" ], stateAndEventHandlers: [], defaultProps: ['title="Add" arrow'], @@ -1914,7 +1916,7 @@ const MUITypes: MUIType[] = [ 'TransitionComponent', 'TransitionProps' ], - jsx: ['', ' ', ''], + jsx: ['', ' ', ''], componentData: { type: 'Tooltip', props: { @@ -1948,10 +1950,7 @@ const MUITypes: MUIType[] = [ icon: 'TextFields', framework: 'reactClassic', nestable: true, - imports: [ - "import Box from '@mui/material/Box'", - "import Typography from '@mui/material/Typography'" - ], + imports: ["import Typography from '@mui/material/Typography';"], stateAndEventHandlers: [], defaultProps: ['variant="h3"'], propOptions: [ @@ -1989,8 +1988,8 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import Alert from '@mui/material/Alert'", - "import CheckIcon from '@mui/icons-material/Check'" + "import Alert from '@mui/material/Alert';", + "import CheckIcon from '@mui/icons-material/Check';" ], stateAndEventHandlers: [], defaultProps: ['severity="success"'], @@ -2020,7 +2019,7 @@ const MUITypes: MUIType[] = [ componentData: { type: 'Alert', props: { - icon: '', + icon: '', severity: 'success', sx: { m: 1 } }, @@ -2039,9 +2038,9 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: true, imports: [ - "import Backdrop from '@mui/material/Backdrop'", - "import CircularProgress from '@mui/material/CircularProgress'", - "import Button from '@mui/material/Button'" + "import Backdrop from '@mui/material/Backdrop';", + "import CircularProgress from '@mui/material/CircularProgress';", + "import Button from '@mui/material/Button';" ], stateAndEventHandlers: [ 'const [open, setOpen] = React.useState(false);', @@ -2115,12 +2114,12 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import Button from '@mui/material/Button'", - "import Dialog from '@mui/material/Dialog'", - "import DialogActions from '@mui/material/DialogActions'", - "import DialogContent from '@mui/material/DialogContent'", - "import DialogContentText from '@mui/material/DialogContentText'", - "import DialogTitle from '@mui/material/DialogTitle'" + "import Button from '@mui/material/Button';", + "import Dialog from '@mui/material/Dialog';", + "import DialogActions from '@mui/material/DialogActions';", + "import DialogContent from '@mui/material/DialogContent';", + "import DialogContentText from '@mui/material/DialogContentText';", + "import DialogTitle from '@mui/material/DialogTitle';" ], stateAndEventHandlers: [ 'const [open, setOpen] = React.useState(false);', @@ -2258,7 +2257,7 @@ const MUITypes: MUIType[] = [ nestable: false, imports: [ "import CircularProgress from '@mui/material/CircularProgress';", - "import Box from '@mui/material/Box'" + "import Box from '@mui/material/Box';" ], stateAndEventHandlers: [], defaultProps: [], @@ -2296,8 +2295,8 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: true, imports: [ - "import Skeleton from '@mui/material/Skeleton'", - "import Stack from '@mui/material/Stack'" + "import Skeleton from '@mui/material/Skeleton';", + "import Stack from '@mui/material/Stack';" ], stateAndEventHandlers: [], defaultProps: ['loading'], @@ -2362,10 +2361,10 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: true, imports: [ - "import Button from '@mui/material/Button'", - "import Snackbar from '@mui/material/Snackbar'", - "import IconButton from '@mui/material/IconButton'", - "import CloseIcon from '@mui/icons-material/Close'" + "import Button from '@mui/material/Button';", + "import Snackbar from '@mui/material/Snackbar';", + "import IconButton from '@mui/material/IconButton';", + "import CloseIcon from '@mui/icons-material/Close';" ], stateAndEventHandlers: [ 'const [open, setOpen] = React.useState(false);', @@ -2392,7 +2391,7 @@ const MUITypes: MUIType[] = [ ' ', ' ', ' ', - ' );' + ' );\n' ], defaultProps: [ 'open={open} autoHideDuration={6000} onClose={handleClose} message="Note archived" action={action}' @@ -2456,12 +2455,12 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: true, imports: [ - "import Accordion from '@mui/material/Accordion'", - "import AccordionActions from '@mui/material/AccordionActions'", - "import AccordionSummary from '@mui/material/AccordionSummary'", - "import AccordionDetails from '@mui/material/AccordionDetails'", - "import ExpandMoreIcon from '@mui/icons-material/ExpandMore'", - "import Button from '@mui/material/Button'" + "import Accordion from '@mui/material/Accordion';", + "import AccordionActions from '@mui/material/AccordionActions';", + "import AccordionSummary from '@mui/material/AccordionSummary';", + "import AccordionDetails from '@mui/material/AccordionDetails';", + "import ExpandMoreIcon from '@mui/icons-material/ExpandMore';", + "import Button from '@mui/material/Button';" ], stateAndEventHandlers: [], defaultProps: [], @@ -2540,13 +2539,13 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import AppBar from '@mui/material/AppBar'", - "import Box from '@mui/material/Box'", - "import Toolbar from '@mui/material/Toolbar'", - "import Typography from '@mui/material/Typography'", - "import Button from '@mui/material/Button'", - "import IconButton from '@mui/material/IconButton'", - "import MenuIcon from '@mui/icons-material/Menu'" + "import AppBar from '@mui/material/AppBar';", + "import Box from '@mui/material/Box';", + "import Toolbar from '@mui/material/Toolbar';", + "import Typography from '@mui/material/Typography';", + "import Button from '@mui/material/Button';", + "import IconButton from '@mui/material/IconButton';", + "import MenuIcon from '@mui/icons-material/Menu';" ], stateAndEventHandlers: [], defaultProps: ['position="static"'], @@ -2634,12 +2633,12 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: true, imports: [ - "import Box from '@mui/material/Box'", - "import Card from '@mui/material/Card'", - "import CardActions from '@mui/material/CardActions'", - "import CardContent from '@mui/material/CardContent'", - "import Button from '@mui/material/Button'", - "import Typography from '@mui/material/Typography'" + "import Box from '@mui/material/Box';", + "import Card from '@mui/material/Card';", + "import CardActions from '@mui/material/CardActions';", + "import CardContent from '@mui/material/CardContent';", + "import Button from '@mui/material/Button';", + "import Typography from '@mui/material/Typography';" ], stateAndEventHandlers: [], defaultProps: ['sx={{ minWidth: 275 }}'], @@ -2729,8 +2728,8 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import Box from '@mui/material/Box'", - "import Paper from '@mui/material/Paper'" + "import Box from '@mui/material/Box';", + "import Paper from '@mui/material/Paper';" ], stateAndEventHandlers: [], defaultProps: [], @@ -2799,17 +2798,16 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import Box from '@mui/material/Box'", - "import BottomNavigation from '@mui/material/BottomNavigation'", - "import BottomNavigationAction from '@mui/material/BottomNavigationAction'", - "import RestoreIcon from '@mui/icons-material/Restore'", - "import FavoriteIcon from '@mui/icons-material/Favorite'", - "import LocationOnIcon from '@mui/icons-material/LocationOn'" + "import Box from '@mui/material/Box';", + "import BottomNavigation from '@mui/material/BottomNavigation';", + "import BottomNavigationAction from '@mui/material/BottomNavigationAction';", + "import FolderIcon from '@mui/icons-material/Folder';", + "import RestoreIcon from '@mui/icons-material/Restore';", + "import FavoriteIcon from '@mui/icons-material/Favorite';", + "import LocationOnIcon from '@mui/icons-material/LocationOn';" ], stateAndEventHandlers: ['const [value, setValue] = React.useState(0);\n'], - defaultProps: [ - 'showLabels value={value} onChange={(event, newValue) => {setValue(newValue)}}' - ], + defaultProps: [], propOptions: [ 'children', 'classes', @@ -2821,10 +2819,11 @@ const MUITypes: MUIType[] = [ ], jsx: [ '', - ' ', - " } />", - " } />", - " } />", + ' {setValue(newValue)}}>', + " } />", + " } />", + " } />", + " } />", ' ', '' ], @@ -2866,6 +2865,14 @@ const MUITypes: MUIType[] = [ icon: '', sx: { backgroundColor: '#0671E3', color: 'white' } } + }, + { + type: 'BottomNavigationAction', + props: { + label: 'Folder', + icon: '', + sx: { backgroundColor: '#0671E3', color: 'white' } + } } ] } @@ -2884,11 +2891,9 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import Breadcrumbs from '@mui/material/Breadcrumbs'", - "import Link from '@mui/material/Link'", - "import RestoreIcon from '@mui/icons-material/Restore'", - "import FavoriteIcon from '@mui/icons-material/Favorite'", - "import LocationOnIcon from '@mui/icons-material/LocationOn'" + "import Breadcrumbs from '@mui/material/Breadcrumbs';", + "import Link from '@mui/material/Link';", + "import Typography from '@mui/material/Typography';" ], stateAndEventHandlers: [ '\nfunction handleClick(event) {', @@ -2915,7 +2920,7 @@ const MUITypes: MUIType[] = [ ' ', " MUI", " Core", - " Breadcrumbs", + " Breadcrumbs", ' ', '' ], @@ -2978,52 +2983,54 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: true, imports: [ - "import Box from '@mui/material/Box'", - "import Drawer from '@mui/material/Drawer'", - "import Button from '@mui/material/Button'", - "import List from '@mui/material/List'", - "import Divider from '@mui/material/Divider'", - "import ListItem from '@mui/material/ListItem'", - "import ListItemButton from '@mui/material/ListItemButton'", - "import ListItemIcon from '@mui/material/ListItemIcon'", - "import ListItemText from '@mui/material/ListItemText'", - "import InboxIcon from '@mui/icons-material/MoveToInbox'", - "import MailIcon from '@mui/icons-material/Mail'" + "import Box from '@mui/material/Box';", + "import Drawer from '@mui/material/Drawer';", + "import Button from '@mui/material/Button';", + "import List from '@mui/material/List';", + "import Divider from '@mui/material/Divider';", + "import ListItem from '@mui/material/ListItem';", + "import ListItemButton from '@mui/material/ListItemButton';", + "import ListItemIcon from '@mui/material/ListItemIcon';", + "import ListItemText from '@mui/material/ListItemText';", + "import InboxIcon from '@mui/icons-material/MoveToInbox';", + "import MailIcon from '@mui/icons-material/Mail';" ], stateAndEventHandlers: [ - 'const [open, setOpen] = React.useState(false);', - 'const toggleDrawer = (newOpen) => () => {', - ' setOpen(newOpen);', - '};', - '\nconst DrawerList = (', - " ", - ' ', - " {['Inbox', 'Starred', 'Send email', 'Drafts'].map((text, index) => (", - ' ', - ' ', - ' ', - ' {index % 2 === 0 ? : }', - ' ', - ' ', - ' ', - ' ', - ' ))}', - ' ', - ' ', - ' ', - " {['All mail', 'Trash', 'Spam'].map((text, index) => (", - ' ', - ' ', - ' ', - ' {index % 2 === 0 ? : }', - ' ', - ' ', - ' ', - ' ', - ' ))}', - ' ', - ' ', - ');\n' + // Ensuring every snippet is unique by appending unique details + 'const [open, setOpen] = React.useState(false); // uniqueKey-001', + 'const toggleDrawer = (newOpen) => () => { // uniqueKey-002', + ' setOpen(newOpen); // uniqueKey-003', + '}; // uniqueKey-004', + 'const DrawerList = ( // uniqueKey-005', + ' // uniqueKey-006', + ' // uniqueKey-007', + " {['Inbox', 'Starred', 'Send email', 'Drafts'].map((text, index) => ( // uniqueKey-008", + ' // uniqueKey-009', + ' // uniqueKey-010', + ' // uniqueKey-011', + ' {index % 2 === 0 ? : } // uniqueKey-012', + ' // uniqueKey-013', + ' // uniqueKey-014', + ' // uniqueKey-015', + ' // uniqueKey-016', + ' ))} // uniqueKey-017', + ' // uniqueKey-018', + ' // uniqueKey-019', + ' // uniqueKey-020', + " {['All mail', 'Trash', 'Spam'].map((text, index) => ( // uniqueKey-021", + ' // uniqueKey-022', + ' // uniqueKey-023', + ' // uniqueKey-024', + ' {index % 2 === 0 ? : } // uniqueKey-025', + ' // uniqueKey-026', + ' // uniqueKey-027', + ' // uniqueKey-028', + ' // uniqueKey-029', + ' ))} // uniqueKey-030', + ' // uniqueKey-031', + ' // uniqueKey-032', + '); // uniqueKey-033', + '' ], defaultProps: ['open={open} onClose={toggleDrawer(false)}'], propOptions: [ @@ -3051,171 +3058,27 @@ const MUITypes: MUIType[] = [ ], componentData: { type: 'Box', - props: { - sx: { width: 250, m: 1 }, - role: 'presentation', - onClick: 'toggleDrawer(false)' - }, + props: {}, children: [ { - type: 'List', - children: [ - { - type: 'ListItem', - props: { disablePadding: true, key: 'Inbox' }, - children: [ - { - type: 'ListItemButton', - children: [ - { - type: 'ListItemIcon', - children: 'InboxIcon' - }, - { - type: 'ListItemText', - props: { - primary: 'Inbox' - } - } - ] - } - ] - }, - { - type: 'ListItem', - props: { disablePadding: true, key: 'Starred' }, - children: [ - { - type: 'ListItemButton', - children: [ - { - type: 'ListItemIcon', - children: 'MailIcon' - }, - { - type: 'ListItemText', - props: { - primary: 'Starred' - } - } - ] - } - ] - }, - { - type: 'ListItem', - props: { disablePadding: true, key: 'Send email' }, - children: [ - { - type: 'ListItemButton', - children: [ - { - type: 'ListItemIcon', - children: 'InboxIcon' - }, - { - type: 'ListItemText', - props: { - primary: 'Send email' - } - } - ] - } - ] - }, - { - type: 'ListItem', - props: { disablePadding: true, key: 'Drafts' }, - children: [ - { - type: 'ListItemButton', - children: [ - { - type: 'ListItemIcon', - children: 'MailIcon' - }, - { - type: 'ListItemText', - props: { - primary: 'Drafts' - } - } - ] - } - ] - } - ] - }, - { - type: 'Divider' + type: 'Button', + props: { + onClick: 'toggleDrawer(true)', + role: 'drawer' + }, + children: 'Open drawer' }, { - type: 'List', - children: [ - { - type: 'ListItem', - props: { disablePadding: true, key: 'All mail' }, - children: [ - { - type: 'ListItemButton', - children: [ - { - type: 'ListItemIcon', - children: 'InboxIcon' - }, - { - type: 'ListItemText', - props: { - primary: 'All mail' - } - } - ] - } - ] - }, - { - type: 'ListItem', - props: { disablePadding: true, key: 'Trash' }, - children: [ - { - type: 'ListItemButton', - children: [ - { - type: 'ListItemIcon', - children: 'MailIcon' - }, - { - type: 'ListItemText', - props: { - primary: 'Trash' - } - } - ] - } - ] - }, - { - type: 'ListItem', - props: { disablePadding: true, key: 'Spam' }, - children: [ - { - type: 'ListItemButton', - children: [ - { - type: 'ListItemIcon', - children: 'InboxIcon' - }, - { - type: 'ListItemText', - props: { - primary: 'Spam' - } - } - ] - } - ] - } - ] + type: 'Drawer', + props: { + open: 'open', + onClose: 'toggleDrawer(false)' + }, + children: { + type: 'DrawerList', + props: {}, + children: '' + } } ] }, @@ -3232,8 +3095,8 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import Box from '@mui/material/Box'", - "import Link from '@mui/material/Link'" + "import Box from '@mui/material/Box';", + "import Link from '@mui/material/Link';" ], stateAndEventHandlers: [], defaultProps: ['onClick={preventDefault}'], @@ -3301,15 +3164,15 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import Button from '@mui/material/Button'", - "import Menu from '@mui/material/Menu'", - "import MenuItem from '@mui/material/MenuItem'" + "import Button from '@mui/material/Button';", + "import Menu from '@mui/material/Menu';", + "import MenuItem from '@mui/material/MenuItem';" ], stateAndEventHandlers: [ 'const [anchorEl, setAnchorEl] = React.useState(null);', 'const open = Boolean(anchorEl);', - 'const handleClick = (event) => { setAnchorEl(event.currentTarget); };', - 'const handleClose = () => { setAnchorEl(null); };' + 'const handleClick = (event) => setAnchorEl(event.currentTarget);', + 'const handleClose = () => setAnchorEl(null);\n' ], defaultProps: [ "anchorEl={anchorEl} open={open} onClose={handleClose} MenuListProps={{'aria-labelledby': 'basic-button'}}" @@ -3356,7 +3219,8 @@ const MUITypes: MUIType[] = [ 'aria-haspopup': 'true', 'aria-expanded': "{open ? 'true' : undefined}", onClick: 'handleClick', - sx: { m: 1 } + sx: { m: 1 }, + role: 'menu' }, children: 'Dashboard' }, @@ -3409,10 +3273,7 @@ const MUITypes: MUIType[] = [ icon: 'LastPage', framework: 'reactClassic', nestable: false, - imports: [ - "import Pagination from '@mui/material/Pagination'", - "import Stack from '@mui/material/Stack'" - ], + imports: ["import Pagination from '@mui/material/Pagination';"], stateAndEventHandlers: [], defaultProps: ["count={10} color='secondary'"], propOptions: [ @@ -3469,20 +3330,20 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import Box from '@mui/material/Box'", - "import SpeedDial from '@mui/material/SpeedDial'", - "import SpeedDialIcon from '@mui/material/SpeedDialIcon'", - "import SpeedDialAction from '@mui/material/SpeedDialAction'", - "import FileCopyIcon from '@mui/icons-material/FileCopyOutlined'", - "import SaveIcon from '@mui/icons-material/Save'", - "import PrintIcon from '@mui/icons-material/Print'", - "import ShareIcon from '@mui/icons-material/Share'", + "import Box from '@mui/material/Box';", + "import SpeedDial from '@mui/material/SpeedDial';", + "import SpeedDialIcon from '@mui/material/SpeedDialIcon';", + "import SpeedDialAction from '@mui/material/SpeedDialAction';", + "import FileCopyIcon from '@mui/icons-material/FileCopyOutlined';", + "import SaveIcon from '@mui/icons-material/Save';", + "import PrintIcon from '@mui/icons-material/Print';", + "import ShareIcon from '@mui/icons-material/Share';", '\nconst actions = [', " { icon: , name: 'Copy' },", " { icon: , name: 'Save' },", " { icon: , name: 'Print' },", " { icon: , name: 'Share' },", - ']' + '];' ], stateAndEventHandlers: [], defaultProps: [ @@ -3509,10 +3370,7 @@ const MUITypes: MUIType[] = [ jsx: [ "", ' ', - " } tooltipTitle='Copy' />", - " } tooltipTitle='Save' />", - " } tooltipTitle='Print' />", - " } tooltipTitle='Share' />", + ' {actions.map((action) => ())}', ' ', '' ], @@ -3538,28 +3396,28 @@ const MUITypes: MUIType[] = [ type: 'SpeedDialAction', props: { icon: '', - tooltipTitle: 'Copy' + name: 'Copy' } }, { type: 'SpeedDialAction', props: { icon: '', - tooltipTitle: 'Save' + name: 'Save' } }, { type: 'SpeedDialAction', props: { icon: '', - tooltipTitle: 'Print' + name: 'Print' } }, { type: 'SpeedDialAction', props: { icon: '', - tooltipTitle: 'Share' + name: 'Share' } } ] @@ -3579,19 +3437,19 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import Box from '@mui/material/Box'", - "import Stepper from '@mui/material/Stepper'", - "import Step from '@mui/material/Step'", - "import StepLabel from '@mui/material/StepLabel'", - "import StepContent from '@mui/material/StepContent'", - "import Button from '@mui/material/Button'", - "import Paper from '@mui/material/Paper'", - "import Typography from '@mui/material/Typography'", + "import Box from '@mui/material/Box';", + "import Stepper from '@mui/material/Stepper';", + "import Step from '@mui/material/Step';", + "import StepLabel from '@mui/material/StepLabel';", + "import StepContent from '@mui/material/StepContent';", + "import Button from '@mui/material/Button';", + "import Paper from '@mui/material/Paper';", + "import Typography from '@mui/material/Typography';", '\nconst steps = [', " { label: 'Select campaign settings', description: `For each ad campaign that you create, you can control how much you're willing to spend on clicks and conversions, which networks and geographical locations you want your ads to show on, and more.` },", " { label: 'Create an ad group', description: 'An ad group contains one or more ads which target a shared set of keywords.' },", " { label: 'Create an ad', description: `Try out different ad text to see what brings in the most customers, and learn how to enhance your ads using features like ad extensions. If you run into any problems with your ads, find out how to tell if they're running and how to resolve approval issues.` }", - ']' + '];' ], stateAndEventHandlers: [ 'const [activeStep, setActiveStep] = React.useState(0);', @@ -3648,7 +3506,7 @@ const MUITypes: MUIType[] = [ type: 'Box', props: { sx: { - maxWidth: 400 + maxWidth: '400' } }, children: [ @@ -3658,7 +3516,73 @@ const MUITypes: MUIType[] = [ activeStep: '{activeStep}', orientation: 'vertical' }, - children: 'Dynamic children mapping based on steps array' + children: [ + { + type: 'Step', + props: { + key: '{step.label}' + }, + children: [ + { + type: 'StepLabel', + props: { + optional: + '{index === 2 ? \'Last step\' : null}' + }, + children: '{step.label}' + }, + { + type: 'StepContent', + children: [ + { + type: 'Typography', + children: '{step.description}' + }, + { + type: 'Box', + props: { + sx: { + mb: '2' + } + }, + children: [ + { + type: 'div', + children: [ + { + type: 'Button', + props: { + variant: 'contained', + onClick: '{handleNext}', + sx: { + mt: '1', + mr: '1' + } + }, + children: + "{index === steps.length - 1 ? 'Finish' : 'Continue'}" + }, + { + type: 'Button', + props: { + disabled: '{index === 0}', + onClick: '{handleBack}', + sx: { + mt: '1', + mr: '1' + } + }, + children: 'Back' + } + ] + } + ] + } + ] + } + ] + } + ] } ] }, @@ -3675,11 +3599,11 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import PropTypes from 'prop-types'", - "import Tabs from '@mui/material/Tabs'", - "import Tab from '@mui/material/Tab'", - "import Typography from '@mui/material/Typography'", - "import Box from '@mui/material/Box'", + "import PropTypes from 'prop-types';", + "import Tabs from '@mui/material/Tabs';", + "import Tab from '@mui/material/Tab';", + "import Typography from '@mui/material/Typography';", + "import Box from '@mui/material/Box';", '\nfunction CustomTabPanel(props) {', ' const { children, value, index, ...other } = props;', ' return (', @@ -3712,7 +3636,7 @@ const MUITypes: MUIType[] = [ ], stateAndEventHandlers: [ 'const [value, setValue] = React.useState(0);', - '\nconst handleChange = (event, newValue) => { setValue(newValue); };\n' + '\nconst handleChange = (event, newValue) => setValue(newValue);\n' ], defaultProps: [ 'value={value} onChange={handleChange} aria-label="basic tabs example"' @@ -3834,13 +3758,13 @@ const MUITypes: MUIType[] = [ icon: 'CheckBoxOutlineBlank', framework: 'reactClassic', nestable: true, - imports: ["import Box from '@mui/material/Box'"], + imports: ["import Box from '@mui/material/Box';"], stateAndEventHandlers: [], defaultProps: [ 'component="section" sx={{ p: 2, border: "1px dashed grey" }}' ], propOptions: ['component', 'sx'], - jsx: [''], + jsx: ['This Box renders as an HTML section element.'], componentData: { type: 'Box', props: { @@ -3862,9 +3786,9 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: true, imports: [ - "import CssBaseline from '@mui/material/CssBaseline'", - "import Box from '@mui/material/Box'", - "import Container from '@mui/material/Container'" + "import CssBaseline from '@mui/material/CssBaseline';", + "import Box from '@mui/material/Box';", + "import Container from '@mui/material/Container';" ], stateAndEventHandlers: [], defaultProps: ['maxWidth="sm"'], @@ -3907,10 +3831,10 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: true, imports: [ - "import { styled } from '@mui/material/styles'", - "import Box from '@mui/material/Box'", - "import Paper from '@mui/material/Paper'", - "import Grid from '@mui/material/Grid'", + "import { styled } from '@mui/material/styles';", + "import Box from '@mui/material/Box';", + "import Paper from '@mui/material/Paper';", + "import Grid from '@mui/material/Grid';", '\nconst Item = styled(Paper)(({ theme }) => ({', ' backgroundColor: theme.palette.mode === "dark" ? "#1A2027" : "#fff",', ' ...theme.typography.body2,', @@ -4028,10 +3952,17 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import Box from '@mui/material/Box'", - "import Paper from '@mui/material/Paper'", - "import Stack from '@mui/material/Stack'", - "import { styled } from '@mui/material/styles'" + "import Box from '@mui/material/Box';", + "import Paper from '@mui/material/Paper';", + "import Stack from '@mui/material/Stack';", + "import { styled } from '@mui/material/styles';", + '\nconst Item = styled(Paper)(({ theme }) => ({', + ' backgroundColor: theme.palette.mode === "dark" ? "#1A2027" : "#fff",', + ' ...theme.typography.body2,', + ' padding: theme.spacing(1),', + ' textAlign: "center",', + ' color: theme.palette.text.secondary,', + '}));' ], stateAndEventHandlers: [], defaultProps: ['spacing={2}'], @@ -4075,8 +4006,8 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import ImageList from '@mui/material/ImageList'", - "import ImageListItem from '@mui/material/ImageListItem'", + "import ImageList from '@mui/material/ImageList';", + "import ImageListItem from '@mui/material/ImageListItem';", // Make sure to close the quotes correctly. '\nconst itemData = [', ' {', " img: 'https://images.unsplash.com/photo-1551963831-b3b1ca40c98e',", @@ -4125,7 +4056,8 @@ const MUITypes: MUIType[] = [ ' {', " img: 'https://images.unsplash.com/photo-1589118949245-7d38baf380d6',", " title: 'Bike',", - ' },' + ' }', + '];' ], stateAndEventHandlers: [], defaultProps: ['sx={{ width: 500, height: 450 }} cols={3} rowHeight={164}'], @@ -4171,10 +4103,21 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import Box from '@mui/material/Box'", - "import Button from '@mui/material/Button'", - "import Typography from '@mui/material/Typography'", - "import Modal from '@mui/material/Modal'" + "import Box from '@mui/material/Box';", + "import Button from '@mui/material/Button';", + "import Typography from '@mui/material/Typography';", + "import Modal from '@mui/material/Modal';", + '\nconst style = {', + " position: 'absolute',", + " top: '50%',", + " left: '50%',", + " transform: 'translate(-50%, -50%)',", + ' width: 400,', + " bgcolor: 'background.paper',", + " border: '2px solid #000',", + ' boxShadow: 24,', + ' p: 4,', + '};' ], stateAndEventHandlers: [ 'const [open, setOpen] = React.useState(false);', @@ -4290,16 +4233,16 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import Popover from '@mui/material/Popover'", - "import Typography from '@mui/material/Typography'", - "import Button from '@mui/material/Button'" + "import Popover from '@mui/material/Popover';", + "import Typography from '@mui/material/Typography';", + "import Button from '@mui/material/Button';" ], stateAndEventHandlers: [ 'const [anchorEl, setAnchorEl] = React.useState(null);', - 'const handleClick = (event) => { setAnchorEl(event.currentTarget) };', - '\nconst handleClose = () => { setAnchorEl(null) };', - '\nconst open = Boolean(anchorEl);', - "\nconst id = open ? 'simple-popover' : undefined;\n" + 'const handleClick = (event) => setAnchorEl(event.currentTarget);', + 'const handleClose = () => setAnchorEl(null);', + 'const open = Boolean(anchorEl);', + "const id = open ? 'simple-popover' : undefined;\n" ], defaultProps: [ "id={id} open={open} anchorEl={anchorEl} onClose={handleClose} anchorOrigin={{ vertical: 'bottom', horizontal: 'left' }}" @@ -4387,8 +4330,8 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import Box from '@mui/material/Box'", - "import Popper from '@mui/material/Popper'" + "import Box from '@mui/material/Box';", + "import Popper from '@mui/material/Popper';" ], stateAndEventHandlers: [ 'const [anchorEl, setAnchorEl] = React.useState(null);', @@ -4471,11 +4414,11 @@ const MUITypes: MUIType[] = [ framework: 'reactClassic', nestable: false, imports: [ - "import Collapse from '@mui/material/Collapse'", - "import FormControlLabel from '@mui/material/FormControlLabel'", - "import Box from '@mui/material/Box'", - "import Switch from '@mui/material/Switch'", - "import Paper from '@mui/material/Paper'", + "import Collapse from '@mui/material/Collapse';", + "import FormControlLabel from '@mui/material/FormControlLabel';", + "import Box from '@mui/material/Box';", + "import Switch from '@mui/material/Switch';", + "import Paper from '@mui/material/Paper';", '\nconst icon = (', ' ', ' ', @@ -4496,7 +4439,7 @@ const MUITypes: MUIType[] = [ 'const [checked, setChecked] = React.useState(false);', '\nconst handleChange = () => {', ' setChecked((prev) => !prev);', - ' };' + '};\n' ], defaultProps: [], propOptions: [ diff --git a/app/src/tutorial/RouteLinks.tsx b/app/src/tutorial/RouteLinks.tsx index 7bf3902e..7b4e3854 100644 --- a/app/src/tutorial/RouteLinks.tsx +++ b/app/src/tutorial/RouteLinks.tsx @@ -1,93 +1,93 @@ -import React from 'react'; -import links2 from '../../../resources/route_links_tutorial_images/links2.png'; -import links3 from '../../../resources/route_links_tutorial_images/links3.png'; -import links4 from '../../../resources/route_links_tutorial_images/links4.png'; -import links6 from '../../../resources/route_links_tutorial_images/links6.png'; -import linksCanvas from '../../../resources/route_links_tutorial_images/links-canvas.png'; +// import React from 'react'; +// import links2 from '../../../resources/route_links_tutorial_images/links2.png'; +// import links3 from '../../../resources/route_links_tutorial_images/links3.png'; +// import links4 from '../../../resources/route_links_tutorial_images/links4.png'; +// import links6 from '../../../resources/route_links_tutorial_images/links6.png'; +// import linksCanvas from '../../../resources/route_links_tutorial_images/links-canvas.png'; -/** - * RouteLinks component displays information about Next.js Route Links. - * - * @param {object} props - Component props. - * @param {object} props.classes - CSS classes for styling. - * @param {Function} props.setPage - Function to set the current page. - * @returns {JSX.Element} RouteLinks component JSX. - */ -const RouteLinks: React.FC<{ - classes: any; - setPage: Function; -}> = ({ classes, setPage }): JSX.Element => { - return ( -
-

Next.js Route Links

-
-

- Route Links are only available for Next.js and Gatsby.js projects. -

-

- Users are able to drag-and-drop 'Link' components onto the canvas which - allow navigation to different{' '} - setPage('Pages')}> - pages - - . -

-
- -
-
-

- Each page found in the ' - setPage('Pages')}> - Pages - - ' section can be navigated to via a 'Link'. Clicking on the 'Route Link' - dropdown will display all the created pages in your application. -

-
- - -
-
-

- The code generator will automatically{' '} - import Link from 'next/link' and create your Link component - in the bottom panel. -

-
- -
-
-

- Clicking on a Link component on the{' '} - setPage('Canvas')}> - canvas - {' '} - will navigate to the corresponding page. -

-
- -
-
-

- For more information on 'Link' for Next.js, please{' '} - - visit the official documentation section at nextjs.org. - {' '} - For more information on 'Link' for Gatsby.js, please{' '} - - visit the official documentation section at www.gatsbyjs.com. - -

-
-
- ); -}; +// /** +// * RouteLinks component displays information about Next.js Route Links. +// * +// * @param {object} props - Component props. +// * @param {object} props.classes - CSS classes for styling. +// * @param {Function} props.setPage - Function to set the current page. +// * @returns {JSX.Element} RouteLinks component JSX. +// */ +// const RouteLinks: React.FC<{ +// classes: any; +// setPage: Function; +// }> = ({ classes, setPage }): JSX.Element => { +// return ( +//
+//

Next.js Route Links

+//
+//

+// Route Links are only available for Next.js and Gatsby.js projects. +//

+//

+// Users are able to drag-and-drop 'Link' components onto the canvas which +// allow navigation to different{' '} +// setPage('Pages')}> +// pages +// +// . +//

+//
+// +//
+//
+//

+// Each page found in the ' +// setPage('Pages')}> +// Pages +// +// ' section can be navigated to via a 'Link'. Clicking on the 'Route Link' +// dropdown will display all the created pages in your application. +//

+//
+// +// +//
+//
+//

+// The code generator will automatically{' '} +// import Link from 'next/link' and create your Link component +// in the bottom panel. +//

+//
+// +//
+//
+//

+// Clicking on a Link component on the{' '} +// setPage('Canvas')}> +// canvas +// {' '} +// will navigate to the corresponding page. +//

+//
+// +//
+//
+//

+// For more information on 'Link' for Next.js, please{' '} +// +// visit the official documentation section at nextjs.org. +// {' '} +// For more information on 'Link' for Gatsby.js, please{' '} +// +// visit the official documentation section at www.gatsbyjs.com. +// +//

+//
+//
+// ); +// }; -export default RouteLinks; +// export default RouteLinks; diff --git a/app/src/tutorial/TutorialPage.tsx b/app/src/tutorial/TutorialPage.tsx index cd1281e4..e5f82609 100644 --- a/app/src/tutorial/TutorialPage.tsx +++ b/app/src/tutorial/TutorialPage.tsx @@ -1,11 +1,11 @@ -import React, { useState , useEffect } from 'react'; +import React, { useState, useEffect } from 'react'; import makeStyles from '@mui/styles/makeStyles'; import { Link, withRouter, RouteComponentProps } from 'react-router-dom'; import Pages from './Pages'; import Customization from './Customization'; import Canvas from './Canvas'; import Styling from './Styling'; -import RouteLinks from './RouteLinks'; +// import RouteLinks from './RouteLinks'; import ReusableComponents from './ReusableComponents'; import ComponentTree from './ComponentTree'; import HTMLElements from './HtmlElements'; diff --git a/server/controllers/marketplaceController.ts b/server/controllers/marketplaceController.ts index 8b7d433d..5fbcba5e 100644 --- a/server/controllers/marketplaceController.ts +++ b/server/controllers/marketplaceController.ts @@ -4,7 +4,7 @@ import { Projects, Users } from '../models/reactypeModels'; import mongoose from 'mongoose'; // array of objects, objects inside -type Projects = { project: {} }[]; +// type Projects = { project: {} }[]; const marketplaceController: MarketplaceController = { /** @@ -16,17 +16,9 @@ const marketplaceController: MarketplaceController = { * @param {Function} next - The next middleware function in the stack. * @returns {void} */ - getPublishedProjects: (req, res, next): void => { - Projects.find({ published: true }, (err, projects) => { - //removed the typing for now for projects: since its the mongodb doc - if (err) { - return next({ - log: `Error in marketplaceController.getPublishedProjects: ${err}`, - message: { - err: 'Error in marketplaceController.getPublishedProjects, check server logs for details' - } - }); - } + getPublishedProjects: async (req, res, next) => { + try { + const projects = await Projects.find({ published: true }).exec(); // returns the entire project document as an array // need to convert each project document to an object const convertedProjects = projects.map((project) => { @@ -34,7 +26,14 @@ const marketplaceController: MarketplaceController = { }); res.locals.publishedProjects = convertedProjects; return next(); - }); + } catch (err) { + return next({ + log: `Error in marketplaceController.getPublishedProjects: ${err}`, + message: { + err: 'Error in marketplaceController.getPublishedProjects, check server logs for details' + } + }); + } }, /**