-
-
Notifications
You must be signed in to change notification settings - Fork 728
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract my projects component (#8317)
- Loading branch information
Showing
3 changed files
with
251 additions
and
204 deletions.
There are no files selected for viewing
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,31 @@ | ||
import { Box, Grid, styled } from '@mui/material'; | ||
import type { Theme } from '@mui/material/styles/createTheme'; | ||
|
||
export const ContentGrid = styled(Grid)(({ theme }) => ({ | ||
backgroundColor: theme.palette.background.paper, | ||
borderRadius: `${theme.shape.borderRadiusLarge}px`, | ||
})); | ||
|
||
export const SpacedGridItem = styled(Grid)(({ theme }) => ({ | ||
padding: theme.spacing(4), | ||
border: `0.5px solid ${theme.palette.divider}`, | ||
})); | ||
|
||
export const ListItemBox = styled(Box)(({ theme }) => ({ | ||
display: 'flex', | ||
gap: theme.spacing(2), | ||
alignItems: 'center', | ||
width: '100%', | ||
})); | ||
|
||
export const listItemStyle = (theme: Theme) => ({ | ||
borderRadius: theme.spacing(0.5), | ||
borderLeft: `${theme.spacing(0.5)} solid transparent`, | ||
'&.Mui-selected': { | ||
borderLeft: `${theme.spacing(0.5)} solid ${theme.palette.primary.main}`, | ||
}, | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'flex-start', | ||
gap: theme.spacing(1), | ||
}); |
175 changes: 175 additions & 0 deletions
175
frontend/src/component/personalDashboard/MyProjects.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,175 @@ | ||
import { | ||
Box, | ||
IconButton, | ||
Link, | ||
List, | ||
ListItem, | ||
ListItemButton, | ||
Typography, | ||
} from '@mui/material'; | ||
import { Badge } from '../common/Badge/Badge'; | ||
import { ProjectIcon } from '../common/ProjectIcon/ProjectIcon'; | ||
import LinkIcon from '@mui/icons-material/Link'; | ||
import { ProjectSetupComplete } from './ProjectSetupComplete'; | ||
import { ConnectSDK, CreateFlag, ExistingFlag } from './ConnectSDK'; | ||
import { LatestProjectEvents } from './LatestProjectEvents'; | ||
import { RoleAndOwnerInfo } from './RoleAndOwnerInfo'; | ||
import type { FC } from 'react'; | ||
import { StyledCardTitle } from './PersonalDashboard'; | ||
import type { | ||
PersonalDashboardProjectDetailsSchema, | ||
PersonalDashboardSchemaProjectsItem, | ||
} from '../../openapi'; | ||
import { | ||
ContentGrid, | ||
ListItemBox, | ||
listItemStyle, | ||
SpacedGridItem, | ||
} from './Grid'; | ||
|
||
const ActiveProjectDetails: FC<{ | ||
project: PersonalDashboardSchemaProjectsItem; | ||
}> = ({ project }) => { | ||
return ( | ||
<Box sx={{ display: 'flex', gap: 2 }}> | ||
<Box sx={{ display: 'flex', flexDirection: 'column' }}> | ||
<Typography variant='subtitle2' color='primary'> | ||
{project.featureCount} | ||
</Typography> | ||
<Typography variant='caption' color='text.secondary'> | ||
flags | ||
</Typography> | ||
</Box> | ||
<Box sx={{ display: 'flex', flexDirection: 'column' }}> | ||
<Typography variant='subtitle2' color='primary'> | ||
{project.memberCount} | ||
</Typography> | ||
<Typography variant='caption' color='text.secondary'> | ||
members | ||
</Typography> | ||
</Box> | ||
<Box sx={{ display: 'flex', flexDirection: 'column' }}> | ||
<Typography variant='subtitle2' color='primary'> | ||
{project.health}% | ||
</Typography> | ||
<Typography variant='caption' color='text.secondary'> | ||
health | ||
</Typography> | ||
</Box> | ||
</Box> | ||
); | ||
}; | ||
|
||
export const MyProjects: FC<{ | ||
projects: PersonalDashboardSchemaProjectsItem[]; | ||
personalDashboardProjectDetails?: PersonalDashboardProjectDetailsSchema; | ||
activeProject: string; | ||
setActiveProject: (project: string) => void; | ||
}> = ({ | ||
projects, | ||
personalDashboardProjectDetails, | ||
setActiveProject, | ||
activeProject, | ||
}) => { | ||
const activeProjectStage = | ||
personalDashboardProjectDetails?.onboardingStatus.status ?? 'loading'; | ||
const setupIncomplete = | ||
activeProjectStage === 'onboarding-started' || | ||
activeProjectStage === 'first-flag-created'; | ||
|
||
return ( | ||
<ContentGrid container columns={{ lg: 12, md: 1 }}> | ||
<SpacedGridItem item lg={4} md={1}> | ||
<Typography variant='h3'>My projects</Typography> | ||
</SpacedGridItem> | ||
<SpacedGridItem | ||
item | ||
lg={8} | ||
md={1} | ||
sx={{ display: 'flex', justifyContent: 'flex-end' }} | ||
> | ||
{setupIncomplete ? ( | ||
<Badge color='warning'>Setup incomplete</Badge> | ||
) : null} | ||
</SpacedGridItem> | ||
<SpacedGridItem item lg={4} md={1}> | ||
<List | ||
disablePadding={true} | ||
sx={{ maxHeight: '400px', overflow: 'auto' }} | ||
> | ||
{projects.map((project) => { | ||
return ( | ||
<ListItem | ||
key={project.id} | ||
disablePadding={true} | ||
sx={{ mb: 1 }} | ||
> | ||
<ListItemButton | ||
sx={listItemStyle} | ||
selected={project.id === activeProject} | ||
onClick={() => setActiveProject(project.id)} | ||
> | ||
<ListItemBox> | ||
<ProjectIcon color='primary' /> | ||
<StyledCardTitle> | ||
{project.name} | ||
</StyledCardTitle> | ||
<IconButton | ||
component={Link} | ||
href={`projects/${project.id}`} | ||
size='small' | ||
sx={{ ml: 'auto' }} | ||
> | ||
<LinkIcon | ||
titleAccess={`projects/${project.id}`} | ||
/> | ||
</IconButton> | ||
</ListItemBox> | ||
{project.id === activeProject ? ( | ||
<ActiveProjectDetails | ||
project={project} | ||
/> | ||
) : null} | ||
</ListItemButton> | ||
</ListItem> | ||
); | ||
})} | ||
</List> | ||
</SpacedGridItem> | ||
<SpacedGridItem item lg={4} md={1}> | ||
{activeProjectStage === 'onboarded' ? ( | ||
<ProjectSetupComplete project={activeProject} /> | ||
) : null} | ||
{activeProjectStage === 'onboarding-started' || | ||
activeProjectStage === 'loading' ? ( | ||
<CreateFlag project={activeProject} /> | ||
) : null} | ||
{activeProjectStage === 'first-flag-created' ? ( | ||
<ExistingFlag project={activeProject} /> | ||
) : null} | ||
</SpacedGridItem> | ||
<SpacedGridItem item lg={4} md={1}> | ||
{activeProjectStage === 'onboarded' && | ||
personalDashboardProjectDetails ? ( | ||
<LatestProjectEvents | ||
latestEvents={ | ||
personalDashboardProjectDetails.latestEvents | ||
} | ||
/> | ||
) : null} | ||
{setupIncomplete || activeProjectStage === 'loading' ? ( | ||
<ConnectSDK project={activeProject} /> | ||
) : null} | ||
</SpacedGridItem> | ||
<SpacedGridItem item lg={4} md={1} /> | ||
<SpacedGridItem item lg={8} md={1}> | ||
{activeProject ? ( | ||
<RoleAndOwnerInfo | ||
roles={['owner', 'custom']} | ||
owners={[{ ownerType: 'system' }]} | ||
/> | ||
) : null} | ||
</SpacedGridItem> | ||
</ContentGrid> | ||
); | ||
}; |
Oops, something went wrong.