From 1e7c285fefb281278f366e38a09659b38fedc320 Mon Sep 17 00:00:00 2001 From: Dave Richer Date: Tue, 20 Aug 2024 13:46:35 -0400 Subject: [PATCH 1/2] - Address changes to profile from call Signed-off-by: Dave Richer --- ...oduction-list-config-manager.component.jsx | 25 ++++++++++++++++--- client/src/translations/en_us/common.json | 2 +- 2 files changed, 22 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 c16f8e40f..ebe001c3e 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 @@ -59,11 +59,30 @@ export function ProductionListConfigManager({ const defaultConfig = { name: t("production.constants.main_profile"), columns: { - columnKeys: columns.map((i) => ({ key: i.key, width: i.width })), + columnKeys: [ + { key: "ro_number", width: 100 }, + { key: "ownr", width: 100 }, + { key: "vehicle", width: 100 }, + { key: "ins_co_nm", width: 100 }, + { key: "actual_in", width: 100 }, + { key: "scheduled_completion", width: 100 }, + { key: "labhrs", width: 100 }, + { key: "employee_body", width: 100 }, + { key: "larhrs", width: 100 }, + { key: "employee_refinish", width: 100 }, + { key: "tt", width: 100 }, + { key: "status", width: 100 }, + { key: "sublets", width: 100 }, + { key: "viewdetail", width: 100 } + ], tableState: ensureDefaultState(state) } }; + // Immediately update the columns and state to reflect the new default view + setColumns(defaultConfig.columns.columnKeys); + setState(defaultConfig.columns.tableState); + const result = await updateShop({ variables: { id: bodyshop.id, @@ -75,9 +94,7 @@ export function ProductionListConfigManager({ if (!result.errors) { await updateActiveProdView(t("production.constants.main_profile")); - setColumns(defaultConfig.columns.columnKeys); - setState(defaultConfig.columns.tableState); - notification.success({ message: t("bodyshop.successes.defaultviewcreated") }); + window.location.reload(); // Reload the page } else { notification.error({ message: t("bodyshop.errors.creatingdefaultview", { diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index 79e208d91..ff93baff8 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -2737,7 +2737,7 @@ }, "production": { "constants":{ - "main_profile": "Main" + "main_profile": "Default" }, "options": { "small": "Small", From 8018daa2dca4ca5cb968e9a07312376d1fe31941 Mon Sep 17 00:00:00 2001 From: Dave Richer Date: Tue, 20 Aug 2024 14:12:19 -0400 Subject: [PATCH 2/2] - Address changes to profile from call Signed-off-by: Dave Richer --- ...oduction-list-config-manager.component.jsx | 83 +++++++++++++++++-- 1 file changed, 77 insertions(+), 6 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 ebe001c3e..c33b164ff 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 @@ -79,10 +79,6 @@ export function ProductionListConfigManager({ } }; - // Immediately update the columns and state to reflect the new default view - setColumns(defaultConfig.columns.columnKeys); - setState(defaultConfig.columns.tableState); - const result = await updateShop({ variables: { id: bodyshop.id, @@ -161,6 +157,41 @@ export function ProductionListConfigManager({ const selectedConfig = bodyshop.production_config.find((pc) => pc.name === value); + // If the selected profile doesn't exist, revert to the main profile + if (!selectedConfig) { + const mainProfileConfig = bodyshop.production_config.find( + (pc) => pc.name === t("production.constants.main_profile") + ); + + if (mainProfileConfig) { + await updateActiveProdView(t("production.constants.main_profile")); + setColumns( + mainProfileConfig.columns.columnKeys.map((k) => { + return { + ...ProductionListColumns({ + bodyshop, + refetch, + technician, + state: ensureDefaultState(state), + data: data, + activeStatuses: bodyshop.md_ro_statuses.active_statuses, + treatments: { Enhanced_Payroll } + }).find((e) => e.key === k.key), + width: k.width + }; + }) + ); + const newState = ensureDefaultState(mainProfileConfig.columns.tableState); + setState(newState); + + if (onSave && isFunction(onSave)) { + onSave(); + } + return; + } + } + + // If the selected profile exists, proceed as normal if (selectedConfig) { const newColumns = selectedConfig.columns.columnKeys.map((k) => { return { @@ -191,6 +222,7 @@ export function ProductionListConfigManager({ if (name === t("production.constants.main_profile")) return; const remainingConfigs = bodyshop.production_config.filter((b) => b.name !== name); + await updateShop({ variables: { id: bodyshop.id, @@ -202,6 +234,7 @@ export function ProductionListConfigManager({ }); if (name === activeView) { + // Only switch profiles if the deleted profile was the active profile if (remainingConfigs.length > 0) { const nextConfig = remainingConfigs[0]; await updateActiveProdView(nextConfig.name); @@ -277,12 +310,50 @@ export function ProductionListConfigManager({ }; useEffect(() => { + const validateAndSetDefaultView = () => { + const configExists = bodyshop.production_config.some((pc) => pc.name === defaultView); + + if (!configExists) { + // If the default view doesn't exist, revert to the main profile + const mainProfileConfig = bodyshop.production_config.find( + (pc) => pc.name === t("production.constants.main_profile") + ); + + if (mainProfileConfig) { + setActiveView(t("production.constants.main_profile")); + + setColumns( + mainProfileConfig.columns.columnKeys.map((k) => { + return { + ...ProductionListColumns({ + bodyshop, + refetch, + technician, + state: ensureDefaultState(state), + data: data, + activeStatuses: bodyshop.md_ro_statuses.active_statuses, + treatments: { Enhanced_Payroll } + }).find((e) => e.key === k.key), + width: k.width + }; + }) + ); + setState(ensureDefaultState(mainProfileConfig.columns.tableState)); + + updateActiveProdView(t("production.constants.main_profile")); + } + } else { + // If the default view exists, set it as active + setActiveView(defaultView); + } + }; + if (!bodyshop.production_config || bodyshop.production_config.length === 0) { createDefaultView().catch((e) => { console.error("Something went wrong saving the production list view Config."); }); } else { - setActiveView(defaultView); + validateAndSetDefaultView(); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [defaultView, bodyshop.production_config]); @@ -326,7 +397,7 @@ export function ProductionListConfigManager({ placeholder={t("production.labels.selectview")} optionLabelProp="label" popupMatchSelectWidth={false} - value={activeView} + value={activeView} // Ensure this only changes when appropriate > {bodyshop.production_config .slice()