From 5fb62aa16b62ac1acce0c819cc6464e1afeb9c11 Mon Sep 17 00:00:00 2001 From: swtmply Date: Fri, 26 May 2023 00:15:35 +0800 Subject: [PATCH] IO-2264 added filter by estimators for the schedule --- .../schedule-calendar.component.jsx | 65 +++++++++++++++---- client/src/graphql/appointments.queries.js | 2 + client/src/translations/en_us/common.json | 1 + 3 files changed, 55 insertions(+), 13 deletions(-) diff --git a/client/src/components/schedule-calendar/schedule-calendar.component.jsx b/client/src/components/schedule-calendar/schedule-calendar.component.jsx index b565a15bf..144ef5392 100644 --- a/client/src/components/schedule-calendar/schedule-calendar.component.jsx +++ b/client/src/components/schedule-calendar/schedule-calendar.component.jsx @@ -39,20 +39,44 @@ export function ScheduleCalendarComponent({ data, refetch, bodyshop }) { employeevacation: true, ins_co_nm: null, }); + const [estimatorsFilter, setEstimatiorsFilter] = useLocalStorage( + "estimators", + [] + ); + + const estimators = useMemo( + () => + data + .filter((d) => d.__typename === "appointments") + .map((app) => `${app.job.est_ct_fn} ${app.job.est_ct_ln}`), + [data] + ); + const filteredData = useMemo(() => { - return data.filter( - (d) => - (d.block || - (filter.intake && d.isintake) || - (filter.manual && !d.isintake && d.block === false) || - (d.__typename === "employee_vacation" && - filter.employeevacation && - !!d.employee)) && - (filter.ins_co_nm && filter.ins_co_nm.length > 0 - ? filter.ins_co_nm.includes(d.job?.ins_co_nm) - : true) - ); - }, [data, filter]); + return data + .filter((d) => { + if (d.__typename === "appointments") { + if (estimatorsFilter.length === 0) return true; + + return !!estimatorsFilter.find( + (e) => e !== `${d.job.est_ct_fn} ${d.job.est_ct_ln}` + ); + } + return true; + }) + .filter( + (d) => + (d.block || + (filter.intake && d.isintake) || + (filter.manual && !d.isintake && d.block === false) || + (d.__typename === "employee_vacation" && + filter.employeevacation && + !!d.employee)) && + (filter.ins_co_nm && filter.ins_co_nm.length > 0 + ? filter.ins_co_nm.includes(d.job?.ins_co_nm) + : true) + ); + }, [data, filter, estimatorsFilter]); return ( @@ -63,6 +87,21 @@ export function ScheduleCalendarComponent({ data, refetch, bodyshop }) { extra={ +