diff --git a/frontend/app/dashboard/page.tsx b/frontend/app/dashboard/page.tsx index 95bd06e8..46457ba5 100644 --- a/frontend/app/dashboard/page.tsx +++ b/frontend/app/dashboard/page.tsx @@ -1,11 +1,17 @@ -"use client" +"use client"; + +import { useMemo, useState } from "react"; +import { useDashboardData } from "@/services/dashboard.service"; + + + +import { getDateRange } from "@/libs/dateUtils"; +import DashboardHeader from "@/components/dashboard/dashboard-header"; +import DashboardOverview from "@/components/dashboard/dashboard-overview"; + + -import { useMemo, useState } from "react" -import { useDashboardData } from "@/services/dashboard.service" -import { getDateRange } from "@/libs/dateUtils" -import DashboardHeader from "@/components/dashboard/dashboard-header" -import DashboardOverview from "@/components/dashboard/dashboard-overview" export default function DashboardPage() { const [selectedDays, setSelectedDays] = useState(7) @@ -14,7 +20,7 @@ export default function DashboardPage() { }, [selectedDays]) const { - topVesselsInActivity, + topVesselsInMpas, topAmpsVisited, totalVesselsInActivity, totalAmpsVisited, @@ -31,7 +37,7 @@ export default function DashboardPage() {
{ setSelectedDays(Number(value)) }} - topVesselsInActivityLoading={isLoading.topVesselsInActivity} + topVesselsInMpasLoading={isLoading.topVesselsInMpas} topAmpsVisitedLoading={isLoading.topAmpsVisited} totalVesselsActiveLoading={isLoading.totalVesselsInActivity} totalAmpsVisitedLoading={isLoading.totalAmpsVisited} @@ -49,4 +55,4 @@ export default function DashboardPage() {
) -} +} \ No newline at end of file diff --git a/frontend/components/dashboard/dashboard-overview.tsx b/frontend/components/dashboard/dashboard-overview.tsx index 7f4c3c1d..ad992733 100644 --- a/frontend/components/dashboard/dashboard-overview.tsx +++ b/frontend/components/dashboard/dashboard-overview.tsx @@ -1,16 +1,21 @@ -"use client" +"use client"; -import { TOTAL_AMPS, TOTAL_VESSELS } from "@/constants/totals.constants" +import { TOTAL_AMPS, TOTAL_VESSELS } from "@/constants/totals.constants"; -import { Item } from "@/types/item" -import ListCard from "@/components/ui/list-card" -import KPICard from "@/components/dashboard/kpi-card" -import { DateRangeSelector } from "../ui/date-range-selector" + +import { Item } from "@/types/item"; +import ListCard from "@/components/ui/list-card"; +import KPICard from "@/components/dashboard/kpi-card"; + + + +import { DateRangeSelector } from "../ui/date-range-selector"; + type Props = { - topVesselsInActivity: Item[] - topVesselsInActivityLoading: boolean + topVesselsInMpas: Item[] + topVesselsInMpasLoading: boolean topAmpsVisited: Item[] topAmpsVisitedLoading: boolean totalVesselsActive: number @@ -23,8 +28,8 @@ type Props = { } export default function DashboardOverview({ - topVesselsInActivity, - topVesselsInActivityLoading, + topVesselsInMpas, + topVesselsInMpasLoading, topAmpsVisited, topAmpsVisitedLoading, totalVesselsActive, @@ -74,9 +79,9 @@ export default function DashboardOverview({ @@ -84,4 +89,4 @@ export default function DashboardOverview({ ) -} +} \ No newline at end of file diff --git a/frontend/libs/mapper.tsx b/frontend/libs/mapper.tsx index 9799cb0e..6778da8f 100644 --- a/frontend/libs/mapper.tsx +++ b/frontend/libs/mapper.tsx @@ -11,7 +11,7 @@ export function convertVesselDtoToItem(metrics: VesselMetrics[]): Item[] { id: `${vessel.id}`, title: vessel.ship_name, description: `IMO ${vessel.imo} / MMSI ${vessel.mmsi} / ${vessel.length} m`, - value: convertDurationToString(vesselMetrics.total_time_at_sea), + value: convertDurationToString(vesselMetrics.total_time_in_mpas), type: "vessel", countryIso3: vessel.country_iso3, } diff --git a/frontend/services/backend-rest-client.ts b/frontend/services/backend-rest-client.ts index f4f600f6..3aa81fe2 100644 --- a/frontend/services/backend-rest-client.ts +++ b/frontend/services/backend-rest-client.ts @@ -83,12 +83,12 @@ export async function getVesselFirstExcursionSegments(vesselId: number) { } } -export function getTopVesselsInActivity( +export function getTopVesselsInMpas( startAt: string, endAt: string, topVesselsLimit: number ) { - const url = `${BASE_URL}/metrics/vessels-in-activity?start_at=${startAt}&end_at=${endAt}&limit=${topVesselsLimit}&order=DESC` + const url = `${BASE_URL}/metrics/vessels/activity-in-mpas?start_at=${startAt}&end_at=${endAt}&limit=${topVesselsLimit}&order=DESC` console.log(`GET ${url}`) return axios.get(url) } diff --git a/frontend/services/dashboard.service.ts b/frontend/services/dashboard.service.ts index ef74e743..832c5b96 100644 --- a/frontend/services/dashboard.service.ts +++ b/frontend/services/dashboard.service.ts @@ -1,6 +1,6 @@ import { TOTAL_VESSELS } from "@/constants/totals.constants" import { - getTopVesselsInActivity, + getTopVesselsInMpas, getTopZonesVisited, getVesselsAtSea, getVesselsTrackedCount, @@ -13,13 +13,13 @@ import { convertVesselDtoToItem, convertZoneDtoToItem } from "@/libs/mapper" const TOP_ITEMS_SIZE = 5 type DashboardData = { - topVesselsInActivity: any[] + topVesselsInMpas: any[] topAmpsVisited: any[] totalVesselsInActivity: number totalAmpsVisited: number totalVesselsTracked: number isLoading: { - topVesselsInActivity: boolean + topVesselsInMpas: boolean topAmpsVisited: boolean totalVesselsInActivity: boolean totalAmpsVisited: boolean @@ -32,13 +32,13 @@ export const useDashboardData = ( endAt: string ): DashboardData => { const { - data: topVesselsInActivity = [], - isLoading: topVesselsInActivityLoading, + data: topVesselsInMpas = [], + isLoading: topVesselsInMpasLoading, } = useSWR( - `topVesselsInActivity-${startAt}`, + `topVesselsInMpas-${startAt}`, async () => { try { - const response = await getTopVesselsInActivity( + const response = await getTopVesselsInMpas( startAt, endAt, TOP_ITEMS_SIZE @@ -46,7 +46,7 @@ export const useDashboardData = ( return convertVesselDtoToItem(response?.data || []) } catch (error) { console.log( - "An error occurred while fetching top vessels in activity: " + error + "An error occurred while fetching top vessels in MPAs: " + error ) return [] } @@ -137,13 +137,13 @@ export const useDashboardData = ( ) return { - topVesselsInActivity, + topVesselsInMpas, topAmpsVisited, totalVesselsInActivity, totalAmpsVisited, totalVesselsTracked, isLoading: { - topVesselsInActivity: topVesselsInActivityLoading, + topVesselsInMpas: topVesselsInMpasLoading, topAmpsVisited: topAmpsVisitedLoading, totalVesselsInActivity: totalVesselsInActivityLoading, totalAmpsVisited: totalAmpsVisitedLoading, diff --git a/frontend/types/vessel.ts b/frontend/types/vessel.ts index f8626549..af5933ed 100644 --- a/frontend/types/vessel.ts +++ b/frontend/types/vessel.ts @@ -17,7 +17,7 @@ export type Vessel = { export type VesselMetrics = { vessel: VesselDetails - total_time_at_sea: string + total_time_in_mpas: string } export type VesselDetails = {