trithuc-mvc-react 1.7.4 → 1.8.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.
|
@@ -13,7 +13,7 @@ import { TableRowRender } from "./TableRowRender";
|
|
|
13
13
|
import TableToolbar from "./TableToolbar";
|
|
14
14
|
import { useDataTable } from "./hooks";
|
|
15
15
|
import { usePermission } from "../../hooks";
|
|
16
|
-
const DataTable = () => {
|
|
16
|
+
const DataTable = ({ multipleActions = [] }) => {
|
|
17
17
|
const {
|
|
18
18
|
tableName,
|
|
19
19
|
selectedField,
|
|
@@ -24,10 +24,11 @@ const DataTable = () => {
|
|
|
24
24
|
setOpenViewDialog,
|
|
25
25
|
onEditClick
|
|
26
26
|
} = useDataTable();
|
|
27
|
-
|
|
27
|
+
|
|
28
|
+
const { set: setPermission } = usePermission(tableName);
|
|
28
29
|
const queryClient = useQueryClient();
|
|
29
30
|
const confirm = useConfirm();
|
|
30
|
-
const [
|
|
31
|
+
const [selectedItems, setSelectedItems] = useState([]);
|
|
31
32
|
const [page, setPage] = useState(0);
|
|
32
33
|
const [rowsPerPage, setRowsPerPage] = useState(5);
|
|
33
34
|
|
|
@@ -74,7 +75,7 @@ const DataTable = () => {
|
|
|
74
75
|
const deleteMultipleMutation = useMutation(deleteMultipleDataFromTable, {
|
|
75
76
|
onSuccess: () => {
|
|
76
77
|
toast.success("Xóa thành công !");
|
|
77
|
-
|
|
78
|
+
setSelectedItems([]);
|
|
78
79
|
queryClient.invalidateQueries({ queryKey: [tableName] });
|
|
79
80
|
},
|
|
80
81
|
onError: () => {
|
|
@@ -120,46 +121,53 @@ const DataTable = () => {
|
|
|
120
121
|
useEffect(() => {
|
|
121
122
|
let PermissionModel = data?.PermissionModel;
|
|
122
123
|
PermissionModel && setPermission(PermissionModel);
|
|
124
|
+
}, [data]);
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
const newSelectedItems = selectedItems.filter((selectedId) => {
|
|
127
|
+
return rows?.some((row) => row.Id == selectedId);
|
|
128
|
+
});
|
|
129
|
+
setSelectedItems(newSelectedItems);
|
|
123
130
|
}, [rows]);
|
|
124
|
-
|
|
125
131
|
const handleChangePage = (event, newPage) => {
|
|
126
132
|
setPage(newPage);
|
|
127
133
|
};
|
|
128
|
-
const isSelected = (Id) =>
|
|
134
|
+
const isSelected = (Id) => selectedItems.indexOf(Id) !== -1;
|
|
135
|
+
|
|
129
136
|
const handleSelect = (event, Id) => {
|
|
130
|
-
const selectedIndex =
|
|
137
|
+
const selectedIndex = selectedItems.indexOf(Id);
|
|
131
138
|
let newSelected = [];
|
|
132
139
|
|
|
133
140
|
if (selectedIndex === -1) {
|
|
134
|
-
newSelected = newSelected.concat(
|
|
141
|
+
newSelected = newSelected.concat(selectedItems, Id);
|
|
135
142
|
} else if (selectedIndex === 0) {
|
|
136
|
-
newSelected = newSelected.concat(
|
|
137
|
-
} else if (selectedIndex ===
|
|
138
|
-
newSelected = newSelected.concat(
|
|
143
|
+
newSelected = newSelected.concat(selectedItems.slice(1));
|
|
144
|
+
} else if (selectedIndex === selectedItems.length - 1) {
|
|
145
|
+
newSelected = newSelected.concat(selectedItems.slice(0, -1));
|
|
139
146
|
} else if (selectedIndex > 0) {
|
|
140
|
-
newSelected = newSelected.concat(
|
|
147
|
+
newSelected = newSelected.concat(selectedItems.slice(0, selectedIndex), selectedItems.slice(selectedIndex + 1));
|
|
141
148
|
}
|
|
142
149
|
|
|
143
|
-
|
|
150
|
+
setSelectedItems(newSelected);
|
|
144
151
|
};
|
|
145
152
|
const handleSelectAllClick = (event) => {
|
|
146
153
|
if (event.target.checked) {
|
|
147
154
|
const newSelected = rows.map((n) => n[selectedField]);
|
|
148
|
-
|
|
155
|
+
setSelectedItems(newSelected);
|
|
149
156
|
return;
|
|
150
157
|
}
|
|
151
|
-
|
|
158
|
+
setSelectedItems([]);
|
|
152
159
|
};
|
|
160
|
+
|
|
153
161
|
const handleChangeRowsPerPage = (event) => {
|
|
154
162
|
setRowsPerPage(parseInt(event.target.value, 10));
|
|
155
163
|
setPage(0);
|
|
156
164
|
};
|
|
157
165
|
const handleDeleteMultiple = () => {
|
|
158
|
-
confirm({ description: `Bạn có chắc chắn muốn xóa ${
|
|
166
|
+
confirm({ description: `Bạn có chắc chắn muốn xóa ${selectedItems?.length} bản ghi này không?`, title: "Xác nhận" })
|
|
159
167
|
.then(() => {
|
|
160
168
|
deleteMultipleMutation.mutate({
|
|
161
169
|
tableName,
|
|
162
|
-
ids:
|
|
170
|
+
ids: selectedItems
|
|
163
171
|
});
|
|
164
172
|
})
|
|
165
173
|
.catch(() => {});
|
|
@@ -172,15 +180,18 @@ const DataTable = () => {
|
|
|
172
180
|
<TableContainer sx={{ position: "relative" }}>
|
|
173
181
|
<TableToolbar
|
|
174
182
|
onSelectAllClick={handleSelectAllClick}
|
|
175
|
-
numSelected={
|
|
183
|
+
numSelected={selectedItems?.length}
|
|
176
184
|
rowCount={rows.length}
|
|
177
185
|
onDeleteMultiple={handleDeleteMultiple}
|
|
186
|
+
selected={selectedItems}
|
|
187
|
+
multipleActions={multipleActions}
|
|
178
188
|
/>
|
|
189
|
+
|
|
179
190
|
<Table className="border" size={downXL ? "small" : "medium"}>
|
|
180
191
|
<TableHead
|
|
181
192
|
headLabel={columns}
|
|
182
193
|
onSelectAllClick={handleSelectAllClick}
|
|
183
|
-
numSelected={
|
|
194
|
+
numSelected={selectedItems?.length}
|
|
184
195
|
rowCount={rows.length}
|
|
185
196
|
/>
|
|
186
197
|
{isLoading ? (
|
|
@@ -16,7 +16,7 @@ export const FilterGod = ({ filters, elementSize = "small" }) => {
|
|
|
16
16
|
const { setDataSearch, dataSearch } = useDataTable();
|
|
17
17
|
|
|
18
18
|
return (
|
|
19
|
-
<Box component={"form"}
|
|
19
|
+
<Box component={"form"}>
|
|
20
20
|
<Accordion>
|
|
21
21
|
<AccordionSummary
|
|
22
22
|
sx={{
|
|
@@ -170,7 +170,7 @@ function FormField({
|
|
|
170
170
|
render={({ field }) => {
|
|
171
171
|
return (
|
|
172
172
|
<FormControl fullWidth size={size}>
|
|
173
|
-
<FormLabel>{label}</FormLabel>
|
|
173
|
+
{/* <FormLabel>{label}</FormLabel> */}
|
|
174
174
|
<RadioGroup row {...field}>
|
|
175
175
|
{[...datas].map(({ label, value }) => (
|
|
176
176
|
<FormControlLabel key={value} value={value} control={<Radio />} label={label} />
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Checkbox, IconButton, Tooltip, Typography, Box, useMediaQuery } from "@mui/material";
|
|
1
|
+
import { Checkbox, IconButton, Tooltip, Typography, Box, useMediaQuery, Stack } from "@mui/material";
|
|
2
2
|
import { Delete } from "@mui/icons-material";
|
|
3
3
|
|
|
4
4
|
import PropTypes from "prop-types";
|
|
@@ -6,14 +6,23 @@ import { useTheme } from "@mui/material/styles";
|
|
|
6
6
|
import { RootStyle } from "./TableRowRender";
|
|
7
7
|
import { usePermission } from "../../hooks";
|
|
8
8
|
import { useDataTable } from "./hooks";
|
|
9
|
+
import { useMemo } from "react";
|
|
9
10
|
// ----------------------------------------------------------------------
|
|
10
|
-
const TableToolbar = ({ numSelected, onSelectAllClick, rowCount, onDeleteMultiple }) => {
|
|
11
|
+
const TableToolbar = ({ selected, multipleActions = [], numSelected, onSelectAllClick, rowCount, onDeleteMultiple }) => {
|
|
11
12
|
const theme = useTheme();
|
|
12
13
|
const isLight = theme.palette.mode === "light";
|
|
13
14
|
const { tableName } = useDataTable();
|
|
14
|
-
const { canDeleteMulti } = usePermission(tableName);
|
|
15
|
+
const { canDeleteMulti, canAction } = usePermission(tableName);
|
|
15
16
|
const downXl = useMediaQuery(theme.breakpoints.down("xl"));
|
|
16
17
|
|
|
18
|
+
const actions = useMemo(() => {
|
|
19
|
+
const actions = [...multipleActions].filter(({ permissionType }) => {
|
|
20
|
+
return !(permissionType == "action" && !canAction);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return actions;
|
|
24
|
+
}, [canAction, multipleActions]);
|
|
25
|
+
|
|
17
26
|
return (
|
|
18
27
|
numSelected > 0 && (
|
|
19
28
|
<RootStyle
|
|
@@ -41,13 +50,28 @@ const TableToolbar = ({ numSelected, onSelectAllClick, rowCount, onDeleteMultipl
|
|
|
41
50
|
</Typography>
|
|
42
51
|
</Box>
|
|
43
52
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
<
|
|
47
|
-
<
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
<Stack direction="row" alignItems="center" spacing={1}>
|
|
54
|
+
{actions.map(({ title, onClick, element }) => (
|
|
55
|
+
<Tooltip key={title} title={title}>
|
|
56
|
+
<IconButton
|
|
57
|
+
size={downXl ? "small" : "medium"}
|
|
58
|
+
onClick={() => {
|
|
59
|
+
onClick(selected);
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
{element}
|
|
63
|
+
</IconButton>
|
|
64
|
+
</Tooltip>
|
|
65
|
+
))}
|
|
66
|
+
|
|
67
|
+
{canDeleteMulti && (
|
|
68
|
+
<Tooltip title="Xóa tất cả" onClick={onDeleteMultiple}>
|
|
69
|
+
<IconButton size={downXl ? "small" : "medium"}>
|
|
70
|
+
<Delete color="primary" />
|
|
71
|
+
</IconButton>
|
|
72
|
+
</Tooltip>
|
|
73
|
+
)}
|
|
74
|
+
</Stack>
|
|
51
75
|
</RootStyle>
|
|
52
76
|
)
|
|
53
77
|
);
|
|
@@ -55,7 +55,10 @@ function DataManagement({
|
|
|
55
55
|
disableStatus = false,
|
|
56
56
|
disableAdd = false,
|
|
57
57
|
disableCellThaoTac = false,
|
|
58
|
+
|
|
58
59
|
tableActions = [],
|
|
60
|
+
multipleActions = [],
|
|
61
|
+
|
|
59
62
|
disableEditor = false,
|
|
60
63
|
onAddClick = () => {},
|
|
61
64
|
onEditClick = () => {},
|
|
@@ -180,9 +183,11 @@ function DataManagement({
|
|
|
180
183
|
{tabPanel}
|
|
181
184
|
<FilterGod filters={filters} elementSize={elementSize} />
|
|
182
185
|
{backParentNavigator}
|
|
183
|
-
|
|
186
|
+
|
|
187
|
+
<DataTable multipleActions={multipleActions} />
|
|
184
188
|
</Card>
|
|
185
189
|
</FormProvider>
|
|
190
|
+
|
|
186
191
|
{disableEditor || (
|
|
187
192
|
<EditorDialog
|
|
188
193
|
open={openEditorDialog}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trithuc-mvc-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
"lodash": "^4.17.21",
|
|
23
23
|
"moment": "^2.29.4",
|
|
24
24
|
"prop-types": "^15.8.1",
|
|
25
|
-
"react-hook-form": "^7.45.2",
|
|
26
25
|
"yup": "^1.2.0"
|
|
27
26
|
},
|
|
28
27
|
"devDependencies": {
|
|
@@ -43,6 +42,7 @@
|
|
|
43
42
|
"react-query": "^3.39.3",
|
|
44
43
|
"react-toastify": "^9.1.3",
|
|
45
44
|
"material-ui-confirm": "^3.0.9",
|
|
46
|
-
"@mui/x-date-pickers": "^6.10.2"
|
|
45
|
+
"@mui/x-date-pickers": "^6.10.2",
|
|
46
|
+
"react-hook-form": "^7.45.2"
|
|
47
47
|
}
|
|
48
48
|
}
|