refactor(workorders): extract slide-over open-tab effect to meet function size cap

This commit is contained in:
Alexandre Brandizzi 2026-10-01 23:17:33 -03:00
parent f9b5d3e0ea
commit e6548ffa17

View file

@ -77,6 +77,29 @@ function useSlideOverInitialization({
}, [row?.id, editMode]);
}
// Re-apply the requested tab on every open, including a second notification for the work order
// already on screen (same row id) where the identity effect does not re-run. Tab-only so an
// in-flight edit draft is never discarded.
function useSlideOverOpenRequestTab({
row,
editMode,
initialTab,
setTab,
openRequestKey,
}: {
row: WorkOrderTableRow | null;
editMode: boolean;
initialTab: SlideOverTab;
setTab: (tab: SlideOverTab) => void;
openRequestKey: number;
}) {
useEffect(() => {
if (!row) return;
setTab(editMode ? "info" : initialTab);
// eslint-disable-next-line react-hooks/exhaustive-deps -- openRequestKey gates each open
}, [openRequestKey]);
}
export function useSlideOverEditState({
row,
editMode,
@ -109,14 +132,7 @@ export function useSlideOverEditState({
setUnsavedIntent,
});
// Re-apply the requested tab on every open, including a second notification for the work order
// already on screen (same row id) where the identity effect above does not re-run. Tab-only so
// an in-flight edit draft is never discarded.
useEffect(() => {
if (!row) return;
setTab(editMode ? "info" : initialTab);
// eslint-disable-next-line react-hooks/exhaustive-deps -- openRequestKey gates each open
}, [openRequestKey]);
useSlideOverOpenRequestTab({ row, editMode, initialTab, setTab, openRequestKey });
const lockStatus = infoSource?.status ?? row?.status;
const isInfoLocked = isSlideOverInfoLocked(lockStatus);