Skip to content

Commit

Permalink
Merge pull request #2603 from bcgov/fix-grid-link
Browse files Browse the repository at this point in the history
Fix grid link
  • Loading branch information
BCerki authored Dec 17, 2024
2 parents 1f14b22 + ea18847 commit bd5b1cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ describe("OperationsDataGrid component", () => {

expect(operationInfoLinks[0]).toHaveAttribute(
"href",
"/operations/1?operations_title=Operation 1",
"/administration/operations/1?operations_title=Operation 1",
);
expect(operationInfoLinks[1]).toHaveAttribute(
"href",
"/operations/2?operations_title=Operation 2",
"/administration/operations/2?operations_title=Operation 2",
);
});

Expand All @@ -241,24 +241,27 @@ describe("OperationsDataGrid component", () => {
screen.getByRole("link", {
name: /Start registration/i,
}),
).toHaveAttribute("href", "../registration/register-an-operation");
).toHaveAttribute("href", "/registration/register-an-operation");
expect(
screen.getByRole("link", {
name: /view operation/i,
}),
).toHaveAttribute("href", "/operations/2?operations_title=Operation 2");
).toHaveAttribute(
"href",
"/administration/operations/2?operations_title=Operation 2",
);

const continueRegistrationlinks = screen.getAllByRole("link", {
name: /continue registration/i,
});

expect(continueRegistrationlinks[0]).toHaveAttribute(
"href",
"../registration/register-an-operation/1/1",
"/registration/register-an-operation/1/1",
);
expect(continueRegistrationlinks[1]).toHaveAttribute(
"href",
"../registration/register-an-operation/4/1",
"/registration/register-an-operation/4/1",
);
});
});
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
import { GridRenderCellParams } from "@mui/x-data-grid";
import { OperationStatus } from "@bciers/utils/src/enums";
import Link from "next/link";

const OperationsActionCell = (isInternalUser: boolean) => {
const renderCell = (params: GridRenderCellParams) => {
let actionText = "View Operation";
let url = `/operations/${params.row.id}?operations_title=${params.row.name}`;
let url = `/administration/operations/${params.row.id}?operations_title=${params.row.name}`;
if (!isInternalUser) {
switch (params.row.status) {
case OperationStatus.NOT_STARTED:
actionText = "Start Registration";
url = "../registration/register-an-operation";
url = "/registration/register-an-operation";
break;
case OperationStatus.DRAFT:
actionText = "Continue Registration";
url = `../registration/register-an-operation/${params.row.id}/1`;
url = `/registration/register-an-operation/${params.row.id}/1`;
break;
}
}
return (
<div>
{/*To make external links (e.g., to a different module like registration) work, we have to passHref */}
<Link className="action-cell-text" href={url} passHref={true}>
{/*To make external links (e.g., to a different module like registration) work, we have use <a> instead of <Link> */}
<a className="action-cell-text" href={url}>
{actionText}
</Link>
</a>
</div>
);
};
Expand Down

0 comments on commit bd5b1cd

Please sign in to comment.