-
-
Notifications
You must be signed in to change notification settings - Fork 736
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: create and edit release plan template milestones #8768
Changes from 4 commits
335fd6a
43f82a7
ac1cb64
7485525
da2c153
65cf461
31e3cbd
da9dc11
4ac82e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import Input from 'component/common/Input/Input'; | ||
import { Box, Button, Card, Grid, styled } from '@mui/material'; | ||
import Edit from '@mui/icons-material/Edit'; | ||
import type { IReleasePlanMilestonePayload } from 'interfaces/releasePlans'; | ||
import { useState } from 'react'; | ||
|
||
const StyledEditIcon = styled(Edit)(({ theme }) => ({ | ||
cursor: 'pointer', | ||
marginTop: theme.spacing(-0.25), | ||
marginLeft: theme.spacing(0.5), | ||
height: theme.spacing(2.5), | ||
width: theme.spacing(2.5), | ||
color: theme.palette.text.secondary, | ||
})); | ||
|
||
const StyledMilestoneCard = styled(Card)(({ theme }) => ({ | ||
marginTop: theme.spacing(2), | ||
display: 'flex', | ||
flexDirection: 'column', | ||
justifyContent: 'space-between', | ||
boxShadow: 'none', | ||
border: `1px solid ${theme.palette.divider}`, | ||
[theme.breakpoints.down('sm')]: { | ||
justifyContent: 'center', | ||
}, | ||
transition: 'background-color 0.2s ease-in-out', | ||
backgroundColor: theme.palette.background.default, | ||
'&:hover': { | ||
backgroundColor: theme.palette.neutral.light, | ||
}, | ||
borderRadius: theme.shape.borderRadiusMedium, | ||
})); | ||
|
||
const StyledMilestoneCardBody = styled(Box)(({ theme }) => ({ | ||
padding: theme.spacing(2, 2), | ||
})); | ||
|
||
const StyledGridItem = styled(Grid)(({ theme }) => ({ | ||
display: 'flex', | ||
alignItems: 'center', | ||
})); | ||
|
||
const StyledInput = styled(Input)(({ theme }) => ({ | ||
width: '100%', | ||
})); | ||
|
||
const StyledMilestoneCardTitle = styled('span')(({ theme }) => ({ | ||
fontWeight: theme.fontWeight.bold, | ||
fontSize: theme.fontSizes.bodySize, | ||
})); | ||
|
||
interface IMilestoneCard { | ||
daveleek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
index: number; | ||
milestone: IReleasePlanMilestonePayload; | ||
milestoneNameChanged: (index: number, name: string) => void; | ||
showAddStrategyDialog: (index: number) => void; | ||
errors: { [key: string]: string }; | ||
clearErrors: () => void; | ||
} | ||
|
||
export const MilestoneCard = ({ | ||
index, | ||
milestone, | ||
milestoneNameChanged, | ||
showAddStrategyDialog, | ||
errors, | ||
clearErrors, | ||
}: IMilestoneCard) => { | ||
const [editMode, setEditMode] = useState(false); | ||
|
||
return ( | ||
<StyledMilestoneCard> | ||
<StyledMilestoneCardBody> | ||
<Grid container> | ||
<StyledGridItem item xs={10} md={10}> | ||
{editMode && ( | ||
<StyledInput | ||
label='' | ||
value={milestone.name} | ||
onChange={(e) => | ||
milestoneNameChanged(index, e.target.value) | ||
} | ||
error={Boolean(errors?.name)} | ||
errorText={errors?.name} | ||
onFocus={() => clearErrors()} | ||
onBlur={() => setEditMode(false)} | ||
autoFocus | ||
onKeyDownCapture={(e) => { | ||
if (e.code === 'Enter') { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
setEditMode(false); | ||
} | ||
}} | ||
/> | ||
)} | ||
{!editMode && ( | ||
<> | ||
<StyledMilestoneCardTitle | ||
onClick={() => setEditMode(true)} | ||
> | ||
{milestone.name} | ||
</StyledMilestoneCardTitle> | ||
<StyledEditIcon | ||
onClick={() => setEditMode(true)} | ||
/> | ||
</> | ||
)} | ||
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. Why isn't this a part of the above block, since the condition is the same? 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. Argh, I moved things around and forgot to remove the duplicate condition 🙄 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. I think you could have added the onClick handler on the parent component, catching any click in the children, instead of duplicating it. 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. Parent is the same for this and the other section which is only shown during edit mode, and would have a weird effect if you click inside. I'll have a think if I can introduce a parent just for these two while doing add strategies |
||
</StyledGridItem> | ||
<Grid item xs={2} md={2}> | ||
<Button | ||
variant='outlined' | ||
color='primary' | ||
onClick={() => showAddStrategyDialog(index)} | ||
> | ||
Add strategy | ||
</Button> | ||
</Grid> | ||
</Grid> | ||
</StyledMilestoneCardBody> | ||
</StyledMilestoneCard> | ||
); | ||
}; |
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.
I still think you could have potentially merged the edit and create components into a single one, with a simple
const isEdit = Boolean(templateId)
, but this is probably fine for now, and has much less duplicated code than before, so good job 👍