BOD-20 Added resizing for production list + fixed sorter state saving error.
This commit is contained in:
@@ -155,7 +155,7 @@ export default [
|
||||
title: i18n.t("production.labels.alert"),
|
||||
dataIndex: "alert",
|
||||
key: "alert",
|
||||
width: "4%",
|
||||
|
||||
render: (text, record) => <ProductionListColumnAlert record={record} />,
|
||||
},
|
||||
{
|
||||
@@ -169,7 +169,7 @@ export default [
|
||||
title: i18n.t("production.labels.cycletime"),
|
||||
dataIndex: "ct",
|
||||
key: "ct",
|
||||
width: "3%",
|
||||
|
||||
render: (text, record) => {
|
||||
let ct = 0;
|
||||
if (!!record.actual_in) {
|
||||
@@ -185,7 +185,7 @@ export default [
|
||||
title: i18n.t("production.labels.bodypriority"),
|
||||
dataIndex: "bodypriority",
|
||||
key: "bodypriority",
|
||||
width: "3%",
|
||||
|
||||
sorter: (a, b) =>
|
||||
((a.production_vars && a.production_vars.bodypriority) || 11) -
|
||||
((b.production_vars && b.production_vars.bodypriority) || 11),
|
||||
@@ -197,7 +197,7 @@ export default [
|
||||
title: i18n.t("production.labels.paintpriority"),
|
||||
dataIndex: "paintpriority",
|
||||
key: "paintpriority",
|
||||
width: "3%",
|
||||
|
||||
sorter: (a, b) =>
|
||||
((a.production_vars && a.production_vars.paintpriority) || 11) -
|
||||
((b.production_vars && b.production_vars.paintpriority) || 11),
|
||||
|
||||
@@ -18,18 +18,20 @@ const mapDispatchToProps = (dispatch) => ({
|
||||
export function ProductionListSaveConfigButton({
|
||||
columns,
|
||||
bodyshop,
|
||||
|
||||
tableState,
|
||||
}) {
|
||||
const [updateShop] = useMutation(UPDATE_SHOP);
|
||||
const { t } = useTranslation();
|
||||
|
||||
const handleSaveConfig = () => {
|
||||
updateShop({
|
||||
variables: {
|
||||
id: bodyshop.id,
|
||||
shop: {
|
||||
production_config: {
|
||||
columnKeys: columns.map((i) => i.key),
|
||||
columnKeys: columns.map((i) => {
|
||||
return { key: i.key, width: i.width };
|
||||
}),
|
||||
tableState,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -9,6 +9,7 @@ import ReactDragListView from "react-drag-listview"; //TODO Is there a better wa
|
||||
import "./production-list-table.styles.scss";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import ProductionListColumnsAdd from "../production-list-columns/production-list-columns.add.component";
|
||||
import ResizeableTitle from "./production-list-table.resizeable.component";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser
|
||||
@@ -36,8 +37,14 @@ export function ProductionListTable({
|
||||
}
|
||||
);
|
||||
const { t } = useTranslation();
|
||||
|
||||
const handleTableChange = (pagination, filters, sorter) => {
|
||||
setState({ ...state, filteredInfo: filters, sortedInfo: sorter });
|
||||
console.log("sorter", sorter);
|
||||
setState({
|
||||
...state,
|
||||
filteredInfo: filters,
|
||||
sortedInfo: { columnKey: sorter.columnKey, order: sorter.order },
|
||||
});
|
||||
};
|
||||
|
||||
const onDragEnd = (fromIndex, toIndex) => {
|
||||
@@ -52,10 +59,20 @@ export function ProductionListTable({
|
||||
setColumns(columns.filter((i) => i.key !== key));
|
||||
};
|
||||
|
||||
const handleResize = (index) => (e, { size }) => {
|
||||
const nextColumns = [...columns];
|
||||
nextColumns[index] = {
|
||||
...nextColumns[index],
|
||||
width: size.width,
|
||||
};
|
||||
setColumns(nextColumns);
|
||||
};
|
||||
|
||||
const Now = new Date();
|
||||
|
||||
const headerItem = (col) => (
|
||||
<Dropdown
|
||||
className='prod-header-dropdown'
|
||||
overlay={
|
||||
<Menu onClick={removeColumn}>
|
||||
<Menu.Item key={col.key}>
|
||||
@@ -70,10 +87,18 @@ export function ProductionListTable({
|
||||
if (!!!columns) return <div>No columns found.</div>;
|
||||
|
||||
return (
|
||||
<ReactDragListView.DragColumn onDragEnd={onDragEnd} nodeSelector='th'>
|
||||
<ReactDragListView.DragColumn
|
||||
onDragEnd={onDragEnd}
|
||||
nodeSelector='th'
|
||||
handleSelector='.prod-header-dropdown'>
|
||||
<Table
|
||||
size='small'
|
||||
pagination={false}
|
||||
components={{
|
||||
header: {
|
||||
cell: ResizeableTitle,
|
||||
},
|
||||
}}
|
||||
title={() => (
|
||||
<div style={{ display: "flex" }}>
|
||||
<ProductionListColumnsAdd columnState={columnState} />
|
||||
@@ -94,12 +119,16 @@ export function ProductionListTable({
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
columns={columns.map((c) => {
|
||||
columns={columns.map((c, index) => {
|
||||
return {
|
||||
...c,
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === c.key && state.sortedInfo.order,
|
||||
title: headerItem(c),
|
||||
onHeaderCell: (column) => ({
|
||||
width: column.width,
|
||||
onResize: handleResize(index),
|
||||
}),
|
||||
};
|
||||
})}
|
||||
rowKey='id'
|
||||
@@ -141,11 +170,7 @@ export function ProductionListTable({
|
||||
const classes = [];
|
||||
if (!!record.scheduled_completion) {
|
||||
if (new Date(record.scheduled_completion) - Now < OneCalendarDay)
|
||||
console.log(
|
||||
"new Date(record.scheduled_completion) - Now < OneCalendarDay",
|
||||
new Date(record.scheduled_completion) - Now < OneCalendarDay
|
||||
);
|
||||
classes.push("production-completion-1");
|
||||
classes.push("production-completion-1");
|
||||
}
|
||||
return classes.join(" ");
|
||||
}} //TODO What could be good usage here?
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import React from "react";
|
||||
import { Resizable } from "react-resizable";
|
||||
|
||||
export default (props) => {
|
||||
const { onResize, width, ...restProps } = props;
|
||||
return (
|
||||
<Resizable width={width || 200} height={0} onResize={onResize}>
|
||||
<th {...restProps} />
|
||||
</Resizable>
|
||||
);
|
||||
};
|
||||
@@ -22,3 +22,18 @@
|
||||
background: rgba(207, 12, 12, 0.555);
|
||||
}
|
||||
}
|
||||
|
||||
.react-resizable {
|
||||
position: relative;
|
||||
background-clip: padding-box;
|
||||
}
|
||||
|
||||
.react-resizable-handle {
|
||||
position: absolute;
|
||||
width: 10px;
|
||||
height: 100%;
|
||||
bottom: 0;
|
||||
right: -5px;
|
||||
cursor: col-resize;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user