mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-09 00:18:00 +01:00
Merge branch 'main' of https://github.com/Unleash/unleash
This commit is contained in:
commit
6ba30a0e31
@ -21,6 +21,8 @@ import { useChangeRequestApi } from 'hooks/api/actions/useChangeRequestApi/useCh
|
|||||||
import { ChangeRequestStatusBadge } from '../ChangeRequestStatusBadge/ChangeRequestStatusBadge';
|
import { ChangeRequestStatusBadge } from '../ChangeRequestStatusBadge/ChangeRequestStatusBadge';
|
||||||
import CloseIcon from '@mui/icons-material/Close';
|
import CloseIcon from '@mui/icons-material/Close';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
import useToast from 'hooks/useToast';
|
||||||
|
import { formatUnknownError } from 'utils/formatUnknownError';
|
||||||
|
|
||||||
interface IChangeRequestSidebarProps {
|
interface IChangeRequestSidebarProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
@ -123,26 +125,26 @@ export const ChangeRequestSidebar: VFC<IChangeRequestSidebarProps> = ({
|
|||||||
loading,
|
loading,
|
||||||
refetch: refetchChangeRequest,
|
refetch: refetchChangeRequest,
|
||||||
} = useChangeRequestOpen(project);
|
} = useChangeRequestOpen(project);
|
||||||
const { changeState } = useChangeRequestApi();
|
const { changeState, discardDraft } = useChangeRequestApi();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const { setToastApiError } = useToast();
|
||||||
|
|
||||||
const onReview = async (draftId: number) => {
|
const onReview = async (draftId: number) => {
|
||||||
try {
|
try {
|
||||||
await changeState(project, draftId, { state: 'In review' });
|
await changeState(project, draftId, { state: 'In review' });
|
||||||
refetchChangeRequest();
|
refetchChangeRequest();
|
||||||
} catch (e) {
|
} catch (error: unknown) {
|
||||||
console.log('something went wrong');
|
setToastApiError(formatUnknownError(error));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const onDiscard = async () => {
|
|
||||||
alert('discard');
|
const onDiscard = async (draftId: number) => {
|
||||||
};
|
|
||||||
const onApply = async () => {
|
|
||||||
try {
|
try {
|
||||||
alert('apply');
|
await discardDraft(project, draftId);
|
||||||
} catch (e) {
|
refetchChangeRequest();
|
||||||
console.log(e);
|
} catch (error: unknown) {
|
||||||
|
setToastApiError(formatUnknownError(error));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -257,36 +259,6 @@ export const ChangeRequestSidebar: VFC<IChangeRequestSidebarProps> = ({
|
|||||||
onRefetch={refetchChangeRequest}
|
onRefetch={refetchChangeRequest}
|
||||||
/>
|
/>
|
||||||
<Box sx={{ display: 'flex' }}>
|
<Box sx={{ display: 'flex' }}>
|
||||||
<ConditionallyRender
|
|
||||||
condition={
|
|
||||||
environmentChangeRequest.state ===
|
|
||||||
'Approved'
|
|
||||||
}
|
|
||||||
show={<Typography>Applied</Typography>}
|
|
||||||
/>
|
|
||||||
<ConditionallyRender
|
|
||||||
condition={
|
|
||||||
environmentChangeRequest.state === 'Applied'
|
|
||||||
}
|
|
||||||
show={<Typography>Applied</Typography>}
|
|
||||||
/>
|
|
||||||
<ConditionallyRender
|
|
||||||
condition={
|
|
||||||
environmentChangeRequest.state ===
|
|
||||||
'Approved'
|
|
||||||
}
|
|
||||||
show={
|
|
||||||
<>
|
|
||||||
<Button
|
|
||||||
sx={{ mt: 2 }}
|
|
||||||
variant="contained"
|
|
||||||
onClick={onApply}
|
|
||||||
>
|
|
||||||
Apply changes
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<ConditionallyRender
|
<ConditionallyRender
|
||||||
condition={
|
condition={
|
||||||
environmentChangeRequest?.state === 'Draft'
|
environmentChangeRequest?.state === 'Draft'
|
||||||
@ -308,7 +280,11 @@ export const ChangeRequestSidebar: VFC<IChangeRequestSidebarProps> = ({
|
|||||||
<Button
|
<Button
|
||||||
sx={{ mt: 2, ml: 2 }}
|
sx={{ mt: 2, ml: 2 }}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onClick={onDiscard}
|
onClick={() =>
|
||||||
|
onDiscard(
|
||||||
|
environmentChangeRequest.id
|
||||||
|
)
|
||||||
|
}
|
||||||
>
|
>
|
||||||
Discard changes
|
Discard changes
|
||||||
</Button>
|
</Button>
|
||||||
@ -318,7 +294,9 @@ export const ChangeRequestSidebar: VFC<IChangeRequestSidebarProps> = ({
|
|||||||
<ConditionallyRender
|
<ConditionallyRender
|
||||||
condition={
|
condition={
|
||||||
environmentChangeRequest.state ===
|
environmentChangeRequest.state ===
|
||||||
'In review'
|
'In review' ||
|
||||||
|
environmentChangeRequest.state ===
|
||||||
|
'Approved'
|
||||||
}
|
}
|
||||||
show={
|
show={
|
||||||
<>
|
<>
|
||||||
|
@ -28,7 +28,7 @@ const DraftBannerContent: FC<{
|
|||||||
<Box className={classes.content}>
|
<Box className={classes.content}>
|
||||||
<DraftBannerContentWrapper>
|
<DraftBannerContentWrapper>
|
||||||
<WarningAmberIcon />
|
<WarningAmberIcon />
|
||||||
<Typography variant="body2" sx={{ ml: 1 }}>
|
<Typography variant="body2" sx={{ ml: 1, maxWidth: '500px' }}>
|
||||||
<strong>Draft mode!</strong> – You have changes{' '}
|
<strong>Draft mode!</strong> – You have changes{' '}
|
||||||
<ConditionallyRender
|
<ConditionallyRender
|
||||||
condition={Boolean(changeRequest.environment)}
|
condition={Boolean(changeRequest.environment)}
|
||||||
@ -46,6 +46,12 @@ const DraftBannerContent: FC<{
|
|||||||
condition={changeRequest.state === 'In review'}
|
condition={changeRequest.state === 'In review'}
|
||||||
show={'that are in review'}
|
show={'that are in review'}
|
||||||
/>
|
/>
|
||||||
|
<ConditionallyRender
|
||||||
|
condition={changeRequest.state === 'Approved'}
|
||||||
|
show={
|
||||||
|
'that are approved. Adding more changes will clear the approvals and require a new review'
|
||||||
|
}
|
||||||
|
/>
|
||||||
</Typography>
|
</Typography>
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
@ -54,9 +60,6 @@ const DraftBannerContent: FC<{
|
|||||||
>
|
>
|
||||||
View changes ({changeRequest.features.length})
|
View changes ({changeRequest.features.length})
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="text" onClick={() => {}} sx={{ ml: 1 }}>
|
|
||||||
Discard all
|
|
||||||
</Button>
|
|
||||||
</DraftBannerContentWrapper>
|
</DraftBannerContentWrapper>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
@ -84,7 +87,9 @@ export const DraftBanner: VFC<IDraftBannerProps> = ({ project }) => {
|
|||||||
{draft &&
|
{draft &&
|
||||||
draft
|
draft
|
||||||
.filter(changeRequest =>
|
.filter(changeRequest =>
|
||||||
['Draft', 'In review'].includes(changeRequest.state)
|
['Draft', 'In review', 'Approved'].includes(
|
||||||
|
changeRequest.state
|
||||||
|
)
|
||||||
)
|
)
|
||||||
.map(changeRequest => (
|
.map(changeRequest => (
|
||||||
<DraftBannerContent
|
<DraftBannerContent
|
||||||
|
@ -77,6 +77,20 @@ export const useChangeRequestApi = () => {
|
|||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: JSON.stringify({ changeRequestsEnabled: enabled }),
|
body: JSON.stringify({ changeRequestsEnabled: enabled }),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await makeRequest(req.caller, req.id);
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const discardDraft = async (projectId: string, draftId: number) => {
|
||||||
|
const path = `api/admin/projects/${projectId}/change-requests/${draftId}`;
|
||||||
|
const req = createRequest(path, {
|
||||||
|
method: 'DELETE',
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await makeRequest(req.caller, req.id);
|
return await makeRequest(req.caller, req.id);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -89,6 +103,7 @@ export const useChangeRequestApi = () => {
|
|||||||
changeState,
|
changeState,
|
||||||
discardChangeRequestEvent,
|
discardChangeRequestEvent,
|
||||||
updateChangeRequestEnvironmentConfig,
|
updateChangeRequestEnvironmentConfig,
|
||||||
|
discardDraft,
|
||||||
errors,
|
errors,
|
||||||
loading,
|
loading,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user