#138 fix on filtration of projects by id and active status

parent 3deb8fcb
...@@ -18,9 +18,9 @@ export default function MyTaskToolBar({projects,onClickActiveTasks,activeTasksOn ...@@ -18,9 +18,9 @@ export default function MyTaskToolBar({projects,onClickActiveTasks,activeTasksOn
projectsFilter= projectsFilter=
<MultipleSelect <MultipleSelect
projects={projects} projects={projects}
onClose={onCloseFilterByProjects} onCloseFilterByProjects={onCloseFilterByProjects}
projectName={projectIdListForTaskSelect} projectIdListForTaskSelect={projectIdListForTaskSelect}
setProjectName={setProjectIdListForTaskSelect} setProjectIdListForTaskSelect={setProjectIdListForTaskSelect}
/> />
} }
...@@ -40,7 +40,7 @@ export default function MyTaskToolBar({projects,onClickActiveTasks,activeTasksOn ...@@ -40,7 +40,7 @@ export default function MyTaskToolBar({projects,onClickActiveTasks,activeTasksOn
style={{ style={{
backgroundColor: activeTasksOn === true ? "red" : "inherit", backgroundColor: activeTasksOn === true ? "red" : "inherit",
}} }}
onClick={onClickActiveTasks} onClick={()=>onClickActiveTasks()}
> >
Активные задачи Активные задачи
</Button> </Button>
......
...@@ -28,15 +28,15 @@ function getStyles(name, personName, theme) { ...@@ -28,15 +28,15 @@ function getStyles(name, personName, theme) {
}; };
} }
export default function MultipleSelect({projects,projectName,onClose,setProjectName}) { export default function MultipleSelect({projects,onCloseFilterByProjects}) {
const theme = useTheme(); const theme = useTheme();
const [listProjectIds, setListProjectIds ] = React.useState([])
const handleChange = (event) => { const handleChange = (event) => {
const { const {
target: { value }, target: { value },
} = event; } = event;
setProjectName( setListProjectIds(
// On autofill we get a stringified value. // On autofill we get a stringified value.
typeof value === 'string' ? value.split(',') : value, typeof value === 'string' ? value.split(',') : value,
); );
...@@ -55,18 +55,18 @@ export default function MultipleSelect({projects,projectName,onClose,setProjectN ...@@ -55,18 +55,18 @@ export default function MultipleSelect({projects,projectName,onClose,setProjectN
name='Choose Project' name='Choose Project'
id="demo-multiple-name" id="demo-multiple-name"
multiple multiple
value={projectName} value={listProjectIds}
onChange={handleChange} onChange={handleChange}
input={<OutlinedInput label="Name" />} input={<OutlinedInput label="Name" />}
MenuProps={MenuProps} MenuProps={MenuProps}
sx={{color:'white' }} sx={{color:'white' }}
onClose={(e)=>{onClose(projectName)}} onClose={(e)=>{onCloseFilterByProjects(listProjectIds)}}
> >
{projects?.map((project,index) => ( {projects?.map((project,index) => (
<MenuItem <MenuItem
key={index} key={index}
value={project.id} value={project.id}
style={getStyles(project.title, projectName, theme)} style={getStyles(project.title, listProjectIds, theme)}
> >
{project.title} {project.title}
</MenuItem> </MenuItem>
......
...@@ -50,11 +50,24 @@ export default function EnhancedTable() { ...@@ -50,11 +50,24 @@ export default function EnhancedTable() {
addTaskForm, setAddTaskForm, addTaskForm, setAddTaskForm,
// onClickActiveTasks, // onClickActiveTasks,
// activeTasksOn, // activeTasksOn,
dispatch]); dispatch
]);
// console.log('tasks ', tasks, 'projects ', projects,"recievedTasks ", recievedTasks ) // console.log('tasks ', tasks, 'projects ', projects,"recievedTasks ", recievedTasks )
useEffect(() => {
let filteredTasks = tasks;
if (activeTasksOn) {
filteredTasks = filteredTasks.filter(task=>task.accomplish==='opened' || task.accomplish==='progress')
}
if (projectIdListForTaskSelect.length>0) {
filteredTasks = filteredTasks.filter(task=>projectIdListForTaskSelect.includes(task.project?.id))
}
setRecievedTasks(filteredTasks)
}, [activeTasksOn, projectIdListForTaskSelect]);
const handleRequestSort = ( property) => { const handleRequestSort = ( property) => {
const isAsc = orderBy === property && order === "asc"; const isAsc = orderBy === property && order === "asc";
...@@ -186,21 +199,16 @@ export default function EnhancedTable() { ...@@ -186,21 +199,16 @@ export default function EnhancedTable() {
const onCloseFilterByProjects=(projectIdListForTaskSelect)=>{ const onCloseFilterByProjects=(listProjectIds)=>{
let tasksFilteredByProject = tasks setProjectIdListForTaskSelect(listProjectIds)
if (projectIdListForTaskSelect.length>0) {
tasksFilteredByProject = tasks.filter(task=>projectIdListForTaskSelect.includes(task.project?.id))
}
console.log('tasksFilteredByProject ', tasksFilteredByProject)
setRecievedTasks(tasksFilteredByProject)
// setFilterProjectTumbler(true)
} }
const onClickActiveTasks= ()=>{ const onClickActiveTasks= ()=>{
console.log('active tasts before switched to ', activeTasksOn) console.log('active tasts before switched to ', activeTasksOn)
setActiveTasksOn((prevState)=>{return !prevState}) // setActiveTasksOn((prevState)=>{return !prevState})
setActiveTasksOn(!activeTasksOn)
console.log('active tasts after switch ', activeTasksOn) console.log('active tasts after switch ', activeTasksOn)
if (activeTasksOn) { if (activeTasksOn) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment