mirror of
https://github.com/Buriburizaem0n/admin-frontend-domain.git
synced 2026-11-04 08:50:20 +00:00
feat: batch set server config (#114)
* feat: batch set server config * make every field optional * chore: auto-fix linting and formatting issues * update * [WIP] improve batch edit ux * chore: auto-fix linting and formatting issues
This commit is contained in:
1 parent
70b8f39bd6
commit
a52bf64779
10 files changed
+349
-77
No files matched your search
@@ -0,0 +1,104 @@
|
||||
import { setServerConfig } from "@/api/server"
|
||||
import { Button, ButtonProps } from "@/components/ui/button"
|
||||
import {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Label } from "@/components/ui/label"
|
||||
import { ScrollArea } from "@/components/ui/scroll-area"
|
||||
import { Textarea } from "@/components/ui/textarea"
|
||||
import { IconButton } from "@/components/xui/icon-button"
|
||||
import { ModelServerTaskResponse } from "@/types"
|
||||
import { useState } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { Pusher } from "./xui/pusher"
|
||||
|
||||
interface ServerConfigCardBatchProps extends ButtonProps {
|
||||
sid: number[]
|
||||
}
|
||||
|
||||
export const ServerConfigCardBatch: React.FC<ServerConfigCardBatchProps> = ({ sid, ...props }) => {
|
||||
const { t } = useTranslation()
|
||||
const [data, setData] = useState<Record<string, any>>({})
|
||||
const [open, setOpen] = useState(false)
|
||||
const [currentKey, setCurrentKey] = useState<string>("")
|
||||
const [currentVal, setCurrentVal] = useState<string>("")
|
||||
|
||||
const onSubmit = async () => {
|
||||
let resp: ModelServerTaskResponse = {}
|
||||
try {
|
||||
resp = await setServerConfig({ config: JSON.stringify(data), servers: sid })
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
toast(t("Error"), {
|
||||
description: t("Results.UnExpectedError"),
|
||||
})
|
||||
return
|
||||
}
|
||||
toast(t("Done"), {
|
||||
description:
|
||||
t("Results.ForceUpdate") +
|
||||
(resp.success?.length ? t(`Success`) + ` [${resp.success.join(",")}]` : "") +
|
||||
(resp.failure?.length ? t(`Failure`) + ` [${resp.failure.join(",")}]` : "") +
|
||||
(resp.offline?.length ? t(`Offline`) + ` [${resp.offline.join(",")}]` : ""),
|
||||
})
|
||||
setOpen(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<IconButton {...props} icon="cog" />
|
||||
</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-xl">
|
||||
<ScrollArea className="max-h-[calc(100dvh-5rem)] p-3">
|
||||
<div className="items-center mx-1">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t("EditServerConfig")}</DialogTitle>
|
||||
<DialogDescription />
|
||||
</DialogHeader>
|
||||
<div className="flex flex-col gap-3 mt-4">
|
||||
<Label>Option</Label>
|
||||
<Input
|
||||
type="text"
|
||||
placeholder="option"
|
||||
value={currentKey}
|
||||
onChange={(e) => {
|
||||
setCurrentKey(e.target.value)
|
||||
}}
|
||||
/>
|
||||
<Label>Value</Label>
|
||||
<Textarea
|
||||
className="resize-y"
|
||||
value={currentVal}
|
||||
onChange={(e) => {
|
||||
setCurrentVal(e.target.value)
|
||||
}}
|
||||
/>
|
||||
<Pusher property={[currentKey, currentVal]} setData={setData} />
|
||||
<DialogFooter className="justify-end">
|
||||
<DialogClose asChild>
|
||||
<Button type="button" className="my-2" variant="secondary">
|
||||
{t("Close")}
|
||||
</Button>
|
||||
</DialogClose>
|
||||
<Button type="submit" className="my-2" onClick={onSubmit}>
|
||||
{t("Submit")}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</div>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user