mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-02 10:53:13 +00:00
fix(workorders): match renamed service filter aliases
This commit is contained in:
parent
315a26c07d
commit
24107ee3b2
3 changed files with 50 additions and 3 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import type { WorkOrderAdvancedFilters } from "@/domain/work-orders/types/work-order-advanced-filters";
|
||||
import type { Service } from "@/domain/services/types/service";
|
||||
import { ASSIGNEE_FILTER_UNASSIGNED } from "@/domain/work-orders/types/work-order-list";
|
||||
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
|
||||
import { dateRangeFor } from "@/domain/work-orders/utils/advanced-filters-utils";
|
||||
|
|
@ -12,6 +13,7 @@ import { addDaysIso } from "@/domain/work-orders/utils/wizard-date-utils";
|
|||
type AdvancedFilterPredicate = (
|
||||
row: WorkOrderTableRow,
|
||||
filters: WorkOrderAdvancedFilters,
|
||||
serviceHistory: Service[],
|
||||
) => boolean;
|
||||
|
||||
const isOpenUndated = (row: WorkOrderTableRow): boolean =>
|
||||
|
|
@ -60,8 +62,15 @@ const matchesDispatcher: AdvancedFilterPredicate = (row, filters) => {
|
|||
const matchesStatus: AdvancedFilterPredicate = (row, filters) =>
|
||||
!filters.statuses.size || (!!row.status && filters.statuses.has(row.status as never));
|
||||
|
||||
const matchesPmType: AdvancedFilterPredicate = (row, filters) =>
|
||||
!filters.pmTypes.size || filters.pmTypes.has(row.pm);
|
||||
const matchesPmType: AdvancedFilterPredicate = (row, filters, serviceHistory) => {
|
||||
if (!filters.pmTypes.size || filters.pmTypes.has(row.pm)) return true;
|
||||
if (row.serviceId == null) return false;
|
||||
|
||||
const linkedService = serviceHistory.find(
|
||||
(service) => String(service.id) === String(row.serviceId),
|
||||
);
|
||||
return linkedService != null && filters.pmTypes.has(linkedService.name);
|
||||
};
|
||||
|
||||
const matchesVendorTech: AdvancedFilterPredicate = (row, filters) =>
|
||||
!filters.vendorTechs.size ||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import type { WorkOrderAdvancedFilters } from "@/domain/work-orders/types/work-order-advanced-filters";
|
||||
import type { Service } from "@/domain/services/types/service";
|
||||
import { ASSIGNEE_FILTER_UNASSIGNED } from "@/domain/work-orders/types/work-order-list";
|
||||
import type { WorkOrderBarFilters } from "@/domain/work-orders/types/work-order-list-filters";
|
||||
import type { WOType } from "@/domain/work-orders/types/work-order-wizard";
|
||||
|
|
@ -36,8 +37,9 @@ export function enrichTableRow(row: WorkOrderTableRow): WorkOrderTableRow {
|
|||
export function matchesAdvancedFilters(
|
||||
row: WorkOrderTableRow,
|
||||
filters: WorkOrderAdvancedFilters,
|
||||
serviceHistory: Service[] = [],
|
||||
): boolean {
|
||||
return ADVANCED_FILTER_PREDICATES.every((predicate) => predicate(row, filters));
|
||||
return ADVANCED_FILTER_PREDICATES.every((predicate) => predicate(row, filters, serviceHistory));
|
||||
}
|
||||
|
||||
function rowMatchesSearch(row: WorkOrderTableRow, query: string): boolean {
|
||||
|
|
|
|||
|
|
@ -370,6 +370,42 @@ describe("buildDayGroups", () => {
|
|||
});
|
||||
|
||||
describe("matchesAdvancedFilters", () => {
|
||||
it("matches inactive renamed registry services across the global date range", () => {
|
||||
const row = makeRow({
|
||||
pm: "Historic Service Name",
|
||||
serviceId: 701,
|
||||
scheduledOn: "2024-03-12",
|
||||
});
|
||||
const filters = {
|
||||
...EMPTY_ADVANCED_FILTERS,
|
||||
pmTypes: new Set(["Current Service Name"]),
|
||||
};
|
||||
const serviceHistory = [
|
||||
{
|
||||
id: 701,
|
||||
name: "Current Service Name",
|
||||
trade: "Electrical",
|
||||
iconKey: "wrench",
|
||||
requiresCompletionDocument: false,
|
||||
completionDocTemplate: null,
|
||||
isActive: false,
|
||||
supportedWorkOrderTypes: ["PM" as const],
|
||||
},
|
||||
];
|
||||
|
||||
expect(matchesAdvancedFilters(row, filters, serviceHistory)).toBe(true);
|
||||
expect(row.pm).toBe("Historic Service Name");
|
||||
});
|
||||
|
||||
it("continues matching legacy service labels without a linked registry identity", () => {
|
||||
const filters = {
|
||||
...EMPTY_ADVANCED_FILTERS,
|
||||
pmTypes: new Set(["Legacy Problem"]),
|
||||
};
|
||||
|
||||
expect(matchesAdvancedFilters(makeRow({ pm: "Legacy Problem" }), filters, [])).toBe(true);
|
||||
});
|
||||
|
||||
it("filters by site and type", () => {
|
||||
const weekMonday = mondayOf(todayIso());
|
||||
const row = makeRow({
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue