feat(task-filters): enhance archived task handling in task management

- Introduced state management for archived tasks in the task management slice, allowing for better control over task visibility.
- Updated ImprovedTaskFilters component to utilize the new archived state, enabling toggling of archived tasks based on the current view (list or kanban).
- Refactored related functions to ensure proper dispatching of archived state changes, improving user experience and task management efficiency.
This commit is contained in:
chamiakJ
2025-07-07 02:38:50 +05:30
parent 8d8250bc17
commit 9a57413624
3 changed files with 40 additions and 9 deletions

View File

@@ -26,6 +26,9 @@ import { toggleField } from '@/features/task-management/taskListFields.slice';
import { import {
fetchTasksV3, fetchTasksV3,
setSearch as setTaskManagementSearch, setSearch as setTaskManagementSearch,
setArchived as setTaskManagementArchived,
toggleArchived as toggleTaskManagementArchived,
selectArchived,
} from '@/features/task-management/task-management.slice'; } from '@/features/task-management/task-management.slice';
import { import {
setCurrentGrouping, setCurrentGrouping,
@@ -828,13 +831,17 @@ const ImprovedTaskFilters: React.FC<ImprovedTaskFiltersProps> = ({ position, cla
// Enhanced Kanban state // Enhanced Kanban state
const kanbanState = useAppSelector((state: RootState) => state.enhancedKanbanReducer); const kanbanState = useAppSelector((state: RootState) => state.enhancedKanbanReducer);
// Get archived state from the appropriate slice based on position
const taskManagementArchived = useAppSelector(selectArchived);
const taskReducerArchived = useAppSelector(state => state.taskReducer.archived);
const showArchived = position === 'list' ? taskManagementArchived : taskReducerArchived;
// Use the filter data loader hook // Use the filter data loader hook
useFilterDataLoader(); useFilterDataLoader();
// Local state for filter sections // Local state for filter sections
const [filterSections, setFilterSections] = useState<FilterSection[]>([]); const [filterSections, setFilterSections] = useState<FilterSection[]>([]);
const [searchValue, setSearchValue] = useState(''); const [searchValue, setSearchValue] = useState('');
const [showArchived, setShowArchived] = useState(false);
const [openDropdown, setOpenDropdown] = useState<string | null>(null); const [openDropdown, setOpenDropdown] = useState<string | null>(null);
const [activeFiltersCount, setActiveFiltersCount] = useState(0); const [activeFiltersCount, setActiveFiltersCount] = useState(0);
const [clearingFilters, setClearingFilters] = useState(false); const [clearingFilters, setClearingFilters] = useState(false);
@@ -1079,7 +1086,6 @@ const ImprovedTaskFilters: React.FC<ImprovedTaskFiltersProps> = ({ position, cla
const batchUpdates = () => { const batchUpdates = () => {
// Clear local state immediately for UI feedback // Clear local state immediately for UI feedback
setSearchValue(''); setSearchValue('');
setShowArchived(false);
// Update local filter sections state immediately // Update local filter sections state immediately
setFilterSections(prev => setFilterSections(prev =>
@@ -1118,6 +1124,13 @@ const ImprovedTaskFilters: React.FC<ImprovedTaskFiltersProps> = ({ position, cla
// Clear priority filters // Clear priority filters
dispatch(setPriorities([])); dispatch(setPriorities([]));
// Clear archived state based on position
if (position === 'list') {
dispatch(setTaskManagementArchived(false));
} else {
dispatch(setKanbanArchived(false));
}
}; };
// Execute Redux updates // Execute Redux updates
@@ -1139,14 +1152,17 @@ const ImprovedTaskFilters: React.FC<ImprovedTaskFiltersProps> = ({ position, cla
}, [projectId, projectView, dispatch, currentTaskLabels, currentTaskAssignees, clearingFilters]); }, [projectId, projectView, dispatch, currentTaskLabels, currentTaskAssignees, clearingFilters]);
const toggleArchived = useCallback(() => { const toggleArchived = useCallback(() => {
setShowArchived(!showArchived);
if (position === 'board') { if (position === 'board') {
dispatch(setKanbanArchived(!showArchived)); dispatch(setKanbanArchived(!showArchived));
if (projectId) { if (projectId) {
dispatch(fetchEnhancedKanbanGroups(projectId)); dispatch(fetchEnhancedKanbanGroups(projectId));
} }
} else { } else {
// ... existing logic ... // For TaskListV2, use the task management slice
dispatch(toggleTaskManagementArchived());
if (projectId) {
dispatch(fetchTasksV3(projectId));
}
} }
}, [dispatch, projectId, position, showArchived]); }, [dispatch, projectId, position, showArchived]);

View File

@@ -57,6 +57,7 @@ const initialState: TaskManagementState = {
grouping: undefined, grouping: undefined,
selectedPriorities: [], selectedPriorities: [],
search: '', search: '',
archived: false,
loadingSubtasks: {}, loadingSubtasks: {},
// Add column-related state // Add column-related state
loadingColumns: false, loadingColumns: false,
@@ -227,9 +228,12 @@ export const fetchTasksV3 = createAsyncThunk(
// Get search value from taskReducer // Get search value from taskReducer
const searchValue = state.taskReducer.search || ''; const searchValue = state.taskReducer.search || '';
// Get archived state from task management slice
const archivedState = state.taskManagement.archived;
const config: ITaskListConfigV2 = { const config: ITaskListConfigV2 = {
id: projectId, id: projectId,
archived: false, archived: archivedState,
group: currentGrouping || '', group: currentGrouping || '',
field: '', field: '',
order: '', order: '',
@@ -240,13 +244,11 @@ export const fetchTasksV3 = createAsyncThunk(
isSubtasksInclude: false, isSubtasksInclude: false,
labels: selectedLabels, labels: selectedLabels,
priorities: selectedPriorities, priorities: selectedPriorities,
customColumns: true, // Include custom columns in the response customColumns: true,
}; };
const response = await tasksApiService.getTaskListV3(config); const response = await tasksApiService.getTaskListV3(config);
// Ensure tasks are properly normalized // Ensure tasks are properly normalized
const tasks: Task[] = response.body.allTasks.map((task: any) => { const tasks: Task[] = response.body.allTasks.map((task: any) => {
const now = new Date().toISOString(); const now = new Date().toISOString();
@@ -276,7 +278,7 @@ export const fetchTasksV3 = createAsyncThunk(
logged: convertTimeValue(task.time_spent), logged: convertTimeValue(task.time_spent),
}, },
customFields: {}, customFields: {},
custom_column_values: task.custom_column_values || {}, // Include custom column values custom_column_values: task.custom_column_values || {},
createdAt: task.created_at || now, createdAt: task.created_at || now,
updatedAt: task.updated_at || now, updatedAt: task.updated_at || now,
created_at: task.created_at || now, created_at: task.created_at || now,
@@ -738,6 +740,12 @@ const taskManagementSlice = createSlice({
setSearch: (state, action: PayloadAction<string>) => { setSearch: (state, action: PayloadAction<string>) => {
state.search = action.payload; state.search = action.payload;
}, },
setArchived: (state, action: PayloadAction<boolean>) => {
state.archived = action.payload;
},
toggleArchived: (state) => {
state.archived = !state.archived;
},
resetTaskManagement: state => { resetTaskManagement: state => {
state.loading = false; state.loading = false;
state.error = null; state.error = null;
@@ -745,6 +753,7 @@ const taskManagementSlice = createSlice({
state.grouping = undefined; state.grouping = undefined;
state.selectedPriorities = []; state.selectedPriorities = [];
state.search = ''; state.search = '';
state.archived = false;
state.ids = []; state.ids = [];
state.entities = {}; state.entities = {};
}, },
@@ -1077,6 +1086,8 @@ export const {
setError, setError,
setSelectedPriorities, setSelectedPriorities,
setSearch, setSearch,
setArchived,
toggleArchived,
resetTaskManagement, resetTaskManagement,
toggleTaskExpansion, toggleTaskExpansion,
addSubtaskToParent, addSubtaskToParent,
@@ -1114,6 +1125,9 @@ export const selectTasksByPriority = (state: RootState, priority: string) =>
export const selectTasksByPhase = (state: RootState, phase: string) => export const selectTasksByPhase = (state: RootState, phase: string) =>
Object.values(state.taskManagement.entities).filter(task => task.phase === phase); Object.values(state.taskManagement.entities).filter(task => task.phase === phase);
// Add archived selector
export const selectArchived = (state: RootState) => state.taskManagement.archived;
// Export the reducer as default // Export the reducer as default
export default taskManagementSlice.reducer; export default taskManagementSlice.reducer;

View File

@@ -100,6 +100,7 @@ export interface TaskManagementState {
grouping: string | undefined; grouping: string | undefined;
selectedPriorities: string[]; selectedPriorities: string[];
search: string; search: string;
archived: boolean;
loadingSubtasks: Record<string, boolean>; // Track loading state for individual tasks loadingSubtasks: Record<string, boolean>; // Track loading state for individual tasks
loadingColumns: boolean; loadingColumns: boolean;
columns: ITaskListColumn[]; columns: ITaskListColumn[];