-
-
Notifications
You must be signed in to change notification settings - Fork 713
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New card view for list of projects. Co-authored-by: Thomas Heartman <thomas@getunleash.io>
- Loading branch information
1 parent
0572d37
commit fd4bcff
Showing
8 changed files
with
370 additions
and
3 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
frontend/src/component/project/NewProjectCard/NewProjectCard.styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { styled } from '@mui/material'; | ||
import { Card, Box } from '@mui/material'; | ||
import Delete from '@mui/icons-material/Delete'; | ||
import Edit from '@mui/icons-material/Edit'; | ||
import { flexRow } from 'themes/themeStyles'; | ||
|
||
export const StyledProjectCard = styled(Card)(({ theme }) => ({ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
justifyContent: 'space-between', | ||
height: '100%', | ||
boxShadow: 'none', | ||
border: `1px solid ${theme.palette.divider}`, | ||
[theme.breakpoints.down('sm')]: { | ||
justifyContent: 'center', | ||
}, | ||
'&:hover': { | ||
transition: 'background-color 0.2s ease-in-out', | ||
backgroundColor: theme.palette.neutral.light, | ||
}, | ||
borderRadius: theme.shape.borderRadiusMedium, | ||
})); | ||
|
||
export const StyledProjectCardBody = styled(Box)(({ theme }) => ({ | ||
padding: theme.spacing(1, 2, 2, 2), | ||
})); | ||
|
||
export const StyledDivHeader = styled('div')(({ theme }) => ({ | ||
...flexRow, | ||
width: '100%', | ||
marginBottom: theme.spacing(2), | ||
})); | ||
|
||
export const StyledH2Title = styled('h2')(({ theme }) => ({ | ||
fontWeight: 'normal', | ||
fontSize: theme.fontSizes.bodySize, | ||
lineClamp: '2', | ||
WebkitLineClamp: 2, | ||
lineHeight: '1.2', | ||
display: '-webkit-box', | ||
boxOrient: 'vertical', | ||
textOverflow: 'ellipsis', | ||
overflow: 'hidden', | ||
alignItems: 'flex-start', | ||
WebkitBoxOrient: 'vertical', | ||
wordBreak: 'break-word', | ||
})); | ||
|
||
export const StyledBox = styled(Box)(() => ({ | ||
...flexRow, | ||
marginRight: 'auto', | ||
})); | ||
|
||
export const StyledEditIcon = styled(Edit)(({ theme }) => ({ | ||
color: theme.palette.neutral.main, | ||
marginRight: theme.spacing(1), | ||
})); | ||
|
||
export const StyledDeleteIcon = styled(Delete)(({ theme }) => ({ | ||
color: theme.palette.neutral.main, | ||
marginRight: theme.spacing(1), | ||
})); | ||
|
||
export const StyledDivInfo = styled('div')(({ theme }) => ({ | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
fontSize: theme.fontSizes.smallerBody, | ||
})); | ||
|
||
export const StyledDivInfoContainer = styled('div')(() => ({ | ||
textAlign: 'center', | ||
})); | ||
|
||
export const StyledParagraphInfo = styled('p')(({ theme }) => ({ | ||
color: theme.palette.primary.dark, | ||
fontWeight: 'bold', | ||
})); |
143 changes: 143 additions & 0 deletions
143
frontend/src/component/project/NewProjectCard/NewProjectCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import type React from 'react'; | ||
import { Menu, MenuItem } from '@mui/material'; | ||
import MoreVertIcon from '@mui/icons-material/MoreVert'; | ||
import { type SyntheticEvent, useState } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { getProjectEditPath } from 'utils/routePathHelpers'; | ||
import PermissionIconButton from 'component/common/PermissionIconButton/PermissionIconButton'; | ||
import { UPDATE_PROJECT } from 'component/providers/AccessProvider/permissions'; | ||
import { DEFAULT_PROJECT_ID } from 'hooks/api/getters/useDefaultProject/useDefaultProjectId'; | ||
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; | ||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; | ||
import { DeleteProjectDialogue } from '../Project/DeleteProject/DeleteProjectDialogue'; | ||
import { | ||
StyledProjectCard, | ||
StyledDivHeader, | ||
StyledBox, | ||
StyledH2Title, | ||
StyledEditIcon, | ||
StyledDivInfo, | ||
StyledDivInfoContainer, | ||
StyledParagraphInfo, | ||
StyledProjectCardBody, | ||
} from './NewProjectCard.styles'; | ||
import { ProjectCardFooter } from './ProjectCardFooter/ProjectCardFooter'; | ||
import { ProjectCardIcon } from './ProjectCardIcon/ProjectCardIcon'; | ||
|
||
interface IProjectCardProps { | ||
name: string; | ||
featureCount: number; | ||
health: number; | ||
memberCount: number; | ||
id: string; | ||
onHover: () => void; | ||
isFavorite?: boolean; | ||
mode: string; | ||
} | ||
|
||
export const ProjectCard = ({ | ||
name, | ||
featureCount, | ||
health, | ||
memberCount, | ||
onHover, | ||
id, | ||
mode, | ||
isFavorite = false, | ||
}: IProjectCardProps) => { | ||
const { isOss } = useUiConfig(); | ||
const [anchorEl, setAnchorEl] = useState<Element | null>(null); | ||
const [showDelDialog, setShowDelDialog] = useState(false); | ||
const navigate = useNavigate(); | ||
|
||
const handleClick = (event: React.SyntheticEvent) => { | ||
event.preventDefault(); | ||
setAnchorEl(event.currentTarget); | ||
}; | ||
|
||
return ( | ||
<StyledProjectCard onMouseEnter={onHover}> | ||
<StyledProjectCardBody> | ||
<StyledDivHeader data-loading> | ||
<ProjectCardIcon mode={mode} /> | ||
<StyledBox> | ||
<StyledH2Title>{name}</StyledH2Title> | ||
</StyledBox> | ||
<PermissionIconButton | ||
style={{ transform: 'translateX(7px)' }} | ||
permission={UPDATE_PROJECT} | ||
hidden={isOss()} | ||
projectId={id} | ||
data-loading | ||
onClick={handleClick} | ||
tooltipProps={{ | ||
title: 'Options', | ||
}} | ||
> | ||
<MoreVertIcon /> | ||
</PermissionIconButton> | ||
|
||
<Menu | ||
id='project-card-menu' | ||
open={Boolean(anchorEl)} | ||
anchorEl={anchorEl} | ||
style={{ top: 0, left: -100 }} | ||
onClick={(event) => { | ||
event.preventDefault(); | ||
}} | ||
onClose={(event: SyntheticEvent) => { | ||
event.preventDefault(); | ||
setAnchorEl(null); | ||
}} | ||
> | ||
<MenuItem | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
navigate(getProjectEditPath(id)); | ||
}} | ||
> | ||
<StyledEditIcon /> | ||
Edit project | ||
</MenuItem> | ||
</Menu> | ||
</StyledDivHeader> | ||
<StyledDivInfo> | ||
<StyledDivInfoContainer> | ||
<StyledParagraphInfo data-loading> | ||
{featureCount} | ||
</StyledParagraphInfo> | ||
<p data-loading>toggles</p> | ||
</StyledDivInfoContainer> | ||
<StyledDivInfoContainer> | ||
<StyledParagraphInfo data-loading> | ||
{health}% | ||
</StyledParagraphInfo> | ||
<p data-loading>health</p> | ||
</StyledDivInfoContainer> | ||
|
||
<ConditionallyRender | ||
condition={id !== DEFAULT_PROJECT_ID} | ||
show={ | ||
<StyledDivInfoContainer> | ||
<StyledParagraphInfo data-loading> | ||
{memberCount} | ||
</StyledParagraphInfo> | ||
<p data-loading>members</p> | ||
</StyledDivInfoContainer> | ||
} | ||
/> | ||
</StyledDivInfo> | ||
</StyledProjectCardBody> | ||
<ProjectCardFooter id={id} isFavorite={isFavorite} /> | ||
<DeleteProjectDialogue | ||
project={id} | ||
open={showDelDialog} | ||
onClose={(e) => { | ||
e.preventDefault(); | ||
setAnchorEl(null); | ||
setShowDelDialog(false); | ||
}} | ||
/> | ||
</StyledProjectCard> | ||
); | ||
}; |
58 changes: 58 additions & 0 deletions
58
frontend/src/component/project/NewProjectCard/ProjectCardFooter/ProjectCardFooter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import type { VFC } from 'react'; | ||
import { Box, styled } from '@mui/material'; | ||
import { FavoriteIconButton } from 'component/common/FavoriteIconButton/FavoriteIconButton'; | ||
import useToast from 'hooks/useToast'; | ||
import { useFavoriteProjectsApi } from 'hooks/api/actions/useFavoriteProjectsApi/useFavoriteProjectsApi'; | ||
import useProjects from 'hooks/api/getters/useProjects/useProjects'; | ||
|
||
interface IProjectCardFooterProps { | ||
id: string; | ||
isFavorite?: boolean; | ||
} | ||
|
||
const StyledFooter = styled(Box)(({ theme }) => ({ | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
padding: theme.spacing(1, 2), | ||
borderTop: `1px solid ${theme.palette.grey[300]}`, | ||
backgroundColor: theme.palette.grey[100], | ||
boxShadow: 'inset 0px 2px 4px rgba(32, 32, 33, 0.05)', // FIXME: replace with variable | ||
})); | ||
|
||
const StyledFavoriteIconButton = styled(FavoriteIconButton)(({ theme }) => ({ | ||
marginRight: theme.spacing(-1), | ||
marginLeft: 'auto', | ||
})); | ||
|
||
export const ProjectCardFooter: VFC<IProjectCardFooterProps> = ({ | ||
id, | ||
isFavorite = false, | ||
}) => { | ||
const { setToastApiError } = useToast(); | ||
const { favorite, unfavorite } = useFavoriteProjectsApi(); | ||
const { refetch } = useProjects(); | ||
|
||
const onFavorite = async (e: React.SyntheticEvent) => { | ||
e.preventDefault(); | ||
try { | ||
if (isFavorite) { | ||
await unfavorite(id); | ||
} else { | ||
await favorite(id); | ||
} | ||
refetch(); | ||
} catch (error) { | ||
setToastApiError('Something went wrong, could not update favorite'); | ||
} | ||
}; | ||
return ( | ||
<StyledFooter> | ||
<StyledFavoriteIconButton | ||
onClick={onFavorite} | ||
isFavorite={isFavorite} | ||
size='medium' | ||
/> | ||
</StyledFooter> | ||
); | ||
}; |
68 changes: 68 additions & 0 deletions
68
frontend/src/component/project/NewProjectCard/ProjectCardIcon/ProjectCardIcon.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import type { VFC } from 'react'; | ||
import { styled } from '@mui/material'; | ||
import { Box } from '@mui/material'; | ||
import BarChartIcon from '@mui/icons-material/BarChart'; | ||
import LockIcon from '@mui/icons-material/Lock'; | ||
import VisibilityOffIcon from '@mui/icons-material/VisibilityOff'; | ||
import { HtmlTooltip } from 'component/common/HtmlTooltip/HtmlTooltip'; | ||
|
||
interface IProjectCardIconProps { | ||
mode: 'private' | 'protected' | 'public' | string; | ||
} | ||
|
||
const StyledVisibilityIcon = styled(VisibilityOffIcon)(({ theme }) => ({ | ||
color: theme.palette.action.disabled, | ||
})); | ||
|
||
const StyledLockIcon = styled(LockIcon)(({ theme }) => ({ | ||
color: theme.palette.action.disabled, | ||
})); | ||
|
||
const StyledProjectIcon = styled(BarChartIcon)(({ theme }) => ({ | ||
color: theme.palette.primary.main, | ||
})); | ||
|
||
export const StyledIconBox = styled(Box)(({ theme }) => ({ | ||
display: 'flex', | ||
justifyContent: 'center', | ||
borderWidth: '1px', | ||
borderRadius: theme.shape.borderRadius, | ||
borderStyle: 'solid', | ||
borderColor: theme.palette.neutral.border, | ||
padding: theme.spacing(0.5), | ||
marginRight: theme.spacing(2), | ||
})); | ||
|
||
export const ProjectCardIcon: VFC<IProjectCardIconProps> = ({ mode }) => { | ||
if (mode === 'private') { | ||
return ( | ||
<StyledIconBox data-loading> | ||
<HtmlTooltip | ||
title="This project's collaboration mode is set to private. The project and associated feature flags can only be seen by members of the project." | ||
arrow | ||
> | ||
<StyledVisibilityIcon /> | ||
</HtmlTooltip> | ||
</StyledIconBox> | ||
); | ||
} | ||
|
||
if (mode === 'protected') { | ||
return ( | ||
<StyledIconBox data-loading> | ||
<HtmlTooltip | ||
title="This project's collaboration mode is set to protected. Only admins and project members can submit change requests." | ||
arrow | ||
> | ||
<StyledLockIcon /> | ||
</HtmlTooltip> | ||
</StyledIconBox> | ||
); | ||
} | ||
|
||
return ( | ||
<StyledIconBox data-loading> | ||
<StyledProjectIcon /> | ||
</StyledIconBox> | ||
); | ||
}; |
Oops, something went wrong.