trithuc-mvc-react 2.4.8 → 2.5.1

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 = ({ multipleActions = [],page, setPage = () => { } }) => {
16
+ const DataTable = ({ multipleActions = [],page, setPage = () => { }, disableEdit, disableDelete }) => {
17
17
  const {
18
18
  tableName,
19
19
  selectedField,
@@ -209,6 +209,8 @@ const DataTable = ({ multipleActions = [],page, setPage = () => { } }) => {
209
209
  selected={isSelected(row[selectedField])}
210
210
  onSelect={handleSelect}
211
211
  onEdit={handlEdit}
212
+ disableEdit={disableEdit}
213
+ disableDelete={disableDelete}
212
214
  onView={handlViewDetail}
213
215
  onChangeStatus={handleChangeStatus}
214
216
  onDelete={handleDelete}
@@ -1,10 +1,19 @@
1
- import { Autocomplete, FormControl, InputAdornment, InputLabel, MenuItem, OutlinedInput, Select, TextField } from "@mui/material";
2
- import { useCallback, useMemo } from "react";
1
+ import {
2
+ Autocomplete,
3
+ FormControl,
4
+ IconButton,
5
+ InputAdornment,
6
+ InputLabel,
7
+ MenuItem,
8
+ Select,
9
+ TextField
10
+ } from "@mui/material";
11
+ import { useCallback } from "react";
3
12
  import { SearchOutlined } from "@mui/icons-material";
4
13
  import { useController, useFormContext } from "react-hook-form";
5
14
  import { debounce } from "lodash";
6
15
  import { useDataTable } from "./hooks";
7
-
16
+ import ClearIcon from "@mui/icons-material/Clear";
8
17
  export function FilterElement({
9
18
  name,
10
19
  type,
@@ -14,10 +23,10 @@ export function FilterElement({
14
23
  childrenFields,
15
24
  datas,
16
25
  loading = false,
17
- onChange = () => { },
26
+ onChange = () => {},
18
27
  size = "small",
19
- handleChange = () => { },
20
- setPage = () => { },
28
+ handleChange = () => {},
29
+ setPage = () => {}
21
30
  }) {
22
31
  const { control, setValue } = useFormContext();
23
32
 
@@ -33,7 +42,11 @@ export function FilterElement({
33
42
  }, 500),
34
43
  [dataSearch]
35
44
  );
36
-
45
+ const handleClearIconClick = () => {
46
+ onFieldChange(""); // Clear the field value
47
+ handleFilterChangeDebounce(name, ""); // Clear the filter value
48
+ setPage(0);
49
+ };
37
50
  switch (type) {
38
51
  case "search":
39
52
  return (
@@ -53,6 +66,15 @@ export function FilterElement({
53
66
  <InputAdornment position="start">
54
67
  <SearchOutlined />
55
68
  </InputAdornment>
69
+ ),
70
+ endAdornment: (
71
+ <InputAdornment position="end">
72
+ {value && (
73
+ <IconButton onClick={handleClearIconClick}>
74
+ <ClearIcon />
75
+ </IconButton>
76
+ )}
77
+ </InputAdornment>
56
78
  )
57
79
  }}
58
80
  />
@@ -71,7 +93,7 @@ export function FilterElement({
71
93
  noOptionsText="Không có dữ liệu"
72
94
  fullWidth
73
95
  options={datas ?? []}
74
- onChange={(event, newValue, reason) => {
96
+ onChange={(event, newValue) => {
75
97
  let updateObject = { [name]: newValue?.[keyValue] };
76
98
  onFieldChange(newValue?.[keyValue]);
77
99
  onChange(newValue);
@@ -35,7 +35,7 @@ export const FilterGod = ({ filters, elementSize = "small",setPage=()=>{} }) =>
35
35
  <Grid container spacing={1}>
36
36
  {filters.map(({ field, size, ...rest }) => {
37
37
  if (rest.type === "date-range") {
38
- let label = ["từ ngày", "tới ngày"];
38
+ let label = ["Từ ngày", "Đến ngày"];
39
39
 
40
40
  if (Array.isArray(field.label)) {
41
41
  label = field.label;
@@ -21,12 +21,14 @@ export const TableRowRender = ({
21
21
  onChangeStatus,
22
22
  onDelete,
23
23
  onEdit,
24
- onView
24
+ onView,
25
+ disableEdit,
26
+ disableDelete
25
27
  }) => {
26
28
  const { selectedField, columns, statusKey, disableStatus, tableActions, disableCellThaoTac, tableName, sttLuyKe } =
27
29
  useDataTable();
28
30
  const { canEdit, canDelete, canView, canAction } = usePermission(tableName);
29
-
31
+
30
32
  const { tableActionsOnTable, tableActionsOnMoreMenu } = useMemo(() => {
31
33
  const tableActionsAfterFilter = [...tableActions]
32
34
  .filter((x) => x)
@@ -96,7 +98,7 @@ export const TableRowRender = ({
96
98
 
97
99
  {!disableCellThaoTac && (
98
100
  <TableCell align="center">
99
- {canEdit && (
101
+ {!disableEdit && (
100
102
  <Tooltip title="Chỉnh sửa">
101
103
  <IconButton size={downXl ? "small" : "medium"} onClick={() => onEdit(row)}>
102
104
  <EditOutlined fontSize="inherit" color="primary" />
@@ -110,7 +112,7 @@ export const TableRowRender = ({
110
112
  </IconButton>
111
113
  </Tooltip>
112
114
  )}
113
- {canDelete && (
115
+ {!disableDelete && (
114
116
  <Tooltip title="Xóa">
115
117
  <IconButton
116
118
  size={downXl ? "small" : "medium"}
@@ -210,7 +210,7 @@ function DataManagement({
210
210
  {tabPanel}
211
211
  <FilterGod filters={filters} elementSize={elementSize} setPage={setPage} />
212
212
  {backParentNavigator}
213
- <DataTable multipleActions={multipleActions} page={page} setPage={setPage}/>
213
+ <DataTable multipleActions={multipleActions} page={page} setPage={setPage} disableEdit={disableEditor} disableDelete = {disableEditor}/>
214
214
  </Card>
215
215
  </FormProvider>
216
216
 
@@ -1,6 +1,8 @@
1
1
  import { DateField } from "@mui/x-date-pickers";
2
2
  import { DEFAULT_DATE_FORMAT } from "../../constants";
3
- import { ClickAwayListener, Popover, Popper, Stack, Typography } from "@mui/material";
3
+ import { ClickAwayListener, Popover, Popper, Stack, Typography, IconButton } from "@mui/material";
4
+ import ClearIcon from "@mui/icons-material/Clear";
5
+ import InputAdornment from "@mui/material/InputAdornment";
4
6
  import StaticDateRangePicker from "./StaticDateRangePicker";
5
7
  import moment from "moment";
6
8
  import { memo, useEffect, useRef, useState } from "react";
@@ -77,25 +79,6 @@ const DateRangePicker = ({ label = ["Từ ngày", "Đến ngày"] }) => {
77
79
  useEffect(() => {
78
80
  setAnchorEl(containerRef.current);
79
81
  }, []);
80
- // useEffect(() => {
81
- // console.log("CHANGEEEE");
82
- // }, [isFocusStart, isFocusEnd]);
83
- // useEffect(() => {
84
- // if (dateFns.isBefore(dateRange.startDate, dateRange.endDate) || dateFns.isSameDay(dateRange.startDate, dateRange.endDate)) {
85
- // onChange([dateRange.startDate, dateRange.endDate]);
86
- // }
87
- // }, [dateRange]);
88
-
89
- // useEffect(() => {
90
- // if (!value) return;
91
- // if (dateFns.isSameDay(dateRange.startDate, value[0]) && dateFns.isSameDay(dateRange.endDate, value[1])) {
92
- // return;
93
- // }
94
- // setDateRange({
95
- // startDate: value?.[0],
96
- // endDate: value?.[1]
97
- // });
98
- // }, [value]);
99
82
 
100
83
  return (
101
84
  <>
@@ -114,6 +97,23 @@ const DateRangePicker = ({ label = ["Từ ngày", "Đến ngày"] }) => {
114
97
  }}
115
98
  value={dateRange.startDate && moment(dateRange.startDate)}
116
99
  maxDate={dateRange.endDate ?? moment(dateRange.endDate)}
100
+ InputProps={{
101
+ endAdornment: (
102
+ <InputAdornment position="end">
103
+ <IconButton
104
+ onClick={() => {
105
+ setDateRange((d) => ({
106
+ ...d,
107
+ startDate: null
108
+ }));
109
+ }}
110
+ edge="end"
111
+ >
112
+ <ClearIcon />
113
+ </IconButton>
114
+ </InputAdornment>
115
+ )
116
+ }}
117
117
  />
118
118
  <Typography variant="body1" sx={{ height: "24px", alignSelf: "center" }}>
119
119
 
@@ -132,6 +132,23 @@ const DateRangePicker = ({ label = ["Từ ngày", "Đến ngày"] }) => {
132
132
  }}
133
133
  value={dateRange.endDate && moment(dateRange.endDate)}
134
134
  minDate={dateRange.startDate ?? moment(dateRange.startDate)}
135
+ InputProps={{
136
+ endAdornment: (
137
+ <InputAdornment position="end">
138
+ <IconButton
139
+ onClick={() => {
140
+ setDateRange((d) => ({
141
+ ...d,
142
+ endDate: null
143
+ }));
144
+ }}
145
+ edge="end"
146
+ >
147
+ <ClearIcon />
148
+ </IconButton>
149
+ </InputAdornment>
150
+ )
151
+ }}
135
152
  />
136
153
  </Stack>
137
154
  <ClickAwayListener onClickAway={handleClickAway}>
@@ -145,29 +162,6 @@ const DateRangePicker = ({ label = ["Từ ngày", "Đến ngày"] }) => {
145
162
  anchorEl={anchorEl}
146
163
  onClose={handleClose}
147
164
  onClick={handleClickPopper}
148
-
149
- // modifiers={[
150
- // {
151
- // name: "flip",
152
- // enabled: true,
153
- // options: {
154
- // altBoundary: true,
155
- // rootBoundary: "viewport",
156
- // padding: 8
157
- // }
158
- // },
159
- // {
160
- // name: "preventOverflow",
161
- // enabled: true,
162
- // options: {
163
- // altAxis: true,
164
- // altBoundary: true,
165
- // tether: true,
166
- // rootBoundary: "document",
167
- // padding: 8
168
- // }
169
- // }
170
- // ]}
171
165
  >
172
166
  <StaticDateRangePicker
173
167
  value={dateRange}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trithuc-mvc-react",
3
- "version": "2.4.8",
3
+ "version": "2.5.1",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"