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

108 lines
3.8 KiB
TypeScript
Raw Normal View History

2023-02-03 12:58:21 +01:00
import { Box, styled, useMediaQuery, useTheme } from '@mui/material';
import type { ProjectStatsSchema } from 'openapi/models/projectStatsSchema';
2023-01-27 13:00:23 +01:00
import type { IFeatureToggleListItem } from 'interfaces/featureToggle';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { DEFAULT_PROJECT_ID } from 'hooks/api/getters/useDefaultProject/useDefaultProjectId';
import { HealthWidget } from './HealthWidget';
import { ToggleTypesWidget } from './ToggleTypesWidget';
2023-01-27 13:00:23 +01:00
import { MetaWidget } from './MetaWidget';
import { ProjectMembersWidget } from './ProjectMembersWidget';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
2023-01-31 11:06:45 +01:00
import { ChangeRequestsWidget } from './ChangeRequestsWidget';
2023-02-03 12:58:21 +01:00
import { flexRow } from 'themes/themeStyles';
import { useChangeRequestsEnabled } from 'hooks/useChangeRequestsEnabled';
interface IProjectInfoProps {
id: string;
memberCount: number;
features: IFeatureToggleListItem[];
health: number;
description?: string;
stats: ProjectStatsSchema;
}
2023-02-03 12:58:21 +01:00
const StyledProjectInfoSidebarContainer = styled(Box)(({ theme }) => ({
...flexRow,
width: '225px',
flexDirection: 'column',
gap: theme.spacing(2),
boxShadow: 'none',
[theme.breakpoints.down('md')]: {
display: 'grid',
width: '100%',
alignItems: 'stretch',
marginBottom: theme.spacing(2),
},
[theme.breakpoints.down('sm')]: {
display: 'flex',
},
}));
const ProjectInfo = ({
id,
2023-01-27 13:00:23 +01:00
description,
memberCount,
health,
features,
stats,
}: IProjectInfoProps) => {
const { isEnterprise } = useUiConfig();
2023-02-03 12:58:21 +01:00
const theme = useTheme();
const isSmallScreen = useMediaQuery(theme.breakpoints.down('md'));
const { isChangeRequestConfiguredInAnyEnv } = useChangeRequestsEnabled(id);
2023-02-03 12:58:21 +01:00
const showChangeRequestsWidget =
isEnterprise() && isChangeRequestConfiguredInAnyEnv();
2023-02-03 12:58:21 +01:00
const showProjectMembersWidget = id !== DEFAULT_PROJECT_ID;
const fitMoreColumns =
(!showChangeRequestsWidget && !showProjectMembersWidget) ||
(isSmallScreen && showChangeRequestsWidget && showProjectMembersWidget);
return (
<aside>
2023-02-03 12:58:21 +01:00
<StyledProjectInfoSidebarContainer
sx={
fitMoreColumns
? {
gridTemplateColumns:
'repeat(auto-fill, minmax(225px, 1fr))',
}
: { gridTemplateColumns: 'repeat(2, 1fr)' }
}
>
2023-01-31 11:06:45 +01:00
<ConditionallyRender
2023-02-03 12:58:21 +01:00
condition={showChangeRequestsWidget}
show={
<Box
sx={{
gridColumnStart: showProjectMembersWidget
? 'span 2'
: 'span 1',
flex: 1,
display: 'flex',
}}
>
<ChangeRequestsWidget projectId={id} />
</Box>
2023-01-31 11:06:45 +01:00
}
/>
2023-02-03 12:58:21 +01:00
<MetaWidget id={id} description={description} />
<HealthWidget projectId={id} health={health} />
2023-01-27 13:00:23 +01:00
<ConditionallyRender
2023-02-03 12:58:21 +01:00
condition={showProjectMembersWidget}
show={
<ProjectMembersWidget
projectId={id}
memberCount={memberCount}
change={stats?.projectMembersAddedCurrentWindow}
/>
}
/>
2023-02-03 12:58:21 +01:00
<ToggleTypesWidget features={features} />
2023-01-27 13:00:23 +01:00
</StyledProjectInfoSidebarContainer>
</aside>
);
};
export default ProjectInfo;