Commit b6d42153 authored by Ermolaev Timur's avatar Ermolaev Timur

#149 немного починил сортировки и сделал более стабильное отображение таблицы

parent 4b9c6870
...@@ -101,7 +101,7 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen, ...@@ -101,7 +101,7 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen,
const returnTask = useMemo(() => { const returnTask = useMemo(() => {
if (copyModeTask?.id === task?.mainTaskId) { if (copyModeTask?.id === task?.mainTaskId) {
return (<> return (<>
<span style={{ textOverflow: 'ellipsis', padding: '5px 0 0 5px' }}> <span style={{ maxWidth: '80%', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', padding: '5px 0 0 5px' }}>
{task.title} {task.title}
</span> </span>
<DeleteIcon <DeleteIcon
...@@ -121,7 +121,7 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen, ...@@ -121,7 +121,7 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen,
</>) </>)
} else { } else {
return (<> return (<>
<span style={{ textOverflow: 'ellipsis', padding: '5px 0 0 5px' }}> <span style={{ maxWidth: '80%', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', padding: '5px 0 0 5px' }}>
{task.title} {task.title}
</span> </span>
<CopyIcon <CopyIcon
......
import { TableBody, TableCell, TableRow} from "@mui/material"; import { Divider, TableBody, TableCell, TableRow, Tooltip } from "@mui/material";
import moment from "moment";
import { memo } from "react"; import { memo } from "react";
import DeleteButton from "../../../UI/DeleteButton/DeleteButton";
import { getComparator, stableSort } from "./helpers"; import { getComparator, stableSort } from "./helpers";
import { Done, Edit } from "@mui/icons-material";
function UsersTasksTableBody({rows, page, rowsPerPage, order, orderBy}) { function UsersTasksTableBody({ rows, page, rowsPerPage, order, orderBy }) {
return ( return (
<TableBody> <TableBody>
...@@ -12,24 +15,29 @@ function UsersTasksTableBody({rows, page, rowsPerPage, order, orderBy}) { ...@@ -12,24 +15,29 @@ function UsersTasksTableBody({rows, page, rowsPerPage, order, orderBy}) {
return ( return (
<TableRow <TableRow
hover hover
tabIndex={-1} key={row.id}
key={row.name}
> >
<TableCell <TableCell sx={{ width: '4%' }}>{row.priority ? row.priority : null}</TableCell>
component="th" <TableCell sx={{ width: '10%' }}>{moment(row.createdAt).format('DD.MM.YYYY')}</TableCell>
scope="row" <Tooltip title={row.description}>
padding="none" <TableCell sx={{ width: '25%', overflow: 'hidden', overflow: 'hidden', textOverflow: 'ellipsis'}}>
> {row.title}
{row.name} </TableCell>
</Tooltip>
<TableCell sx={{ width: '10%' }}>{row.projectTitle}</TableCell>
<TableCell sx={{ width: '8%' }}>{row.executorName}</TableCell>
<TableCell sx={{ width: '8%' }}>{row.authorName}</TableCell>
<TableCell sx={{ width: '15%' }}>{row.dateTimeTasks.length ? row.dateTimeTasks[0].dateTimeStart : null}</TableCell>
<TableCell sx={{ width: '10%' }}>{row.dateTimeDeadLine ? moment(row.dateTimeDeadLine).utcOffset('+000').format('DD.MM.YYYY HH:MM') : null}</TableCell>
<TableCell sx={{ width: '7%' }}>{row.accomplish}</TableCell>
<TableCell size='medium' sx={{ width: '5%', position: 'relative' }}>
<Edit sx={{position: 'absolute', left: -10}}/>
<DeleteButton/>
</TableCell> </TableCell>
<TableCell align="right">{row.calories}</TableCell>
<TableCell align="right">{row.fat}</TableCell>
<TableCell align="right">{row.carbs}</TableCell>
<TableCell align="right">{row.protein}</TableCell>
</TableRow> </TableRow>
); );
})} })}
</TableBody> </TableBody >
); );
} }
......
function descendingComparator(a, b, orderBy) { function descendingComparator(a, b, orderBy, order) {
if (!b[orderBy]) {
if (order ==='asc') {
return 1
}
return -1
}
if (b[orderBy] < a[orderBy]) { if (b[orderBy] < a[orderBy]) {
return -1; return -1;
} }
...@@ -9,9 +16,10 @@ function descendingComparator(a, b, orderBy) { ...@@ -9,9 +16,10 @@ function descendingComparator(a, b, orderBy) {
} }
export function getComparator(order, orderBy) { export function getComparator(order, orderBy) {
console.log(order)
return order === 'desc' return order === 'desc'
? (a, b) => descendingComparator(a, b, orderBy) ? (a, b) => descendingComparator(a, b, orderBy)
: (a, b) => -descendingComparator(a, b, orderBy); : (a, b) => -descendingComparator(a, b, orderBy, order);
} }
export function stableSort(array, comparator) { export function stableSort(array, comparator) {
......
...@@ -4,34 +4,84 @@ import { memo } from "react"; ...@@ -4,34 +4,84 @@ import { memo } from "react";
const headCells = [ const headCells = [
{ {
id: 'name', id: "priority",
numeric: false, label: "Приоритет",
disablePadding: false, canSort: true,
label: 'Dessert (100g serving)', style: {
width: '4%'
}
}, },
{ {
id: 'calories', id: "createdAt",
numeric: true, label: "Дата создания",
disablePadding: false, canSort: true,
label: 'Calories', style: {
width: '10%'
}
}, },
{ {
id: 'fat', id: "title",
numeric: true, label: "Заголовок",
disablePadding: false, canSort: true,
label: 'Fat (g)', style: {
width: '25%'
}
}, },
{ {
id: 'carbs', id: "projectTitle",
numeric: true, label: "Проект",
disablePadding: false, canSort: true,
label: 'Carbs (g)', style: {
width: '10%'
}
}, },
{ {
id: 'protein', id: "executorName",
numeric: true, label: "Исполнитель",
disablePadding: false, canSort: true,
label: 'Protein (g)', style: {
width: '8%'
}
},
{
id: "authorName",
label: "Автор",
canSort: true,
style: {
width: '8%'
}
},
{
id: "dateTimeStart",
label: "Дата и время выполнения",
canSort: false,
style: {
width: '15%'
}
},
{
id: "dateTimeDeadLine",
label: "Дедлайн",
canSort: true,
style: {
width: '10%'
}
},
{
id: "accomplish",
label: "Статус",
canSort: true,
style: {
width: '7%'
}
},
{
id: "buttons",
label: "",
canSort: false,
style: {
width: '5%'
}
}, },
]; ];
...@@ -46,11 +96,10 @@ function UsersTasksTableHead({ order, orderBy, handleRequestSort }) { ...@@ -46,11 +96,10 @@ function UsersTasksTableHead({ order, orderBy, handleRequestSort }) {
{headCells.map((headCell) => ( {headCells.map((headCell) => (
<TableCell <TableCell
key={headCell.id} key={headCell.id}
align={headCell.numeric ? 'right' : 'left'}
padding={headCell.disablePadding ? 'none' : 'normal'}
sortDirection={orderBy === headCell.id ? order : false} sortDirection={orderBy === headCell.id ? order : false}
sx={headCell.style}
> >
<TableSortLabel {headCell.canSort ? <TableSortLabel
active={orderBy === headCell.id} active={orderBy === headCell.id}
direction={orderBy === headCell.id ? order : 'asc'} direction={orderBy === headCell.id ? order : 'asc'}
onClick={createSortHandler(headCell.id)} onClick={createSortHandler(headCell.id)}
...@@ -61,7 +110,8 @@ function UsersTasksTableHead({ order, orderBy, handleRequestSort }) { ...@@ -61,7 +110,8 @@ function UsersTasksTableHead({ order, orderBy, handleRequestSort }) {
{order === 'desc' ? 'sorted descending' : 'sorted ascending'} {order === 'desc' ? 'sorted descending' : 'sorted ascending'}
</Box> </Box>
) : null} ) : null}
</TableSortLabel> </TableSortLabel> : headCell.label}
</TableCell> </TableCell>
))} ))}
</TableRow> </TableRow>
......
import { Toolbar, Typography } from "@mui/material"; import { AppBar, Toolbar, Typography } from "@mui/material";
import { memo } from "react"; import { memo } from "react";
function UsersTasksTableToolbar() { function UsersTasksTableToolbar() {
return ( return (
<Toolbar> <AppBar position="static" sx={{padding: 3}}>
<Typography <Typography
sx={{ flex: '1 1 100%' }} sx={{ flex: '1 1 100%' }}
variant="h6" variant="h6"
id="tableTitle" id="tableTitle"
component="div" component="div"
> >
Nutrition Задачи сотрудников
</Typography> </Typography>
</Toolbar> </AppBar>
); );
} }
......
...@@ -199,6 +199,7 @@ function MonthCalendar() { ...@@ -199,6 +199,7 @@ function MonthCalendar() {
executor: userId, executor: userId,
author: user.id, author: user.id,
calendar: true, calendar: true,
priority: currentTask.priority === '' ? null : currentTask.priority
} }
delete newTask.infoForCell delete newTask.infoForCell
delete newTask.id delete newTask.id
......
import * as React from 'react';
import Paper from '@mui/material/Paper'; import Paper from '@mui/material/Paper';
import UsersTasksTableToolbar from '../../components/UsersTasksCompoments/UsersTasksTableToolbar/UsersTasksTableToolbar'; import UsersTasksTableToolbar from '../../components/UsersTasksCompoments/UsersTasksTableToolbar/UsersTasksTableToolbar';
import UsersTasksTablePagination from '../../components/UsersTasksCompoments/UsersTasksTablePagination/UsersTasksTablePagination'; import UsersTasksTablePagination from '../../components/UsersTasksCompoments/UsersTasksTablePagination/UsersTasksTablePagination';
import UsersTasksTableContainer from '../../components/UsersTasksCompoments/UsersTasksTableContainer/UsersTasksTableContainer'; import UsersTasksTableContainer from '../../components/UsersTasksCompoments/UsersTasksTableContainer/UsersTasksTableContainer';
import { fetchAllTasksByMembership } from '../../store/actions/tasksActions';
import { shallowEqual, useDispatch, useSelector } from 'react-redux';
import { useEffect, useState } from 'react';
function createData(name, calories, fat, carbs, protein) { export default function EnhancedTable() {
return { const dispatch = useDispatch();
name,
calories,
fat,
carbs,
protein,
};
}
const rows = [ const {tasks} = useSelector((state) => state.tasks, shallowEqual);
createData('Cupcake', 305, 3.7, 67, 4.3), const projects = useSelector((state) => state.tasks.projects);
createData('Donut', 452, 25.0, 51, 4.9), const user = useSelector((state) => state.users.user);
createData('Eclair', 262, 16.0, 24, 6.0), console.log(tasks)
createData('Frozen yoghurt', 159, 6.0, 24, 4.0), const [order, setOrder] = useState('asc');
createData('Gingerbread', 356, 16.0, 49, 3.9), const [orderBy, setOrderBy] =useState('createdAt');
createData('Honeycomb', 408, 3.2, 87, 6.5), const [page, setPage] = useState(0);
createData('Ice cream sandwich', 237, 9.0, 37, 4.3), const [rowsPerPage, setRowsPerPage] = useState(10);
createData('Jelly Bean', 375, 0.0, 94, 0.0),
createData('KitKat', 518, 26.0, 65, 7.0),
createData('Lollipop', 392, 0.2, 98, 0.0),
createData('Marshmallow', 318, 0, 81, 2.0),
createData('Nougat', 360, 19.0, 9, 37.0),
createData('Oreo', 437, 18.0, 63, 4.0),
];
export default function EnhancedTable() { useEffect(() => {
const [order, setOrder] = React.useState('asc'); dispatch(fetchAllTasksByMembership());
const [orderBy, setOrderBy] = React.useState('calories'); }, [dispatch]);
const [page, setPage] = React.useState(0);
const [rowsPerPage, setRowsPerPage] = React.useState(5);
const handleRequestSort = (event, property) => { const handleRequestSort = (event, property) => {
const isAsc = orderBy === property && order === 'asc'; const isAsc = orderBy === property && order === 'asc';
...@@ -58,12 +44,12 @@ export default function EnhancedTable() { ...@@ -58,12 +44,12 @@ export default function EnhancedTable() {
order={order} order={order}
orderBy={orderBy} orderBy={orderBy}
handleRequestSort={handleRequestSort} handleRequestSort={handleRequestSort}
rows={rows} rows={tasks}
page={page} page={page}
rowsPerPage={rowsPerPage} rowsPerPage={rowsPerPage}
/> />
<UsersTasksTablePagination <UsersTasksTablePagination
count={rows.length} count={tasks.length}
rowsPerPage={rowsPerPage} rowsPerPage={rowsPerPage}
page={page} page={page}
handleChangePage={handleChangePage} handleChangePage={handleChangePage}
......
...@@ -178,6 +178,7 @@ function WeekCalendar() { ...@@ -178,6 +178,7 @@ function WeekCalendar() {
executor: userId, executor: userId,
author: user.id, author: user.id,
calendar: true, calendar: true,
priority: currentTask.priority === '' ? null : currentTask.priority
} }
delete newTask.infoForCell delete newTask.infoForCell
delete newTask.id delete newTask.id
......
...@@ -35,9 +35,9 @@ const initialState = { ...@@ -35,9 +35,9 @@ const initialState = {
}; };
const tasksReduсer = (state = initialState, action) => { const tasksReduсer = (state = initialState, action) => {
switch(action.type) { switch (action.type) {
case FETCH_CALENDAR_TASKS_REQUEST: case FETCH_CALENDAR_TASKS_REQUEST:
return {...state, loading: true}; return { ...state, loading: true };
case FETCH_CALENDAR_TASKS_SUCCESS: case FETCH_CALENDAR_TASKS_SUCCESS:
const newTasksWithoutInfoForCell = [] const newTasksWithoutInfoForCell = []
const newTasksWithInfoForCell = [] const newTasksWithInfoForCell = []
...@@ -56,7 +56,7 @@ const tasksReduсer = (state = initialState, action) => { ...@@ -56,7 +56,7 @@ const tasksReduсer = (state = initialState, action) => {
}) })
} }
} }
newTasksWithoutInfoForCell.forEach((task)=>{ newTasksWithoutInfoForCell.forEach((task) => {
if (task.dateTimeStart && task.dateTimeDue) { if (task.dateTimeStart && task.dateTimeDue) {
if (new Date(task.dateTimeDue).getTime() - new Date(task.dateTimeStart).getTime() < (24 * 3600000) && if (new Date(task.dateTimeDue).getTime() - new Date(task.dateTimeStart).getTime() < (24 * 3600000) &&
new Date(task.dateTimeDue).getTime() - new Date(task.dateTimeStart).getTime() > 0) { new Date(task.dateTimeDue).getTime() - new Date(task.dateTimeStart).getTime() > 0) {
...@@ -70,7 +70,8 @@ const tasksReduсer = (state = initialState, action) => { ...@@ -70,7 +70,8 @@ const tasksReduсer = (state = initialState, action) => {
const timeEndHour = parseInt(timeEnd.split(':')[0]) const timeEndHour = parseInt(timeEnd.split(':')[0])
const timeStartMinute = parseInt(timeStart.split(':')[1]) const timeStartMinute = parseInt(timeStart.split(':')[1])
const timeEndMinute = parseInt(timeEnd.split(':')[1]) const timeEndMinute = parseInt(timeEnd.split(':')[1])
const newObj = {...task, const newObj = {
...task,
infoForCell: { infoForCell: {
startDay: dayStart, startDay: dayStart,
startHour: timeStartHour, startHour: timeStartHour,
...@@ -85,50 +86,57 @@ const tasksReduсer = (state = initialState, action) => { ...@@ -85,50 +86,57 @@ const tasksReduсer = (state = initialState, action) => {
} }
} }
}) })
return {...state, loading: false, calendarTasks: newTasksWithInfoForCell}; return { ...state, loading: false, calendarTasks: newTasksWithInfoForCell };
case FETCH_ALL_TASKS_SUCCESS: case FETCH_ALL_TASKS_SUCCESS:
return {...state, loading: false, tasks: action.tasks, projects:action.projects}; return { ...state, loading: false, tasks: action.tasks , projects: action.projects };
case FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS: case FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS:
return {...state, loading: false, tasks: action.tasks, projects:action.projects}; console.log(action.tasks)
const newArr = action.tasks.map((task)=>{return {
...task,
authorName: task.author.displayName,
projectTitle: task.project.title,
executorName: task?.executor?.displayName || null,
}})
return { ...state, loading: false, tasks: newArr, projects: action.projects };
case FETCH_CALENDAR_TASKS_FAILURE: case FETCH_CALENDAR_TASKS_FAILURE:
return {...state, loading: false, error: action.error}; return { ...state, loading: false, error: action.error };
case ADD_NEW_TASK_SUCCESS: case ADD_NEW_TASK_SUCCESS:
return {...state, loading: false}; return { ...state, loading: false };
case ADD_NEW_TASK_REQUEST: case ADD_NEW_TASK_REQUEST:
return {...state, loading: true}; return { ...state, loading: true };
case ADD_NEW_TASK_FAILURE: case ADD_NEW_TASK_FAILURE:
return {...state, loading: false, error: action.error}; return { ...state, loading: false, error: action.error };
case FETCH_TASKS_BY_PROJECT_SUCCESS: case FETCH_TASKS_BY_PROJECT_SUCCESS:
return {...state, loading: false, tasks: action.tasks}; return { ...state, loading: false, tasks: action.tasks };
case FETCH_TASKS_BY_PROJECT_REQUEST: case FETCH_TASKS_BY_PROJECT_REQUEST:
return {...state, loading: true}; return { ...state, loading: true };
case FETCH_TASKS_BY_PROJECT_FAILURE: case FETCH_TASKS_BY_PROJECT_FAILURE:
return {...state, loading: false, error: action.error}; return { ...state, loading: false, error: action.error };
case EDIT_TASK_SUCCESS: case EDIT_TASK_SUCCESS:
return {...state, loading: false}; return { ...state, loading: false };
case EDIT_TASK_REQUEST: case EDIT_TASK_REQUEST:
return {...state, loading: true}; return { ...state, loading: true };
case EDIT_TASK_FAILURE: case EDIT_TASK_FAILURE:
return {...state, loading: false, error: action.error}; return { ...state, loading: false, error: action.error };
case DELETE_TASK_SUCCESS: case DELETE_TASK_SUCCESS:
return {...state, loading: false}; return { ...state, loading: false };
case DELETE_TASK_REQUEST: case DELETE_TASK_REQUEST:
return {...state, loading: true}; return { ...state, loading: true };
case DELETE_TASK_FAILURE: case DELETE_TASK_FAILURE:
return {...state, loading: false, error: action.error}; return { ...state, loading: false, error: action.error };
case DELETE_DATETIMETASK_SUCCESS: case DELETE_DATETIMETASK_SUCCESS:
return {...state, loading: false}; return { ...state, loading: false };
case DELETE_DATETIMETASK_REQUEST: case DELETE_DATETIMETASK_REQUEST:
return {...state, loading: true}; return { ...state, loading: true };
case DELETE_DATETIMETASK_FAILURE: case DELETE_DATETIMETASK_FAILURE:
return {...state, loading: false, error: action.error}; return { ...state, loading: false, error: action.error };
case ACTIVATE_CREATE_COPY_TASKS_MODE: case ACTIVATE_CREATE_COPY_TASKS_MODE:
return {...state, copyMode: {working: true, task: action.task}} return { ...state, copyMode: { working: true, task: action.task } }
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 } }
default: default:
return state; return state;
} }
}; };
export default tasksReduсer; export default tasksReduсer;
\ No newline at end of file
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