From ce900830cb04e157a35f219e5e7373d81c3a759c Mon Sep 17 00:00:00 2001 From: Tymoteusz Czech <2625371+Tymek@users.noreply.github.com> Date: Tue, 4 Jul 2023 09:09:05 +0200 Subject: [PATCH] Fix: change request info (#3971) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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) --- .../EnvironmentChangeRequest.tsx | 2 +- .../MainLayout/DraftBanner/DraftBanner.tsx | 97 +++++++++++-------- 2 files changed, 60 insertions(+), 39 deletions(-) diff --git a/frontend/src/component/changeRequest/ChangeRequestSidebar/EnvironmentChangeRequest/EnvironmentChangeRequest.tsx b/frontend/src/component/changeRequest/ChangeRequestSidebar/EnvironmentChangeRequest/EnvironmentChangeRequest.tsx index f664c2825a..c13d3e50b5 100644 --- a/frontend/src/component/changeRequest/ChangeRequestSidebar/EnvironmentChangeRequest/EnvironmentChangeRequest.tsx +++ b/frontend/src/component/changeRequest/ChangeRequestSidebar/EnvironmentChangeRequest/EnvironmentChangeRequest.tsx @@ -46,7 +46,7 @@ const ChangeRequestHeader = styled(Box)(({ theme }) => ({ const ChangeRequestContent = styled(Box)(({ theme }) => ({ padding: theme.spacing(3, 3, 3, 3), border: '2px solid', - mb: 5, + marginBottom: theme.spacing(5), borderColor: theme.palette.divider, borderRadius: `0 0 ${theme.shape.borderRadiusLarge}px ${theme.shape.borderRadiusLarge}px`, borderTop: 'none', diff --git a/frontend/src/component/layout/MainLayout/DraftBanner/DraftBanner.tsx b/frontend/src/component/layout/MainLayout/DraftBanner/DraftBanner.tsx index dbefa5f066..68d1c03071 100644 --- a/frontend/src/component/layout/MainLayout/DraftBanner/DraftBanner.tsx +++ b/frontend/src/component/layout/MainLayout/DraftBanner/DraftBanner.tsx @@ -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 { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; import { ChangeRequestSidebar } from 'component/changeRequest/ChangeRequestSidebar/ChangeRequestSidebar'; @@ -37,43 +37,61 @@ const StyledBox = styled(Box)(({ theme }) => ({ })); const DraftBannerContent: FC<{ - changeRequest: IChangeRequest; + changeRequests: IChangeRequest[]; 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 ( Change request mode – You have changes{' '} - in {changeRequest.environment} + in{' '} + {environments.map((env, i) => + i === 0 ? ( + + {env} + + ) : ( + + {i === environments.length - 1 + ? ' and ' + : ', '} + {env} + + ) + )} } /> - - - + {explanation}. @@ -94,30 +112,33 @@ export const DraftBanner: VFC = ({ project }) => { const [isSidebarOpen, setIsSidebarOpen] = useState(false); 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) { return null; } return ( - {data?.length - ? data - .filter(changeRequest => - ['Draft', 'In review', 'Approved'].includes( - changeRequest.state - ) - ) - .map(changeRequest => ( - { - setIsSidebarOpen(true); - }} - /> - )) - : null} - + { + setIsSidebarOpen(true); + }} + /> + } + />