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 {
|
|
|
|
StyledColumn,
|
|
|
|
StyledDiv,
|
|
|
|
StyledFavoriteIconButton,
|
|
|
|
StyledHeader,
|
|
|
|
StyledInnerContainer,
|
|
|
|
StyledName,
|
|
|
|
StyledProjectTitle,
|
|
|
|
StyledSeparator,
|
|
|
|
StyledTab,
|
|
|
|
StyledTabContainer,
|
|
|
|
StyledText,
|
|
|
|
StyledTitle,
|
|
|
|
StyledTopRow,
|
|
|
|
} from './Project.styles';
|
|
|
|
import { Tabs } from '@mui/material';
|
2023-01-19 11:42:58 +01:00
|
|
|
import { Delete, Edit, 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';
|
2022-08-08 11:59:36 +02:00
|
|
|
import {
|
2023-02-17 15:01:32 +01:00
|
|
|
UPDATE_FEATURE,
|
2022-08-08 11:59:36 +02:00
|
|
|
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-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';
|
2022-08-08 11:59:36 +02:00
|
|
|
|
2023-03-17 13:41:59 +01:00
|
|
|
const NAVIGATE_TO_EDIT_PROJECT = 'NAVIGATE_TO_EDIT_PROJECT';
|
|
|
|
|
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();
|
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();
|
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-01-19 11:42:58 +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-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-12-15 13:43:06 +01:00
|
|
|
const tabs = [
|
|
|
|
{
|
|
|
|
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',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Project settings',
|
|
|
|
path: `${basePath}/settings`,
|
|
|
|
name: 'settings',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Event log',
|
|
|
|
path: `${basePath}/logs`,
|
|
|
|
name: 'logs',
|
|
|
|
},
|
|
|
|
];
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
/* 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 (
|
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>
|
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(
|
|
|
|
uiConfig?.flags?.featuresExportImport
|
|
|
|
)}
|
|
|
|
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
|
|
|
<ConditionallyRender
|
|
|
|
condition={!isOss()}
|
|
|
|
show={
|
|
|
|
<PermissionIconButton
|
|
|
|
permission={UPDATE_PROJECT}
|
|
|
|
projectId={projectId}
|
|
|
|
onClick={() =>
|
|
|
|
navigate(
|
|
|
|
`/projects/${projectId}/edit`
|
|
|
|
)
|
|
|
|
}
|
|
|
|
tooltipProps={{ title: 'Edit project' }}
|
|
|
|
data-loading
|
2023-03-17 13:41:59 +01:00
|
|
|
data-testid={NAVIGATE_TO_EDIT_PROJECT}
|
2023-02-16 08:08:51 +01:00
|
|
|
>
|
|
|
|
<Edit />
|
|
|
|
</PermissionIconButton>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={!isOss()}
|
|
|
|
show={
|
|
|
|
<PermissionIconButton
|
|
|
|
permission={DELETE_PROJECT}
|
|
|
|
projectId={projectId}
|
|
|
|
onClick={() => {
|
|
|
|
setShowDelDialog(true);
|
|
|
|
}}
|
|
|
|
tooltipProps={{
|
|
|
|
title: 'Delete project',
|
|
|
|
}}
|
|
|
|
data-loading
|
|
|
|
>
|
|
|
|
<Delete />
|
|
|
|
</PermissionIconButton>
|
2022-12-13 14:19:21 +01:00
|
|
|
}
|
2023-02-16 08:08:51 +01:00
|
|
|
/>
|
2022-12-13 14:19:21 +01:00
|
|
|
</StyledDiv>
|
|
|
|
</StyledTopRow>
|
2023-01-27 13:00:23 +01:00
|
|
|
<ConditionallyRender
|
2023-02-03 12:58:21 +01:00
|
|
|
condition={
|
|
|
|
!Boolean(uiConfig?.flags?.newProjectOverview)
|
|
|
|
}
|
2023-01-27 13:00:23 +01:00
|
|
|
// TODO: !!! Remove entire block when removing feature flag!
|
2023-02-03 12:58:21 +01:00
|
|
|
show={() => (
|
2023-01-27 13:00:23 +01:00
|
|
|
<StyledColumn>
|
|
|
|
<StyledProjectTitle>
|
|
|
|
<div>
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={Boolean(
|
|
|
|
project.description
|
|
|
|
)}
|
|
|
|
show={
|
|
|
|
<StyledDiv>
|
|
|
|
<StyledTitle data-loading>
|
2023-02-03 12:58:21 +01:00
|
|
|
Description:
|
2023-01-27 13:00:23 +01:00
|
|
|
</StyledTitle>
|
|
|
|
<StyledText data-loading>
|
|
|
|
{project.description}
|
|
|
|
</StyledText>
|
|
|
|
</StyledDiv>
|
|
|
|
}
|
|
|
|
/>
|
2022-12-08 13:41:51 +01:00
|
|
|
<StyledDiv>
|
|
|
|
<StyledTitle data-loading>
|
2023-02-03 12:58:21 +01:00
|
|
|
projectId:
|
2022-12-08 13:41:51 +01:00
|
|
|
</StyledTitle>
|
|
|
|
<StyledText data-loading>
|
2023-01-27 13:00:23 +01:00
|
|
|
{projectId}
|
2022-12-08 13:41:51 +01:00
|
|
|
</StyledText>
|
|
|
|
</StyledDiv>
|
2023-01-27 13:00:23 +01:00
|
|
|
</div>
|
|
|
|
</StyledProjectTitle>
|
|
|
|
</StyledColumn>
|
2023-02-03 12:58:21 +01:00
|
|
|
)}
|
2023-01-27 13:00:23 +01:00
|
|
|
/>
|
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}
|
2021-10-01 12:15:02 +02:00
|
|
|
indicatorColor="primary"
|
|
|
|
textColor="primary"
|
2022-12-06 17:01:14 +01:00
|
|
|
variant="scrollable"
|
2022-12-07 12:52:17 +01:00
|
|
|
allowScrollButtonsMobile
|
2021-10-01 12:15:02 +02:00
|
|
|
>
|
2022-08-04 14:44:18 +02:00
|
|
|
{tabs.map(tab => (
|
2023-01-03 16:15:22 +01:00
|
|
|
<StyledTab
|
2022-08-04 14:44:18 +02:00
|
|
|
key={tab.title}
|
|
|
|
label={tab.title}
|
|
|
|
value={tab.path}
|
|
|
|
onClick={() => navigate(tab.path)}
|
2023-03-17 13:41:59 +01:00
|
|
|
data-testid={`TAB_${tab.title}`}
|
2022-08-04 14:44:18 +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>
|
|
|
|
<Route path="health" element={<ProjectHealth />} />
|
2022-12-13 12:41:40 +01:00
|
|
|
<Route
|
|
|
|
path="access/*"
|
|
|
|
element={
|
|
|
|
<Navigate
|
|
|
|
replace
|
|
|
|
to={`/projects/${projectId}/settings/access`}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
2022-08-04 13:57:25 +02:00
|
|
|
<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-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
|
2022-11-02 07:34:14 +01:00
|
|
|
path="change-requests/:id"
|
2022-12-15 13:43:06 +01:00
|
|
|
element={<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>
|
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
|
|
|
);
|
|
|
|
};
|