Skip to content

Commit

Permalink
telemetry, logs, resources, danger zone for near nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-abdelhamid committed Oct 3, 2023
1 parent 949f2ff commit cf5a614
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { DeleteNodeForm } from "@/components/delete-node-form";
import { useToast } from "@/components/ui/use-toast";
import { TabsFooter } from "@/components/ui/tabs";
import { Button } from "@/components/ui/button";
import { BitcoinNode } from "@/types";
import { NEARNode } from "@/types";
import { client } from "@/lib/client-instance";

interface DangerZoneTabProps {
node: BitcoinNode;
node: NEARNode;
}

export const DangerZoneTab: React.FC<DangerZoneTabProps> = ({ node }) => {
Expand All @@ -23,16 +23,16 @@ export const DangerZoneTab: React.FC<DangerZoneTabProps> = ({ node }) => {

const [open, setOpen] = useState(false);

async function onDeleteBitcoinNode() {
async function onDeleteNEARNode() {
const url = qs.stringifyUrl({
url: `/bitcoin/nodes/${node.name}`,
url: `/near/nodes/${node.name}`,
query: { workspace_id: params.workspaceId },
});
await client.delete(url);
router.push(`/${params.workspaceId}/deployments/bitcoin`);
router.push(`/${params.workspaceId}/deployments/near`);
router.refresh();
toast({
title: "Bitcoin node has been deleted",
title: "Near node has been deleted",
description: `${node.name} node has been deleted successfully.`,
});
setOpen(false);
Expand Down Expand Up @@ -66,10 +66,10 @@ export const DangerZoneTab: React.FC<DangerZoneTabProps> = ({ node }) => {
<AlertModal
isOpen={open}
onClose={() => setOpen(false)}
title="Delete Bitcoin Node"
description={`This action cann't be undone. This will permnantly delete (${node.name}) Bitcoin Node.`}
title="Delete NEAR Node"
description={`This action cann't be undone. This will permnantly delete (${node.name}) NEAR Node.`}
>
<DeleteNodeForm nodeName={node.name} onDelete={onDeleteBitcoinNode} />
<DeleteNodeForm nodeName={node.name} onDelete={onDeleteNEARNode} />
</AlertModal>
</>
);
Expand Down
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>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { DangerZoneTab } from "./components/danger-zone-tab";
import { ValidatorTab } from "./components/validator-tab";
import { NetworkingTab } from "./components/networking-tab";
import { PrometheusTab } from "./components/prometheus-tab";
import { TelemetryTab } from "./components/telemetry-tab";

export default async function BitcoinPage({
params,
Expand Down Expand Up @@ -91,6 +92,7 @@ export default async function BitcoinPage({
<TabsTrigger value="rpc">RPC</TabsTrigger>
<TabsTrigger value="validator">Validator</TabsTrigger>
<TabsTrigger value="prometheus">Prometheus</TabsTrigger>
<TabsTrigger value="telemetry">Telemetry</TabsTrigger>
<TabsTrigger value="logs">Logs</TabsTrigger>
<TabsTrigger value="resources">Resources</TabsTrigger>
{role === Roles.Admin && (
Expand Down Expand Up @@ -126,10 +128,16 @@ export default async function BitcoinPage({
>
<PrometheusTab node={node} role={role} />
</TabsContent>
<TabsContent
className="px-4 py-3 sm:px-6 sm:py-4"
value="telemetry"
>
<TelemetryTab node={node} role={role} />
</TabsContent>
<TabsContent className="px-4 py-3 sm:px-6 sm:py-4" value="logs">
{token && (
<Logs
url={`bitcoin/nodes/${node.name}/logs?authorization=Bearer ${token.value}&workspace_id=${workspaceId}`}
url={`near/nodes/${node.name}/logs?authorization=Bearer ${token.value}&workspace_id=${workspaceId}`}
/>
)}
</TabsContent>
Expand All @@ -140,7 +148,7 @@ export default async function BitcoinPage({
<ResourcesForm
node={node}
role={role}
updateUrl={`/bitcoin/nodes/${node.name}?workspace_id=${workspaceId}`}
updateUrl={`/near/nodes/${node.name}?workspace_id=${workspaceId}`}
/>
</TabsContent>
{role === Roles.Admin && (
Expand Down

0 comments on commit cf5a614

Please sign in to comment.