import {useEffect, useState} from "react"; import {useMutation, useQuery, useQueryClient} from "@tanstack/react-query"; import {Plus, RefreshCw, Trash2} from "lucide-react"; import {getLoadBalancingDependencies} from "@/api/cloudProxyClient"; import { createCacheParameterGroup, createCacheSubnetGroup, createElastiCacheUser, deleteCacheParameterGroup, deleteCacheSubnetGroup, deleteElastiCacheUser, listCacheParameterGroups, listCacheParameters, listCacheSubnetGroups, listElastiCacheUsers, modifyCacheSubnetGroup, modifyElastiCacheUser, setCacheParameters, } from "@/api/elasticacheClient"; type Tab = "users" | "subnet-groups" | "parameter-groups"; export function ElastiCacheManagementPanel({runtimeReachable}: {runtimeReachable: boolean}) { const [tab, setTab] = useState("users"); return

ElastiCache management

Users and configuration groups

{(["users", "subnet-groups", "parameter-groups"] as Tab[]).map((item) => )}
{tab === "users" && } {tab === "subnet-groups" && } {tab === "parameter-groups" && }
; } function Users({runtimeReachable}: {runtimeReachable: boolean}) { const qc = useQueryClient(); const [userId, setUserId] = useState(""); const [userName, setUserName] = useState(""); const [engine, setEngine] = useState<"redis" | "valkey">("redis"); const [accessString, setAccessString] = useState("on ~* +@all"); const [mode, setMode] = useState<"password" | "no-password-required" | "iam">("no-password-required"); const [passwords, setPasswords] = useState(""); const query = useQuery({queryKey: ["elasticache", "users"], queryFn: listElastiCacheUsers, enabled: runtimeReachable}); const refresh = () => void qc.invalidateQueries({queryKey: ["elasticache", "users"]}); const create = useMutation({mutationFn: () => createElastiCacheUser({userId: userId.trim(), userName: userName.trim(), engine, accessString: accessString.trim(), authenticationMode: mode, ...(passwords.trim() && {passwords: passwords.split("\n").map((value) => value.trim()).filter(Boolean)})}), onSuccess: () => {setUserId(""); setUserName(""); setPasswords(""); refresh();}}); const remove = useMutation({mutationFn: deleteElastiCacheUser, onSuccess: refresh}); const modify = useMutation({mutationFn: (id: string) => modifyElastiCacheUser(id, {accessString: accessString.trim(), authenticationMode: mode, ...(passwords.trim() && {passwords: passwords.split("\n").map((value) => value.trim()).filter(Boolean)})}), onSuccess: refresh}); return <>
{event.preventDefault(); create.mutate();}}> query.refetch()} loading={query.isFetching}/>{query.data?.map((user) =>
{user.UserName ?? user.UserId}{user.Engine} · {user.Authentication?.Type ?? "authentication unset"} · {user.AccessString}
)}; } function UserSettings(props: {accessString: string; setAccessString: (value: string) => void; mode: "password" | "no-password-required" | "iam"; setMode: (value: "password" | "no-password-required" | "iam") => void; passwords: string; setPasswords: (value: string) => void}) { return <>{props.mode === "password" &&