-
-
Notifications
You must be signed in to change notification settings - Fork 741
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: edit release plan template #8723
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5c5d7b0
feat: edit release plan template
daveleek c682249
chore: add path to snapshot
daveleek 7463d50
Merge branch 'main' into feat/edit-release-plan-template-overview
daveleek 5694e0e
Update frontend/src/component/releases/ReleasePlanTemplate/EditReleas…
daveleek 15c59d2
chore: clean up
daveleek 2452bc1
chore: add missing property rename
daveleek 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
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
139 changes: 139 additions & 0 deletions
139
frontend/src/component/releases/ReleasePlanTemplate/EditReleasePlanTemplate.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,139 @@ | ||
import { useUiFlag } from 'hooks/useUiFlag'; | ||
import { usePageTitle } from 'hooks/usePageTitle'; | ||
import { useRequiredPathParam } from 'hooks/useRequiredPathParam'; | ||
import { useReleasePlanTemplateInstance } from 'hooks/api/getters/useReleasePlanTemplates/useReleasePlanTemplateInstance'; | ||
import FormTemplate from 'component/common/FormTemplate/FormTemplate'; | ||
import { useTemplateForm } from '../hooks/useTemplateForm'; | ||
import { TemplateForm } from './TemplateForm'; | ||
import { Box, Button, Card, styled } from '@mui/material'; | ||
import { UpdateButton } from 'component/common/UpdateButton/UpdateButton'; | ||
import { ADMIN } from '@server/types/permissions'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { formatUnknownError } from 'utils/formatUnknownError'; | ||
import useToast from 'hooks/useToast'; | ||
import useReleasePlanTemplatesApi from 'hooks/api/actions/useReleasePlanTemplatesApi/useReleasePlanTemplatesApi'; | ||
|
||
const StyledForm = styled('form')(() => ({ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
height: '100%', | ||
})); | ||
|
||
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(3, 2, 3, 2), | ||
daveleek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
})); | ||
|
||
const StyledMilestoneCardTitle = styled('span')(({ theme }) => ({ | ||
fontWeight: theme.fontWeight.bold, | ||
fontSize: theme.fontSizes.bodySize, | ||
})); | ||
|
||
const StyledButtonContainer = styled('div')(() => ({ | ||
marginTop: 'auto', | ||
display: 'flex', | ||
justifyContent: 'flex-end', | ||
})); | ||
|
||
const StyledCancelButton = styled(Button)(({ theme }) => ({ | ||
marginLeft: theme.spacing(3), | ||
})); | ||
|
||
export const EditReleasePlanTemplate = () => { | ||
const releasePlansEnabled = useUiFlag('releasePlans'); | ||
if (!releasePlansEnabled) { | ||
return null; | ||
} | ||
daveleek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const templateId = useRequiredPathParam('templateId'); | ||
const { template, loading, error, refetch } = | ||
useReleasePlanTemplateInstance(templateId); | ||
usePageTitle(`Edit template: ${template.name}`); | ||
const navigate = useNavigate(); | ||
const { setToastApiError } = useToast(); | ||
const { updateReleasePlanTemplate } = useReleasePlanTemplatesApi(); | ||
const { | ||
name, | ||
setName, | ||
description, | ||
setDescription, | ||
errors, | ||
clearErrors, | ||
validate, | ||
getTemplatePayload, | ||
} = useTemplateForm(template.name, template.description); | ||
|
||
const handleCancel = () => {}; | ||
daveleek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const handleSubmit = async (e: React.FormEvent) => { | ||
e.preventDefault(); | ||
clearErrors(); | ||
const isValid = validate(); | ||
if (isValid) { | ||
const payload = getTemplatePayload(); | ||
try { | ||
updateReleasePlanTemplate({ | ||
...payload, | ||
id: templateId, | ||
milestones: template.milestones, | ||
}).then(() => { | ||
daveleek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
navigate('/release-management'); | ||
}); | ||
} catch (error: unknown) { | ||
setToastApiError(formatUnknownError(error)); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<FormTemplate | ||
title={`Edit template ${template.name}`} | ||
description='Edit a release plan template that makes it easier for you and your team to release features.' | ||
> | ||
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 assume we'll add other props like 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. Yeah, we have to look at extending this to fit other type of information as well |
||
<StyledForm onSubmit={handleSubmit}> | ||
<TemplateForm | ||
name={name} | ||
setName={setName} | ||
description={description} | ||
setDescription={setDescription} | ||
errors={errors} | ||
clearErrors={clearErrors} | ||
/> | ||
|
||
{template.milestones.map((milestone) => ( | ||
<StyledMilestoneCard> | ||
daveleek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<StyledMilestoneCardBody> | ||
<StyledMilestoneCardTitle> | ||
{milestone.name} | ||
</StyledMilestoneCardTitle> | ||
</StyledMilestoneCardBody> | ||
</StyledMilestoneCard> | ||
))} | ||
<StyledButtonContainer> | ||
<UpdateButton name='template' permission={ADMIN} /> | ||
<StyledCancelButton onClick={handleCancel}> | ||
Cancel | ||
</StyledCancelButton> | ||
</StyledButtonContainer> | ||
</StyledForm> | ||
</FormTemplate> | ||
</> | ||
); | ||
}; |
57 changes: 57 additions & 0 deletions
57
frontend/src/component/releases/ReleasePlanTemplate/TemplateForm.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,57 @@ | ||
import Input from 'component/common/Input/Input'; | ||
import { styled } from '@mui/material'; | ||
|
||
const StyledInputDescription = styled('p')(({ theme }) => ({ | ||
marginBottom: theme.spacing(1), | ||
})); | ||
|
||
const StyledInput = styled(Input)(({ theme }) => ({ | ||
width: '100%', | ||
marginBottom: theme.spacing(2), | ||
})); | ||
|
||
interface ITemplateForm { | ||
name: string; | ||
setName: React.Dispatch<React.SetStateAction<string>>; | ||
description: string; | ||
setDescription: React.Dispatch<React.SetStateAction<string>>; | ||
errors: { [key: string]: string }; | ||
clearErrors: () => void; | ||
} | ||
|
||
export const TemplateForm: React.FC<ITemplateForm> = ({ | ||
name, | ||
setName, | ||
description, | ||
setDescription, | ||
errors, | ||
clearErrors, | ||
}) => { | ||
return ( | ||
<> | ||
<StyledInputDescription> | ||
What would you like to call your template? | ||
</StyledInputDescription> | ||
<StyledInput | ||
label='Template name' | ||
value={name} | ||
onChange={(e) => setName(e.target.value)} | ||
error={Boolean(errors.name)} | ||
errorText={errors.name} | ||
onFocus={() => clearErrors()} | ||
autoFocus | ||
/> | ||
<StyledInputDescription> | ||
What's the purpose of this template? | ||
daveleek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</StyledInputDescription> | ||
<StyledInput | ||
label='Template description (optional)' | ||
value={description} | ||
onChange={(e) => setDescription(e.target.value)} | ||
error={Boolean(errors.description)} | ||
errorText={errors.description} | ||
onFocus={() => clearErrors()} | ||
/> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.
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.
This one confuses me a bit. If we always want to navigate on click, why not wrap the card in a link instead?
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.
The card is already wrapped in a click, but I have to override that for the menu, and thus also specify an onclick for the menu items