Skip to content

Commit

Permalink
Merge pull request #372 from OpenElements/patch25
Browse files Browse the repository at this point in the history
Fix the create invironment form to capture all the details
  • Loading branch information
Ndacyayisenga-droid authored Apr 22, 2024
2 parents 9422602 + 132f40d commit 701ed96
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions frontend/src/pages/create-environment-page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect } from "react";
import { zodResolver } from "@hookform/resolvers/zod";
import { useNavigate } from "react-router-dom";
import { useForm, Controller } from "react-hook-form";
import { useOSFamily } from "../../hooks";
import { useOSFamily, useEnvironmentMetadata } from "../../hooks";
import { createAppBarConfig } from "../../utils";
import { z } from "zod";
import { Select } from "../../components";
Expand All @@ -17,6 +17,8 @@ const schema = z.object({
memory: z.string(),
java: z.string(),
jmh: z.string(),
jvm: z.string(),
systemArch: z.string(),
});

type EnvironmentFormData = z.infer<typeof schema>;
Expand All @@ -26,6 +28,8 @@ const inputClasses =

const CreateEnvironment = () => {
const { data: osFamilyOptions } = useOSFamily();
const { data: archOptions } = useEnvironmentMetadata("arch");
const { data: jvmNameOptions } = useEnvironmentMetadata("jvmName");
const { handleSubmit, register, control } = useForm<EnvironmentFormData>({
mode: "all",
resolver: zodResolver(schema),
Expand All @@ -43,17 +47,21 @@ const CreateEnvironment = () => {
cores,
osName,
osVersion,
jvm,
systemArch,
} = data;

const payload = {
osName,
osVersion: osVersion,
name: infraName,
description: infraDescription,
systemMemoryReadable: memory,
systemMemory: Number(memory),
jmhVersion: jmh,
jvmVersion: java,
systemProcessors: Number(cores),
systemArch: systemArch,
jvmName: jvm,
};
await saveEnvironment(payload).then(() => navigate("/environments"));
};
Expand Down Expand Up @@ -151,6 +159,24 @@ const CreateEnvironment = () => {
/>
</div>
</div>
<div className="flex justify-between items-center">
<div className="text-sm text-gray-800">Jvm Name</div>
<div className="text-sm text-gray-800">
<Controller
name="jvm"
control={control}
render={({ field }) => (
<Select
options={jvmNameOptions}
value={field.value}
valueExtractor={(name) => name}
labelExtractor={(label) => label }
onChange={(e) => field.onChange(e)}
/>
)}
/>
</div>
</div>
<div className="flex justify-between items-center">
<div className="text-sm text-gray-800">Java</div>
<div className="text-sm text-gray-800 flex items-center">
Expand All @@ -161,6 +187,24 @@ const CreateEnvironment = () => {
/>
</div>
</div>
<div className="flex justify-between items-center">
<div className="text-sm text-gray-800">System Arch</div>
<div className="text-sm text-gray-800">
<Controller
name="systemArch"
control={control}
render={({ field }) => (
<Select
options={archOptions}
value={field.value}
valueExtractor={(name) => name}
labelExtractor={(label) => label }
onChange={(e) => field.onChange(e)}
/>
)}
/>
</div>
</div>
<div className="flex justify-between items-center">
<div className="text-sm text-gray-800">JMH</div>
<div className="text-sm text-gray-800 flex items-center">
Expand Down

0 comments on commit 701ed96

Please sign in to comment.