diff --git a/src/components/albums/potential-albums/PotentialDateItem.tsx b/src/components/albums/potential-albums/PotentialDateItem.tsx index 7081fd9..b622ff2 100644 --- a/src/components/albums/potential-albums/PotentialDateItem.tsx +++ b/src/components/albums/potential-albums/PotentialDateItem.tsx @@ -1,7 +1,9 @@ import { usePotentialAlbumContext } from "@/contexts/PotentialAlbumContext"; import { IPotentialAlbumsDatesResponse } from "@/handlers/api/album.handler"; +import { formatDate } from "@/helpers/date.helper"; +import { parseDate } from "@/helpers/date.helper"; import { cn } from "@/lib/utils"; -import React from "react"; +import React, { useMemo } from "react"; interface IProps { record: IPotentialAlbumsDatesResponse; @@ -9,6 +11,9 @@ interface IProps { } export default function PotentialDateItem({ record, onSelect }: IProps) { const { startDate } = usePotentialAlbumContext() + const dateLabel = useMemo(() => { + return formatDate(parseDate(record.date, "yyyy-MM-dd").toISOString(), "do MMM yyyy") + }, [record.date]) return (
-

{record.date}

-

{record.asset_count} Orphan Assets

+

{dateLabel}

+

{record.asset_count} Orphan Assets

); } diff --git a/src/components/assets/missing-location/MissingLocationDateItem.tsx b/src/components/assets/missing-location/MissingLocationDateItem.tsx index 650625a..dde352b 100644 --- a/src/components/assets/missing-location/MissingLocationDateItem.tsx +++ b/src/components/assets/missing-location/MissingLocationDateItem.tsx @@ -1,8 +1,9 @@ import { useMissingLocationContext } from "@/contexts/MissingLocationContext"; import { IMissingLocationDatesResponse } from "@/handlers/api/asset.handler"; +import { parseDate, formatDate } from "@/helpers/date.helper"; import { cn } from "@/lib/utils"; -import React from "react"; +import React, { useMemo } from "react"; interface IProps { record: IMissingLocationDatesResponse; @@ -10,6 +11,10 @@ interface IProps { } export default function MissingLocationDateItem({ record, onSelect }: IProps) { const { startDate } = useMissingLocationContext() + const dateLabel = useMemo(() => { + if (!record.date) return "Unknown" + return formatDate(parseDate(record.date, "yyyy-MM-dd").toISOString(), "do MMM yyyy") + }, [record.date]) return (
-

{record.date}

-

{record.asset_count} W/O Location

+

{dateLabel}

+

{record.asset_count} Orphan Assets

); } diff --git a/src/components/assets/missing-location/MissingLocationDates.tsx b/src/components/assets/missing-location/MissingLocationDates.tsx index 41f6216..d7c6fad 100644 --- a/src/components/assets/missing-location/MissingLocationDates.tsx +++ b/src/components/assets/missing-location/MissingLocationDates.tsx @@ -4,6 +4,9 @@ import { IMissingLocationDatesResponse, listMissingLocationDates } from "@/handl import MissingLocationDateItem from "./MissingLocationDateItem"; import { useMissingLocationContext } from "@/contexts/MissingLocationContext"; import { useRouter } from "next/router"; +import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue } from "@/components/ui/select"; +import { Button } from "@/components/ui/button"; +import { SortAsc, SortDesc } from "lucide-react"; export default function MissingLocationDates() { const { updateContext } = useMissingLocationContext(); @@ -11,12 +14,16 @@ export default function MissingLocationDates() { const [dateRecords, setDateRecords] = React.useState< IMissingLocationDatesResponse[] >([]); + const [filters, setFilters] = useState<{ sortBy: string, sortOrder: string }>({ sortBy: "date", sortOrder: "desc" }); const [loading, setLoading] = useState(false); const [errorMessage, setErrorMessage] = useState(null); const fetchData = async () => { - return listMissingLocationDates({}) + return listMissingLocationDates({ + sortBy: filters.sortBy, + sortOrder: filters.sortOrder, + }) .then(setDateRecords) .catch(setErrorMessage) .finally(() => setLoading(false)); @@ -30,12 +37,37 @@ export default function MissingLocationDates() { }); }; + + useEffect(() => { fetchData(); - }, []); + }, [filters]); return ( -
+
+
+ +
+ +
+
+ {dateRecords.map((record) => ( { + const aDate = parseDate(a.date, "yyyy-MM-dd"); + const bDate = parseDate(b.date, "yyyy-MM-dd"); + return sortOrder === "asc" ? aDate.getTime() - bDate.getTime() : bDate.getTime() - aDate.getTime(); + }); + } else if (sortBy === "asset_count") { + rows.sort((a, b) => { + return sortOrder === "asc" ? a.asset_count - b.asset_count : b.asset_count - a.asset_count; + }); + } return res.status(200).json(rows); } catch (error: any) { res.status(500).json({