Skip to content

Commit 1e85eec

Browse files
committed
NCL-9058 Add skip Brew Push option to Close Milestone modal
1 parent 270d753 commit 1e85eec

File tree

3 files changed

+62
-7
lines changed

3 files changed

+62
-7
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { MilestoneCloseRequest } from 'pnc-api-types-ts';
2+
3+
import { TEntityAttributes } from 'common/entityAttributes';
4+
5+
export const productMilestoneCloseRequestEntityAttributes = {
6+
skipBrewPush: {
7+
id: 'skipBrewPush',
8+
title: 'Skip Brew push',
9+
tooltip: 'Brew push of the Builds in the Milestone will be skipped and the Milestone will be closed immediately.',
10+
},
11+
} as const satisfies TEntityAttributes<MilestoneCloseRequest>;
Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1+
import { Form, FormGroup, Switch } from '@patternfly/react-core';
2+
13
import { ProductMilestone } from 'pnc-api-types-ts';
24

5+
import { productMilestoneCloseRequestEntityAttributes } from 'common/productMilestoneCloseRequestEntityAttributes';
6+
7+
import { IFieldConfigs, IFieldValues, useForm } from 'hooks/useForm';
38
import { useServiceContainer } from 'hooks/useServiceContainer';
49

510
import { ActionModal } from 'components/ActionModal/ActionModal';
11+
import { FormInput } from 'components/FormInput/FormInput';
12+
import { TooltipWrapper } from 'components/TooltipWrapper/TooltipWrapper';
613

714
import * as productMilestoneApi from 'services/productMilestoneApi';
815

16+
const fieldConfigs = {
17+
skipBrewPush: {
18+
value: false,
19+
},
20+
} satisfies IFieldConfigs;
21+
922
export interface IProductMilestoneCloseModalProps {
1023
isModalOpen: boolean;
1124
toggleModal: () => void;
@@ -15,9 +28,11 @@ export interface IProductMilestoneCloseModalProps {
1528
export const ProductMilestoneCloseModal = ({ isModalOpen, toggleModal, productMilestone }: IProductMilestoneCloseModalProps) => {
1629
const serviceContainerProductMilestoneClose = useServiceContainer(productMilestoneApi.closeProductMilestone, 0);
1730

18-
const confirmModal = () => {
31+
const { register, handleSubmit, isSubmitDisabled, hasFormChanged } = useForm();
32+
33+
const confirmModal = (data: IFieldValues) => {
1934
return serviceContainerProductMilestoneClose.run({
20-
serviceData: { id: productMilestone.id },
35+
serviceData: { id: productMilestone.id, data: { skipBrewPush: data.skipBrewPush } },
2136
onError: () => console.error('Failed to close Product Milestone.'),
2237
});
2338
};
@@ -28,11 +43,37 @@ export const ProductMilestoneCloseModal = ({ isModalOpen, toggleModal, productMi
2843
actionTitle="Close Milestone"
2944
isOpen={isModalOpen}
3045
onToggle={toggleModal}
31-
onSubmit={confirmModal}
46+
isSubmitDisabled={isSubmitDisabled}
47+
wereSubmitDataChanged={hasFormChanged}
48+
onSubmit={handleSubmit(confirmModal)}
3249
serviceContainer={serviceContainerProductMilestoneClose}
33-
modalVariant="medium"
50+
modalVariant="large"
3451
>
35-
Product Milestone <b>{productMilestone.version}</b> will be closed.
52+
<Form
53+
onSubmit={(e) => {
54+
e.preventDefault();
55+
}}
56+
>
57+
<FormGroup
58+
label={productMilestoneCloseRequestEntityAttributes.skipBrewPush.title}
59+
fieldId={productMilestoneCloseRequestEntityAttributes.skipBrewPush.id}
60+
labelIcon={<TooltipWrapper tooltip={productMilestoneCloseRequestEntityAttributes.skipBrewPush.tooltip} />}
61+
>
62+
<FormInput<boolean>
63+
{...register<boolean>(productMilestoneCloseRequestEntityAttributes.skipBrewPush.id, fieldConfigs.skipBrewPush)}
64+
render={({ value, ...rest }) => (
65+
<Switch
66+
id={productMilestoneCloseRequestEntityAttributes.skipBrewPush.id}
67+
name={productMilestoneCloseRequestEntityAttributes.skipBrewPush.id}
68+
label="Enabled"
69+
labelOff="Disabled"
70+
isChecked={value}
71+
{...rest}
72+
/>
73+
)}
74+
/>
75+
</FormGroup>
76+
</Form>
3677
</ActionModal>
3778
);
3879
};

src/services/productMilestoneApi.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,11 @@ export const getProductMilestoneComparison = (
223223
* - id - Product Milestone ID
224224
* @param requestConfig - Axios based request config
225225
*/
226-
export const closeProductMilestone = ({ id }: IProductMilestoneApiData, requestConfig: AxiosRequestConfig = {}) => {
227-
return pncClient.getHttpClient().post<undefined>(`/product-milestones/${id}/close`, undefined, requestConfig);
226+
export const closeProductMilestone = (
227+
{ id, data }: { id: string; data: { skipBrewPush: boolean } },
228+
requestConfig: AxiosRequestConfig = {}
229+
) => {
230+
return pncClient.getHttpClient().post<undefined>(`/product-milestones/${id}/close`, data, requestConfig);
228231
};
229232

230233
/**

0 commit comments

Comments
 (0)