trithuc-mvc-react 1.5.0 → 1.5.2

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.
@@ -1,4 +1,4 @@
1
- import { Table, TableBody, TableCell, TableContainer, TableRow } from "@mui/material";
1
+ import { Table, TableBody, TableCell, TableContainer, TableRow, useMediaQuery, useTheme } from "@mui/material";
2
2
  import TablePaginationCustom from "../table/TablePagination";
3
3
  import { useMemo, useState } from "react";
4
4
 
@@ -142,6 +142,9 @@ const DataTable = () => {
142
142
  })
143
143
  .catch(() => {});
144
144
  };
145
+ const theme = useTheme();
146
+ const downXL = useMediaQuery(theme.breakpoints.down("xl"));
147
+ console.log("downXL", downXL);
145
148
  return (
146
149
  <>
147
150
  <TableContainer sx={{ position: "relative" }}>
@@ -151,8 +154,13 @@ const DataTable = () => {
151
154
  rowCount={rows.length}
152
155
  onDeleteMultiple={handleDeleteMultiple}
153
156
  />
154
- <Table className="border">
155
- <TableHead headLabel={columns} onSelectAllClick={handleSelectAllClick} numSelected={selected?.length} rowCount={rows.length} />
157
+ <Table className="border" size={downXL ? "small" : "medium"}>
158
+ <TableHead
159
+ headLabel={columns}
160
+ onSelectAllClick={handleSelectAllClick}
161
+ numSelected={selected?.length}
162
+ rowCount={rows.length}
163
+ />
156
164
  {isLoading ? (
157
165
  <TableRowsLoader rowsNum={5} colsNum={columns.length + 4} />
158
166
  ) : (
@@ -169,10 +177,12 @@ const DataTable = () => {
169
177
  onDelete={handleDelete}
170
178
  />
171
179
  ))}
172
-
180
+
173
181
  {rows?.length == 0 && (
174
182
  <TableRow>
175
- <TableCell colSpan={columns.length + 4} align="center">Không có dữ liệu</TableCell>
183
+ <TableCell colSpan={columns.length + 4} align="center">
184
+ Không có dữ liệu
185
+ </TableCell>
176
186
  </TableRow>
177
187
  )}
178
188
  </TableBody>
@@ -3,7 +3,7 @@ import { exportExcel } from "../../api";
3
3
  import { Button } from "@mui/material";
4
4
  import { Download } from "@mui/icons-material";
5
5
 
6
- const ExportExcelButton = ({ tableName, data }) => {
6
+ const ExportExcelButton = ({ tableName, data, size = "small" }) => {
7
7
  const handleExportExcel = async (tableName, data) => {
8
8
  const _data = await exportExcel({ tableName, data });
9
9
  if (_data.status) {
@@ -14,14 +14,15 @@ const ExportExcelButton = ({ tableName, data }) => {
14
14
  };
15
15
  return (
16
16
  <Button
17
+ size={size}
17
18
  variant="outlined"
18
19
  startIcon={<Download />}
19
20
  onClick={() => {
20
- handleExportExcel(tableName,data);
21
+ handleExportExcel(tableName, data);
21
22
  }}
22
23
  >
23
24
  Excel
24
25
  </Button>
25
26
  );
26
- }
27
- export default ExportExcelButton;
27
+ };
28
+ export default ExportExcelButton;
@@ -29,6 +29,7 @@ export function FilterElement({ name, type, label, keyValue, keyLabel, childrenF
29
29
 
30
30
  switch (type) {
31
31
  case "search":
32
+ console.log(size)
32
33
  return (
33
34
  <OutlinedInput
34
35
  {...rest}
@@ -5,7 +5,7 @@ import DateRangePicker from "../date/DateRangePicker";
5
5
  import { FilterElement } from "./FilterElement";
6
6
  import { useDataTable } from "./hooks";
7
7
 
8
- export const FilterGod = ({ filters, elementSize = "medium" }) => {
8
+ export const FilterGod = ({ filters, elementSize = "small" }) => {
9
9
  const { handleSubmit } = useFormContext();
10
10
  const onSubmit = (data) => console.log(data);
11
11
  const { setDataSearch, dataSearch } = useDataTable();
@@ -17,7 +17,7 @@ export const FilterGod = ({ filters, elementSize = "medium" }) => {
17
17
  onSubmit={handleSubmit(onSubmit)}
18
18
  sx={{
19
19
  px: 1,
20
- my: 2,
20
+ my: elementSize == "small" ? 0 : 2,
21
21
  display: "flex",
22
22
  alignItems: "center"
23
23
  }}
@@ -13,14 +13,18 @@ export function TableHead({ numSelected, rowCount, onSelectAllClick, headLabel }
13
13
  onChange={onSelectAllClick}
14
14
  />
15
15
  </TableCell>
16
- <TableCell sx={{ fontWeight: 700 }}>STT</TableCell>
16
+ <TableCell sx={{ textAlign: "center" }}>STT</TableCell>
17
17
  {headLabel.map((headCell) => (
18
- <TableCell key={headCell.field} align={headCell.alignRight ? "right" : "left"} sx={{ fontWeight: 700 }}>
18
+ <TableCell
19
+ key={headCell.field}
20
+ align={headCell.alignRight ? "right" : "left"}
21
+ sx={{ textAlign: "center" }}
22
+ >
19
23
  {headCell.label}
20
24
  </TableCell>
21
25
  ))}
22
- {!disableStatus && canEdit && <TableCell>Kích hoạt</TableCell>}
23
- <TableCell sx={{minWidth: '136px'}}>Thao tác</TableCell>
26
+ {!disableStatus && canEdit && <TableCell sx={{ textAlign: "center"} }>Kích hoạt</TableCell>}
27
+ <TableCell sx={{ minWidth: "136px", textAlign: "center" }} >Thao tác</TableCell>
24
28
  </TableRow>
25
29
  </MuiTableHead>
26
30
  );
@@ -32,19 +32,20 @@ export const TableRowRender = ({ index, row, selected, onSelect, onChangeStatus,
32
32
  <TableCell padding="checkbox">
33
33
  <Checkbox checked={selected} onChange={(event) => onSelect(event, row[selectedField])} />
34
34
  </TableCell>
35
- <TableCell>{index + 1}</TableCell>
35
+ <TableCell align="center">{index + 1}</TableCell>
36
36
  {columns.map(
37
37
  ({
38
38
  field,
39
- alignRight = false,
39
+ type="text",
40
40
  valueGetter = (row) => {
41
41
  return row[field];
42
42
  },
43
43
  renderCell,
44
44
  valueFormat = (e) => e
45
45
  }) => {
46
+ let align = ( type=="image" || type == "number" || type =="date"|| type == "datetime") ? "right" : "left";
46
47
  return (
47
- <TableCell key={`${row[selectedField]}-${field}`} align={alignRight ? "right" : "left"}>
48
+ <TableCell key={`${row[selectedField]}-${field}`} align={align}>
48
49
  {renderCell ? renderCell(row) : valueFormat(valueGetter(row))}
49
50
  </TableCell>
50
51
  );
@@ -1,4 +1,4 @@
1
- import { Button, Card, IconButton, Stack, Tooltip, Typography } from "@mui/material";
1
+ import { Button, Card, IconButton, Stack, Tooltip, Typography, useTheme, useMediaQuery } from "@mui/material";
2
2
 
3
3
  import { useEffect, useMemo, useState } from "react";
4
4
 
@@ -12,6 +12,7 @@ import EditorDialog from "./EditorDialog";
12
12
 
13
13
  import ExportExcelButton from "./ExportExcelButton";
14
14
  import { FilterGod } from "./FilterGod";
15
+ import { useDataTable } from "./hooks";
15
16
 
16
17
  DataManagement.propTypes = {
17
18
  columns: PropTypes.array,
@@ -36,8 +37,7 @@ DataManagement.propTypes = {
36
37
  disableEditor: PropTypes.bool,
37
38
  onAddClick: PropTypes.func,
38
39
  onEditClick: PropTypes.func,
39
- tabPanel: PropTypes.node,
40
- filterSize: PropTypes.oneOf(["small", "medium"])
40
+ tabPanel: PropTypes.node
41
41
  };
42
42
 
43
43
  function DataManagement({
@@ -55,7 +55,11 @@ function DataManagement({
55
55
  onAddClick = () => {},
56
56
  onEditClick = () => {},
57
57
  tabPanel,
58
- filterSize = "medium"
58
+ slotProps = {
59
+ header: {
60
+ sx: {}
61
+ }
62
+ }
59
63
  }) {
60
64
  const [openEditorDialog, setOpenEditorDialog] = useState(false);
61
65
  const [selectedEditItem, setSelectedEditItem] = useState(null);
@@ -73,6 +77,13 @@ function DataManagement({
73
77
  return { defaults, filters };
74
78
  }, [tableFilters]);
75
79
 
80
+ const theme = useTheme();
81
+ const upXL = useMediaQuery(theme.breakpoints.up("xl"));
82
+ const elementSize = useMemo(() => {
83
+ const elementSize = upXL ? "medium" : "small";
84
+ return elementSize;
85
+ }, [upXL]);
86
+
76
87
  useEffect(() => {
77
88
  if (selectedEditItem && disableEditor) {
78
89
  onEditClick(selectedEditItem);
@@ -114,13 +125,14 @@ function DataManagement({
114
125
  <DataTableContext.Provider value={values}>
115
126
  <PermissionContext.Provider value={permissionValues}>
116
127
  <FormProvider {...methods}>
117
- <Stack direction="row" justifyContent={"space-between"} sx={{ mb: 4 }}>
128
+ <Stack direction="row" justifyContent={"space-between"} sx={{ mb: upXL ? 2 : 1, ...slotProps?.header?.sx }}>
118
129
  <Typography variant="h4">{title}</Typography>
119
130
  <Stack direction="row" spacing={1}>
120
131
  <Tooltip title="Làm mới">
121
132
  <IconButton
122
133
  variant="outlined"
123
134
  color="primary"
135
+ size={elementSize}
124
136
  onClick={() => {
125
137
  setDataSearch({ ...defaults });
126
138
  [...filters].forEach((filter) => {
@@ -134,9 +146,10 @@ function DataManagement({
134
146
  </IconButton>
135
147
  </Tooltip>
136
148
 
137
- <ExportExcelButton tableName={tableName} data={dataSearch} />
149
+ <ExportExcelButton tableName={tableName} data={dataSearch} size={elementSize} />
138
150
  {(!Permission || Permission.Create) && (
139
151
  <Button
152
+ size={elementSize}
140
153
  variant="contained"
141
154
  startIcon={<Add />}
142
155
  onClick={(e) => {
@@ -152,9 +165,10 @@ function DataManagement({
152
165
  )}
153
166
  </Stack>
154
167
  </Stack>
168
+
155
169
  <Card>
156
170
  {tabPanel}
157
- <FilterGod filters={filters} elementSize={filterSize} />
171
+ <FilterGod filters={filters} elementSize={elementSize} />
158
172
  <DataTable />
159
173
  </Card>
160
174
  </FormProvider>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trithuc-mvc-react",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"