2022-05-05 13:42:18 +02:00
|
|
|
import { useNavigate } from 'react-router';
|
2022-03-28 10:49:59 +02:00
|
|
|
import useProject from 'hooks/api/getters/useProject/useProject';
|
|
|
|
import useLoading from 'hooks/useLoading';
|
2022-05-02 12:52:33 +02:00
|
|
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
2023-01-03 16:15:22 +01:00
|
|
|
import {
|
|
|
|
StyledDiv,
|
|
|
|
StyledFavoriteIconButton,
|
|
|
|
StyledHeader,
|
|
|
|
StyledInnerContainer,
|
|
|
|
StyledName,
|
|
|
|
StyledProjectTitle,
|
|
|
|
StyledSeparator,
|
|
|
|
StyledTab,
|
|
|
|
StyledTabContainer,
|
|
|
|
StyledTopRow,
|
|
|
|
} from './Project.styles';
|
2023-09-13 15:50:42 +02:00
|
|
|
import { Box, Paper, Tabs, Typography, styled } from '@mui/material';
|
2023-09-08 09:21:11 +02:00
|
|
|
import { FileUpload } from '@mui/icons-material';
|
2022-03-28 10:49:59 +02:00
|
|
|
import useToast from 'hooks/useToast';
|
|
|
|
import useQueryParams from 'hooks/useQueryParams';
|
2022-12-15 13:43:06 +01:00
|
|
|
import { useEffect, useState } from 'react';
|
2021-10-01 12:15:02 +02:00
|
|
|
import ProjectEnvironment from '../ProjectEnvironment/ProjectEnvironment';
|
2022-05-03 16:27:43 +02:00
|
|
|
import { ProjectFeaturesArchive } from './ProjectFeaturesArchive/ProjectFeaturesArchive';
|
2021-10-01 12:15:02 +02:00
|
|
|
import ProjectOverview from './ProjectOverview';
|
|
|
|
import ProjectHealth from './ProjectHealth/ProjectHealth';
|
2022-03-28 10:49:59 +02:00
|
|
|
import PermissionIconButton from 'component/common/PermissionIconButton/PermissionIconButton';
|
2023-09-08 09:21:11 +02:00
|
|
|
import { UPDATE_FEATURE } from 'component/providers/AccessProvider/permissions';
|
2022-05-05 13:42:18 +02:00
|
|
|
import { useRequiredPathParam } from 'hooks/useRequiredPathParam';
|
2022-06-10 16:09:50 +02:00
|
|
|
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
2022-12-13 12:41:40 +01:00
|
|
|
import { Navigate, Route, Routes, useLocation } from 'react-router-dom';
|
2022-08-08 11:59:36 +02:00
|
|
|
import { DeleteProjectDialogue } from './DeleteProject/DeleteProjectDialogue';
|
2022-10-12 14:40:37 +02:00
|
|
|
import { ProjectLog } from './ProjectLog/ProjectLog';
|
2022-11-02 07:34:14 +01:00
|
|
|
import { ChangeRequestOverview } from 'component/changeRequest/ChangeRequestOverview/ChangeRequestOverview';
|
|
|
|
import { ProjectChangeRequests } from '../../changeRequest/ProjectChangeRequests/ProjectChangeRequests';
|
2022-11-10 10:46:23 +01:00
|
|
|
import { ProjectSettings } from './ProjectSettings/ProjectSettings';
|
2022-12-13 14:19:21 +01:00
|
|
|
import { useFavoriteProjectsApi } from 'hooks/api/actions/useFavoriteProjectsApi/useFavoriteProjectsApi';
|
2023-01-19 11:42:58 +01:00
|
|
|
import { ImportModal } from './Import/ImportModal';
|
2023-02-08 10:16:38 +01:00
|
|
|
import { IMPORT_BUTTON } from 'utils/testIds';
|
2023-08-07 18:13:56 +02:00
|
|
|
import { EnterpriseBadge } from 'component/common/EnterpriseBadge/EnterpriseBadge';
|
2023-09-08 14:18:58 +02:00
|
|
|
import { Badge } from 'component/common/Badge/Badge';
|
2023-08-30 14:39:43 +02:00
|
|
|
import { ProjectDoraMetrics } from './ProjectDoraMetrics/ProjectDoraMetrics';
|
2023-10-11 13:44:54 +02:00
|
|
|
import { UiFlags } from 'interfaces/uiConfig';
|
2023-11-21 11:49:50 +01:00
|
|
|
import { HiddenProjectIconWithTooltip } from './HiddenProjectIconWithTooltip/HiddenProjectIconWithTooltip';
|
2022-08-08 11:59:36 +02:00
|
|
|
|
2023-09-13 15:50:42 +02:00
|
|
|
const StyledBadge = styled(Badge)(({ theme }) => ({
|
|
|
|
position: 'absolute',
|
|
|
|
top: 5,
|
|
|
|
right: 20,
|
|
|
|
[theme.breakpoints.down('md')]: {
|
|
|
|
top: 2,
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
2023-10-11 13:44:54 +02:00
|
|
|
interface ITab {
|
|
|
|
title: string;
|
|
|
|
path: string;
|
|
|
|
name: string;
|
|
|
|
flag?: keyof UiFlags;
|
|
|
|
new?: boolean;
|
|
|
|
isEnterprise?: boolean;
|
|
|
|
}
|
|
|
|
|
2023-01-12 11:34:45 +01:00
|
|
|
export const Project = () => {
|
2022-05-05 13:42:18 +02:00
|
|
|
const projectId = useRequiredPathParam('projectId');
|
2021-07-16 15:41:54 +02:00
|
|
|
const params = useQueryParams();
|
2023-06-29 12:48:32 +02:00
|
|
|
const { project, loading, error, refetch } = useProject(projectId);
|
2021-07-07 11:04:36 +02:00
|
|
|
const ref = useLoading(loading);
|
2023-11-07 09:19:55 +01:00
|
|
|
const { setToastData, setToastApiError } = useToast();
|
2023-01-19 11:42:58 +01:00
|
|
|
const [modalOpen, setModalOpen] = useState(false);
|
2022-05-05 13:42:18 +02:00
|
|
|
const navigate = useNavigate();
|
2022-08-04 13:57:25 +02:00
|
|
|
const { pathname } = useLocation();
|
2023-08-07 18:13:56 +02:00
|
|
|
const { isOss, uiConfig, isPro } = useUiConfig();
|
2022-05-05 13:42:18 +02:00
|
|
|
const basePath = `/projects/${projectId}`;
|
2022-06-21 09:08:37 +02:00
|
|
|
const projectName = project?.name || projectId;
|
2022-12-02 08:16:03 +01:00
|
|
|
const { favorite, unfavorite } = useFavoriteProjectsApi();
|
2022-08-04 13:57:25 +02:00
|
|
|
|
2022-08-08 11:59:36 +02:00
|
|
|
const [showDelDialog, setShowDelDialog] = useState(false);
|
|
|
|
|
2023-10-11 13:44:54 +02:00
|
|
|
const tabs: ITab[] = [
|
2022-12-15 13:43:06 +01:00
|
|
|
{
|
|
|
|
title: 'Overview',
|
|
|
|
path: basePath,
|
|
|
|
name: 'overview',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Health',
|
|
|
|
path: `${basePath}/health`,
|
|
|
|
name: 'health',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Archive',
|
|
|
|
path: `${basePath}/archive`,
|
|
|
|
name: 'archive',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Change requests',
|
|
|
|
path: `${basePath}/change-requests`,
|
|
|
|
name: 'change-request',
|
2023-08-07 18:13:56 +02:00
|
|
|
isEnterprise: true,
|
2023-08-30 14:39:43 +02:00
|
|
|
},
|
|
|
|
{
|
2023-09-08 14:18:58 +02:00
|
|
|
title: 'Metrics',
|
|
|
|
path: `${basePath}/metrics`,
|
2023-08-30 14:39:43 +02:00
|
|
|
name: 'dora',
|
2023-11-21 08:18:00 +01:00
|
|
|
isEnterprise: true,
|
2022-12-15 13:43:06 +01:00
|
|
|
},
|
2023-08-23 11:42:20 +02:00
|
|
|
{
|
|
|
|
title: 'Event log',
|
|
|
|
path: `${basePath}/logs`,
|
|
|
|
name: 'logs',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Project settings',
|
2023-09-12 08:39:55 +02:00
|
|
|
path: `${basePath}/settings${isOss() ? '/environments' : ''}`,
|
2023-08-23 11:42:20 +02:00
|
|
|
name: 'settings',
|
|
|
|
},
|
2023-10-11 13:44:54 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
const filteredTabs = tabs
|
2023-10-02 14:25:46 +02:00
|
|
|
.filter((tab) => {
|
2023-08-30 14:39:43 +02:00
|
|
|
if (tab.flag) {
|
|
|
|
return uiConfig.flags[tab.flag];
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
})
|
2023-10-02 14:25:46 +02:00
|
|
|
.filter((tab) => !(isOss() && tab.isEnterprise));
|
2021-07-07 11:04:36 +02:00
|
|
|
|
2023-10-11 13:44:54 +02:00
|
|
|
const activeTab = [...filteredTabs]
|
2022-08-04 13:57:25 +02:00
|
|
|
.reverse()
|
2023-10-02 14:25:46 +02:00
|
|
|
.find((tab) => pathname.startsWith(tab.path));
|
2022-04-21 09:37:35 +02:00
|
|
|
|
2021-07-16 15:41:54 +02:00
|
|
|
useEffect(() => {
|
|
|
|
const created = params.get('created');
|
|
|
|
const edited = params.get('edited');
|
|
|
|
|
|
|
|
if (created || edited) {
|
|
|
|
const text = created ? 'Project created' : 'Project updated';
|
|
|
|
setToastData({
|
|
|
|
type: 'success',
|
2022-01-14 15:50:02 +01:00
|
|
|
title: text,
|
2021-07-16 15:41:54 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
/* eslint-disable-next-line */
|
|
|
|
}, []);
|
2021-07-07 11:04:36 +02:00
|
|
|
|
2023-06-29 12:48:32 +02:00
|
|
|
if (error?.status === 404) {
|
|
|
|
return (
|
2023-10-02 14:25:46 +02:00
|
|
|
<Paper sx={(theme) => ({ padding: theme.spacing(2, 4, 4) })}>
|
|
|
|
<Typography variant='h1'>404 Not Found</Typography>
|
2023-06-29 12:48:32 +02:00
|
|
|
<Typography>
|
|
|
|
Project <strong>{projectId}</strong> does not exist.
|
|
|
|
</Typography>
|
|
|
|
</Paper>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-02 08:16:03 +01:00
|
|
|
const onFavorite = async () => {
|
2023-11-07 09:19:55 +01:00
|
|
|
try {
|
|
|
|
if (project?.favorite) {
|
|
|
|
await unfavorite(projectId);
|
|
|
|
} else {
|
|
|
|
await favorite(projectId);
|
|
|
|
}
|
|
|
|
refetch();
|
|
|
|
} catch (error) {
|
|
|
|
setToastApiError('Something went wrong, could not update favorite');
|
2022-12-02 08:16:03 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-08-07 18:13:56 +02:00
|
|
|
const enterpriseIcon = (
|
|
|
|
<Box
|
2023-10-02 14:25:46 +02:00
|
|
|
sx={(theme) => ({
|
2023-08-07 18:13:56 +02:00
|
|
|
marginLeft: theme.spacing(1),
|
|
|
|
display: 'flex',
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<EnterpriseBadge />
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
|
2021-07-07 11:04:36 +02:00
|
|
|
return (
|
2023-01-04 10:24:39 +01:00
|
|
|
<div ref={ref}>
|
2023-01-03 16:15:22 +01:00
|
|
|
<StyledHeader>
|
|
|
|
<StyledInnerContainer>
|
2022-12-13 14:19:21 +01:00
|
|
|
<StyledTopRow>
|
|
|
|
<StyledDiv>
|
2022-12-21 13:03:06 +01:00
|
|
|
<StyledFavoriteIconButton
|
|
|
|
onClick={onFavorite}
|
|
|
|
isFavorite={project?.favorite}
|
2022-12-13 14:19:21 +01:00
|
|
|
/>
|
2023-01-03 16:15:22 +01:00
|
|
|
<StyledProjectTitle>
|
2023-11-21 11:49:50 +01:00
|
|
|
<ConditionallyRender
|
|
|
|
condition={project?.mode === 'private'}
|
|
|
|
show={<HiddenProjectIconWithTooltip />}
|
|
|
|
/>
|
2022-12-13 14:19:21 +01:00
|
|
|
<StyledName data-loading>
|
|
|
|
{projectName}
|
|
|
|
</StyledName>
|
2023-01-03 16:15:22 +01:00
|
|
|
</StyledProjectTitle>
|
2022-12-13 14:19:21 +01:00
|
|
|
</StyledDiv>
|
|
|
|
<StyledDiv>
|
2023-03-29 08:19:33 +02:00
|
|
|
<ConditionallyRender
|
|
|
|
condition={Boolean(
|
2023-10-02 14:25:46 +02:00
|
|
|
uiConfig?.flags?.featuresExportImport,
|
2023-03-29 08:19:33 +02:00
|
|
|
)}
|
|
|
|
show={
|
|
|
|
<PermissionIconButton
|
|
|
|
permission={UPDATE_FEATURE}
|
|
|
|
projectId={projectId}
|
|
|
|
onClick={() => setModalOpen(true)}
|
|
|
|
tooltipProps={{ title: 'Import' }}
|
|
|
|
data-testid={IMPORT_BUTTON}
|
|
|
|
data-loading
|
|
|
|
>
|
|
|
|
<FileUpload />
|
|
|
|
</PermissionIconButton>
|
|
|
|
}
|
2023-02-16 08:08:51 +01:00
|
|
|
/>
|
2022-12-13 14:19:21 +01:00
|
|
|
</StyledDiv>
|
|
|
|
</StyledTopRow>
|
2023-01-03 16:15:22 +01:00
|
|
|
</StyledInnerContainer>
|
2022-11-14 12:54:41 +01:00
|
|
|
|
2023-01-03 16:15:22 +01:00
|
|
|
<StyledSeparator />
|
|
|
|
<StyledTabContainer>
|
2021-10-01 12:15:02 +02:00
|
|
|
<Tabs
|
2022-08-04 13:57:25 +02:00
|
|
|
value={activeTab?.path}
|
2023-10-02 14:25:46 +02:00
|
|
|
indicatorColor='primary'
|
|
|
|
textColor='primary'
|
|
|
|
variant='scrollable'
|
2022-12-07 12:52:17 +01:00
|
|
|
allowScrollButtonsMobile
|
2021-10-01 12:15:02 +02:00
|
|
|
>
|
2023-10-11 13:44:54 +02:00
|
|
|
{filteredTabs.map((tab) => {
|
2023-08-30 14:39:43 +02:00
|
|
|
return (
|
|
|
|
<StyledTab
|
2023-11-13 14:08:48 +01:00
|
|
|
data-loading
|
2023-08-30 14:39:43 +02:00
|
|
|
key={tab.title}
|
|
|
|
label={tab.title}
|
|
|
|
value={tab.path}
|
|
|
|
onClick={() => navigate(tab.path)}
|
|
|
|
data-testid={`TAB_${tab.title}`}
|
|
|
|
iconPosition={
|
|
|
|
tab.isEnterprise ? 'end' : undefined
|
|
|
|
}
|
|
|
|
icon={
|
2023-09-08 14:18:58 +02:00
|
|
|
<>
|
|
|
|
<ConditionallyRender
|
2023-10-11 13:44:54 +02:00
|
|
|
condition={Boolean(tab.new)}
|
2023-09-08 14:18:58 +02:00
|
|
|
show={
|
2023-10-02 14:25:46 +02:00
|
|
|
<StyledBadge color='success'>
|
2023-09-08 14:18:58 +02:00
|
|
|
New
|
2023-09-13 15:50:42 +02:00
|
|
|
</StyledBadge>
|
2023-09-08 14:18:58 +02:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
{(tab.isEnterprise &&
|
|
|
|
isPro() &&
|
|
|
|
enterpriseIcon) ||
|
|
|
|
undefined}
|
|
|
|
</>
|
2023-08-30 14:39:43 +02:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
})}
|
2021-10-01 12:15:02 +02:00
|
|
|
</Tabs>
|
2023-01-03 16:15:22 +01:00
|
|
|
</StyledTabContainer>
|
|
|
|
</StyledHeader>
|
2022-08-08 11:59:36 +02:00
|
|
|
<DeleteProjectDialogue
|
|
|
|
project={projectId}
|
|
|
|
open={showDelDialog}
|
|
|
|
onClose={() => {
|
|
|
|
setShowDelDialog(false);
|
|
|
|
}}
|
|
|
|
onSuccess={() => {
|
|
|
|
navigate('/projects');
|
|
|
|
}}
|
|
|
|
/>
|
2022-08-04 13:57:25 +02:00
|
|
|
<Routes>
|
2023-10-02 14:25:46 +02:00
|
|
|
<Route path='health' element={<ProjectHealth />} />
|
2022-12-13 12:41:40 +01:00
|
|
|
<Route
|
2023-10-02 14:25:46 +02:00
|
|
|
path='access/*'
|
2022-12-13 12:41:40 +01:00
|
|
|
element={
|
|
|
|
<Navigate
|
|
|
|
replace
|
|
|
|
to={`/projects/${projectId}/settings/access`}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
2023-10-02 14:25:46 +02:00
|
|
|
<Route path='environments' element={<ProjectEnvironment />} />
|
|
|
|
<Route path='archive' element={<ProjectFeaturesArchive />} />
|
|
|
|
<Route path='logs' element={<ProjectLog />} />
|
2022-10-28 10:24:13 +02:00
|
|
|
<Route
|
2023-10-02 14:25:46 +02:00
|
|
|
path='change-requests'
|
2022-12-15 13:43:06 +01:00
|
|
|
element={<ProjectChangeRequests />}
|
2022-10-28 10:24:13 +02:00
|
|
|
/>
|
2022-10-26 09:45:24 +02:00
|
|
|
<Route
|
2023-10-02 14:25:46 +02:00
|
|
|
path='change-requests/:id'
|
2022-12-15 13:43:06 +01:00
|
|
|
element={<ChangeRequestOverview />}
|
2022-10-26 09:45:24 +02:00
|
|
|
/>
|
2023-10-02 14:25:46 +02:00
|
|
|
<Route path='settings/*' element={<ProjectSettings />} />
|
|
|
|
<Route path='metrics' element={<ProjectDoraMetrics />} />
|
|
|
|
<Route path='*' element={<ProjectOverview />} />
|
2022-08-04 13:57:25 +02:00
|
|
|
</Routes>
|
2023-01-19 11:42:58 +01:00
|
|
|
<ImportModal
|
|
|
|
open={modalOpen}
|
|
|
|
setOpen={setModalOpen}
|
|
|
|
project={projectId}
|
|
|
|
/>
|
2023-01-04 10:24:39 +01:00
|
|
|
</div>
|
2021-07-07 11:04:36 +02:00
|
|
|
);
|
|
|
|
};
|