Skip to content

Commit

Permalink
feat: add placeholder dashboard page and give row an onclick to navig…
Browse files Browse the repository at this point in the history
…ate to it
  • Loading branch information
andreaslhjulstad committed Oct 8, 2024
1 parent ddb35d9 commit ff1b797
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
23 changes: 23 additions & 0 deletions frontend/cypress/e2e/pages/overview.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,27 @@ describe("DataTable component displays data correctly", () => {

cy.get("table tbody tr").as("rows").should("have.length", 6);
});

it("navigates to new page when clicked on row", () => {
// Find the index for the case number column
cy.get("table thead th").then(($headers) => {
const caseNumberIndex =
[...$headers].findIndex((header) =>
header.innerText.includes("Saksnummer"),
) + 1;
// Get the case number of the first row
cy.get(`table tbody tr td:nth-child(${caseNumberIndex})`)
.first()
.invoke("text")
.then((caseNumber) => {
// Click on the first
cy.get("table tbody tr").first().click();
// Check that the URL has changed to the correct case number
cy.url().should(
"include",
`/mottakskontroll/dine-saker/dashbord/${caseNumber}`,
);
});
});
});
});
9 changes: 8 additions & 1 deletion frontend/src/app/mottakskontroll/dine-saker/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
import { useEffect, useState } from "react";
import { type Application } from "~/types/application";
import FilterDropdown from "../../_components/FilterDropdown";
import { useRouter } from "next/navigation";

interface DataTableProps<TData, TValue> {
columns: ColumnDef<TData, TValue>[];
Expand All @@ -33,6 +34,8 @@ const DataTable = <TData extends Application, TValue>({
columns,
data,
}: DataTableProps<TData, TValue>) => {
const router = useRouter();

const [sorting, setSorting] = useState<SortingState>([]);
const [filteredData, setFilteredData] = useState<TData[]>(data);
const [selectedMunicipalities, setSelectedMunicipalities] = useState<
Expand Down Expand Up @@ -155,7 +158,11 @@ const DataTable = <TData extends Application, TValue>({
<TableRow
key={row.id}
data-state={row.getIsSelected() && "selected"}
onClick={() => console.log(row.original)}
onClick={() =>
router.push(
`/mottakskontroll/dine-saker/dashbord/${row.original.id}`,
)
}
>
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id} className="w-[calc(100%/6)]">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use client";

import { useParams } from "next/navigation";
import React from "react";

const CaseDashboard: React.FC = () => {
const { caseNumber } = useParams();

return (
<div>
<h1>Dashbord for saksnummer: {caseNumber}</h1>
</div>
);
};

export default CaseDashboard;

0 comments on commit ff1b797

Please sign in to comment.