1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

Fix: change request info (#3971)

<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->

## About the changes
- fixed spacing in sidebar
- consolidated info into one banner

closes
[#1-969/change-requests-ui-inconsistency](https://linear.app/unleash/issue/1-969/change-requests-ui-inconsistency)
This commit is contained in:
Tymoteusz Czech 2023-07-04 09:09:05 +02:00 committed by GitHub
parent b50b06c257
commit ce900830cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 39 deletions

View File

@ -46,7 +46,7 @@ const ChangeRequestHeader = styled(Box)(({ theme }) => ({
const ChangeRequestContent = styled(Box)(({ theme }) => ({ const ChangeRequestContent = styled(Box)(({ theme }) => ({
padding: theme.spacing(3, 3, 3, 3), padding: theme.spacing(3, 3, 3, 3),
border: '2px solid', border: '2px solid',
mb: 5, marginBottom: theme.spacing(5),
borderColor: theme.palette.divider, borderColor: theme.palette.divider,
borderRadius: `0 0 ${theme.shape.borderRadiusLarge}px ${theme.shape.borderRadiusLarge}px`, borderRadius: `0 0 ${theme.shape.borderRadiusLarge}px ${theme.shape.borderRadiusLarge}px`,
borderTop: 'none', borderTop: 'none',

View File

@ -1,4 +1,4 @@
import { FC, useState, VFC } from 'react'; import { FC, Fragment, useMemo, useState, VFC } from 'react';
import { Box, Button, styled, Typography } from '@mui/material'; import { Box, Button, styled, Typography } from '@mui/material';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { ChangeRequestSidebar } from 'component/changeRequest/ChangeRequestSidebar/ChangeRequestSidebar'; import { ChangeRequestSidebar } from 'component/changeRequest/ChangeRequestSidebar/ChangeRequestSidebar';
@ -37,43 +37,61 @@ const StyledBox = styled(Box)(({ theme }) => ({
})); }));
const DraftBannerContent: FC<{ const DraftBannerContent: FC<{
changeRequest: IChangeRequest; changeRequests: IChangeRequest[];
onClick: () => void; onClick: () => void;
}> = ({ changeRequest, onClick }) => { }> = ({ changeRequests, onClick }) => {
const environments = changeRequests.map(({ environment }) => environment);
const allChangesCount = changeRequests.reduce(
(acc, curr) => acc + changesCount(curr),
0
);
const showOneLongExplanation =
changeRequests.length === 1 &&
['Draft', 'In review', 'Approved'].includes(changeRequests[0].state);
const explanation = showOneLongExplanation
? {
Draft: ' that need to be reviewed',
'In review': ' that are in review',
Approved:
' that are approved. Adding more changes will clear the approvals and require a new review',
}[changeRequests[0].state as 'Draft' | 'In review' | 'Approved']
: '';
return ( return (
<StyledBox> <StyledBox>
<DraftBannerContentWrapper> <DraftBannerContentWrapper>
<Typography variant="body2" sx={{ mr: 4 }}> <Typography variant="body2" sx={{ mr: 4 }}>
<strong>Change request mode</strong> You have changes{' '} <strong>Change request mode</strong> You have changes{' '}
<ConditionallyRender <ConditionallyRender
condition={Boolean(changeRequest.environment)} condition={Boolean(environments)}
show={ show={
<> <>
in <strong>{changeRequest.environment} </strong> in{' '}
{environments.map((env, i) =>
i === 0 ? (
<Fragment key={env}>
<strong>{env}</strong>
</Fragment>
) : (
<Fragment key={env}>
{i === environments.length - 1
? ' and '
: ', '}
<strong>{env}</strong>
</Fragment>
)
)}
</> </>
} }
/> />
<ConditionallyRender {explanation}.
condition={changeRequest.state === 'Draft'}
show={'that need to be reviewed'}
/>
<ConditionallyRender
condition={changeRequest.state === '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"
onClick={onClick} onClick={onClick}
sx={{ ml: 'auto' }} sx={{ ml: 'auto' }}
> >
View changes ({changesCount(changeRequest)}) View changes ({allChangesCount})
</Button> </Button>
</DraftBannerContentWrapper> </DraftBannerContentWrapper>
</StyledBox> </StyledBox>
@ -94,30 +112,33 @@ export const DraftBanner: VFC<IDraftBannerProps> = ({ project }) => {
const [isSidebarOpen, setIsSidebarOpen] = useState(false); const [isSidebarOpen, setIsSidebarOpen] = useState(false);
const { data, loading } = usePendingChangeRequests(project); const { data, loading } = usePendingChangeRequests(project);
const unfinishedChangeRequests = useMemo(
() =>
data?.filter(changeRequest =>
['Draft', 'In review', 'Approved'].includes(changeRequest.state)
),
[data]
);
if ((!loading && !data) || data?.length === 0) { if ((!loading && !data) || data?.length === 0) {
return null; return null;
} }
return ( return (
<StickyBanner> <StickyBanner>
{data?.length <ConditionallyRender
? data condition={Boolean(unfinishedChangeRequests?.length)}
.filter(changeRequest => show={
['Draft', 'In review', 'Approved'].includes( <DraftBannerContent
changeRequest.state changeRequests={
) unfinishedChangeRequests as IChangeRequest[]
) }
.map(changeRequest => ( onClick={() => {
<DraftBannerContent setIsSidebarOpen(true);
key={changeRequest.id} }}
changeRequest={changeRequest} />
onClick={() => { }
setIsSidebarOpen(true); />
}}
/>
))
: null}
<ChangeRequestSidebar <ChangeRequestSidebar
project={project} project={project}
open={isSidebarOpen} open={isSidebarOpen}