-
-
Notifications
You must be signed in to change notification settings - Fork 735
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rework frontend validation for release plan templates (#9055)
- Loading branch information
Showing
4 changed files
with
182 additions
and
100 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
85 changes: 85 additions & 0 deletions
85
frontend/src/component/releases/ReleasePlanTemplate/MilestoneCardName.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,85 @@ | ||
import type { IReleasePlanMilestonePayload } from 'interfaces/releasePlans'; | ||
import Edit from '@mui/icons-material/Edit'; | ||
import { styled } from '@mui/material'; | ||
import { useState } from 'react'; | ||
import Input from 'component/common/Input/Input'; | ||
|
||
const StyledInput = styled(Input)(({ theme }) => ({ | ||
width: '100%', | ||
})); | ||
|
||
const StyledMilestoneCardTitle = styled('span')(({ theme }) => ({ | ||
fontWeight: theme.fontWeight.bold, | ||
fontSize: theme.fontSizes.bodySize, | ||
})); | ||
|
||
const StyledEditIcon = styled(Edit, { | ||
shouldForwardProp: (prop) => prop !== 'hasError', | ||
})<{ hasError: boolean }>(({ theme, hasError = false }) => ({ | ||
cursor: 'pointer', | ||
marginTop: theme.spacing(-0.25), | ||
marginLeft: theme.spacing(0.5), | ||
height: theme.spacing(2.5), | ||
width: theme.spacing(2.5), | ||
color: hasError ? theme.palette.error.main : theme.palette.text.secondary, | ||
})); | ||
|
||
interface IMilestoneCardNameProps { | ||
milestone: IReleasePlanMilestonePayload; | ||
errors: { [key: string]: string }; | ||
clearErrors: () => void; | ||
milestoneNameChanged: (name: string) => void; | ||
} | ||
|
||
export const MilestoneCardName = ({ | ||
milestone, | ||
errors, | ||
clearErrors, | ||
milestoneNameChanged, | ||
}: IMilestoneCardNameProps) => { | ||
const [editMode, setEditMode] = useState(false); | ||
return ( | ||
<> | ||
{editMode && ( | ||
<StyledInput | ||
label='' | ||
value={milestone.name} | ||
onChange={(e) => milestoneNameChanged(e.target.value)} | ||
error={Boolean(errors?.[`${milestone.id}_name`])} | ||
errorText={errors?.[`${milestone.id}_name`]} | ||
onFocus={() => clearErrors()} | ||
onBlur={() => setEditMode(false)} | ||
autoFocus | ||
onKeyDownCapture={(e) => { | ||
if (e.code === 'Enter') { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
setEditMode(false); | ||
} | ||
}} | ||
/> | ||
)} | ||
{!editMode && ( | ||
<> | ||
<StyledMilestoneCardTitle | ||
onClick={(ev) => { | ||
setEditMode(true); | ||
ev.preventDefault(); | ||
ev.stopPropagation(); | ||
}} | ||
> | ||
{milestone.name} | ||
</StyledMilestoneCardTitle> | ||
<StyledEditIcon | ||
hasError={Boolean(errors?.[`${milestone.id}_name`])} | ||
onClick={(ev) => { | ||
setEditMode(true); | ||
ev.preventDefault(); | ||
ev.stopPropagation(); | ||
}} | ||
/> | ||
</> | ||
)} | ||
</> | ||
); | ||
}; |
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