mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-02 09:43:12 +00:00
fix(work-orders): hide CompDoc affordance until dialog slice
Omit onOpenCompDoc on board-core so View Doc/Draft are not no-ops.
This commit is contained in:
parent
becc4913e3
commit
c97d752dd6
5 changed files with 40 additions and 10 deletions
|
|
@ -10,7 +10,8 @@ type CompDocCellProps = {
|
|||
status: CompletionDocStatus;
|
||||
woType: WOType | "";
|
||||
mediaCount?: number;
|
||||
onOpen: () => void;
|
||||
/** Omit until completion-doc slice mounts CompDocDialog. */
|
||||
onOpen?: () => void;
|
||||
onOpenMedia: () => void;
|
||||
};
|
||||
|
||||
|
|
@ -38,6 +39,10 @@ export function CompDocCell({
|
|||
);
|
||||
}
|
||||
|
||||
if (!onOpen) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const generated = status === "Yes";
|
||||
const notRequired = status === "NN";
|
||||
const color = generated ? "var(--color-success)" : "var(--color-text-muted)";
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ export type WoTableRowHandlers = {
|
|||
onRowClick: (row: WorkOrderTableRow) => void;
|
||||
onView: (row: WorkOrderTableRow) => void;
|
||||
onEdit: (row: WorkOrderTableRow) => void;
|
||||
onOpenCompDoc: (row: WorkOrderTableRow) => void;
|
||||
onOpenCompDoc?: (row: WorkOrderTableRow) => void;
|
||||
onOpenMedia: (row: WorkOrderTableRow) => void;
|
||||
onPatch: (id: string | number, patch: Partial<WorkOrderTableRow>) => void;
|
||||
onDuplicateFound?: (existing: WorkOrderTableRow) => void;
|
||||
|
|
@ -305,7 +305,7 @@ export function WoTableRow({
|
|||
status={row.docStatus}
|
||||
woType={row.type}
|
||||
mediaCount={row.mediaCount}
|
||||
onOpen={() => handlers.onOpenCompDoc(row)}
|
||||
onOpen={handlers.onOpenCompDoc ? () => handlers.onOpenCompDoc!(row) : undefined}
|
||||
onOpenMedia={() => handlers.onOpenMedia(row)}
|
||||
/>
|
||||
</td>
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ type WoTableProps = {
|
|||
vendors: VendorDropdownItem[];
|
||||
pmTypes: string[];
|
||||
onOpenSlideOver: (row: WorkOrderTableRow, edit?: boolean) => void;
|
||||
onOpenCompDoc: (row: WorkOrderTableRow) => void;
|
||||
/** Omit until completion-doc slice mounts CompDocDialog. */
|
||||
onOpenCompDoc?: (row: WorkOrderTableRow) => void;
|
||||
onOpenMedia: (row: WorkOrderTableRow) => void;
|
||||
onClearSearch?: () => void;
|
||||
onOpenAdvancedFilters?: () => void;
|
||||
|
|
@ -111,10 +112,12 @@ export function WoTable({
|
|||
tableData.setSelectedId(row.id);
|
||||
onOpenSlideOver(row, true);
|
||||
},
|
||||
onOpenCompDoc: (row: WorkOrderTableRow) => {
|
||||
tableData.setSelectedId(row.id);
|
||||
onOpenCompDoc(row);
|
||||
},
|
||||
onOpenCompDoc: onOpenCompDoc
|
||||
? (row: WorkOrderTableRow) => {
|
||||
tableData.setSelectedId(row.id);
|
||||
onOpenCompDoc(row);
|
||||
}
|
||||
: undefined,
|
||||
onOpenMedia: (row: WorkOrderTableRow) => {
|
||||
tableData.setSelectedId(row.id);
|
||||
onOpenMedia(row);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { useMemo, useState } from "react";
|
||||
import { useMemo, useState } from "react";
|
||||
import { Box } from "@mui/material";
|
||||
import { useNavigate } from "react-router";
|
||||
import { PageHeader } from "@/components/ui/page-header";
|
||||
|
|
@ -102,7 +102,6 @@ export default function WorkOrdersListPage() {
|
|||
tableData.setSelectedId(row.id);
|
||||
navigate(edit ? `/workorders/edit/${row.id}` : `/workorders/${row.id}`);
|
||||
}}
|
||||
onOpenCompDoc={() => undefined}
|
||||
onOpenMedia={setMediaRow}
|
||||
onClearSearch={() => filters.handleSearchChange("")}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { fireEvent, screen } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { WorkOrdersListHeader } from "@/app/(protected)/workorders/_components/list/work-orders-list-header";
|
||||
import { CompDocCell } from "@/app/(protected)/workorders/_components/list/table/cells/comp-doc-cell";
|
||||
import WorkOrdersListPage from "@/app/(protected)/workorders/index";
|
||||
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
|
||||
import { renderWithProviders } from "@/test/test-utils";
|
||||
|
|
@ -140,8 +141,30 @@ describe("WorkOrdersListPage board-core public interface", () => {
|
|||
|
||||
expect(screen.queryByRole("button", { name: /new wo/i })).not.toBeInTheDocument();
|
||||
expect(screen.queryByLabelText("Advanced Filters")).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: /view doc|draft/i })).not.toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: /view canceled row/i }));
|
||||
expect(navigate).toHaveBeenCalledWith("/workorders/77");
|
||||
});
|
||||
});
|
||||
|
||||
describe("CompDocCell slice affordances", () => {
|
||||
it("hides View Doc / Draft when onOpen is omitted", () => {
|
||||
const { container } = renderWithProviders(
|
||||
<CompDocCell status="No" woType="Preventative" onOpenMedia={vi.fn()} />,
|
||||
{ withAuth: false },
|
||||
);
|
||||
|
||||
expect(screen.queryByRole("button", { name: /view doc|draft|n\/n/i })).not.toBeInTheDocument();
|
||||
expect(container.textContent).toBe("");
|
||||
});
|
||||
|
||||
it("shows View Doc when onOpen is provided", () => {
|
||||
renderWithProviders(
|
||||
<CompDocCell status="Yes" woType="Preventative" onOpen={vi.fn()} onOpenMedia={vi.fn()} />,
|
||||
{ withAuth: false },
|
||||
);
|
||||
|
||||
expect(screen.getByRole("button", { name: /view doc/i })).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue