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';
|
2021-07-16 15:41:54 +02:00
|
|
|
import { useStyles } from './Project.styles';
|
2022-08-08 11:59:36 +02:00
|
|
|
import { styled, Tab, Tabs } from '@mui/material';
|
|
|
|
import { Delete, Edit } from '@mui/icons-material';
|
2022-03-28 10:49:59 +02:00
|
|
|
import useToast from 'hooks/useToast';
|
|
|
|
import useQueryParams from 'hooks/useQueryParams';
|
2022-12-02 08:16:03 +01:00
|
|
|
import React, { useEffect, useMemo, useState } from 'react';
|
2022-02-09 12:25:02 +01:00
|
|
|
import { ProjectAccess } from '../ProjectAccess/ProjectAccess';
|
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';
|
2022-08-08 11:59:36 +02:00
|
|
|
import {
|
|
|
|
DELETE_PROJECT,
|
|
|
|
UPDATE_PROJECT,
|
|
|
|
} 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-08-04 13:57:25 +02:00
|
|
|
import { Routes, Route, 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 { DraftBanner } from 'component/changeRequest/DraftBanner/DraftBanner';
|
2022-10-20 14:00:48 +02:00
|
|
|
import { MainLayout } from 'component/layout/MainLayout/MainLayout';
|
2022-11-02 07:34:14 +01:00
|
|
|
import { ProjectChangeRequests } from '../../changeRequest/ProjectChangeRequests/ProjectChangeRequests';
|
2022-11-10 10:46:23 +01:00
|
|
|
import { ProjectSettings } from './ProjectSettings/ProjectSettings';
|
2022-11-14 12:34:38 +01:00
|
|
|
import { useChangeRequestsEnabled } from 'hooks/useChangeRequestsEnabled';
|
2022-12-02 08:16:03 +01:00
|
|
|
import { FavoriteIconButton } from '../../common/FavoriteIconButton/FavoriteIconButton';
|
|
|
|
import { useFavoriteProjectsApi } from '../../../hooks/api/actions/useFavoriteProjectsApi/useFavoriteProjectsApi';
|
2022-08-08 11:59:36 +02:00
|
|
|
|
|
|
|
const StyledDiv = styled('div')(() => ({
|
|
|
|
display: 'flex',
|
|
|
|
}));
|
|
|
|
|
|
|
|
const StyledName = styled('div')(({ theme }) => ({
|
|
|
|
overflow: 'hidden',
|
|
|
|
textOverflow: 'ellipsis',
|
|
|
|
whiteSpace: 'nowrap',
|
|
|
|
paddingBottom: theme.spacing(2),
|
|
|
|
}));
|
|
|
|
|
|
|
|
const StyledTitle = styled('span')(({ theme }) => ({
|
|
|
|
fontSize: theme.fontSizes.smallBody,
|
|
|
|
fontWeight: 'normal',
|
|
|
|
}));
|
|
|
|
const StyledText = styled(StyledTitle)(({ theme }) => ({
|
|
|
|
color: theme.palette.grey[800],
|
|
|
|
}));
|
2021-07-07 11:04:36 +02:00
|
|
|
|
|
|
|
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();
|
2022-12-02 08:16:03 +01:00
|
|
|
const { project, loading, refetch } = useProject(projectId);
|
2021-07-07 11:04:36 +02:00
|
|
|
const ref = useLoading(loading);
|
2022-01-14 15:50:02 +01:00
|
|
|
const { setToastData } = useToast();
|
2022-05-02 15:52:41 +02:00
|
|
|
const { classes: styles } = useStyles();
|
2022-05-05 13:42:18 +02:00
|
|
|
const navigate = useNavigate();
|
2022-08-04 13:57:25 +02:00
|
|
|
const { pathname } = useLocation();
|
2022-12-02 08:16:03 +01:00
|
|
|
const { isOss, uiConfig } = 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-11-14 12:34:38 +01:00
|
|
|
const { isChangeRequestConfiguredInAnyEnv, isChangeRequestFlagEnabled } =
|
|
|
|
useChangeRequestsEnabled(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);
|
|
|
|
|
2022-11-04 09:17:37 +01:00
|
|
|
const tabs = useMemo(() => {
|
|
|
|
const tabArray = [
|
|
|
|
{
|
|
|
|
title: 'Overview',
|
|
|
|
path: basePath,
|
|
|
|
name: 'overview',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Health',
|
|
|
|
path: `${basePath}/health`,
|
|
|
|
name: 'health',
|
|
|
|
},
|
2022-11-14 12:34:38 +01:00
|
|
|
...(!isChangeRequestFlagEnabled
|
2022-11-10 10:46:23 +01:00
|
|
|
? [
|
|
|
|
{
|
|
|
|
title: 'Access',
|
|
|
|
path: `${basePath}/access`,
|
|
|
|
name: 'access',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Environments',
|
|
|
|
path: `${basePath}/environments`,
|
|
|
|
name: 'environments',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
: []),
|
2022-11-04 09:17:37 +01:00
|
|
|
{
|
|
|
|
title: 'Archive',
|
|
|
|
path: `${basePath}/archive`,
|
|
|
|
name: 'archive',
|
|
|
|
},
|
2022-11-14 12:34:38 +01:00
|
|
|
...(isChangeRequestFlagEnabled
|
2022-11-10 10:46:23 +01:00
|
|
|
? [
|
|
|
|
{
|
|
|
|
title: 'Project settings',
|
|
|
|
path: `${basePath}/settings`,
|
|
|
|
name: 'settings',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
: []),
|
2022-11-04 09:17:37 +01:00
|
|
|
{
|
|
|
|
title: 'Event log',
|
|
|
|
path: `${basePath}/logs`,
|
|
|
|
name: 'logs',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const changeRequestTab = {
|
2022-10-28 10:24:13 +02:00
|
|
|
title: 'Change requests',
|
2022-11-02 07:34:14 +01:00
|
|
|
path: `${basePath}/change-requests`,
|
2022-11-30 10:52:13 +01:00
|
|
|
name: 'change-request',
|
2022-11-04 09:17:37 +01:00
|
|
|
};
|
|
|
|
|
2022-11-14 12:34:38 +01:00
|
|
|
if (isChangeRequestFlagEnabled) {
|
2022-11-04 09:17:37 +01:00
|
|
|
tabArray.splice(tabArray.length - 2, 0, changeRequestTab);
|
|
|
|
}
|
|
|
|
return tabArray;
|
2022-11-14 12:34:38 +01:00
|
|
|
}, [isChangeRequestFlagEnabled]);
|
2021-07-07 11:04:36 +02:00
|
|
|
|
2022-08-04 13:57:25 +02:00
|
|
|
const activeTab = [...tabs]
|
|
|
|
.reverse()
|
|
|
|
.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
|
|
|
});
|
|
|
|
}
|
2021-10-12 09:39:31 +02:00
|
|
|
|
2021-07-16 15:41:54 +02:00
|
|
|
/* eslint-disable-next-line */
|
|
|
|
}, []);
|
2021-07-07 11:04:36 +02:00
|
|
|
|
2022-12-02 08:16:03 +01:00
|
|
|
const onFavorite = async () => {
|
|
|
|
if (project?.favorite) {
|
|
|
|
await unfavorite(projectId);
|
|
|
|
} else {
|
|
|
|
await favorite(projectId);
|
|
|
|
}
|
|
|
|
refetch();
|
|
|
|
};
|
|
|
|
|
2021-07-07 11:04:36 +02:00
|
|
|
return (
|
2022-10-20 14:00:48 +02:00
|
|
|
<MainLayout
|
|
|
|
ref={ref}
|
2022-10-28 09:43:49 +02:00
|
|
|
subheader={
|
2022-11-14 12:34:38 +01:00
|
|
|
isChangeRequestConfiguredInAnyEnv() ? (
|
2022-10-28 09:43:49 +02:00
|
|
|
<DraftBanner project={projectId} />
|
|
|
|
) : null
|
|
|
|
}
|
2022-10-20 14:00:48 +02:00
|
|
|
>
|
2021-10-01 12:15:02 +02:00
|
|
|
<div className={styles.header}>
|
|
|
|
<div className={styles.innerContainer}>
|
2022-12-02 08:16:03 +01:00
|
|
|
<ConditionallyRender
|
|
|
|
condition={Boolean(uiConfig?.flags?.favorites)}
|
|
|
|
show={() => (
|
|
|
|
<FavoriteIconButton
|
|
|
|
onClick={onFavorite}
|
|
|
|
isFavorite={project?.favorite}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
2022-05-18 11:56:55 +02:00
|
|
|
<h2 className={styles.title}>
|
2022-08-08 11:59:36 +02:00
|
|
|
<div>
|
|
|
|
<StyledName data-loading>{projectName}</StyledName>
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={Boolean(project.description)}
|
|
|
|
show={
|
|
|
|
<StyledDiv>
|
|
|
|
<StyledTitle data-loading>
|
|
|
|
Description:
|
|
|
|
</StyledTitle>
|
|
|
|
<StyledText data-loading>
|
|
|
|
{project.description}
|
|
|
|
</StyledText>
|
|
|
|
</StyledDiv>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<StyledDiv>
|
|
|
|
<StyledTitle data-loading>
|
|
|
|
projectId:
|
|
|
|
</StyledTitle>
|
|
|
|
<StyledText data-loading>
|
|
|
|
{projectId}
|
|
|
|
</StyledText>
|
|
|
|
</StyledDiv>
|
2022-05-18 11:56:55 +02:00
|
|
|
</div>
|
2022-08-08 11:59:36 +02:00
|
|
|
<StyledDiv>
|
|
|
|
<PermissionIconButton
|
|
|
|
permission={UPDATE_PROJECT}
|
|
|
|
projectId={projectId}
|
|
|
|
sx={{
|
|
|
|
visibility: isOss() ? 'hidden' : 'visible',
|
|
|
|
}}
|
|
|
|
onClick={() =>
|
|
|
|
navigate(`/projects/${projectId}/edit`)
|
|
|
|
}
|
|
|
|
tooltipProps={{ title: 'Edit project' }}
|
|
|
|
data-loading
|
|
|
|
>
|
|
|
|
<Edit />
|
|
|
|
</PermissionIconButton>
|
|
|
|
<PermissionIconButton
|
|
|
|
permission={DELETE_PROJECT}
|
|
|
|
projectId={projectId}
|
|
|
|
sx={{
|
|
|
|
visibility: isOss() ? 'hidden' : 'visible',
|
|
|
|
}}
|
|
|
|
onClick={() => {
|
|
|
|
setShowDelDialog(true);
|
|
|
|
}}
|
|
|
|
tooltipProps={{ title: 'Delete project' }}
|
|
|
|
data-loading
|
|
|
|
>
|
|
|
|
<Delete />
|
|
|
|
</PermissionIconButton>
|
|
|
|
</StyledDiv>
|
2021-10-01 12:15:02 +02:00
|
|
|
</h2>
|
|
|
|
</div>
|
2022-11-14 12:54:41 +01:00
|
|
|
|
2021-10-01 12:15:02 +02:00
|
|
|
<div className={styles.separator} />
|
|
|
|
<div className={styles.tabContainer}>
|
|
|
|
<Tabs
|
2022-08-04 13:57:25 +02:00
|
|
|
value={activeTab?.path}
|
2021-10-01 12:15:02 +02:00
|
|
|
indicatorColor="primary"
|
|
|
|
textColor="primary"
|
|
|
|
>
|
2022-08-04 14:44:18 +02:00
|
|
|
{tabs.map(tab => (
|
|
|
|
<Tab
|
|
|
|
key={tab.title}
|
|
|
|
label={tab.title}
|
|
|
|
value={tab.path}
|
|
|
|
onClick={() => navigate(tab.path)}
|
|
|
|
className={styles.tabButton}
|
|
|
|
/>
|
|
|
|
))}
|
2021-10-01 12:15:02 +02:00
|
|
|
</Tabs>
|
|
|
|
</div>
|
2021-07-07 11:04:36 +02:00
|
|
|
</div>
|
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>
|
|
|
|
<Route path="health" element={<ProjectHealth />} />
|
|
|
|
<Route path="access/*" element={<ProjectAccess />} />
|
|
|
|
<Route path="environments" element={<ProjectEnvironment />} />
|
|
|
|
<Route path="archive" element={<ProjectFeaturesArchive />} />
|
2022-10-12 14:40:37 +02:00
|
|
|
<Route path="logs" element={<ProjectLog />} />
|
2022-10-28 10:24:13 +02:00
|
|
|
<Route
|
2022-11-02 07:34:14 +01:00
|
|
|
path="change-requests"
|
2022-10-28 10:24:13 +02:00
|
|
|
element={
|
|
|
|
<ConditionallyRender
|
2022-11-14 12:34:38 +01:00
|
|
|
condition={isChangeRequestFlagEnabled}
|
2022-11-02 07:34:14 +01:00
|
|
|
show={<ProjectChangeRequests />}
|
2022-10-28 10:24:13 +02:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
2022-10-26 09:45:24 +02:00
|
|
|
<Route
|
2022-11-02 07:34:14 +01:00
|
|
|
path="change-requests/:id"
|
2022-10-26 09:45:24 +02:00
|
|
|
element={
|
|
|
|
<ConditionallyRender
|
2022-11-14 12:34:38 +01:00
|
|
|
condition={isChangeRequestFlagEnabled}
|
2022-11-02 07:34:14 +01:00
|
|
|
show={<ChangeRequestOverview />}
|
2022-10-26 09:45:24 +02:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
2022-11-10 10:46:23 +01:00
|
|
|
<Route path="settings/*" element={<ProjectSettings />} />
|
2022-08-04 13:57:25 +02:00
|
|
|
<Route path="*" element={<ProjectOverview />} />
|
|
|
|
</Routes>
|
2022-10-20 14:00:48 +02:00
|
|
|
</MainLayout>
|
2021-07-07 11:04:36 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Project;
|