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