35 lines
1.9 KiB
JavaScript
35 lines
1.9 KiB
JavaScript
import { Breadcrumbs, Link, Typography } from '@mui/material';
|
|
import { Link as RouterLink } from 'react-router-dom';
|
|
import { FORM_TYPE_TRANSLATE } from '../../constants/constants';
|
|
import { getListReturnUrl } from '../../utils/listNavigation';
|
|
|
|
export const getTaskLabel = (task) => [
|
|
FORM_TYPE_TRANSLATE[task?.form_type_code] || task?.form_type_code,
|
|
task?.year,
|
|
task?.org_unit?.title
|
|
? `${task.org_unit.title}`
|
|
: null,
|
|
].filter(Boolean).join(' · ');
|
|
|
|
const TaskBreadcrumbs = ({ task, taskId, sheetName, isProject = false, year }) => {
|
|
const projectYears = [...new Set(task?.years || task?.reports?.map((report) => report.year) || [])]
|
|
.filter(Boolean).sort((a, b) => Number(a) - Number(b)).join(', ');
|
|
const projectLabel = [task?.name || `Проект №${taskId}`, task?.org_unit_name || task?.org_unit?.title, !sheetName && projectYears]
|
|
.filter(Boolean).join(' · ');
|
|
const taskLabel = isProject ? projectLabel : getTaskLabel(task) || `Задача №${taskId}`;
|
|
const currentSheetLabel = isProject && /^\d{4}$/.test(String(year)) ? `${sheetName} · ${year}` : sheetName;
|
|
return (
|
|
<Breadcrumbs aria-label={isProject ? 'Навигация по проекту' : 'Навигация по задаче'} sx={{ fontSize: '0.875rem', '& .MuiBreadcrumbs-ol': { rowGap: '0.25rem' } }}>
|
|
<Link component={RouterLink} to={getListReturnUrl(isProject ? 'projects' : 'tasks', taskId)} color='inherit' underline='hover'>{isProject ? 'Проекты' : 'Задачи'}</Link>
|
|
{sheetName ? (
|
|
<Link component={RouterLink} to={`/${isProject ? 'project' : 'task'}/${taskId}`} color='inherit' underline='hover'>{taskLabel}</Link>
|
|
) : (
|
|
<Typography color='text.primary' fontSize='inherit' aria-current='page'>{taskLabel}</Typography>
|
|
)}
|
|
{sheetName && <Typography color='text.primary' fontSize='inherit' aria-current='page'>{currentSheetLabel}</Typography>}
|
|
</Breadcrumbs>
|
|
);
|
|
};
|
|
|
|
export default TaskBreadcrumbs;
|