@@ -11,6 +11,7 @@ import { selectTechnician } from "../../redux/tech/tech.selectors";
|
|||||||
import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selectors";
|
import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selectors";
|
||||||
import ProductionListColumns from "../production-list-columns/production-list-columns.data";
|
import ProductionListColumns from "../production-list-columns/production-list-columns.data";
|
||||||
import { useSplitTreatments } from "@splitsoftware/splitio-react";
|
import { useSplitTreatments } from "@splitsoftware/splitio-react";
|
||||||
|
import { isFunction } from "lodash";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
@@ -18,7 +19,17 @@ const mapStateToProps = createStructuredSelector({
|
|||||||
currentUser: selectCurrentUser
|
currentUser: selectCurrentUser
|
||||||
});
|
});
|
||||||
|
|
||||||
export function ProductionListTable({ refetch, bodyshop, technician, currentUser, state, data, setColumns, setState }) {
|
export function ProductionListTable({
|
||||||
|
refetch,
|
||||||
|
bodyshop,
|
||||||
|
technician,
|
||||||
|
currentUser,
|
||||||
|
state,
|
||||||
|
data,
|
||||||
|
setColumns,
|
||||||
|
setState,
|
||||||
|
onProfileChange
|
||||||
|
}) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [updateDefaultProdView] = useMutation(UPDATE_ACTIVE_PROD_LIST_VIEW);
|
const [updateDefaultProdView] = useMutation(UPDATE_ACTIVE_PROD_LIST_VIEW);
|
||||||
const [updateShop] = useMutation(UPDATE_SHOP);
|
const [updateShop] = useMutation(UPDATE_SHOP);
|
||||||
@@ -32,25 +43,25 @@ export function ProductionListTable({ refetch, bodyshop, technician, currentUser
|
|||||||
});
|
});
|
||||||
|
|
||||||
const handleSelect = async (value, option) => {
|
const handleSelect = async (value, option) => {
|
||||||
setColumns(
|
const newColumns = bodyshop.production_config
|
||||||
bodyshop.production_config
|
.filter((pc) => pc.name === value)[0]
|
||||||
.filter((pc) => pc.name === value)[0]
|
.columns.columnKeys.map((k) => {
|
||||||
.columns.columnKeys.map((k) => {
|
return {
|
||||||
return {
|
...ProductionListColumns({
|
||||||
...ProductionListColumns({
|
bodyshop,
|
||||||
bodyshop,
|
refetch,
|
||||||
refetch,
|
technician,
|
||||||
technician,
|
state,
|
||||||
state,
|
data: data,
|
||||||
data: data,
|
activeStatuses: bodyshop.md_ro_statuses.active_statuses,
|
||||||
activeStatuses: bodyshop.md_ro_statuses.active_statuses,
|
treatments: { Enhanced_Payroll }
|
||||||
treatments: { Enhanced_Payroll }
|
}).find((e) => e.key === k.key),
|
||||||
}).find((e) => e.key === k.key),
|
width: k.width
|
||||||
width: k.width
|
};
|
||||||
};
|
});
|
||||||
})
|
setColumns(newColumns);
|
||||||
);
|
const newState = bodyshop.production_config.filter((pc) => pc.name === value)[0].columns.tableState;
|
||||||
setState(bodyshop.production_config.filter((pc) => pc.name === value)[0].columns.tableState);
|
setState(newState);
|
||||||
|
|
||||||
const assoc = bodyshop.associations.find((a) => a.useremail === currentUser.email);
|
const assoc = bodyshop.associations.find((a) => a.useremail === currentUser.email);
|
||||||
|
|
||||||
@@ -72,6 +83,10 @@ export function ProductionListTable({ refetch, bodyshop, technician, currentUser
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (onProfileChange && isFunction(onProfileChange)) {
|
||||||
|
onProfileChange({ value, option, newColumns, newState, assoc });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleTrash = async (name) => {
|
const handleTrash = async (name) => {
|
||||||
|
|||||||
@@ -96,7 +96,11 @@ export function ProductionListTable({ loading, data, refetch, bodyshop, technici
|
|||||||
width: k.width ?? 100
|
width: k.width ?? 100
|
||||||
};
|
};
|
||||||
}) || [];
|
}) || [];
|
||||||
setColumns(newColumns);
|
|
||||||
|
// Only update columns if they haven't been manually changed by the user
|
||||||
|
if (_.isEqual(initialColumnsRef.current, columns)) {
|
||||||
|
setColumns(newColumns);
|
||||||
|
}
|
||||||
}, [
|
}, [
|
||||||
matchingColumnConfig,
|
matchingColumnConfig,
|
||||||
bodyshop,
|
bodyshop,
|
||||||
@@ -105,7 +109,8 @@ export function ProductionListTable({ loading, data, refetch, bodyshop, technici
|
|||||||
Enhanced_Payroll,
|
Enhanced_Payroll,
|
||||||
Production_List_Status_Colors,
|
Production_List_Status_Colors,
|
||||||
refetch,
|
refetch,
|
||||||
state
|
state,
|
||||||
|
columns
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const handleTableChange = (pagination, filters, sorter) => {
|
const handleTableChange = (pagination, filters, sorter) => {
|
||||||
@@ -121,9 +126,11 @@ export function ProductionListTable({ loading, data, refetch, bodyshop, technici
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onDragEnd = (fromIndex, toIndex) => {
|
const onDragEnd = (fromIndex, toIndex) => {
|
||||||
const columnsCopy = columns.slice();
|
if (fromIndex === toIndex) return;
|
||||||
const item = columnsCopy.splice(fromIndex, 1)[0];
|
|
||||||
columnsCopy.splice(toIndex, 0, item);
|
const columnsCopy = [...columns];
|
||||||
|
const [movedItem] = columnsCopy.splice(fromIndex, 1);
|
||||||
|
columnsCopy.splice(toIndex, 0, movedItem);
|
||||||
|
|
||||||
if (!_.isEqual(columnsCopy, columns)) {
|
if (!_.isEqual(columnsCopy, columns)) {
|
||||||
setColumns(columnsCopy);
|
setColumns(columnsCopy);
|
||||||
@@ -188,21 +195,23 @@ export function ProductionListTable({ loading, data, refetch, bodyshop, technici
|
|||||||
setHasUnsavedChanges(false);
|
setHasUnsavedChanges(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const dataSource =
|
const filterData = (item, searchText) => {
|
||||||
searchText === ""
|
const fieldsToSearch = [
|
||||||
? data
|
item.ro_number,
|
||||||
: data.filter(
|
item.ownr_co_nm,
|
||||||
(j) =>
|
item.ownr_fn,
|
||||||
(j.ro_number || "").toString().toLowerCase().includes(searchText.toLowerCase()) ||
|
item.ownr_ln,
|
||||||
(j.ownr_co_nm || "").toLowerCase().includes(searchText.toLowerCase()) ||
|
item.status,
|
||||||
(j.ownr_fn || "").toLowerCase().includes(searchText.toLowerCase()) ||
|
item.ins_co_nm,
|
||||||
(j.ownr_ln || "").toLowerCase().includes(searchText.toLowerCase()) ||
|
item.clm_no,
|
||||||
(j.status || "").toLowerCase().includes(searchText.toLowerCase()) ||
|
item.v_model_desc,
|
||||||
(j.ins_co_nm || "").toLowerCase().includes(searchText.toLowerCase()) ||
|
item.v_make_desc
|
||||||
(j.clm_no || "").toLowerCase().includes(searchText.toLowerCase()) ||
|
];
|
||||||
(j.v_model_desc || "").toLowerCase().includes(searchText.toLowerCase()) ||
|
|
||||||
(j.v_make_desc || "").toLowerCase().includes(searchText.toLowerCase())
|
return fieldsToSearch.some((field) => (field || "").toString().toLowerCase().includes(searchText.toLowerCase()));
|
||||||
);
|
};
|
||||||
|
|
||||||
|
const dataSource = searchText === "" ? data : data.filter((j) => filterData(j, searchText));
|
||||||
|
|
||||||
if (!!!columns) return <div>No columns found.</div>;
|
if (!!!columns) return <div>No columns found.</div>;
|
||||||
|
|
||||||
@@ -270,17 +279,11 @@ export function ProductionListTable({ loading, data, refetch, bodyshop, technici
|
|||||||
/>
|
/>
|
||||||
<ProductionListTableViewSelect
|
<ProductionListTableViewSelect
|
||||||
state={state}
|
state={state}
|
||||||
setState={(newState) => {
|
setState={setState}
|
||||||
if (!_.isEqual(newState, state)) {
|
setColumns={setColumns}
|
||||||
setState(newState);
|
onProfileChange={() => {
|
||||||
setHasUnsavedChanges(false);
|
initialStateRef.current = state;
|
||||||
}
|
setHasUnsavedChanges(false);
|
||||||
}}
|
|
||||||
setColumns={(newColumns) => {
|
|
||||||
if (!_.isEqual(newColumns, columns)) {
|
|
||||||
setColumns(newColumns);
|
|
||||||
setHasUnsavedChanges(false);
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
refetch={refetch}
|
refetch={refetch}
|
||||||
data={data}
|
data={data}
|
||||||
|
|||||||
Reference in New Issue
Block a user