1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-10-13 11:17:26 +02:00
unleash.unleash/frontend/src/component/project/ProjectList/ProjectGroup.tsx
Tymoteusz Czech 01bd877a81
feat: info about unlimited projects option (#8814)
- refactored projects list header
- added info about unlimited projects to open-source version
2024-11-20 16:40:19 +01:00

126 lines
5.1 KiB
TypeScript

import type { ComponentType, ReactNode } from 'react';
import { Link } from 'react-router-dom';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { ProjectCard as DefaultProjectCard } from '../ProjectCard/ProjectCard';
import type { ProjectSchema } from 'openapi';
import loadingData from './loadingData';
import { TablePlaceholder } from 'component/common/Table';
import { styled } from '@mui/material';
import { useSearchHighlightContext } from 'component/common/Table/SearchHighlightContext/SearchHighlightContext';
import { UpgradeProjectCard } from '../ProjectCard/UpgradeProjectCard';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
const StyledGridContainer = styled('div')(({ theme }) => ({
display: 'grid',
gridTemplateColumns: 'repeat(auto-fill, minmax(280px, 1fr))',
gap: theme.spacing(2),
}));
const StyledCardLink = styled(Link)(({ theme }) => ({
color: 'inherit',
textDecoration: 'none',
border: 'none',
padding: '0',
background: 'transparent',
fontFamily: theme.typography.fontFamily,
pointer: 'cursor',
}));
type ProjectGroupProps = {
sectionTitle?: string;
sectionSubtitle?: string;
HeaderActions?: ReactNode;
projects: ProjectSchema[];
loading: boolean;
placeholder?: string;
ProjectCardComponent?: ComponentType<ProjectSchema & any>;
link?: boolean;
};
export const ProjectGroup = ({
projects,
loading,
placeholder = 'No projects available.',
ProjectCardComponent,
link = true,
}: ProjectGroupProps) => {
const ProjectCard = ProjectCardComponent ?? DefaultProjectCard;
const { isOss } = useUiConfig();
const { searchQuery } = useSearchHighlightContext();
return (
<>
<ConditionallyRender
condition={projects.length < 1 && !loading}
show={
<ConditionallyRender
condition={searchQuery?.length > 0}
show={
<TablePlaceholder>
No projects found matching &ldquo;
{searchQuery}
&rdquo;
</TablePlaceholder>
}
elseShow={
<TablePlaceholder>{placeholder}</TablePlaceholder>
}
/>
}
elseShow={
<StyledGridContainer>
<ConditionallyRender
condition={loading}
show={() => (
<>
{loadingData.map(
(project: ProjectSchema) => (
<ProjectCard
data-loading
createdAt={project.createdAt}
key={project.id}
name={project.name}
id={project.id}
mode={project.mode}
memberCount={2}
health={95}
featureCount={4}
owners={[
{
ownerType: 'user',
name: 'Loading data',
},
]}
/>
),
)}
</>
)}
elseShow={() => (
<>
{projects.map((project) =>
link ? (
<StyledCardLink
key={project.id}
to={`/projects/${project.id}`}
>
<ProjectCard {...project} />
</StyledCardLink>
) : (
<ProjectCard
key={project.id}
{...project}
/>
),
)}
</>
)}
/>
{isOss() ? <UpgradeProjectCard /> : null}
</StyledGridContainer>
}
/>
</>
);
};