-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
telemetry, logs, resources, danger zone for near nodes
- Loading branch information
1 parent
949f2ff
commit cf5a614
Showing
3 changed files
with
146 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
...(dashboard)/[workspaceId]/(main)/deployments/near/[nodeName]/components/telemetry-tab.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
"use client"; | ||
|
||
import * as z from "zod"; | ||
import { isAxiosError } from "axios"; | ||
import { useForm } from "react-hook-form"; | ||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
|
||
import { client } from "@/lib/client-instance"; | ||
import { NEARNode } from "@/types"; | ||
import { Roles } from "@/enums"; | ||
import { | ||
Form, | ||
FormControl, | ||
FormField, | ||
FormItem, | ||
FormLabel, | ||
FormMessage, | ||
} from "@/components/ui/form"; | ||
import { Button } from "@/components/ui/button"; | ||
import { Alert, AlertDescription } from "@/components/ui/alert"; | ||
import { TabsFooter } from "@/components/ui/tabs"; | ||
import { Input } from "@/components/ui/input"; | ||
|
||
interface TelemetryTabProps { | ||
node: NEARNode; | ||
role: Roles; | ||
} | ||
|
||
const schema = z.object({ | ||
telemetryURL: z.string().optional(), | ||
}); | ||
|
||
type Schema = z.input<typeof schema>; | ||
|
||
export const TelemetryTab: React.FC<TelemetryTabProps> = ({ node, role }) => { | ||
const { telemetryURL } = node; | ||
|
||
const form = useForm<Schema>({ | ||
resolver: zodResolver(schema), | ||
defaultValues: { telemetryURL }, | ||
}); | ||
|
||
const { | ||
formState: { | ||
isSubmitted, | ||
isSubmitting, | ||
isValid, | ||
isDirty, | ||
isSubmitSuccessful, | ||
errors, | ||
}, | ||
reset, | ||
setError, | ||
} = form; | ||
|
||
const onSubmit = async (values: Schema) => { | ||
try { | ||
const { data } = await client.put<NEARNode>( | ||
`/near/nodes/${node.name}`, | ||
values | ||
); | ||
const { telemetryURL } = data; | ||
reset({ telemetryURL }); | ||
} catch (error) { | ||
if (isAxiosError(error)) { | ||
const { response } = error; | ||
|
||
setError("root", { | ||
type: response?.status.toString(), | ||
message: "Something went wrong.", | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<Form {...form}> | ||
<form | ||
onSubmit={form.handleSubmit(onSubmit)} | ||
className="relative space-y-4" | ||
> | ||
<FormField | ||
control={form.control} | ||
name="telemetryURL" | ||
render={({ field }) => ( | ||
<FormItem className="max-w-sm"> | ||
<FormLabel>Telemetry Service URL</FormLabel> | ||
<FormControl> | ||
<Input | ||
disabled={isSubmitting || role === Roles.Reader} | ||
{...field} | ||
/> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
|
||
{isSubmitSuccessful && ( | ||
<Alert variant="success" className="text-center"> | ||
<AlertDescription> | ||
Telemetry settings have been updated successfully. | ||
</AlertDescription> | ||
</Alert> | ||
)} | ||
|
||
{errors.root && ( | ||
<Alert variant="destructive" className="text-center"> | ||
<AlertDescription>{errors.root.message}</AlertDescription> | ||
</Alert> | ||
)} | ||
|
||
{role !== Roles.Reader && ( | ||
<TabsFooter> | ||
<Button | ||
disabled={(isSubmitted && !isValid) || isSubmitting || !isDirty} | ||
data-testid="submit" | ||
type="submit" | ||
> | ||
Save | ||
</Button> | ||
</TabsFooter> | ||
)} | ||
</form> | ||
</Form> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters