Skip to content

Commit

Permalink
chore: cleanup breadcrumb query params
Browse files Browse the repository at this point in the history
  • Loading branch information
shon-button committed Dec 11, 2024
1 parent ab87878 commit 4052364
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default function ActivityForm({
if (taskListLength && step === -1) step = taskListLength - 1;

if (step === 0 && !isContinue)
return `/reports/${reportVersionId}/facilities/${facilityId}/review?facilities_title=Facility`; // Facility review page
return `/reports/${reportVersionId}/facilities/${facilityId}/review`; // Facility review page
if (taskListLength && step + 1 >= taskListLength && isContinue)
return "non-attributable"; // Activities done, go to Non-attributable emissions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ const FacilityReview: React.FC<Props> = ({ version_id, facility_id }) => {
});
const [activityList, setActivityList] = useState<Activity[]>([]);
const queryString = serializeSearchParams(useSearchParams());
const reportsTitle = useSearchParams().get("reports_title");
const backUrl = `/reports/${version_id}/person-responsible?reports_title=${reportsTitle}`;
const backUrl = `/reports/${version_id}/person-responsible`;
const continueURL = `activities${queryString}`;
const router = useRouter();
const formRef = useRef<FormContext>(null);
Expand Down Expand Up @@ -153,7 +152,6 @@ const FacilityReview: React.FC<Props> = ({ version_id, facility_id }) => {
}, 3000);
}
} catch (error: any) {
console.error("Error updating facility:", error);
setErrorList([error.message || "An error occurred"]);
} finally {
setIsSaving(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ import {
Contact,
ContactRow,
} from "@reporting/src/app/components/operations/types";
import { useSearchParams } from "next/navigation";
import { actionHandler } from "@bciers/actions";
import { createPersonResponsibleSchema } from "@reporting/src/app/components/operations/personResponsible/createPersonResponsibleSchema";
import { getReportingPersonResponsible } from "@reporting/src/app/utils/getReportingPersonResponsible";
import { getFacilityReport } from "@reporting/src/app/utils/getFacilityReport";
import serializeSearchParams from "@bciers/utils/src/serializeSearchParams";

interface Props {
version_id: number;
Expand All @@ -42,12 +40,11 @@ const PersonResponsible = ({ version_id }: Props) => {

const [schema, setSchema] = useState<RJSFSchema>(personResponsibleSchema);

const queryString = serializeSearchParams(useSearchParams());
const continueUrl =
operationType === "Linear Facility Operation"
? `/reporting/reports/${version_id}/facilities/lfo-facilities${queryString}`
: `/reporting/reports/${version_id}/facilities/${facilityId}/review${queryString}&facilities_title=Facility`;
const backUrl = `/reports/${version_id}/review-operator-data${queryString}`;
? `/reporting/reports/${version_id}/facilities/lfo-facilities`
: `/reporting/reports/${version_id}/facilities/${facilityId}/review`;
const backUrl = `/reports/${version_id}/review-operator-data`;

const taskListElements: TaskListElement[] = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ describe("operationColumns function", () => {
await user.click(screen.getByText("Continue"));

expect(useRouter().push).toHaveBeenCalledWith(
`reports/15/review-operator-data?reports_title=Operation with report`,
`reports/15/review-operator-data`,
);
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render, screen, waitFor, fireEvent } from "@testing-library/react";
import { describe, expect, it, beforeEach, vi } from "vitest";
import { useRouter, useSearchParams } from "next/navigation";
import { useRouter } from "next/navigation";
import { actionHandler } from "@bciers/actions";
import OperationReview from "@reporting/src/app/components/operations/OperationReview";

Expand All @@ -14,19 +14,14 @@ vi.mock("next/navigation", () => ({
}));

const mockUseRouter = useRouter as vi.MockedFunction<typeof useRouter>;
const mockUseSearchParams = useSearchParams as vi.MockedFunction<
typeof useSearchParams
>;

const mockActionHandler = actionHandler as vi.MockedFunction<
typeof actionHandler
>;

describe("OperationReview Component", () => {
beforeEach(() => {
mockUseRouter.mockReturnValue({ push: vi.fn() });
mockUseSearchParams.mockReturnValue(
"reports_title=Operation+3&facilities_title=Facility",
);
mockActionHandler.mockResolvedValue(true); // Mock the action handler to always resolve successfully
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ describe("The ProductionDataForm component", () => {
const calledProps = mockMultiStepFormWithTaskList.mock.calls[0][0];
await calledProps.onSubmit({ formData: { production_data: "test" } });
expect(mockPostProductionData).toHaveBeenCalledWith(1000, "abcd", "test");
expect(mockPush).toHaveBeenCalledWith(
"reports/1000/facilities/abcd/allocation-of-emissions",
);
});

it("on change, adds an item to the form data when a checkbox is checked", async () => {
Expand Down

0 comments on commit 4052364

Please sign in to comment.