table-pagination #29

Merged
nik.polishuk merged 2 commits from table-pagination into main 2024-03-31 20:40:00 +03:00
Showing only changes of commit 35f76abe60 - Show all commits

View File

@ -1,11 +1,11 @@
import React, { useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { getTheme } from "@table-library/react-table-library/baseline"; import { getTheme } from "@table-library/react-table-library/baseline";
import { CompactTable } from "@table-library/react-table-library/compact"; import { CompactTable } from "@table-library/react-table-library/compact";
import { usePagination } from "@table-library/react-table-library/pagination"; import { usePagination } from "@table-library/react-table-library/pagination";
import { useSort } from "@table-library/react-table-library/sort"; import { useSort } from "@table-library/react-table-library/sort";
import { useTheme } from "@table-library/react-table-library/theme"; import { useTheme } from "@table-library/react-table-library/theme";
import { getCorrectDate } from "@utils/calendarHelper"; import React, { useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { Link } from "react-router-dom";
import { import {
getProjects, getProjects,
@ -15,6 +15,7 @@ import {
setToggleTab setToggleTab
} from "@redux/projectsTrackerSlice"; } from "@redux/projectsTrackerSlice";
import { getCorrectDate } from "@utils/calendarHelper";
import { caseOfNum, urlForLocal } from "@utils/helper"; import { caseOfNum, urlForLocal } from "@utils/helper";
import { apiRequest } from "@api/request"; import { apiRequest } from "@api/request";
@ -32,6 +33,7 @@ import ProjectTicket from "@components/ProjectTicket/ProjectTicket";
import addProjectImg from "assets/icons/addProjectImg.svg"; import addProjectImg from "assets/icons/addProjectImg.svg";
import archiveTrackerProjects from "assets/icons/archiveTrackerProjects.svg"; import archiveTrackerProjects from "assets/icons/archiveTrackerProjects.svg";
import rightArrow from "assets/icons/arrows/arrowRight.svg";
import arrowViewReport from "assets/icons/arrows/arrowViewReport.svg"; import arrowViewReport from "assets/icons/arrows/arrowViewReport.svg";
import filterIcon from "assets/icons/filterIcon.svg"; import filterIcon from "assets/icons/filterIcon.svg";
import searchImg from "assets/icons/serchIcon.png"; import searchImg from "assets/icons/serchIcon.png";
@ -44,8 +46,6 @@ import noProjects from "assets/images/noProjects.png";
import statusTimeTask from "assets/images/statusTimeTask.svg"; import statusTimeTask from "assets/images/statusTimeTask.svg";
import "./tracker.scss"; import "./tracker.scss";
import { Link } from "react-router-dom";
import rightArrow from "assets/icons/arrows/arrowRight.svg";
export const Tracker = () => { export const Tracker = () => {
const dispatch = useDispatch(); const dispatch = useDispatch();
@ -67,22 +67,34 @@ export const Tracker = () => {
const COLUMNS = [ const COLUMNS = [
{ {
label: "Задача", label: "Задача",
renderCell: (item) => <p dangerouslySetInnerHTML={{ __html: item.title }}></p>, renderCell: (item) => (
<p dangerouslySetInnerHTML={{ __html: item.title }}></p>
),
sort: { sortKey: "NAME" } sort: { sortKey: "NAME" }
}, },
{ {
label: "Создано", label: "Создано",
renderCell: (item) => <span>{getCorrectDate(item.created_at)}</span>, renderCell: (item) => <span>{getCorrectDate(item.created_at)}</span>,
sort: { sortKey: "CREATE" }, sort: { sortKey: "CREATE" }
}, },
{ {
label: "Дедлайн", label: "Дедлайн",
renderCell: (item) => <span>{item.dead_line ? getCorrectDate(item.dead_line) : 'Без дедлайна'}</span>, renderCell: (item) => (
<span>
{item.dead_line ? getCorrectDate(item.dead_line) : "Без дедлайна"}
</span>
),
sort: { sortKey: "DEADLINE" } sort: { sortKey: "DEADLINE" }
}, },
{ {
label: "Потраченное время", label: "Потраченное время",
renderCell: (item) => <span>{item.timers.length ? getSpendTime(item.timers) : 'Трекер не был включен'}</span>, renderCell: (item) => (
<span>
{item.timers.length
? getSpendTime(item.timers)
: "Трекер не был включен"}
</span>
),
sort: { sortKey: "SPEND" } sort: { sortKey: "SPEND" }
} }
]; ];
@ -97,9 +109,15 @@ export const Tracker = () => {
{ {
sortFns: { sortFns: {
NAME: (array) => array.sort((a, b) => a.title.localeCompare(b.title)), NAME: (array) => array.sort((a, b) => a.title.localeCompare(b.title)),
CREATE: (array) => array.sort((a, b) => new Date(a.created_at) - new Date(b.created_at)), CREATE: (array) =>
DEADLINE: (array) => array.sort((a, b) => new Date(a.dead_line) - new Date(b.dead_line)), array.sort((a, b) => new Date(a.created_at) - new Date(b.created_at)),
SPEND: (array) => array.sort((a, b) => getSpendTime(a.timers, true) - getSpendTime(b.timers, true)), DEADLINE: (array) =>
array.sort((a, b) => new Date(a.dead_line) - new Date(b.dead_line)),
SPEND: (array) =>
array.sort(
(a, b) =>
getSpendTime(a.timers, true) - getSpendTime(b.timers, true)
)
} }
} }
); );
@ -115,11 +133,13 @@ export const Tracker = () => {
let timerSeconds = 0; let timerSeconds = 0;
times.forEach((time) => { times.forEach((time) => {
timerSeconds += time.deltaSeconds; timerSeconds += time.deltaSeconds;
}) });
if (seconds) { if (seconds) {
return timerSeconds return timerSeconds;
} }
return `${Math.floor(timerSeconds / 60 / 60)}:${Math.floor((timerSeconds / 60) % 60)}:${timerSeconds % 60}` return `${Math.floor(timerSeconds / 60 / 60)}:${Math.floor(
(timerSeconds / 60) % 60
)}:${timerSeconds % 60}`;
} }
function onSortChange(action, state) { function onSortChange(action, state) {
@ -130,9 +150,7 @@ export const Tracker = () => {
setSearch(event.target.value); setSearch(event.target.value);
setNodes( setNodes(
initialNodes.filter((item) => initialNodes.filter((item) =>
item.title item.title.toLowerCase().includes(event.target.value.toLowerCase())
.toLowerCase()
.includes(event.target.value.toLowerCase())
) )
); );
}; };
@ -169,8 +187,8 @@ export const Tracker = () => {
: []; : [];
setAllTasks(allTasks); setAllTasks(allTasks);
setFilteredAllTasks(allTasks); setFilteredAllTasks(allTasks);
setNodes(allTasks) setNodes(allTasks);
setInitialNodes(allTasks) setInitialNodes(allTasks);
setAllCompletedTasks(completedTasks); setAllCompletedTasks(completedTasks);
setFilterCompleteTasks(completedTasks); setFilterCompleteTasks(completedTasks);
}) })
@ -365,10 +383,12 @@ export const Tracker = () => {
{/* </div>*/} {/* </div>*/}
{/*</div>*/} {/*</div>*/}
{loader ? <Loader style="green" /> : {loader ? (
<Loader style="green" />
) : (
<> <>
<div className="table__search"> <div className="table__search">
<img src={searchImg} alt='search' /> <img src={searchImg} alt="search" />
<input <input
type="text" type="text"
placeholder="Поиск по задачам" placeholder="Поиск по задачам"
@ -385,7 +405,9 @@ export const Tracker = () => {
/> />
<div className="table__pagination"> <div className="table__pagination">
<button <button
className={pagination.state.page === 0 ? "switch disable" : "switch"} className={
pagination.state.page === 0 ? "switch disable" : "switch"
}
type="button" type="button"
disabled={pagination.state.page === 0} disabled={pagination.state.page === 0}
onClick={() => onClick={() =>
@ -399,7 +421,11 @@ export const Tracker = () => {
<button <button
key={index} key={index}
type="button" type="button"
className={pagination.state.page === index ? "page page--active " : 'page'} className={
pagination.state.page === index
? "page page--active "
: "page"
}
onClick={() => pagination.fns.onSetPage(index)} onClick={() => pagination.fns.onSetPage(index)}
> >
{index + 1} {index + 1}
@ -407,9 +433,17 @@ export const Tracker = () => {
))} ))}
</span> </span>
<button <button
className={pagination.state.page + 1 === pagination.state.getPages(data.nodes).length ? "switch disable" : "switch"} className={
pagination.state.page + 1 ===
pagination.state.getPages(data.nodes).length
? "switch disable"
: "switch"
}
type="button" type="button"
disabled={pagination.state.page + 1 === pagination.state.getPages(data.nodes).length} disabled={
pagination.state.page + 1 ===
pagination.state.getPages(data.nodes).length
}
onClick={() => onClick={() =>
pagination.fns.onSetPage(pagination.state.page + 1) pagination.fns.onSetPage(pagination.state.page + 1)
} }
@ -418,7 +452,7 @@ export const Tracker = () => {
</button> </button>
</div> </div>
</> </>
} )}
{/*<AllTaskTableTracker*/} {/*<AllTaskTableTracker*/}
{/* loader={loader}*/} {/* loader={loader}*/}