2022-11-02 07:34:14 +01:00
|
|
|
import { VFC } from 'react';
|
2022-10-26 13:57:59 +02:00
|
|
|
import { Box } from '@mui/material';
|
2022-11-02 07:34:14 +01:00
|
|
|
import { ChangeRequestFeatureToggleChange } from '../ChangeRequestOverview/ChangeRequestFeatureToggleChange/ChangeRequestFeatureToggleChange';
|
2022-10-26 13:57:59 +02:00
|
|
|
import { objectId } from 'utils/objectId';
|
|
|
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
2022-11-02 07:34:14 +01:00
|
|
|
import { ToggleStatusChange } from '../ChangeRequestOverview/ChangeRequestFeatureToggleChange/ToggleStatusChange';
|
|
|
|
import type { IChangeRequestResponse } from 'hooks/api/getters/useChangeRequestDraft/useChangeRequestDraft';
|
|
|
|
import { useChangeRequestApi } from 'hooks/api/actions/useChangeRequestApi/useChangeRequestApi';
|
2022-10-31 13:46:54 +01:00
|
|
|
import { formatUnknownError } from 'utils/formatUnknownError';
|
|
|
|
import useToast from 'hooks/useToast';
|
2022-10-26 13:57:59 +02:00
|
|
|
|
2022-11-02 07:34:14 +01:00
|
|
|
interface IChangeRequest {
|
|
|
|
changeRequest: IChangeRequestResponse;
|
2022-10-31 13:46:54 +01:00
|
|
|
onRefetch?: () => void;
|
|
|
|
onNavigate?: () => void;
|
|
|
|
}
|
|
|
|
|
2022-11-02 07:34:14 +01:00
|
|
|
export const ChangeRequest: VFC<IChangeRequest> = ({
|
|
|
|
changeRequest,
|
2022-10-31 13:46:54 +01:00
|
|
|
onRefetch,
|
|
|
|
onNavigate,
|
|
|
|
}) => {
|
2022-11-02 07:34:14 +01:00
|
|
|
const { discardChangeRequestEvent } = useChangeRequestApi();
|
2022-10-31 13:46:54 +01:00
|
|
|
const { setToastData, setToastApiError } = useToast();
|
|
|
|
const onDiscard = (id: number) => async () => {
|
|
|
|
try {
|
2022-11-02 07:34:14 +01:00
|
|
|
await discardChangeRequestEvent(
|
|
|
|
changeRequest.project,
|
|
|
|
changeRequest.id,
|
2022-10-31 13:46:54 +01:00
|
|
|
id
|
|
|
|
);
|
|
|
|
setToastData({
|
2022-11-02 07:34:14 +01:00
|
|
|
title: 'Change discarded from change request draft.',
|
2022-10-31 13:46:54 +01:00
|
|
|
type: 'success',
|
|
|
|
});
|
|
|
|
onRefetch?.();
|
|
|
|
} catch (error: unknown) {
|
|
|
|
setToastApiError(formatUnknownError(error));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-10-26 13:57:59 +02:00
|
|
|
return (
|
|
|
|
<Box>
|
|
|
|
Changes
|
2022-11-02 07:34:14 +01:00
|
|
|
{changeRequest.features?.map(featureToggleChange => (
|
|
|
|
<ChangeRequestFeatureToggleChange
|
2022-10-28 09:43:49 +02:00
|
|
|
key={featureToggleChange.name}
|
2022-10-31 13:46:54 +01:00
|
|
|
featureName={featureToggleChange.name}
|
2022-11-02 07:34:14 +01:00
|
|
|
projectId={changeRequest.project}
|
2022-10-31 13:46:54 +01:00
|
|
|
onNavigate={onNavigate}
|
2022-10-26 13:57:59 +02:00
|
|
|
>
|
2022-10-28 09:43:49 +02:00
|
|
|
{featureToggleChange.changes.map(change => (
|
2022-10-26 13:57:59 +02:00
|
|
|
<Box key={objectId(change)}>
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={change.action === 'updateEnabled'}
|
|
|
|
show={
|
|
|
|
<ToggleStatusChange
|
2022-10-28 09:43:49 +02:00
|
|
|
enabled={change?.payload?.enabled}
|
2022-10-31 13:46:54 +01:00
|
|
|
onDiscard={onDiscard(change.id)}
|
2022-10-26 13:57:59 +02:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
2022-10-28 09:43:49 +02:00
|
|
|
{/* <ConditionallyRender
|
2022-10-26 13:57:59 +02:00
|
|
|
condition={change.action === 'addStrategy'}
|
|
|
|
show={
|
|
|
|
<StrategyAddedChange>
|
|
|
|
<GetFeatureStrategyIcon
|
|
|
|
strategyName={change.payload.name}
|
|
|
|
/>
|
|
|
|
{formatStrategyName(
|
|
|
|
change.payload.name
|
|
|
|
)}
|
|
|
|
</StrategyAddedChange>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={change.action === 'deleteStrategy'}
|
|
|
|
show={<StrategyDeletedChange />}
|
|
|
|
/>
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={change.action === 'updateStrategy'}
|
|
|
|
show={<StrategyEditedChange />}
|
2022-10-28 09:43:49 +02:00
|
|
|
/> */}
|
2022-10-26 13:57:59 +02:00
|
|
|
</Box>
|
|
|
|
))}
|
2022-11-02 07:34:14 +01:00
|
|
|
</ChangeRequestFeatureToggleChange>
|
2022-10-26 13:57:59 +02:00
|
|
|
))}
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
};
|