From 02f4677aefc640dbd2b9569750dd2775d4b91577 Mon Sep 17 00:00:00 2001 From: Dave Richer Date: Wed, 21 Aug 2024 16:22:56 -0400 Subject: [PATCH] - Checkpoint Signed-off-by: Dave Richer --- ...oduction-list-config-manager.component.jsx | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/client/src/components/production-list-table/production-list-config-manager.component.jsx b/client/src/components/production-list-table/production-list-config-manager.component.jsx index 26fc45511..973d8d925 100644 --- a/client/src/components/production-list-table/production-list-config-manager.component.jsx +++ b/client/src/components/production-list-table/production-list-config-manager.component.jsx @@ -23,7 +23,6 @@ export function ProductionListConfigManager({ setColumns, setState, onSave, - defaultView, hasUnsavedChanges, setHasUnsavedChanges }) { @@ -34,6 +33,7 @@ export function ProductionListConfigManager({ const [open, setOpen] = useState(false); const [isAddingNewProfile, setIsAddingNewProfile] = useState(false); const [form] = Form.useForm(); + const [activeView, setActiveView] = useState(() => { const assoc = bodyshop.associations.find((a) => a.useremail === currentUser.email); return assoc && assoc.default_prod_list_view; @@ -257,7 +257,29 @@ export function ProductionListConfigManager({ } else { await updateActiveProdView(null); setColumns([]); - setState(defaultState); // Reset to default state if no configs are left + setState(defaultState); + } + } else { + // Revert back to the active view and load its columns and state + const activeConfig = bodyshop.production_config.find((pc) => pc.name === activeView); + if (activeConfig) { + await updateActiveProdView(activeView); + setColumns( + activeConfig.columns.columnKeys.map((k) => { + return { + ...ProductionListColumns({ + technician, + state: ensureDefaultState(state), + refetch, + data: data, + activeStatuses: bodyshop.md_ro_statuses.active_statuses, + treatments: { Enhanced_Payroll } + }).find((e) => e.key === k.key), + width: k.width + }; + }) + ); + setState(ensureDefaultState(activeConfig.columns.tableState)); } } }; @@ -311,7 +333,7 @@ export function ProductionListConfigManager({ useEffect(() => { const validateAndSetDefaultView = () => { - const configExists = bodyshop.production_config.some((pc) => pc.name === defaultView); + const configExists = bodyshop.production_config.some((pc) => pc.name === activeView); if (!configExists) { // If the default view doesn't exist, revert to the main profile @@ -344,7 +366,7 @@ export function ProductionListConfigManager({ } } else { // If the default view exists, set it as active - setActiveView(defaultView); + setActiveView(activeView); } }; @@ -356,7 +378,7 @@ export function ProductionListConfigManager({ validateAndSetDefaultView(); } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [defaultView, bodyshop.production_config]); + }, [activeView, bodyshop.production_config]); const popMenu = (