1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-06 00:07:44 +01:00
unleash.unleash/frontend/src/component/project/Project/ProjectInfo/ChangeRequestsWidget.tsx

111 lines
3.7 KiB
TypeScript
Raw Normal View History

2023-01-31 11:06:45 +01:00
import { FC } from 'react';
import useLoading from 'hooks/useLoading';
2023-02-03 12:58:21 +01:00
import { Box, styled, Typography } from '@mui/material';
2023-01-31 11:06:45 +01:00
import { IChangeRequest } from 'component/changeRequest/changeRequest.types';
import {
StyledCount,
StyledProjectInfoWidgetContainer,
StyledWidgetTitle,
} from './ProjectInfo.styles';
import { useProjectChangeRequests } from 'hooks/api/getters/useProjectChangeRequests/useProjectChangeRequests';
2023-02-03 12:58:21 +01:00
import { WidgetFooterLink } from './WidgetFooterLink';
2023-01-31 11:06:45 +01:00
interface IChangeRequestsWidgetProps {
projectId: string;
}
2023-02-03 12:58:21 +01:00
const StyledContentBox = styled(Box)(({ theme }) => ({
display: 'flex',
flexWrap: 'wrap',
gap: theme.spacing(1.5),
}));
2023-01-31 11:06:45 +01:00
const StyledChangeBox = styled(Box)(({ theme }) => ({
2023-02-03 12:58:21 +01:00
flex: 1,
2023-01-31 11:06:45 +01:00
textAlign: 'left',
padding: theme.spacing(1.5),
borderRadius: theme.shape.borderRadiusMedium,
alignItems: 'center',
2023-02-03 12:58:21 +01:00
minWidth: 175,
2023-01-31 11:06:45 +01:00
}));
const StyledChangeRequestStatusInfo = styled(Box)(({ theme }) => ({
display: 'flex',
alignItems: 'center',
}));
const StyledApprovedCount = styled(StyledCount)(({ theme }) => ({
background: theme.palette.activityIndicators.recent,
padding: theme.spacing(0, 1),
marginRight: theme.spacing(0.5),
borderRadius: theme.shape.borderRadius,
}));
const StyledInReviewCount = styled(StyledCount)(({ theme }) => ({
background: theme.palette.activityIndicators.primary,
padding: theme.spacing(0, 1),
marginRight: theme.spacing(0.5),
borderRadius: theme.shape.borderRadius,
}));
2023-02-03 12:58:21 +01:00
const StyledSubtitle = styled(Typography)(({ theme }) => ({
fontSize: theme.typography.body2.fontSize,
marginBottom: theme.spacing(0.5),
}));
2023-01-31 11:06:45 +01:00
const ChangeRequestsLabel = () => (
2023-02-03 12:58:21 +01:00
<Typography
component="span"
variant="body2"
color="text.secondary"
lineHeight={1}
>
2023-01-31 11:06:45 +01:00
change requests
</Typography>
);
export const ChangeRequestsWidget: FC<IChangeRequestsWidgetProps> = ({
projectId,
}) => {
const { changeRequests, loading } = useProjectChangeRequests(projectId);
const loadingRef = useLoading(loading);
const toBeApplied = changeRequests?.filter(
(changeRequest: IChangeRequest) => changeRequest?.state === 'Approved'
).length;
const toBeReviewed = changeRequests?.filter(
(changeRequest: IChangeRequest) => changeRequest?.state === 'In review'
).length;
return (
<StyledProjectInfoWidgetContainer ref={loadingRef}>
<StyledWidgetTitle>Open change requests</StyledWidgetTitle>
2023-02-03 12:58:21 +01:00
<StyledContentBox>
<StyledChangeBox
sx={{ background: theme => theme.palette.success.light }}
>
<StyledSubtitle>To be applied</StyledSubtitle>
<StyledChangeRequestStatusInfo>
<StyledApprovedCount>{toBeApplied}</StyledApprovedCount>{' '}
<ChangeRequestsLabel />
</StyledChangeRequestStatusInfo>
</StyledChangeBox>
<StyledChangeBox
sx={{ background: theme => theme.palette.secondary.light }}
2023-01-31 11:06:45 +01:00
>
2023-02-03 12:58:21 +01:00
<StyledSubtitle>To be reviewed</StyledSubtitle>
<StyledChangeRequestStatusInfo>
<StyledInReviewCount>
{toBeReviewed}
</StyledInReviewCount>{' '}
<ChangeRequestsLabel />
</StyledChangeRequestStatusInfo>
</StyledChangeBox>
</StyledContentBox>
<WidgetFooterLink to={`/projects/${projectId}/change-requests`}>
View change requests
</WidgetFooterLink>
2023-01-31 11:06:45 +01:00
</StyledProjectInfoWidgetContainer>
);
};