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';
|
|
|
|
import ApiError from 'component/common/ApiError/ApiError';
|
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-05-02 15:52:41 +02:00
|
|
|
import { Tab, Tabs } from '@mui/material';
|
|
|
|
import { Edit } from '@mui/icons-material';
|
2022-03-28 10:49:59 +02:00
|
|
|
import useToast from 'hooks/useToast';
|
|
|
|
import useQueryParams from 'hooks/useQueryParams';
|
2021-07-16 15:41:54 +02:00
|
|
|
import { useEffect } 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';
|
|
|
|
import { UPDATE_PROJECT } from 'component/providers/AccessProvider/permissions';
|
2022-04-21 09:37:35 +02:00
|
|
|
import { TabPanel } from 'component/common/TabNav/TabPanel/TabPanel';
|
2022-05-05 13:42:18 +02:00
|
|
|
import { useRequiredPathParam } from 'hooks/useRequiredPathParam';
|
|
|
|
import { useOptionalPathParam } from 'hooks/useOptionalPathParam';
|
2022-06-10 16:09:50 +02:00
|
|
|
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
2021-07-07 11:04:36 +02:00
|
|
|
|
|
|
|
const Project = () => {
|
2022-05-05 13:42:18 +02:00
|
|
|
const projectId = useRequiredPathParam('projectId');
|
|
|
|
const activeTab = useOptionalPathParam('activeTab');
|
2021-07-16 15:41:54 +02:00
|
|
|
const params = useQueryParams();
|
2022-05-05 13:42:18 +02:00
|
|
|
const { project, error, 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-06-10 16:09:50 +02:00
|
|
|
const { isOss } = useUiConfig();
|
2021-10-01 12:15:02 +02:00
|
|
|
|
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;
|
2021-10-12 09:39:31 +02:00
|
|
|
const tabData = [
|
|
|
|
{
|
|
|
|
title: 'Overview',
|
2022-06-21 09:08:37 +02:00
|
|
|
component: (
|
|
|
|
<ProjectOverview
|
|
|
|
projectId={projectId}
|
|
|
|
projectName={projectName}
|
|
|
|
/>
|
|
|
|
),
|
2021-10-12 09:39:31 +02:00
|
|
|
path: basePath,
|
|
|
|
name: 'overview',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Health',
|
2022-06-21 09:08:37 +02:00
|
|
|
component: (
|
|
|
|
<ProjectHealth
|
|
|
|
projectId={projectId}
|
|
|
|
projectName={projectName}
|
|
|
|
/>
|
|
|
|
),
|
2021-10-12 09:39:31 +02:00
|
|
|
path: `${basePath}/health`,
|
|
|
|
name: 'health',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Access',
|
2022-06-21 09:08:37 +02:00
|
|
|
component: <ProjectAccess projectName={projectName} />,
|
2021-10-12 09:39:31 +02:00
|
|
|
path: `${basePath}/access`,
|
|
|
|
name: 'access',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Environments',
|
2022-06-21 09:08:37 +02:00
|
|
|
component: (
|
|
|
|
<ProjectEnvironment
|
|
|
|
projectId={projectId}
|
|
|
|
projectName={projectName}
|
|
|
|
/>
|
|
|
|
),
|
2021-10-12 09:39:31 +02:00
|
|
|
path: `${basePath}/environments`,
|
|
|
|
name: 'environments',
|
|
|
|
},
|
2022-05-03 16:27:43 +02:00
|
|
|
{
|
|
|
|
title: 'Archive',
|
2022-06-21 09:08:37 +02:00
|
|
|
component: (
|
|
|
|
<ProjectFeaturesArchive
|
|
|
|
projectId={projectId}
|
|
|
|
projectName={projectName}
|
|
|
|
/>
|
|
|
|
),
|
2022-05-03 16:27:43 +02:00
|
|
|
path: `${basePath}/archive`,
|
|
|
|
name: 'archive',
|
|
|
|
},
|
2021-11-24 14:36:21 +01:00
|
|
|
];
|
2021-07-07 11:04:36 +02:00
|
|
|
|
2022-04-21 09:37:35 +02:00
|
|
|
const activeTabIdx = activeTab
|
|
|
|
? tabData.findIndex(tab => tab.name === activeTab)
|
|
|
|
: 0;
|
|
|
|
|
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
|
|
|
|
2021-10-01 12:15:02 +02:00
|
|
|
const renderTabs = () => {
|
|
|
|
return tabData.map((tab, index) => {
|
|
|
|
return (
|
|
|
|
<Tab
|
|
|
|
key={tab.title}
|
2022-04-21 09:37:35 +02:00
|
|
|
id={`tab-${index}`}
|
|
|
|
aria-controls={`tabpanel-${index}`}
|
2021-10-01 12:15:02 +02:00
|
|
|
label={tab.title}
|
2022-05-05 13:42:18 +02:00
|
|
|
onClick={() => navigate(tab.path)}
|
2021-10-01 12:15:02 +02:00
|
|
|
className={styles.tabButton}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const renderTabContent = () => {
|
|
|
|
return tabData.map((tab, index) => {
|
|
|
|
return (
|
|
|
|
<TabPanel value={activeTabIdx} index={index} key={tab.path}>
|
|
|
|
{tab.component}
|
|
|
|
</TabPanel>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-07-07 11:04:36 +02:00
|
|
|
return (
|
|
|
|
<div ref={ref}>
|
2021-10-01 12:15:02 +02:00
|
|
|
<div className={styles.header}>
|
|
|
|
<div className={styles.innerContainer}>
|
2022-05-18 11:56:55 +02:00
|
|
|
<h2 className={styles.title}>
|
|
|
|
<div className={styles.titleText} data-loading>
|
2022-06-21 09:08:37 +02:00
|
|
|
{projectName}
|
2022-05-18 11:56:55 +02:00
|
|
|
</div>
|
2021-11-24 14:36:21 +01:00
|
|
|
<PermissionIconButton
|
|
|
|
permission={UPDATE_PROJECT}
|
2022-06-10 16:09:50 +02:00
|
|
|
projectId={projectId}
|
|
|
|
sx={{ visibility: isOss() ? 'hidden' : 'visible' }}
|
2022-05-05 13:42:18 +02:00
|
|
|
onClick={() =>
|
|
|
|
navigate(`/projects/${projectId}/edit`)
|
|
|
|
}
|
2022-05-09 15:17:20 +02:00
|
|
|
tooltipProps={{ title: 'Edit project' }}
|
2021-11-24 14:36:21 +01:00
|
|
|
data-loading
|
|
|
|
>
|
2021-10-06 13:45:56 +02:00
|
|
|
<Edit />
|
2021-11-24 14:36:21 +01:00
|
|
|
</PermissionIconButton>
|
2021-10-01 12:15:02 +02:00
|
|
|
</h2>
|
|
|
|
</div>
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={error}
|
|
|
|
show={
|
|
|
|
<ApiError
|
|
|
|
data-loading
|
2022-06-01 14:24:24 +02:00
|
|
|
style={{ maxWidth: '400px', margin: '1rem' }}
|
2021-10-01 12:15:02 +02:00
|
|
|
onClick={refetch}
|
|
|
|
text="Could not fetch project"
|
|
|
|
/>
|
|
|
|
}
|
2021-07-07 11:04:36 +02:00
|
|
|
/>
|
2021-10-01 12:15:02 +02:00
|
|
|
<div className={styles.separator} />
|
|
|
|
<div className={styles.tabContainer}>
|
|
|
|
<Tabs
|
|
|
|
value={activeTabIdx}
|
|
|
|
indicatorColor="primary"
|
|
|
|
textColor="primary"
|
|
|
|
>
|
|
|
|
{renderTabs()}
|
|
|
|
</Tabs>
|
|
|
|
</div>
|
2021-07-07 11:04:36 +02:00
|
|
|
</div>
|
2021-10-01 12:15:02 +02:00
|
|
|
{renderTabContent()}
|
2021-07-07 11:04:36 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Project;
|