feat(task-drawer): enhance task navigation and hierarchy display
- Added functionality to navigate back to parent tasks for sub-tasks in the task drawer. - Introduced a breadcrumb component to visually represent the hierarchy of tasks, improving user navigation. - Updated task drawer header to display the current task name with truncation and tooltip for better readability. - Enhanced styling for task name display and breadcrumb for improved user experience.
This commit is contained in:
@@ -7,3 +7,28 @@
|
||||
outline: 1px solid #d9d9d9;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
/* Task name display styles */
|
||||
.task-name-display {
|
||||
margin: 0;
|
||||
padding: 2px 8px;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
width: 100%;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
min-height: 20px;
|
||||
line-height: 1.4;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.task-name-display:hover {
|
||||
background-color: rgba(0, 0, 0, 0.02);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
[data-theme='dark'] .task-name-display:hover {
|
||||
background-color: rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Button, Dropdown, Flex, Input, InputRef, MenuProps } from 'antd';
|
||||
import { Button, Dropdown, Flex, Input, InputRef, MenuProps, Tooltip } from 'antd';
|
||||
import React, { ChangeEvent, useEffect, useRef, useState } from 'react';
|
||||
import { EllipsisOutlined } from '@ant-design/icons';
|
||||
import { TFunction } from 'i18next';
|
||||
@@ -21,12 +21,19 @@ import { deleteBoardTask } from '@/features/board/board-slice';
|
||||
import { deleteTask as deleteKanbanTask, updateEnhancedKanbanSubtask } from '@/features/enhanced-kanban/enhanced-kanban.slice';
|
||||
import useTabSearchParam from '@/hooks/useTabSearchParam';
|
||||
import { ITaskViewModel } from '@/types/tasks/task.types';
|
||||
import TaskHierarchyBreadcrumb from '../task-hierarchy-breadcrumb/task-hierarchy-breadcrumb';
|
||||
|
||||
type TaskDrawerHeaderProps = {
|
||||
inputRef: React.RefObject<InputRef | null>;
|
||||
t: TFunction;
|
||||
};
|
||||
|
||||
// Utility function to truncate text
|
||||
const truncateText = (text: string, maxLength: number = 50): string => {
|
||||
if (!text || text.length <= maxLength) return text;
|
||||
return `${text.substring(0, maxLength)}...`;
|
||||
};
|
||||
|
||||
const TaskDrawerHeader = ({ inputRef, t }: TaskDrawerHeaderProps) => {
|
||||
const dispatch = useAppDispatch();
|
||||
const { socket, connected } = useSocket();
|
||||
@@ -38,6 +45,9 @@ const TaskDrawerHeader = ({ inputRef, t }: TaskDrawerHeaderProps) => {
|
||||
const [taskName, setTaskName] = useState<string>(taskFormViewModel?.task?.name ?? '');
|
||||
const currentSession = useAuthService().getCurrentSession();
|
||||
|
||||
// Check if current task is a sub-task
|
||||
const isSubTask = taskFormViewModel?.task?.is_sub_task || !!taskFormViewModel?.task?.parent_task_id;
|
||||
|
||||
useEffect(() => {
|
||||
setTaskName(taskFormViewModel?.task?.name ?? '');
|
||||
}, [taskFormViewModel?.task?.name]);
|
||||
@@ -126,54 +136,57 @@ const TaskDrawerHeader = ({ inputRef, t }: TaskDrawerHeaderProps) => {
|
||||
// No need for local socket listeners that could interfere with global handlers
|
||||
};
|
||||
|
||||
const displayTaskName = taskName || t('taskHeader.taskNamePlaceholder');
|
||||
const truncatedTaskName = truncateText(displayTaskName, 50);
|
||||
const shouldShowTooltip = displayTaskName.length > 50;
|
||||
|
||||
return (
|
||||
<Flex gap={12} align="center" style={{ marginBlockEnd: 6 }}>
|
||||
<Flex style={{ position: 'relative', width: '100%' }}>
|
||||
{isEditing ? (
|
||||
<Input
|
||||
ref={inputRef}
|
||||
size="large"
|
||||
value={taskName}
|
||||
onChange={e => onTaskNameChange(e)}
|
||||
onBlur={handleInputBlur}
|
||||
placeholder={t('taskHeader.taskNamePlaceholder')}
|
||||
className="task-name-input"
|
||||
style={{
|
||||
width: '100%',
|
||||
border: 'none',
|
||||
}}
|
||||
showCount={true}
|
||||
maxLength={250}
|
||||
autoFocus
|
||||
/>
|
||||
) : (
|
||||
<p
|
||||
onClick={() => setIsEditing(true)}
|
||||
style={{
|
||||
margin: 0,
|
||||
padding: '4px 11px',
|
||||
fontSize: '16px',
|
||||
cursor: 'pointer',
|
||||
wordWrap: 'break-word',
|
||||
overflowWrap: 'break-word',
|
||||
width: '100%',
|
||||
}}
|
||||
>
|
||||
{taskName || t('taskHeader.taskNamePlaceholder')}
|
||||
</p>
|
||||
)}
|
||||
<div>
|
||||
{/* Show breadcrumb for sub-tasks */}
|
||||
{isSubTask && <TaskHierarchyBreadcrumb t={t} />}
|
||||
|
||||
<Flex gap={8} align="center" style={{ marginBlockEnd: 2 }}>
|
||||
<Flex style={{ position: 'relative', width: '100%', alignItems: 'center' }}>
|
||||
{isEditing ? (
|
||||
<Input
|
||||
ref={inputRef}
|
||||
size="large"
|
||||
value={taskName}
|
||||
onChange={e => onTaskNameChange(e)}
|
||||
onBlur={handleInputBlur}
|
||||
placeholder={t('taskHeader.taskNamePlaceholder')}
|
||||
className="task-name-input"
|
||||
style={{
|
||||
width: '100%',
|
||||
border: 'none',
|
||||
}}
|
||||
showCount={true}
|
||||
maxLength={250}
|
||||
autoFocus
|
||||
/>
|
||||
) : (
|
||||
<Tooltip title={shouldShowTooltip ? displayTaskName : ''} trigger="hover">
|
||||
<p
|
||||
onClick={() => setIsEditing(true)}
|
||||
className="task-name-display"
|
||||
>
|
||||
{truncatedTaskName}
|
||||
</p>
|
||||
</Tooltip>
|
||||
)}
|
||||
</Flex>
|
||||
|
||||
<TaskDrawerStatusDropdown
|
||||
statuses={taskFormViewModel?.statuses ?? []}
|
||||
task={taskFormViewModel?.task ?? ({} as ITaskViewModel)}
|
||||
teamId={currentSession?.team_id ?? ''}
|
||||
/>
|
||||
|
||||
<Dropdown overlayClassName={'delete-task-dropdown'} menu={{ items: deletTaskDropdownItems }}>
|
||||
<Button type="text" icon={<EllipsisOutlined />} />
|
||||
</Dropdown>
|
||||
</Flex>
|
||||
|
||||
<TaskDrawerStatusDropdown
|
||||
statuses={taskFormViewModel?.statuses ?? []}
|
||||
task={taskFormViewModel?.task ?? ({} as ITaskViewModel)}
|
||||
teamId={currentSession?.team_id ?? ''}
|
||||
/>
|
||||
|
||||
<Dropdown overlayClassName={'delete-task-dropdown'} menu={{ items: deletTaskDropdownItems }}>
|
||||
<Button type="text" icon={<EllipsisOutlined />} />
|
||||
</Dropdown>
|
||||
</Flex>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import Drawer from 'antd/es/drawer';
|
||||
import { InputRef } from 'antd/es/input';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import { PlusOutlined, CloseOutlined, ArrowLeftOutlined } from '@ant-design/icons';
|
||||
|
||||
import { useAppSelector } from '@/hooks/useAppSelector';
|
||||
import { useAppDispatch } from '@/hooks/useAppDispatch';
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
setTaskFormViewModel,
|
||||
setTaskSubscribers,
|
||||
setTimeLogEditing,
|
||||
fetchTask,
|
||||
} from '@/features/task-drawer/task-drawer.slice';
|
||||
|
||||
import './task-drawer.css';
|
||||
@@ -33,6 +34,7 @@ const TaskDrawer = () => {
|
||||
|
||||
const { showTaskDrawer, timeLogEditing } = useAppSelector(state => state.taskDrawerReducer);
|
||||
const { taskFormViewModel, selectedTaskId } = useAppSelector(state => state.taskDrawerReducer);
|
||||
const { projectId } = useAppSelector(state => state.projectReducer);
|
||||
const taskNameInputRef = useRef<InputRef>(null);
|
||||
const isClosingManually = useRef(false);
|
||||
|
||||
@@ -54,6 +56,17 @@ const TaskDrawer = () => {
|
||||
dispatch(setTaskSubscribers([]));
|
||||
};
|
||||
|
||||
const handleBackToParent = () => {
|
||||
if (taskFormViewModel?.task?.parent_task_id && projectId) {
|
||||
// Navigate to parent task
|
||||
dispatch(setSelectedTaskId(taskFormViewModel.task.parent_task_id));
|
||||
dispatch(fetchTask({
|
||||
taskId: taskFormViewModel.task.parent_task_id,
|
||||
projectId
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
const handleOnClose = (
|
||||
e?: React.MouseEvent<Element, MouseEvent> | React.KeyboardEvent<Element>
|
||||
) => {
|
||||
@@ -68,10 +81,8 @@ const TaskDrawer = () => {
|
||||
if (isClickOutsideDrawer || !taskFormViewModel?.task?.is_sub_task) {
|
||||
resetTaskState();
|
||||
} else {
|
||||
dispatch(setSelectedTaskId(null));
|
||||
dispatch(setTaskFormViewModel({}));
|
||||
dispatch(setTaskSubscribers([]));
|
||||
dispatch(setSelectedTaskId(taskFormViewModel?.task?.parent_task_id || null));
|
||||
// For sub-tasks, navigate to parent instead of closing
|
||||
handleBackToParent();
|
||||
}
|
||||
// Reset the flag after a short delay
|
||||
setTimeout(() => {
|
||||
@@ -205,6 +216,17 @@ const TaskDrawer = () => {
|
||||
};
|
||||
};
|
||||
|
||||
// Check if current task is a sub-task
|
||||
const isSubTask = taskFormViewModel?.task?.is_sub_task || !!taskFormViewModel?.task?.parent_task_id;
|
||||
|
||||
// Custom close icon based on whether it's a sub-task
|
||||
const getCloseIcon = () => {
|
||||
if (isSubTask) {
|
||||
return <ArrowLeftOutlined />;
|
||||
}
|
||||
return <CloseOutlined />;
|
||||
};
|
||||
|
||||
const drawerProps = {
|
||||
open: showTaskDrawer,
|
||||
onClose: handleOnClose,
|
||||
@@ -215,6 +237,7 @@ const TaskDrawer = () => {
|
||||
footer: renderFooter(),
|
||||
bodyStyle: getBodyStyle(),
|
||||
footerStyle: getFooterStyle(),
|
||||
closeIcon: getCloseIcon(),
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
.task-hierarchy-breadcrumb {
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.task-hierarchy-breadcrumb .ant-breadcrumb {
|
||||
font-size: 14px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.task-hierarchy-breadcrumb .ant-breadcrumb-link {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.task-hierarchy-breadcrumb .ant-breadcrumb-separator {
|
||||
color: #8c8c8c;
|
||||
margin: 0 4px;
|
||||
}
|
||||
|
||||
/* Dark mode styles */
|
||||
[data-theme='dark'] .task-hierarchy-breadcrumb .ant-breadcrumb-separator {
|
||||
color: #595959;
|
||||
}
|
||||
|
||||
/* Back button styles */
|
||||
.task-hierarchy-breadcrumb .ant-btn-link {
|
||||
padding: 0;
|
||||
height: auto;
|
||||
font-size: 14px;
|
||||
line-height: 1.3;
|
||||
max-width: 200px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.task-hierarchy-breadcrumb .ant-btn-link .anticon {
|
||||
margin-right: 0; /* Remove default margin */
|
||||
}
|
||||
|
||||
.task-hierarchy-breadcrumb .ant-btn-link:hover {
|
||||
color: #40a9ff;
|
||||
}
|
||||
|
||||
[data-theme='dark'] .task-hierarchy-breadcrumb .ant-btn-link:hover {
|
||||
color: #40a9ff;
|
||||
}
|
||||
|
||||
/* Current task name styles */
|
||||
.task-hierarchy-breadcrumb .current-task-name {
|
||||
font-size: 14px;
|
||||
color: #000000d9;
|
||||
font-weight: 500;
|
||||
max-width: 200px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
display: inline-block;
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
[data-theme='dark'] .task-hierarchy-breadcrumb .current-task-name {
|
||||
color: #ffffffd9;
|
||||
}
|
||||
|
||||
/* Breadcrumb item container */
|
||||
.task-hierarchy-breadcrumb .ant-breadcrumb-item {
|
||||
max-width: 220px;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
/* Ensure breadcrumb items don't break the layout */
|
||||
.task-hierarchy-breadcrumb .ant-breadcrumb ol {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
/* Better alignment for breadcrumb items */
|
||||
.task-hierarchy-breadcrumb .ant-breadcrumb-item .ant-breadcrumb-link {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Breadcrumb, Button, Typography, Tooltip } from 'antd';
|
||||
import { HomeOutlined } from '@ant-design/icons';
|
||||
import { useAppSelector } from '@/hooks/useAppSelector';
|
||||
import { useAppDispatch } from '@/hooks/useAppDispatch';
|
||||
import { fetchTask, setSelectedTaskId } from '@/features/task-drawer/task-drawer.slice';
|
||||
import { tasksApiService } from '@/api/tasks/tasks.api.service';
|
||||
import { TFunction } from 'i18next';
|
||||
import './task-hierarchy-breadcrumb.css';
|
||||
|
||||
interface TaskHierarchyBreadcrumbProps {
|
||||
t: TFunction;
|
||||
onBackClick?: () => void;
|
||||
}
|
||||
|
||||
interface TaskHierarchyItem {
|
||||
id: string;
|
||||
name: string;
|
||||
parent_task_id?: string;
|
||||
}
|
||||
|
||||
// Utility function to truncate text
|
||||
const truncateText = (text: string, maxLength: number = 25): string => {
|
||||
if (!text || text.length <= maxLength) return text;
|
||||
return `${text.substring(0, maxLength)}...`;
|
||||
};
|
||||
|
||||
const TaskHierarchyBreadcrumb: React.FC<TaskHierarchyBreadcrumbProps> = ({ t, onBackClick }) => {
|
||||
const dispatch = useAppDispatch();
|
||||
const { taskFormViewModel } = useAppSelector(state => state.taskDrawerReducer);
|
||||
const { projectId } = useAppSelector(state => state.projectReducer);
|
||||
const themeMode = useAppSelector(state => state.themeReducer.mode);
|
||||
const [hierarchyPath, setHierarchyPath] = useState<TaskHierarchyItem[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const task = taskFormViewModel?.task;
|
||||
const isSubTask = task?.is_sub_task || !!task?.parent_task_id;
|
||||
|
||||
// Recursively fetch the complete hierarchy path
|
||||
const fetchHierarchyPath = async (currentTaskId: string): Promise<TaskHierarchyItem[]> => {
|
||||
if (!projectId) return [];
|
||||
|
||||
const path: TaskHierarchyItem[] = [];
|
||||
let taskId = currentTaskId;
|
||||
|
||||
// Traverse up the hierarchy until we reach the root
|
||||
while (taskId) {
|
||||
try {
|
||||
const response = await tasksApiService.getFormViewModel(taskId, projectId);
|
||||
if (response.done && response.body.task) {
|
||||
const taskData = response.body.task;
|
||||
path.unshift({
|
||||
id: taskData.id,
|
||||
name: taskData.name || '',
|
||||
parent_task_id: taskData.parent_task_id || undefined
|
||||
});
|
||||
|
||||
// Move to parent task
|
||||
taskId = taskData.parent_task_id || '';
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching task in hierarchy:', error);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return path;
|
||||
};
|
||||
|
||||
// Fetch the complete hierarchy when component mounts or task changes
|
||||
useEffect(() => {
|
||||
const loadHierarchy = async () => {
|
||||
if (!isSubTask || !task?.parent_task_id || !projectId) {
|
||||
setHierarchyPath([]);
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const path = await fetchHierarchyPath(task.parent_task_id);
|
||||
setHierarchyPath(path);
|
||||
} catch (error) {
|
||||
console.error('Error loading task hierarchy:', error);
|
||||
setHierarchyPath([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
loadHierarchy();
|
||||
}, [task?.parent_task_id, projectId, isSubTask]);
|
||||
|
||||
const handleNavigateToTask = (taskId: string) => {
|
||||
if (projectId) {
|
||||
if (onBackClick) {
|
||||
onBackClick();
|
||||
}
|
||||
|
||||
// Navigate to the selected task
|
||||
dispatch(setSelectedTaskId(taskId));
|
||||
dispatch(fetchTask({ taskId, projectId }));
|
||||
}
|
||||
};
|
||||
|
||||
if (!isSubTask || hierarchyPath.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Create breadcrumb items from the hierarchy path
|
||||
const breadcrumbItems = [
|
||||
// Add all parent tasks in the hierarchy
|
||||
...hierarchyPath.map((hierarchyTask, index) => {
|
||||
const truncatedName = truncateText(hierarchyTask.name, 25);
|
||||
const shouldShowTooltip = hierarchyTask.name.length > 25;
|
||||
|
||||
return {
|
||||
title: (
|
||||
<Tooltip title={shouldShowTooltip ? hierarchyTask.name : ''} trigger="hover">
|
||||
<Button
|
||||
type="link"
|
||||
icon={index === 0 ? <HomeOutlined /> : undefined}
|
||||
onClick={() => handleNavigateToTask(hierarchyTask.id)}
|
||||
style={{
|
||||
padding: 0,
|
||||
height: 'auto',
|
||||
color: themeMode === 'dark' ? '#1890ff' : '#1890ff',
|
||||
fontSize: '14px',
|
||||
marginRight: '0px',
|
||||
maxWidth: '200px',
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
whiteSpace: 'nowrap',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: index === 0 ? '6px' : '0px', // Add gap between icon and text for root task
|
||||
}}
|
||||
>
|
||||
{truncatedName}
|
||||
</Button>
|
||||
</Tooltip>
|
||||
),
|
||||
};
|
||||
}),
|
||||
// Add the current task as the last item (non-clickable)
|
||||
{
|
||||
title: (() => {
|
||||
const currentTaskName = task?.name || t('taskHeader.currentTask', 'Current Task');
|
||||
const truncatedCurrentName = truncateText(currentTaskName, 25);
|
||||
const shouldShowCurrentTooltip = currentTaskName.length > 25;
|
||||
|
||||
return (
|
||||
<Tooltip title={shouldShowCurrentTooltip ? currentTaskName : ''} trigger="hover">
|
||||
<Typography.Text
|
||||
className="current-task-name"
|
||||
style={{
|
||||
color: themeMode === 'dark' ? '#ffffffd9' : '#000000d9',
|
||||
fontSize: '14px',
|
||||
fontWeight: 500,
|
||||
maxWidth: '200px',
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
whiteSpace: 'nowrap',
|
||||
display: 'inline-block',
|
||||
}}
|
||||
>
|
||||
{truncatedCurrentName}
|
||||
</Typography.Text>
|
||||
</Tooltip>
|
||||
);
|
||||
})(),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="task-hierarchy-breadcrumb">
|
||||
{loading ? (
|
||||
<Typography.Text style={{ color: themeMode === 'dark' ? '#ffffffd9' : '#000000d9' }}>
|
||||
{t('taskHeader.loadingHierarchy', 'Loading hierarchy...')}
|
||||
</Typography.Text>
|
||||
) : (
|
||||
<Breadcrumb items={breadcrumbItems} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default TaskHierarchyBreadcrumb;
|
||||
Reference in New Issue
Block a user