2021-10-01 12:15:02 +02:00
|
|
|
import { useHistory, useParams } 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';
|
|
|
|
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';
|
2021-07-07 11:04:36 +02:00
|
|
|
|
|
|
|
const Project = () => {
|
2021-11-24 14:36:21 +01:00
|
|
|
const { id, activeTab } = useParams<{ id: string; activeTab: string }>();
|
2021-07-16 15:41:54 +02:00
|
|
|
const params = useQueryParams();
|
2021-07-07 11:04:36 +02:00
|
|
|
const { project, error, loading, refetch } = useProject(id);
|
|
|
|
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();
|
2021-10-01 12:15:02 +02:00
|
|
|
const history = useHistory();
|
|
|
|
|
|
|
|
const basePath = `/projects/${id}`;
|
2021-10-12 09:39:31 +02:00
|
|
|
const tabData = [
|
|
|
|
{
|
|
|
|
title: 'Overview',
|
|
|
|
component: <ProjectOverview projectId={id} />,
|
|
|
|
path: basePath,
|
|
|
|
name: 'overview',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Health',
|
|
|
|
component: <ProjectHealth projectId={id} />,
|
|
|
|
path: `${basePath}/health`,
|
|
|
|
name: 'health',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Access',
|
2022-02-25 10:55:39 +01:00
|
|
|
component: <ProjectAccess />,
|
2021-10-12 09:39:31 +02:00
|
|
|
path: `${basePath}/access`,
|
|
|
|
name: 'access',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Environments',
|
2021-11-24 14:36:21 +01:00
|
|
|
component: <ProjectEnvironment projectId={id} />,
|
2021-10-12 09:39:31 +02:00
|
|
|
path: `${basePath}/environments`,
|
|
|
|
name: 'environments',
|
|
|
|
},
|
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
|
|
|
|
2022-03-03 10:01:04 +01:00
|
|
|
// @ts-expect-error
|
2021-10-12 09:39:31 +02:00
|
|
|
tabData.filter(tab => !tab.disabled);
|
|
|
|
|
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
|
2021-11-24 14:36:21 +01:00
|
|
|
data-loading
|
2021-10-01 12:15:02 +02:00
|
|
|
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-04-21 09:37:35 +02:00
|
|
|
onClick={() => history.push(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}>
|
2021-11-24 14:36:21 +01:00
|
|
|
<h2
|
|
|
|
data-loading
|
2022-02-15 10:57:57 +01:00
|
|
|
className={styles.title}
|
2021-11-24 14:36:21 +01:00
|
|
|
style={{ margin: 0 }}
|
|
|
|
>
|
2022-02-15 10:57:57 +01:00
|
|
|
<div className={styles.titleText}>{project?.name}</div>
|
2021-11-24 14:36:21 +01:00
|
|
|
<PermissionIconButton
|
|
|
|
permission={UPDATE_PROJECT}
|
|
|
|
projectId={project?.id}
|
2022-01-19 14:28:55 +01:00
|
|
|
onClick={() => history.push(`/projects/${id}/edit`)}
|
2022-04-21 08:26:49 +02:00
|
|
|
tooltip="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
|
|
|
|
style={{ maxWidth: '400px', marginTop: '1rem' }}
|
|
|
|
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;
|