trithuc-mvc-react 1.0.13 → 1.1.0

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.
@@ -198,7 +198,7 @@ function FormField({
198
198
  <Controller
199
199
  name={name}
200
200
  control={control}
201
- // defaultValue={true}
201
+ defaultValue={true}
202
202
  render={({ field }) => <FormControlLabel control={<Switch {...field} checked={field.value} />} label={label} />}
203
203
  />
204
204
  );
@@ -2,6 +2,7 @@ import { Checkbox, TableRow, TableCell, TableHead as MuiTableHead } from "@mui/m
2
2
  import { useDataTable, usePermission } from "./hooks";
3
3
  export function TableHead({ numSelected, rowCount, onSelectAllClick, headLabel }) {
4
4
  const { canEdit } = usePermission();
5
+ const { disableStatus } = useDataTable();
5
6
  return (
6
7
  <MuiTableHead sx={{ height: 56, visibility: numSelected > 0 ? "hidden" : "visible" }}>
7
8
  <TableRow>
@@ -18,8 +19,8 @@ export function TableHead({ numSelected, rowCount, onSelectAllClick, headLabel }
18
19
  {headCell.label}
19
20
  </TableCell>
20
21
  ))}
21
- {canEdit && <TableCell>Kích hoạt</TableCell>}
22
- <TableCell>Thao tác</TableCell>
22
+ {!disableStatus && canEdit && <TableCell>Kích hoạt</TableCell>}
23
+ <TableCell sx={{minWidth: '136px'}}>Thao tác</TableCell>
23
24
  </TableRow>
24
25
  </MuiTableHead>
25
26
  );
@@ -6,10 +6,15 @@ import { useDataTable, usePermission } from "./hooks";
6
6
 
7
7
  // material
8
8
  import { styled } from "@mui/material/styles";
9
+ import MoreMenu from "../MoreMenu";
10
+
11
+
12
+
9
13
 
10
14
  export const TableRowRender = ({ index, row, selected, onSelect, onChangeStatus, onDelete, onEdit }) => {
11
- const { selectedField, columns } = useDataTable();
15
+ const { selectedField, columns, statusKey, disableStatus, tableActions } = useDataTable();
12
16
  const { canEdit, canDelete } = usePermission();
17
+ console.log("tableActions", tableActions);
13
18
  return (
14
19
  <TableRow hover key={row[selectedField]} selected={selected}>
15
20
  <TableCell padding="checkbox">
@@ -32,10 +37,10 @@ export const TableRowRender = ({ index, row, selected, onSelect, onChangeStatus,
32
37
  );
33
38
  }
34
39
  )}
35
- {canEdit && (
40
+ {!disableStatus && canEdit && (
36
41
  <TableCell>
37
42
  <Switch
38
- checked={row.Status}
43
+ checked={row[statusKey]}
39
44
  onChange={() => {
40
45
  onChangeStatus(row[selectedField]);
41
46
  }}
@@ -64,6 +69,8 @@ export const TableRowRender = ({ index, row, selected, onSelect, onChangeStatus,
64
69
  </IconButton>
65
70
  </Tooltip>
66
71
  )}
72
+
73
+ {<MoreMenu actions={tableActions} data={row}/>}
67
74
  </TableCell>
68
75
  </TableRow>
69
76
  );
@@ -27,10 +27,26 @@ DataManagement.propTypes = {
27
27
  onChangeAfter: PropTypes.func,
28
28
  filters: PropTypes.array
29
29
  })
30
- )
30
+ ),
31
+ editorFields: PropTypes.array,
32
+ validationSchema: PropTypes.object,
33
+ disableStatus: PropTypes.bool,
34
+ statusKey: PropTypes.string,
35
+ tableActions: PropTypes.array
31
36
  };
32
37
 
33
- function DataManagement({ columns = [], title, tableName, selectedField = "Id", filters, editorFields, validationSchema = {} }) {
38
+ function DataManagement({
39
+ columns = [],
40
+ title,
41
+ tableName,
42
+ selectedField = "Id",
43
+ filters,
44
+ editorFields,
45
+ validationSchema = {},
46
+ statusKey = "Status",
47
+ disableStatus = false,
48
+ tableActions = []
49
+ }) {
34
50
  const [openEditorDialog, setOpenEditorDialog] = useState(false);
35
51
  const [selectedEditItem, setSelectedEditItem] = useState(null);
36
52
  const [dataSearch, setDataSearch] = useState({});
@@ -46,9 +62,12 @@ function DataManagement({ columns = [], title, tableName, selectedField = "Id",
46
62
  setOpenEditorDialog,
47
63
  dataSearch,
48
64
  setDataSearch,
49
- validationSchema
65
+ validationSchema,
66
+ statusKey,
67
+ disableStatus,
68
+ tableActions
50
69
  };
51
- }, [tableName, selectedField, columns, selectedEditItem, dataSearch, setDataSearch, validationSchema]);
70
+ }, [tableName, selectedField, columns, selectedEditItem, dataSearch, setDataSearch, validationSchema, tableActions]);
52
71
  const permissionValues = useMemo(() => {
53
72
  return {
54
73
  Permission,
@@ -0,0 +1,50 @@
1
+ import PropTypes from "prop-types";
2
+ import { useRef, useState } from "react";
3
+
4
+ // material
5
+ import { Menu, MenuItem, IconButton, ListItemIcon, ListItemText } from "@mui/material";
6
+ import MoreVertIcon from "@mui/icons-material/MoreVert";
7
+ // ----------------------------------------------------------------------
8
+
9
+ MoreMenu.propTypes = {
10
+ onDelete: PropTypes.func,
11
+ userName: PropTypes.string,
12
+ actions: PropTypes.array,
13
+ data: PropTypes.any
14
+ };
15
+
16
+ export default function MoreMenu({ data, actions }) {
17
+ const ref = useRef(null);
18
+ const [isOpen, setIsOpen] = useState(false);
19
+
20
+ if (actions?.length == 0) {
21
+ return null;
22
+ }
23
+ return (
24
+ <>
25
+ <IconButton ref={ref} onClick={() => setIsOpen(true)}>
26
+ <MoreVertIcon />
27
+ </IconButton>
28
+
29
+ <Menu
30
+ open={isOpen}
31
+ anchorEl={ref.current}
32
+ onClose={() => setIsOpen(false)}
33
+ slotProps={{
34
+ paper: {
35
+ sx: { width: 200, maxWidth: "100%" }
36
+ }
37
+ }}
38
+ anchorOrigin={{ vertical: "top", horizontal: "right" }}
39
+ transformOrigin={{ vertical: "top", horizontal: "right" }}
40
+ >
41
+ {[...actions].map(({ title, onClick, element }) => (
42
+ <MenuItem key={title} onClick={() => onClick(data)} sx={{ color: "text.secondary" }}>
43
+ <ListItemIcon>{element}</ListItemIcon>
44
+ <ListItemText primary={title} primaryTypographyProps={{ variant: "body2" }} />
45
+ </MenuItem>
46
+ ))}
47
+ </Menu>
48
+ </>
49
+ );
50
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trithuc-mvc-react",
3
- "version": "1.0.13",
3
+ "version": "1.1.0",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"