@nethru/ui 1.0.40 → 1.0.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/PropertyTable.js +38 -25
- package/package.json +1 -1
package/dist/PropertyTable.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { useMemo, useState } from "react";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import { forwardRef, useMemo, useState } from "react";
|
|
2
|
+
import MenuItem from "@mui/material/MenuItem";
|
|
3
|
+
import { DataGrid, useGridApiContext } from "@mui/x-data-grid";
|
|
4
|
+
import Select from "./Select";
|
|
4
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
6
|
export default function PropertyTable({
|
|
6
7
|
columns,
|
|
7
8
|
rows,
|
|
8
9
|
onUpdate,
|
|
9
10
|
readOnly,
|
|
10
|
-
customGridCellMap = {},
|
|
11
11
|
sx,
|
|
12
12
|
...props
|
|
13
13
|
}) {
|
|
@@ -54,26 +54,16 @@ export default function PropertyTable({
|
|
|
54
54
|
return !params.row.deletable ? 'fixed' : '';
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
|
+
if (column.type === 'singleSelect' && column.valueOptions) {
|
|
58
|
+
newColumn.renderEditCell = params => /*#__PURE__*/_jsx(SingleSelect, {
|
|
59
|
+
options: column.valueOptions,
|
|
60
|
+
...params
|
|
61
|
+
});
|
|
62
|
+
}
|
|
57
63
|
return newColumn;
|
|
58
64
|
});
|
|
59
65
|
}, [columns, readOnly]);
|
|
60
66
|
const [updatedRows, setUpdatedRows] = useState(rows);
|
|
61
|
-
const CustomGridCell = function (params) {
|
|
62
|
-
let children;
|
|
63
|
-
const func = customGridCellMap[params.column.field];
|
|
64
|
-
if (func) children = func(params);
|
|
65
|
-
if (!children) children = /*#__PURE__*/_jsx(Box, {
|
|
66
|
-
sx: {
|
|
67
|
-
mt: 2,
|
|
68
|
-
mb: 2
|
|
69
|
-
},
|
|
70
|
-
children: params.formattedValue
|
|
71
|
-
});
|
|
72
|
-
return /*#__PURE__*/_jsx(GridCell, {
|
|
73
|
-
...params,
|
|
74
|
-
children: children
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
67
|
const processRowUpdate = row => {
|
|
78
68
|
const newRows = updatedRows.filter(r => r.id !== row.id);
|
|
79
69
|
newRows.push(row);
|
|
@@ -89,10 +79,6 @@ export default function PropertyTable({
|
|
|
89
79
|
isCellEditable: params => {
|
|
90
80
|
return params.row.deletable || !params.colDef.fixed;
|
|
91
81
|
},
|
|
92
|
-
slots: {
|
|
93
|
-
cell: CustomGridCell,
|
|
94
|
-
...props.slots
|
|
95
|
-
},
|
|
96
82
|
processRowUpdate: processRowUpdate,
|
|
97
83
|
onProcessRowUpdateError: error => console.log(error),
|
|
98
84
|
disableColumnMenu: true,
|
|
@@ -104,4 +90,31 @@ export default function PropertyTable({
|
|
|
104
90
|
},
|
|
105
91
|
...props
|
|
106
92
|
});
|
|
107
|
-
}
|
|
93
|
+
}
|
|
94
|
+
const SingleSelect = /*#__PURE__*/forwardRef((props, ref) => {
|
|
95
|
+
const {
|
|
96
|
+
id,
|
|
97
|
+
value,
|
|
98
|
+
field,
|
|
99
|
+
options
|
|
100
|
+
} = props;
|
|
101
|
+
const apiRef = useGridApiContext();
|
|
102
|
+
const handleChange = (event, data) => {
|
|
103
|
+
apiRef.current.setEditCellValue({
|
|
104
|
+
id,
|
|
105
|
+
field,
|
|
106
|
+
value: data.props.value
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
return /*#__PURE__*/_jsx(Select, {
|
|
110
|
+
fontSize: 14,
|
|
111
|
+
ref: ref,
|
|
112
|
+
value: value,
|
|
113
|
+
onChange: handleChange,
|
|
114
|
+
fullWidth: true,
|
|
115
|
+
children: options.map(option => /*#__PURE__*/_jsx(MenuItem, {
|
|
116
|
+
value: option.value,
|
|
117
|
+
children: option.label
|
|
118
|
+
}, option.value))
|
|
119
|
+
});
|
|
120
|
+
});
|