️ improve: Optimized priority input handling in TableRow component.

This commit is contained in:
MartialBE 2024-04-06 16:06:52 +08:00
parent d8e91e8f79
commit f3c2f53fe9
No known key found for this signature in database
GPG Key ID: F5A7AC860020C896

View File

@ -11,10 +11,7 @@ import {
MenuItem, MenuItem,
TableCell, TableCell,
IconButton, IconButton,
FormControl, TextField,
InputLabel,
InputAdornment,
Input,
Dialog, Dialog,
DialogActions, DialogActions,
DialogContent, DialogContent,
@ -31,12 +28,7 @@ import ResponseTimeLabel from "./ResponseTimeLabel";
import GroupLabel from "./GroupLabel"; import GroupLabel from "./GroupLabel";
import NameLabel from "./NameLabel"; import NameLabel from "./NameLabel";
import { import { IconDotsVertical, IconEdit, IconTrash } from "@tabler/icons-react";
IconDotsVertical,
IconEdit,
IconTrash,
IconPencil,
} from "@tabler/icons-react";
export default function ChannelTableRow({ export default function ChannelTableRow({
item, item,
@ -79,11 +71,19 @@ export default function ChannelTableRow({
} }
}; };
const handlePriority = async () => { const handlePriority = async (event) => {
if (priorityValve === "" || priorityValve === item.priority) { const currentValue = parseInt(event.target.value);
if (isNaN(currentValue) || currentValue === priorityValve) {
return; return;
} }
await manageChannel(item.id, "priority", priorityValve);
if (currentValue < 0) {
showError("优先级不能小于 0");
return;
}
await manageChannel(item.id, "priority", currentValue);
setPriority(currentValue);
}; };
const handleResponseTime = async () => { const handleResponseTime = async () => {
@ -170,9 +170,7 @@ export default function ChannelTableRow({
handle_action={handleResponseTime} handle_action={handleResponseTime}
/> />
</TableCell> </TableCell>
<TableCell> <TableCell>{renderNumber(item.used_quota)}</TableCell>
{renderNumber(item.used_quota)}
</TableCell>
<TableCell> <TableCell>
<Tooltip <Tooltip
title={"点击更新余额"} title={"点击更新余额"}
@ -183,27 +181,16 @@ export default function ChannelTableRow({
</Tooltip> </Tooltip>
</TableCell> </TableCell>
<TableCell> <TableCell>
<FormControl sx={{ m: 1, width: "70px" }} variant="standard"> <TextField
<InputLabel htmlFor={`priority-${item.id}`}>优先级</InputLabel> id={`priority-${item.id}`}
<Input onBlur={handlePriority}
id={`priority-${item.id}`} type="number"
type="text" label="优先级"
value={priorityValve} variant="standard"
onChange={(e) => setPriority(e.target.value)} defaultValue={item.priority}
sx={{ textAlign: "center" }} inputProps={{ min: "0" }}
endAdornment={ sx={{ width: 80 }}
<InputAdornment position="end"> />
<IconButton
onClick={handlePriority}
sx={{ color: "rgb(99, 115, 129)" }}
size="small"
>
<IconPencil />
</IconButton>
</InputAdornment>
}
/>
</FormControl>
</TableCell> </TableCell>
<TableCell> <TableCell>