-
-
Notifications
You must be signed in to change notification settings - Fork 684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: enable project creation through new form #6961
Merged
Merged
Changes from 12 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
2d9fd85
feat: start stubbing out form
thomasheartman 6c45609
Stub out the first two inputs
thomasheartman 9cb6df0
chore: use section remove import
thomasheartman 2872a2c
Chore: use form template
thomasheartman bdb0506
feat: style form actions
thomasheartman 9e6d4fc
feat: use some more mui options
thomasheartman 74eea8d
feat: remove spacing
thomasheartman bf59b48
feat: wrap in form, add template selection
thomasheartman dba9427
feat: refactor impl a bit
thomasheartman 811b4e9
Merge branch 'main' into feat/new-project-creation-form-layout
thomasheartman 4f0a604
feat: put implementation behind a flag
thomasheartman 3097c04
feat: allow actual submission of form
thomasheartman e2a4824
Merge branch 'main' into feat/new-project-form-submit
thomasheartman c9b59f4
Chore: add comment
thomasheartman e474411
chore: remove template selector
thomasheartman 179f0a4
Chore: use Unleash's input instead of Mui's
thomasheartman 702944f
Chore: remove unused const
thomasheartman a901cf3
Chore: clean some spacing
thomasheartman 3f0ba86
Chore: wrap input components in divs
thomasheartman c4b96ee
Chore: import type
thomasheartman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
195 changes: 195 additions & 0 deletions
195
frontend/src/component/project/Project/CreateProject/NewProjectForm.tsx
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,195 @@ | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import { | ||
Button, | ||
MenuItem, | ||
Select, | ||
TextField, | ||
Typography, | ||
styled, | ||
} from '@mui/material'; | ||
|
||
const StyledContainer = styled('form')(({ theme }) => ({ | ||
background: theme.palette.background.default, | ||
|
||
'> * + *': { | ||
borderBlockStart: `1px solid ${theme.palette.divider}`, | ||
}, | ||
|
||
'> *': { | ||
padding: theme.spacing(7), | ||
}, | ||
})); | ||
|
||
const TopGrid = styled('div')(({ theme }) => ({ | ||
display: 'grid', | ||
gridTemplateAreas: | ||
'"icon header template" "icon project-name project-name" "icon description description"', | ||
gridTemplateColumns: 'minmax(auto, 50px) 1fr auto', | ||
gap: theme.spacing(2), | ||
|
||
'> span.icon': { | ||
border: `1px solid ${theme.palette.primary.main}`, | ||
width: `100%`, | ||
aspectRatio: '1', | ||
borderRadius: theme.shape.borderRadius, | ||
}, | ||
|
||
'> h2': { | ||
gridArea: 'header', | ||
}, | ||
|
||
'> span.input': { | ||
gridArea: 'template', | ||
}, | ||
|
||
'.project-name': { | ||
gridArea: 'project-name', | ||
margin: 0, | ||
}, | ||
|
||
'.project-name *': { | ||
fontSize: theme.typography.h1.fontSize, | ||
}, | ||
|
||
'.description': { | ||
gridArea: 'description', | ||
margin: 0, | ||
}, | ||
|
||
'.description *': { | ||
fontSize: theme.typography.h2.fontSize, | ||
}, | ||
})); | ||
|
||
const OptionButtons = styled('div')(({ theme }) => ({ | ||
display: 'flex', | ||
gap: theme.spacing(2), | ||
})); | ||
|
||
const StyledInput = styled(TextField)(({ theme }) => ({ | ||
width: '100%', | ||
marginBottom: theme.spacing(2), | ||
paddingRight: theme.spacing(1), | ||
|
||
fieldset: { border: 'none' }, | ||
})); | ||
|
||
const FormActions = styled('div')(({ theme }) => ({ | ||
display: 'flex', | ||
gap: theme.spacing(5), | ||
justifyContent: 'flex-end', | ||
})); | ||
|
||
const CREATE_PROJECT_BTN = 'CREATE_PROJECT_BTN'; | ||
|
||
type FormProps = { | ||
projectId: string; | ||
projectName: string; | ||
projectDesc: string; | ||
projectStickiness?: string; | ||
featureLimit?: string; | ||
featureCount?: number; | ||
projectMode?: string; | ||
setProjectStickiness?: React.Dispatch<React.SetStateAction<string>>; | ||
setProjectId: React.Dispatch<React.SetStateAction<string>>; | ||
setProjectName: React.Dispatch<React.SetStateAction<string>>; | ||
setProjectDesc: React.Dispatch<React.SetStateAction<string>>; | ||
setFeatureLimit?: React.Dispatch<React.SetStateAction<string>>; | ||
setProjectMode?: React.Dispatch<React.SetStateAction<ProjectMode>>; | ||
handleSubmit: (e: any) => void; | ||
errors: { [key: string]: string }; | ||
mode: 'Create' | 'Edit'; | ||
clearErrors: () => void; | ||
validateProjectId: () => void; | ||
}; | ||
Comment on lines
+69
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are all the props from the old form. I've put them here as a template. We'll use the ones we need and remove the ones we don't as we go. |
||
|
||
const PROJECT_NAME_INPUT = 'PROJECT_NAME_INPUT'; | ||
const PROJECT_DESCRIPTION_INPUT = 'PROJECT_DESCRIPTION_INPUT'; | ||
|
||
export const NewProjectForm: React.FC<FormProps> = ({ | ||
children, | ||
handleSubmit, | ||
projectName, | ||
projectDesc, | ||
projectStickiness, | ||
featureLimit, | ||
featureCount, | ||
projectMode, | ||
setProjectMode, | ||
setProjectId, | ||
setProjectName, | ||
setProjectDesc, | ||
setProjectStickiness, | ||
setFeatureLimit, | ||
errors, | ||
mode, | ||
clearErrors, | ||
}) => { | ||
const handleProjectNameUpdate = ( | ||
e: React.ChangeEvent<HTMLInputElement>, | ||
) => { | ||
const input = e.target.value; | ||
setProjectName(input); | ||
const maybeProjectId = input | ||
? `${encodeURIComponent(input.trim())}-${uuidv4().slice(-12)}` | ||
: ''; | ||
setProjectId(maybeProjectId); | ||
}; | ||
|
||
return ( | ||
<StyledContainer | ||
onSubmit={(submitEvent) => { | ||
handleSubmit(submitEvent); | ||
}} | ||
> | ||
<TopGrid> | ||
<span className='icon'>icon</span> | ||
<Typography variant='h2'>New project</Typography> | ||
<Select | ||
className='input' | ||
id='template-selector' | ||
value={'none'} | ||
label='Project creation template' | ||
name='Project creation template' | ||
> | ||
<MenuItem value={'none'}>No template</MenuItem> | ||
</Select> | ||
<StyledInput | ||
className='project-name' | ||
label='Project name' | ||
value={projectName} | ||
onChange={handleProjectNameUpdate} | ||
error={Boolean(errors.name)} | ||
errorText={errors.name} | ||
onFocus={() => { | ||
delete errors.name; | ||
}} | ||
data-testid={PROJECT_NAME_INPUT} | ||
required | ||
autoFocus | ||
InputProps={{ | ||
classes: { | ||
input: 'project-name-input', | ||
}, | ||
}} | ||
/> | ||
<StyledInput | ||
className='description' | ||
label='Description (optional)' | ||
multiline | ||
maxRows={20} | ||
value={projectDesc} | ||
onChange={(e) => setProjectDesc(e.target.value)} | ||
data-testid={PROJECT_DESCRIPTION_INPUT} | ||
/> | ||
</TopGrid> | ||
<OptionButtons> | ||
<Button variant='outlined'>4 selected</Button> | ||
<Button variant='outlined'>clientId</Button> | ||
<Button variant='outlined'>Open</Button> | ||
<Button variant='outlined'>1 environment configured</Button> | ||
</OptionButtons> | ||
<FormActions>{children}</FormActions> | ||
</StyledContainer> | ||
); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just shove in all the props that we send to the existing form for now, so that we have all the stuff we need.