- Checkpoint

Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
Dave Richer
2024-08-21 16:22:56 -04:00
parent 11785f3b86
commit 02f4677aef

View File

@@ -23,7 +23,6 @@ export function ProductionListConfigManager({
setColumns, setColumns,
setState, setState,
onSave, onSave,
defaultView,
hasUnsavedChanges, hasUnsavedChanges,
setHasUnsavedChanges setHasUnsavedChanges
}) { }) {
@@ -34,6 +33,7 @@ export function ProductionListConfigManager({
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [isAddingNewProfile, setIsAddingNewProfile] = useState(false); const [isAddingNewProfile, setIsAddingNewProfile] = useState(false);
const [form] = Form.useForm(); const [form] = Form.useForm();
const [activeView, setActiveView] = useState(() => { const [activeView, setActiveView] = useState(() => {
const assoc = bodyshop.associations.find((a) => a.useremail === currentUser.email); const assoc = bodyshop.associations.find((a) => a.useremail === currentUser.email);
return assoc && assoc.default_prod_list_view; return assoc && assoc.default_prod_list_view;
@@ -257,7 +257,29 @@ export function ProductionListConfigManager({
} else { } else {
await updateActiveProdView(null); await updateActiveProdView(null);
setColumns([]); 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(() => { useEffect(() => {
const validateAndSetDefaultView = () => { 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 (!configExists) {
// If the default view doesn't exist, revert to the main profile // If the default view doesn't exist, revert to the main profile
@@ -344,7 +366,7 @@ export function ProductionListConfigManager({
} }
} else { } else {
// If the default view exists, set it as active // If the default view exists, set it as active
setActiveView(defaultView); setActiveView(activeView);
} }
}; };
@@ -356,7 +378,7 @@ export function ProductionListConfigManager({
validateAndSetDefaultView(); validateAndSetDefaultView();
} }
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [defaultView, bodyshop.production_config]); }, [activeView, bodyshop.production_config]);
const popMenu = ( const popMenu = (
<div> <div>