- Address changes to profile from call
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -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({
|
const result = await updateShop({
|
||||||
variables: {
|
variables: {
|
||||||
id: bodyshop.id,
|
id: bodyshop.id,
|
||||||
@@ -161,6 +157,41 @@ export function ProductionListConfigManager({
|
|||||||
|
|
||||||
const selectedConfig = bodyshop.production_config.find((pc) => pc.name === value);
|
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) {
|
if (selectedConfig) {
|
||||||
const newColumns = selectedConfig.columns.columnKeys.map((k) => {
|
const newColumns = selectedConfig.columns.columnKeys.map((k) => {
|
||||||
return {
|
return {
|
||||||
@@ -191,6 +222,7 @@ export function ProductionListConfigManager({
|
|||||||
if (name === t("production.constants.main_profile")) return;
|
if (name === t("production.constants.main_profile")) return;
|
||||||
|
|
||||||
const remainingConfigs = bodyshop.production_config.filter((b) => b.name !== name);
|
const remainingConfigs = bodyshop.production_config.filter((b) => b.name !== name);
|
||||||
|
|
||||||
await updateShop({
|
await updateShop({
|
||||||
variables: {
|
variables: {
|
||||||
id: bodyshop.id,
|
id: bodyshop.id,
|
||||||
@@ -202,6 +234,7 @@ export function ProductionListConfigManager({
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (name === activeView) {
|
if (name === activeView) {
|
||||||
|
// Only switch profiles if the deleted profile was the active profile
|
||||||
if (remainingConfigs.length > 0) {
|
if (remainingConfigs.length > 0) {
|
||||||
const nextConfig = remainingConfigs[0];
|
const nextConfig = remainingConfigs[0];
|
||||||
await updateActiveProdView(nextConfig.name);
|
await updateActiveProdView(nextConfig.name);
|
||||||
@@ -277,12 +310,50 @@ export function ProductionListConfigManager({
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
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) {
|
if (!bodyshop.production_config || bodyshop.production_config.length === 0) {
|
||||||
createDefaultView().catch((e) => {
|
createDefaultView().catch((e) => {
|
||||||
console.error("Something went wrong saving the production list view Config.");
|
console.error("Something went wrong saving the production list view Config.");
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
setActiveView(defaultView);
|
validateAndSetDefaultView();
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [defaultView, bodyshop.production_config]);
|
}, [defaultView, bodyshop.production_config]);
|
||||||
@@ -326,7 +397,7 @@ export function ProductionListConfigManager({
|
|||||||
placeholder={t("production.labels.selectview")}
|
placeholder={t("production.labels.selectview")}
|
||||||
optionLabelProp="label"
|
optionLabelProp="label"
|
||||||
popupMatchSelectWidth={false}
|
popupMatchSelectWidth={false}
|
||||||
value={activeView}
|
value={activeView} // Ensure this only changes when appropriate
|
||||||
>
|
>
|
||||||
{bodyshop.production_config
|
{bodyshop.production_config
|
||||||
.slice()
|
.slice()
|
||||||
|
|||||||
Reference in New Issue
Block a user