Skip to content

Commit e689e2e

Browse files
authored
feat: implement dialogs for changerequest milestone handling and removing release plans (#9240)
1 parent 61f8236 commit e689e2e

File tree

6 files changed

+278
-48
lines changed

6 files changed

+278
-48
lines changed

frontend/src/component/feature/FeatureStrategy/FeatureStrategyMenu/FeatureStrategyMenu.tsx

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import { formatCreateStrategyPath } from '../FeatureStrategyCreate/FeatureStrate
1111
import MoreVert from '@mui/icons-material/MoreVert';
1212
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
1313
import { useUiFlag } from 'hooks/useUiFlag';
14-
import { ReleasePlanAddChangeRequestDialog } from 'component/feature/FeatureView/FeatureOverview/ReleasePlan/ReleasePlanAddChangeRequestDialog';
14+
import { ReleasePlanAddChangeRequestDialog } from 'component/feature/FeatureView/FeatureOverview/ReleasePlan/ChangeRequest/ReleasePlanAddChangeRequestDialog';
1515
import type { IReleasePlanTemplate } from 'interfaces/releasePlans';
16+
import { useChangeRequestApi } from 'hooks/api/actions/useChangeRequestApi/useChangeRequestApi';
17+
import { usePendingChangeRequests } from 'hooks/api/getters/usePendingChangeRequests/usePendingChangeRequests';
18+
import useToast from 'hooks/useToast';
1619

1720
interface IFeatureStrategyMenuProps {
1821
label: string;
@@ -57,6 +60,10 @@ export const FeatureStrategyMenu = ({
5760
const isPopoverOpen = Boolean(anchor);
5861
const popoverId = isPopoverOpen ? 'FeatureStrategyMenuPopover' : undefined;
5962
const flagOverviewRedesignEnabled = useUiFlag('flagOverviewRedesign');
63+
const { setToastData } = useToast();
64+
const { addChange } = useChangeRequestApi();
65+
const { refetch: refetchChangeRequests } =
66+
usePendingChangeRequests(projectId);
6067

6168
const onClose = () => {
6269
setAnchor(undefined);
@@ -75,6 +82,25 @@ export const FeatureStrategyMenu = ({
7582
setAnchor(event.currentTarget);
7683
};
7784

85+
const addReleasePlanToChangeRequest = async () => {
86+
addChange(projectId, environmentId, {
87+
feature: featureId,
88+
action: 'addReleasePlan',
89+
payload: {
90+
templateId: templateForChangeRequestDialog?.id,
91+
},
92+
});
93+
94+
refetchChangeRequests();
95+
96+
setToastData({
97+
type: 'success',
98+
text: 'Added to draft',
99+
});
100+
101+
setTemplateForChangeRequestDialog(undefined);
102+
};
103+
78104
const createStrategyPath = formatCreateStrategyPath(
79105
projectId,
80106
featureId,
@@ -188,8 +214,9 @@ export const FeatureStrategyMenu = ({
188214
/>
189215
</Popover>
190216
<ReleasePlanAddChangeRequestDialog
191-
projectId={projectId}
217+
onConfirm={addReleasePlanToChangeRequest}
192218
onClosing={() => setTemplateForChangeRequestDialog(undefined)}
219+
isOpen={Boolean(templateForChangeRequestDialog)}
193220
featureId={featureId}
194221
environmentId={environmentId}
195222
releaseTemplate={templateForChangeRequestDialog}
Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,39 @@
11
import { Dialogue } from 'component/common/Dialogue/Dialogue';
2-
import useToast from 'hooks/useToast';
32
import { styled, Button } from '@mui/material';
43
import type { IReleasePlanTemplate } from 'interfaces/releasePlans';
5-
import { useChangeRequestApi } from 'hooks/api/actions/useChangeRequestApi/useChangeRequestApi';
64

75
const StyledBoldSpan = styled('span')(({ theme }) => ({
86
fontWeight: theme.typography.fontWeightBold,
97
}));
108

119
interface IReleasePlanAddChangeRequestDialogProps {
12-
projectId: string;
1310
featureId: string;
1411
environmentId: string;
15-
releaseTemplate: IReleasePlanTemplate | undefined;
12+
releaseTemplate?: IReleasePlanTemplate;
13+
isOpen: boolean;
14+
onConfirm: () => Promise<void>;
1615
onClosing: () => void;
1716
}
1817

1918
export const ReleasePlanAddChangeRequestDialog = ({
20-
projectId,
2119
featureId,
2220
environmentId,
2321
releaseTemplate,
22+
isOpen,
23+
onConfirm,
2424
onClosing,
2525
}: IReleasePlanAddChangeRequestDialogProps) => {
26-
const { setToastData } = useToast();
27-
const { addChange } = useChangeRequestApi();
28-
29-
const addReleasePlanToChangeRequest = async () => {
30-
addChange(projectId, environmentId, {
31-
feature: featureId,
32-
action: 'addReleasePlan',
33-
payload: {
34-
templateId: releaseTemplate?.id,
35-
},
36-
});
37-
38-
setToastData({
39-
type: 'success',
40-
text: 'Added to draft',
41-
});
42-
onClosing();
43-
};
44-
4526
return (
4627
<Dialogue
4728
title='Request changes'
48-
open={Boolean(releaseTemplate)}
29+
open={isOpen}
4930
secondaryButtonText='Cancel'
50-
onClose={() => {
51-
onClosing();
52-
}}
31+
onClose={onClosing}
5332
customButton={
5433
<Button
5534
color='primary'
5635
variant='contained'
57-
onClick={addReleasePlanToChangeRequest}
36+
onClick={onConfirm}
5837
autoFocus={true}
5938
>
6039
Add suggestion to draft
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { Dialogue } from 'component/common/Dialogue/Dialogue';
2+
import { styled, Button, Alert } from '@mui/material';
3+
import type { IReleasePlan } from 'interfaces/releasePlans';
4+
5+
const StyledBoldSpan = styled('span')(({ theme }) => ({
6+
fontWeight: theme.typography.fontWeightBold,
7+
}));
8+
9+
interface IRemoveReleasePlanChangeRequestDialogProps {
10+
featureId: string;
11+
environmentId: string;
12+
releasePlan?: IReleasePlan | undefined;
13+
environmentActive: boolean;
14+
isOpen: boolean;
15+
onConfirm: () => Promise<void>;
16+
onClosing: () => void;
17+
}
18+
19+
export const RemoveReleasePlanChangeRequestDialog = ({
20+
featureId,
21+
environmentId,
22+
releasePlan,
23+
environmentActive,
24+
isOpen,
25+
onConfirm,
26+
onClosing,
27+
}: IRemoveReleasePlanChangeRequestDialogProps) => {
28+
return (
29+
<Dialogue
30+
title='Request changes'
31+
open={isOpen}
32+
secondaryButtonText='Cancel'
33+
onClose={onClosing}
34+
customButton={
35+
<Button
36+
color='primary'
37+
variant='contained'
38+
onClick={onConfirm}
39+
autoFocus={true}
40+
>
41+
Add suggestion to draft
42+
</Button>
43+
}
44+
>
45+
<>
46+
{environmentActive && (
47+
<Alert severity='error' sx={{ mb: 2 }}>
48+
This release plan currently has one active milestone.
49+
Removing the release plan will change which users
50+
receive access to the feature.
51+
</Alert>
52+
)}
53+
<p>
54+
<StyledBoldSpan>Remove</StyledBoldSpan> release plan{' '}
55+
<StyledBoldSpan>{releasePlan?.name}</StyledBoldSpan> from{' '}
56+
<StyledBoldSpan>{featureId}</StyledBoldSpan> in{' '}
57+
<StyledBoldSpan>{environmentId}</StyledBoldSpan>
58+
</p>
59+
</>
60+
</Dialogue>
61+
);
62+
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { Dialogue } from 'component/common/Dialogue/Dialogue';
2+
import { styled, Button } from '@mui/material';
3+
import type {
4+
IReleasePlan,
5+
IReleasePlanMilestone,
6+
} from 'interfaces/releasePlans';
7+
8+
const StyledBoldSpan = styled('span')(({ theme }) => ({
9+
fontWeight: theme.typography.fontWeightBold,
10+
}));
11+
12+
interface IStartMilestoneChangeRequestDialogProps {
13+
featureId: string;
14+
environmentId: string;
15+
releasePlan?: IReleasePlan | undefined;
16+
milestone?: IReleasePlanMilestone | undefined;
17+
isOpen: boolean;
18+
onConfirm: () => Promise<void>;
19+
onClosing: () => void;
20+
}
21+
22+
export const StartMilestoneChangeRequestDialog = ({
23+
featureId,
24+
environmentId,
25+
releasePlan,
26+
milestone,
27+
isOpen,
28+
onConfirm,
29+
onClosing,
30+
}: IStartMilestoneChangeRequestDialogProps) => {
31+
return (
32+
<Dialogue
33+
title='Request changes'
34+
open={isOpen}
35+
secondaryButtonText='Cancel'
36+
onClose={onClosing}
37+
customButton={
38+
<Button
39+
color='primary'
40+
variant='contained'
41+
onClick={onConfirm}
42+
autoFocus={true}
43+
>
44+
Add suggestion to draft
45+
</Button>
46+
}
47+
>
48+
<p>
49+
<StyledBoldSpan>Start</StyledBoldSpan> milestone{' '}
50+
<StyledBoldSpan>{milestone?.name}</StyledBoldSpan> in release
51+
plan <StyledBoldSpan>{releasePlan?.name}</StyledBoldSpan> for{' '}
52+
<StyledBoldSpan>{featureId}</StyledBoldSpan> in{' '}
53+
<StyledBoldSpan>{environmentId}</StyledBoldSpan>
54+
</p>
55+
</Dialogue>
56+
);
57+
};

0 commit comments

Comments
 (0)