diff --git a/src/frontend/src/api/dashboard.ts b/src/frontend/src/api/dashboard.ts index 3b66b639..2e1a3b85 100644 --- a/src/frontend/src/api/dashboard.ts +++ b/src/frontend/src/api/dashboard.ts @@ -1,6 +1,7 @@ /* eslint-disable import/prefer-default-export */ import { UseQueryOptions, useQuery } from '@tanstack/react-query'; import { getRequestedTasks } from '@Services/project'; +import { getTaskList, getTaskStatistics } from '@Services/dashboard'; export const useGetRequestedTasksListQuery = ( queryOptions?: Partial, @@ -12,3 +13,25 @@ export const useGetRequestedTasksListQuery = ( ...queryOptions, }); }; + +export const useGetDashboardTaskStaticsQuery = ( + queryOptions?: Partial, +) => { + return useQuery({ + queryKey: ['task-statistics'], + queryFn: getTaskStatistics, + select: (res: any) => res.data, + ...queryOptions, + }); +}; + +export const useGetTaskListQuery = ( + queryOptions?: Partial, +) => { + return useQuery({ + queryKey: ['task-list'], + queryFn: getTaskList, + select: (res: any) => res.data, + ...queryOptions, + }); +}; diff --git a/src/frontend/src/components/Dashboard/DashboardCard/index.tsx b/src/frontend/src/components/Dashboard/DashboardCard/index.tsx index 7d9407c6..173b38a6 100644 --- a/src/frontend/src/components/Dashboard/DashboardCard/index.tsx +++ b/src/frontend/src/components/Dashboard/DashboardCard/index.tsx @@ -4,13 +4,25 @@ import graphImage from '@Assets/images/graph.svg'; interface IDashboardCardProps { title: string; - value: number; + count: number; active: boolean; } +export const DashboardCardSkeleton = () => { + return ( +
+
+
+
+
+
+
+ ); +}; + export default function DashboardCard({ title, - value, + count, active, }: IDashboardCardProps) { return ( @@ -19,7 +31,7 @@ export default function DashboardCard({ > -

{value}

+

{count}

{title}

diff --git a/src/frontend/src/components/Dashboard/TaskLogs/TaskLogsTable.tsx b/src/frontend/src/components/Dashboard/TaskLogs/TaskLogsTable.tsx new file mode 100644 index 00000000..e22d867e --- /dev/null +++ b/src/frontend/src/components/Dashboard/TaskLogs/TaskLogsTable.tsx @@ -0,0 +1,60 @@ +import { format } from 'date-fns'; +import { useNavigate } from 'react-router-dom'; + +interface ITaskLogsTableProps { + data: any[]; +} + +const TaskLogsTable = ({ data: taskList }: ITaskLogsTableProps) => { + const navigate = useNavigate(); + return ( +
+ + + + + + + + + + + + {taskList?.map(task => ( + + + + + + + + + ))} + +
+ ID + + Total task area + + Est.flight time + + Created Date + + Status + +
{task.task_id}{task.task_area}- + {format(new Date(task.created_at), 'yyyy-MM-dd')} + {task.state} +
navigate(`/tasks/${task.task_id}`)} + > + zoom_in +
+
+
+ ); +}; + +export default TaskLogsTable; diff --git a/src/frontend/src/components/Dashboard/TaskLogs/index.tsx b/src/frontend/src/components/Dashboard/TaskLogs/index.tsx index 0e681c6b..d1a7609d 100644 --- a/src/frontend/src/components/Dashboard/TaskLogs/index.tsx +++ b/src/frontend/src/components/Dashboard/TaskLogs/index.tsx @@ -1,14 +1,37 @@ +import { useMemo } from 'react'; +import { useGetTaskListQuery } from '@Api/dashboard'; +import TaskLogsTable from './TaskLogsTable'; + interface TaskLogsProps { title: string; } +const getStatusByTitle = (title: string): string => { + if (title === 'Ongoing Tasks') return 'ongoing'; + if (title === 'Request Logs') return 'request logs'; + if (title === 'Unflyable Tasks') return 'unflyable task'; + if (title === 'Completed Tasks') return 'completed'; + + return ''; +}; + const TaskLogs = ({ title }: TaskLogsProps) => { + const { data: taskList }: any = useGetTaskListQuery(); + + const filteredData = useMemo( + () => + taskList?.filter( + (task: Record) => task?.state === getStatusByTitle(title), + ), + [title, taskList], + ); + return (

{title}

- {/* */} +
); }; diff --git a/src/frontend/src/constants/dashboard.ts b/src/frontend/src/constants/dashboard.ts index ca59a3ee..52779dd1 100644 --- a/src/frontend/src/constants/dashboard.ts +++ b/src/frontend/src/constants/dashboard.ts @@ -6,18 +6,18 @@ export const dashboardCardsForProjectCreator = [ }, { id: 2, - title: 'Un-flyable Tasks', - value: 'un-flyable_tasks', + title: 'Ongoing Tasks', + value: 'ongoing_tasks', }, { id: 3, - title: 'Ongoing Tasks', - value: 'ongoing_task', + title: 'Unflyable Tasks', + value: 'unflyable_tasks', }, { id: 4, title: 'Completed Tasks', - value: 'complete_tasks', + value: 'completed_tasks', }, ]; @@ -29,8 +29,8 @@ export const dashboardCardsForDroneOperator = [ }, { id: 2, - title: 'Tasks Mapped', - value: 'tasks_mapped', + title: 'Unflyable Tasks', + value: 'unflyable_tasks', }, { id: 3, diff --git a/src/frontend/src/services/dashboard.ts b/src/frontend/src/services/dashboard.ts new file mode 100644 index 00000000..b6e8af2d --- /dev/null +++ b/src/frontend/src/services/dashboard.ts @@ -0,0 +1,6 @@ +import { authenticated, api } from '.'; + +export const getTaskStatistics = () => + authenticated(api).get('/tasks/statistics/'); + +export const getTaskList = () => authenticated(api).get('/tasks/'); diff --git a/src/frontend/src/views/Dashboard/index.tsx b/src/frontend/src/views/Dashboard/index.tsx index e33c65a2..fe463030 100644 --- a/src/frontend/src/views/Dashboard/index.tsx +++ b/src/frontend/src/views/Dashboard/index.tsx @@ -1,6 +1,7 @@ -import { useGetRequestedTasksListQuery } from '@Api/dashboard'; +import { useGetDashboardTaskStaticsQuery } from '@Api/dashboard'; import { FlexRow } from '@Components/common/Layouts'; import { DashboardSidebar, DashboardCard } from '@Components/Dashboard'; +import { DashboardCardSkeleton } from '@Components/Dashboard/DashboardCard'; import RequestLogs from '@Components/Dashboard/RequestLogs'; import TaskLogs from '@Components/Dashboard/TaskLogs'; import { @@ -32,9 +33,16 @@ export default function Dashboard() { ? dashboardCardsForProjectCreator : dashboardCardsForDroneOperator; - const { data: requestedTasks } = useGetRequestedTasksListQuery({ - select: (data: any) => data.data, - }); + const { data: taskStatistics, isLoading }: Record = + useGetDashboardTaskStaticsQuery({ + select: (data: any) => { + const taskCounts: Record = data?.data; + return dashboardCards?.map(card => ({ + ...card, + count: taskCounts?.[`${card?.value}`], + })); + }, + }); return (
@@ -45,29 +53,34 @@ export default function Dashboard() {
- {dashboardCards.map(card => ( -
- setActiveTab({ value: card.value, title: card.title }) - } - onClick={() => - setActiveTab({ value: card.value, title: card.title }) - } - className="naxatw-cursor-pointer" - > - + {Array.from({ length: 4 }, (_, index) => ( + + ))} + + ) : ( + taskStatistics?.map((task: any) => ( +
+ setActiveTab({ value: task.value, title: task.title }) } - active={card.value === activeTab.value} - /> -
- ))} + onClick={() => + setActiveTab({ value: task.value, title: task.title }) + } + className="naxatw-cursor-pointer" + > + +
+ )) + )}
{getContent(activeTab.value, activeTab.title)}