2023-11-01 15:56:06 +01:00
|
|
|
|
import React, { useEffect, useState } from 'react';
|
2022-08-04 13:57:25 +02:00
|
|
|
|
import useProject, {
|
|
|
|
|
useProjectNameOrId,
|
|
|
|
|
} from 'hooks/api/getters/useProject/useProject';
|
2023-01-18 10:10:41 +01:00
|
|
|
|
import { Box, styled } from '@mui/material';
|
2022-02-28 17:20:47 +01:00
|
|
|
|
import { ProjectFeatureToggles } from './ProjectFeatureToggles/ProjectFeatureToggles';
|
2021-10-01 12:15:02 +02:00
|
|
|
|
import ProjectInfo from './ProjectInfo/ProjectInfo';
|
2022-06-21 09:08:37 +02:00
|
|
|
|
import { usePageTitle } from 'hooks/usePageTitle';
|
2022-08-04 13:57:25 +02:00
|
|
|
|
import { useRequiredPathParam } from 'hooks/useRequiredPathParam';
|
2023-03-17 19:21:13 +01:00
|
|
|
|
import { useLastViewedProject } from 'hooks/useLastViewedProject';
|
2023-01-27 13:13:41 +01:00
|
|
|
|
import { ProjectStats } from './ProjectStats/ProjectStats';
|
2023-10-20 10:50:57 +02:00
|
|
|
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
2023-10-20 11:16:05 +02:00
|
|
|
|
import { useUiFlag } from 'hooks/useUiFlag';
|
2023-11-01 15:56:06 +01:00
|
|
|
|
import { useFeatureSearch } from 'hooks/api/getters/useFeatureSearch/useFeatureSearch';
|
2023-11-15 15:01:02 +01:00
|
|
|
|
import {
|
|
|
|
|
ISortingRules,
|
|
|
|
|
PaginatedProjectFeatureToggles,
|
|
|
|
|
} from './ProjectFeatureToggles/PaginatedProjectFeatureToggles';
|
2023-11-08 13:19:40 +01:00
|
|
|
|
import { useSearchParams } from 'react-router-dom';
|
2021-10-01 12:15:02 +02:00
|
|
|
|
|
2023-11-10 14:16:31 +01:00
|
|
|
|
import { PaginationBar } from 'component/common/PaginationBar/PaginationBar';
|
2023-11-15 15:01:02 +01:00
|
|
|
|
import { SortingRule } from 'react-table';
|
2023-11-10 14:16:31 +01:00
|
|
|
|
|
2022-08-04 13:57:25 +02:00
|
|
|
|
const refreshInterval = 15 * 1000;
|
2021-10-01 12:15:02 +02:00
|
|
|
|
|
2023-01-03 16:15:22 +01:00
|
|
|
|
const StyledContainer = styled('div')(({ theme }) => ({
|
|
|
|
|
display: 'flex',
|
|
|
|
|
[theme.breakpoints.down('md')]: {
|
|
|
|
|
flexDirection: 'column',
|
|
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
const StyledProjectToggles = styled('div')(() => ({
|
|
|
|
|
width: '100%',
|
|
|
|
|
minWidth: 0,
|
|
|
|
|
}));
|
|
|
|
|
|
2023-01-18 10:10:41 +01:00
|
|
|
|
const StyledContentContainer = styled(Box)(() => ({
|
|
|
|
|
display: 'flex',
|
|
|
|
|
flexDirection: 'column',
|
|
|
|
|
width: '100%',
|
2023-01-25 14:03:36 +01:00
|
|
|
|
minWidth: 0,
|
2023-01-18 10:10:41 +01:00
|
|
|
|
}));
|
|
|
|
|
|
2023-11-15 15:01:02 +01:00
|
|
|
|
export const DEFAULT_PAGE_LIMIT = 25;
|
|
|
|
|
|
2023-11-08 10:12:42 +01:00
|
|
|
|
const PaginatedProjectOverview = () => {
|
2023-11-01 12:05:42 +01:00
|
|
|
|
const projectId = useRequiredPathParam('projectId');
|
2023-11-08 13:19:40 +01:00
|
|
|
|
const [searchParams, setSearchParams] = useSearchParams();
|
2023-11-01 12:05:42 +01:00
|
|
|
|
const { project, loading: projectLoading } = useProject(projectId, {
|
|
|
|
|
refreshInterval,
|
|
|
|
|
});
|
2023-11-15 15:01:02 +01:00
|
|
|
|
const [pageLimit, setPageLimit] = useState(DEFAULT_PAGE_LIMIT);
|
2023-11-08 10:12:42 +01:00
|
|
|
|
const [currentOffset, setCurrentOffset] = useState(0);
|
2023-11-08 13:19:40 +01:00
|
|
|
|
|
|
|
|
|
const [searchValue, setSearchValue] = useState(
|
|
|
|
|
searchParams.get('search') || '',
|
|
|
|
|
);
|
|
|
|
|
|
2023-11-15 15:01:02 +01:00
|
|
|
|
const [sortingRules, setSortingRules] = useState<ISortingRules>({
|
|
|
|
|
sortBy: 'createdBy',
|
|
|
|
|
sortOrder: 'desc',
|
|
|
|
|
isFavoritesPinned: false,
|
|
|
|
|
});
|
|
|
|
|
|
2023-11-01 12:05:42 +01:00
|
|
|
|
const {
|
|
|
|
|
features: searchFeatures,
|
2023-11-01 15:56:06 +01:00
|
|
|
|
total,
|
2023-11-01 12:05:42 +01:00
|
|
|
|
refetch,
|
|
|
|
|
loading,
|
2023-11-13 14:08:48 +01:00
|
|
|
|
initialLoad,
|
2023-11-15 15:01:02 +01:00
|
|
|
|
} = useFeatureSearch(
|
|
|
|
|
currentOffset,
|
|
|
|
|
pageLimit,
|
|
|
|
|
sortingRules,
|
|
|
|
|
projectId,
|
|
|
|
|
searchValue,
|
|
|
|
|
{
|
|
|
|
|
refreshInterval,
|
|
|
|
|
},
|
|
|
|
|
);
|
2023-11-01 15:56:06 +01:00
|
|
|
|
|
2023-11-01 12:05:42 +01:00
|
|
|
|
const { members, features, health, description, environments, stats } =
|
|
|
|
|
project;
|
2023-11-02 13:32:47 +01:00
|
|
|
|
const fetchNextPage = () => {
|
2023-11-08 10:12:42 +01:00
|
|
|
|
if (!loading) {
|
2023-11-10 14:16:31 +01:00
|
|
|
|
setCurrentOffset(Math.min(total, currentOffset + pageLimit));
|
2023-11-01 15:56:06 +01:00
|
|
|
|
}
|
2023-11-02 13:32:47 +01:00
|
|
|
|
};
|
|
|
|
|
const fetchPrevPage = () => {
|
2023-11-10 14:16:31 +01:00
|
|
|
|
setCurrentOffset(Math.max(0, currentOffset - pageLimit));
|
2023-11-02 13:32:47 +01:00
|
|
|
|
};
|
2023-11-01 12:05:42 +01:00
|
|
|
|
|
2023-11-08 10:12:42 +01:00
|
|
|
|
const hasPreviousPage = currentOffset > 0;
|
2023-11-10 14:16:31 +01:00
|
|
|
|
const hasNextPage = currentOffset + pageLimit < total;
|
2023-11-08 10:12:42 +01:00
|
|
|
|
|
2023-11-01 12:05:42 +01:00
|
|
|
|
return (
|
|
|
|
|
<StyledContainer>
|
|
|
|
|
<ProjectInfo
|
|
|
|
|
id={projectId}
|
|
|
|
|
description={description}
|
|
|
|
|
memberCount={members}
|
|
|
|
|
health={health}
|
|
|
|
|
features={features}
|
|
|
|
|
stats={stats}
|
|
|
|
|
/>
|
|
|
|
|
<StyledContentContainer>
|
|
|
|
|
<ProjectStats stats={project.stats} />
|
|
|
|
|
<StyledProjectToggles>
|
2023-11-08 13:19:40 +01:00
|
|
|
|
<PaginatedProjectFeatureToggles
|
2023-11-01 15:56:06 +01:00
|
|
|
|
key={
|
2023-11-02 13:32:47 +01:00
|
|
|
|
loading && searchFeatures.length === 0
|
2023-11-01 15:56:06 +01:00
|
|
|
|
? 'loading'
|
|
|
|
|
: 'ready'
|
|
|
|
|
}
|
2023-11-02 13:32:47 +01:00
|
|
|
|
features={searchFeatures}
|
2023-11-01 12:05:42 +01:00
|
|
|
|
environments={environments}
|
2023-11-13 14:08:48 +01:00
|
|
|
|
initialLoad={initialLoad && searchFeatures.length === 0}
|
2023-11-02 13:32:47 +01:00
|
|
|
|
loading={loading && searchFeatures.length === 0}
|
2023-11-01 12:05:42 +01:00
|
|
|
|
onChange={refetch}
|
2023-11-01 15:56:06 +01:00
|
|
|
|
total={total}
|
2023-11-08 13:19:40 +01:00
|
|
|
|
searchValue={searchValue}
|
|
|
|
|
setSearchValue={setSearchValue}
|
2023-11-15 15:01:02 +01:00
|
|
|
|
sortingRules={sortingRules}
|
|
|
|
|
setSortingRules={setSortingRules}
|
2023-11-10 14:16:31 +01:00
|
|
|
|
paginationBar={
|
|
|
|
|
<StickyPaginationBar>
|
|
|
|
|
<PaginationBar
|
|
|
|
|
total={total}
|
|
|
|
|
hasNextPage={hasNextPage}
|
|
|
|
|
hasPreviousPage={hasPreviousPage}
|
|
|
|
|
fetchNextPage={fetchNextPage}
|
|
|
|
|
fetchPrevPage={fetchPrevPage}
|
|
|
|
|
currentOffset={currentOffset}
|
|
|
|
|
pageLimit={pageLimit}
|
|
|
|
|
setPageLimit={setPageLimit}
|
|
|
|
|
/>
|
|
|
|
|
</StickyPaginationBar>
|
|
|
|
|
}
|
2023-11-08 10:12:42 +01:00
|
|
|
|
/>
|
2023-11-01 12:05:42 +01:00
|
|
|
|
</StyledProjectToggles>
|
|
|
|
|
</StyledContentContainer>
|
|
|
|
|
</StyledContainer>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-10 14:16:31 +01:00
|
|
|
|
const StyledStickyBar = styled('div')(({ theme }) => ({
|
|
|
|
|
position: 'sticky',
|
|
|
|
|
bottom: 0,
|
|
|
|
|
backgroundColor: theme.palette.background.paper,
|
|
|
|
|
padding: theme.spacing(2),
|
|
|
|
|
marginLeft: theme.spacing(2),
|
2023-11-13 14:08:48 +01:00
|
|
|
|
zIndex: 9999,
|
2023-11-10 14:16:31 +01:00
|
|
|
|
borderBottomLeftRadius: theme.shape.borderRadiusMedium,
|
|
|
|
|
borderBottomRightRadius: theme.shape.borderRadiusMedium,
|
|
|
|
|
borderTop: `1px solid ${theme.palette.divider}`,
|
|
|
|
|
boxShadow: `0px -2px 8px 0px rgba(32, 32, 33, 0.06)`,
|
|
|
|
|
height: '52px',
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
const StyledStickyBarContentContainer = styled(Box)(({ theme }) => ({
|
|
|
|
|
display: 'flex',
|
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
|
width: '100%',
|
|
|
|
|
minWidth: 0,
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
const StickyPaginationBar: React.FC = ({ children }) => {
|
|
|
|
|
return (
|
|
|
|
|
<StyledStickyBar>
|
|
|
|
|
<StyledStickyBarContentContainer>
|
|
|
|
|
{children}
|
|
|
|
|
</StyledStickyBarContentContainer>
|
|
|
|
|
</StyledStickyBar>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-08 13:19:40 +01:00
|
|
|
|
/**
|
|
|
|
|
* @deprecated remove when flag `featureSearchFrontend` is removed
|
|
|
|
|
*/
|
2022-08-04 13:57:25 +02:00
|
|
|
|
const ProjectOverview = () => {
|
|
|
|
|
const projectId = useRequiredPathParam('projectId');
|
|
|
|
|
const projectName = useProjectNameOrId(projectId);
|
2023-11-01 12:05:42 +01:00
|
|
|
|
const { project, loading, refetch } = useProject(projectId, {
|
2023-01-27 13:13:41 +01:00
|
|
|
|
refreshInterval,
|
|
|
|
|
});
|
2023-01-31 14:20:16 +01:00
|
|
|
|
const { members, features, health, description, environments, stats } =
|
|
|
|
|
project;
|
2022-06-21 09:08:37 +02:00
|
|
|
|
usePageTitle(`Project overview – ${projectName}`);
|
2022-11-23 14:58:02 +01:00
|
|
|
|
const { setLastViewed } = useLastViewedProject();
|
2023-11-01 12:05:42 +01:00
|
|
|
|
const featureSearchFrontend = useUiFlag('featureSearchFrontend');
|
2022-11-23 14:58:02 +01:00
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2022-11-24 14:38:39 +01:00
|
|
|
|
setLastViewed(projectId);
|
|
|
|
|
}, [projectId, setLastViewed]);
|
2021-10-01 12:15:02 +02:00
|
|
|
|
|
2023-11-08 10:12:42 +01:00
|
|
|
|
if (featureSearchFrontend) return <PaginatedProjectOverview />;
|
2023-11-01 12:05:42 +01:00
|
|
|
|
|
2021-10-01 12:15:02 +02:00
|
|
|
|
return (
|
2023-01-03 16:15:22 +01:00
|
|
|
|
<StyledContainer>
|
2022-12-07 12:52:17 +01:00
|
|
|
|
<ProjectInfo
|
|
|
|
|
id={projectId}
|
|
|
|
|
description={description}
|
|
|
|
|
memberCount={members}
|
|
|
|
|
health={health}
|
2023-01-25 12:52:36 +01:00
|
|
|
|
features={features}
|
2023-01-31 14:20:16 +01:00
|
|
|
|
stats={stats}
|
2022-12-07 12:52:17 +01:00
|
|
|
|
/>
|
2023-01-18 10:10:41 +01:00
|
|
|
|
<StyledContentContainer>
|
2023-04-17 11:21:52 +02:00
|
|
|
|
<ProjectStats stats={project.stats} />
|
2023-01-18 10:10:41 +01:00
|
|
|
|
<StyledProjectToggles>
|
2023-11-14 13:03:23 +01:00
|
|
|
|
<ProjectFeatureToggles
|
|
|
|
|
key={loading ? 'loading' : 'ready'}
|
|
|
|
|
features={features}
|
|
|
|
|
environments={environments}
|
|
|
|
|
loading={loading}
|
|
|
|
|
onChange={refetch}
|
2023-01-18 10:10:41 +01:00
|
|
|
|
/>
|
|
|
|
|
</StyledProjectToggles>
|
|
|
|
|
</StyledContentContainer>
|
2023-01-03 16:15:22 +01:00
|
|
|
|
</StyledContainer>
|
2021-10-01 12:15:02 +02:00
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ProjectOverview;
|