Commit d8b93d48 authored by Ermolaev Timur's avatar Ermolaev Timur

#154 добавил сортировку по активным задачам

parent 94d3fe63
...@@ -8,7 +8,7 @@ function CreateTaskFromButton({ addFormStatus, onClick }) { ...@@ -8,7 +8,7 @@ function CreateTaskFromButton({ addFormStatus, onClick }) {
color={addFormStatus === true ? "info" : "inherit"} color={addFormStatus === true ? "info" : "inherit"}
style={{ style={{
backgroundColor: addFormStatus === true ? "white" : "inherit", backgroundColor: addFormStatus === true ? "white" : "inherit",
width: '250px' width: '280px'
}} }}
onClick={onClick} onClick={onClick}
> >
......
import { AppBar, Box, Typography } from "@mui/material"; import { AppBar, Box, FormControlLabel, Switch, Typography } from "@mui/material";
import { memo, useMemo } from "react"; import { memo, useMemo } from "react";
import MultipleSelect from "../../UI/MultipleSelect/MultipleSelect"; import MultipleSelect from "../../UI/MultipleSelect/MultipleSelect";
import CreateTaskFromButton from "./CreateTaskFromButton/CreateTaskFromButton"; import CreateTaskFromButton from "./CreateTaskFromButton/CreateTaskFromButton";
function MyTasksTableToolbar({ addFormStatus, createTaskFromButtonHandler, projects, onCloseFilterByProjects, projectIdListForTaskSelect, setProjectIdListForTaskSelect}) { function MyTasksTableToolbar({ addFormStatus, createTaskFromButtonHandler, projects, onCloseFilterByProjects, projectIdListForTaskSelect, setProjectIdListForTaskSelect, activeTasksOn, setActiveTasksOn }) {
const projectsFilter = useMemo(() => { const projectsFilter = useMemo(() => {
if (Array.isArray(projects)) { if (Array.isArray(projects)) {
...@@ -17,27 +17,32 @@ function MyTasksTableToolbar({ addFormStatus, createTaskFromButtonHandler, proje ...@@ -17,27 +17,32 @@ function MyTasksTableToolbar({ addFormStatus, createTaskFromButtonHandler, proje
} else { } else {
return null return null
} }
}, [projects, onCloseFilterByProjects, projectIdListForTaskSelect, setProjectIdListForTaskSelect]) }, [projects, onCloseFilterByProjects, projectIdListForTaskSelect, setProjectIdListForTaskSelect])
return ( return (
<AppBar position="static" sx={{ padding: 3 }}> <AppBar position="static" sx={{ padding: 3 }}>
<Box sx={{ display: 'flex', alignItems: 'center' }}> <Box sx={{ display: 'flex', alignItems: 'center' }}>
<Typography <Typography
sx={{ flex: '1 1 100%' }} sx={{ flex: '1 1 100%' }}
variant="h6" variant="h6"
id="tableTitle" id="tableTitle"
component="div" component="div"
> >
Мои задачи Мои задачи
</Typography> </Typography>
{projectsFilter} <FormControlLabel
<CreateTaskFromButton control={<Switch color='error' checked={activeTasksOn} onChange={() => { setActiveTasksOn(prevState=>!prevState) }} />}
addFormStatus={addFormStatus} label="Активные задачи"
onClick={() => { createTaskFromButtonHandler() }} labelPlacement="end"
/> />
</Box> {projectsFilter}
</AppBar> <CreateTaskFromButton
); addFormStatus={addFormStatus}
onClick={() => { createTaskFromButtonHandler() }}
/>
</Box>
</AppBar>
);
} }
export default memo(MyTasksTableToolbar) export default memo(MyTasksTableToolbar)
\ No newline at end of file
...@@ -8,7 +8,7 @@ function CreateTaskFromButton({ addFormStatus, onClick }) { ...@@ -8,7 +8,7 @@ function CreateTaskFromButton({ addFormStatus, onClick }) {
color={addFormStatus === true ? "info" : "inherit"} color={addFormStatus === true ? "info" : "inherit"}
style={{ style={{
backgroundColor: addFormStatus === true ? "white" : "inherit", backgroundColor: addFormStatus === true ? "white" : "inherit",
width: '250px' width: '280px'
}} }}
onClick={onClick} onClick={onClick}
> >
......
import { AppBar, Box, Typography } from "@mui/material"; import { AppBar, Box, FormControlLabel, Switch, Typography } from "@mui/material";
import { memo, useMemo } from "react"; import { memo, useMemo } from "react";
import MultipleSelect from "../../UI/MultipleSelect/MultipleSelect"; import MultipleSelect from "../../UI/MultipleSelect/MultipleSelect";
import CreateTaskFromButton from "./CreateTaskFromButton/CreateTaskFromButton"; import CreateTaskFromButton from "./CreateTaskFromButton/CreateTaskFromButton";
function UsersTasksTableToolbar({ addFormStatus, createTaskFromButtonHandler, projects, onCloseFilterByProjects, projectIdListForTaskSelect, setProjectIdListForTaskSelect}) { function UsersTasksTableToolbar({ addFormStatus, createTaskFromButtonHandler, projects, onCloseFilterByProjects, projectIdListForTaskSelect, setProjectIdListForTaskSelect, activeTasksOn, setActiveTasksOn}) {
const projectsFilter = useMemo(() => { const projectsFilter = useMemo(() => {
if (Array.isArray(projects)) { if (Array.isArray(projects)) {
...@@ -30,6 +30,11 @@ return ( ...@@ -30,6 +30,11 @@ return (
> >
Задачи сотрудников Задачи сотрудников
</Typography> </Typography>
<FormControlLabel
control={<Switch color='error' checked={activeTasksOn} onChange={() => { setActiveTasksOn(prevState=>!prevState) }} />}
label="Активные задачи"
labelPlacement="end"
/>
{projectsFilter} {projectsFilter}
<CreateTaskFromButton <CreateTaskFromButton
addFormStatus={addFormStatus} addFormStatus={addFormStatus}
......
...@@ -39,6 +39,7 @@ export default function MyTasks() { ...@@ -39,6 +39,7 @@ export default function MyTasks() {
const [rowsPerPage, setRowsPerPage] = useState(10); const [rowsPerPage, setRowsPerPage] = useState(10);
const [addFormStatus, setAddFormStatus] = useState(false); const [addFormStatus, setAddFormStatus] = useState(false);
const [projectIdListForTaskSelect, setProjectIdListForTaskSelect] = useState([]); const [projectIdListForTaskSelect, setProjectIdListForTaskSelect] = useState([]);
const [activeTasksOn, setActiveTasksOn] = useState(false)
useEffect(() => { useEffect(() => {
dispatch(fetchAllTasks()); dispatch(fetchAllTasks());
...@@ -47,8 +48,8 @@ export default function MyTasks() { ...@@ -47,8 +48,8 @@ export default function MyTasks() {
}, [dispatch]); }, [dispatch]);
useEffect(() => { useEffect(() => {
dispatch(sortTaskByProjects(projectIdListForTaskSelect)) dispatch(sortTaskByProjects(projectIdListForTaskSelect, activeTasksOn))
}, [dispatch, projectIdListForTaskSelect]); }, [dispatch, projectIdListForTaskSelect, activeTasksOn, tasks]);
const onChangeNewTaskHandler = useCallback((e) => { const onChangeNewTaskHandler = useCallback((e) => {
...@@ -173,6 +174,7 @@ export default function MyTasks() { ...@@ -173,6 +174,7 @@ export default function MyTasks() {
setProjectIdListForTaskSelect(listProjectIds) setProjectIdListForTaskSelect(listProjectIds)
}, []) }, [])
return ( return (
<Paper sx={{ width: '100%', mb: 2 }}> <Paper sx={{ width: '100%', mb: 2 }}>
<MyTasksTableToolbar <MyTasksTableToolbar
...@@ -182,12 +184,14 @@ export default function MyTasks() { ...@@ -182,12 +184,14 @@ export default function MyTasks() {
projectIdListForTaskSelect={projectIdListForTaskSelect} projectIdListForTaskSelect={projectIdListForTaskSelect}
setProjectIdListForTaskSelect={setProjectIdListForTaskSelect} setProjectIdListForTaskSelect={setProjectIdListForTaskSelect}
projects={projects.projects} projects={projects.projects}
activeTasksOn={activeTasksOn}
setActiveTasksOn={setActiveTasksOn}
/> />
<MyTasksTableContainer <MyTasksTableContainer
order={order} order={order}
orderBy={orderBy} orderBy={orderBy}
handleRequestSort={handleRequestSort} handleRequestSort={handleRequestSort}
rows={projectIdListForTaskSelect.length ? sortedTasks : tasks} rows={sortedTasks.length ? sortedTasks : tasks}
page={page} page={page}
rowsPerPage={rowsPerPage} rowsPerPage={rowsPerPage}
addFormStatus={addFormStatus} addFormStatus={addFormStatus}
...@@ -206,7 +210,7 @@ export default function MyTasks() { ...@@ -206,7 +210,7 @@ export default function MyTasks() {
editCurrentTaskHandler={editCurrentTaskHandler} editCurrentTaskHandler={editCurrentTaskHandler}
/> />
<MyTasksTablePagination <MyTasksTablePagination
count={projectIdListForTaskSelect.length ? sortedTasks.length : tasks.length} count={sortedTasks.length ? sortedTasks.length : tasks.length}
rowsPerPage={rowsPerPage} rowsPerPage={rowsPerPage}
page={page} page={page}
handleChangePage={handleChangePage} handleChangePage={handleChangePage}
......
...@@ -40,6 +40,7 @@ export default function UsersTasks() { ...@@ -40,6 +40,7 @@ export default function UsersTasks() {
const [rowsPerPage, setRowsPerPage] = useState(10); const [rowsPerPage, setRowsPerPage] = useState(10);
const [addFormStatus, setAddFormStatus] = useState(false); const [addFormStatus, setAddFormStatus] = useState(false);
const [projectIdListForTaskSelect, setProjectIdListForTaskSelect] = useState([]); const [projectIdListForTaskSelect, setProjectIdListForTaskSelect] = useState([]);
const [activeTasksOn, setActiveTasksOn] = useState(false)
useEffect(() => { useEffect(() => {
dispatch(fetchAllTasksByMembership()); dispatch(fetchAllTasksByMembership());
...@@ -48,8 +49,8 @@ export default function UsersTasks() { ...@@ -48,8 +49,8 @@ export default function UsersTasks() {
}, [dispatch]); }, [dispatch]);
useEffect(() => { useEffect(() => {
dispatch(sortTaskByProjects(projectIdListForTaskSelect)) dispatch(sortTaskByProjects(projectIdListForTaskSelect, activeTasksOn))
}, [dispatch, projectIdListForTaskSelect]); }, [dispatch, projectIdListForTaskSelect, activeTasksOn, tasks]);
const onChangeNewTaskHandler = useCallback((e) => { const onChangeNewTaskHandler = useCallback((e) => {
...@@ -194,12 +195,14 @@ export default function UsersTasks() { ...@@ -194,12 +195,14 @@ export default function UsersTasks() {
projectIdListForTaskSelect={projectIdListForTaskSelect} projectIdListForTaskSelect={projectIdListForTaskSelect}
setProjectIdListForTaskSelect={setProjectIdListForTaskSelect} setProjectIdListForTaskSelect={setProjectIdListForTaskSelect}
projects={projects.projects} projects={projects.projects}
activeTasksOn={activeTasksOn}
setActiveTasksOn={setActiveTasksOn}
/> />
<UsersTasksTableContainer <UsersTasksTableContainer
order={order} order={order}
orderBy={orderBy} orderBy={orderBy}
handleRequestSort={handleRequestSort} handleRequestSort={handleRequestSort}
rows={projectIdListForTaskSelect.length ? sortedTasks : tasks} rows={sortedTasks.length ? sortedTasks : tasks}
page={page} page={page}
rowsPerPage={rowsPerPage} rowsPerPage={rowsPerPage}
addFormStatus={addFormStatus} addFormStatus={addFormStatus}
...@@ -218,7 +221,7 @@ export default function UsersTasks() { ...@@ -218,7 +221,7 @@ export default function UsersTasks() {
editCurrentTaskHandler={editCurrentTaskHandler} editCurrentTaskHandler={editCurrentTaskHandler}
/> />
<UsersTasksTablePagination <UsersTasksTablePagination
count={projectIdListForTaskSelect.length ? sortedTasks.length : tasks.length} count={sortedTasks.length ? sortedTasks.length : tasks.length}
rowsPerPage={rowsPerPage} rowsPerPage={rowsPerPage}
page={page} page={page}
handleChangePage={handleChangePage} handleChangePage={handleChangePage}
......
...@@ -87,8 +87,8 @@ export const fetchAllTasksByMembership = () => { ...@@ -87,8 +87,8 @@ export const fetchAllTasksByMembership = () => {
//**end*/ //**end*/
export const sortTaskByProjects = (projectIdListForTaskSelect) => { export const sortTaskByProjects = (projectIdListForTaskSelect, activeTasksOn) => {
return { type: SORT_TASKS, projectIdListForTaskSelect } return { type: SORT_TASKS, projectIdListForTaskSelect: projectIdListForTaskSelect, activeTasksOn: activeTasksOn }
} }
......
...@@ -156,7 +156,17 @@ const tasksReduсer = (state = initialState, action) => { ...@@ -156,7 +156,17 @@ const tasksReduсer = (state = initialState, action) => {
case DEACTIVATE_CREATE_COPY_TASKS_MODE: case DEACTIVATE_CREATE_COPY_TASKS_MODE:
return { ...state, copyMode: { working: false, task: null } } return { ...state, copyMode: { working: false, task: null } }
case SORT_TASKS: case SORT_TASKS:
const filteredTasks = state.tasks.filter(task=>action.projectIdListForTaskSelect.includes(task.project?.id)) let filteredTasks = []
if (action.activeTasksOn) {
filteredTasks = state.tasks.filter(task=>task.accomplish==='opened' || task.accomplish==='progress')
}
if (action.projectIdListForTaskSelect.length) {
if (filteredTasks.length) {
filteredTasks = filteredTasks.filter(task=>action.projectIdListForTaskSelect.includes(task.project?.id))
} else {
filteredTasks = state.tasks.filter(task=>action.projectIdListForTaskSelect.includes(task.project?.id))
}
}
return { ...state, loading: false, sortedTasks: filteredTasks }; return { ...state, loading: false, sortedTasks: filteredTasks };
default: default:
return state; return state;
......
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