Skip to content

Commit

Permalink
refactor(create-forms): 🎉 update create forms
Browse files Browse the repository at this point in the history
  • Loading branch information
gokhangunduz committed Nov 1, 2023
1 parent 79f28f6 commit 3aae712
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 32 deletions.
9 changes: 9 additions & 0 deletions src/components/CFEnvCategories/CFEnvCategories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ export default function CFEnvCategories({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [formik?.values?.domainName, formik?.initialValues?.domainName]);

useEffect(() => {
formik?.values?.application?.name &&
formik.setValues({
...formik.values,
ideGpuResource: 0,
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [formik?.values?.application?.name]);

return (
<Fragment>
<CFInfoBar
Expand Down
4 changes: 3 additions & 1 deletion src/components/CFGpuResourceRange/CFGpuResourceRange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ export default function CFGpuResourceRange({
tip="GPU Resource"
dataTut="create-environment-gpu-resource"
InputProps={formik.getFieldProps("ideGpuResource")}
min={1}
min={0}
max={
Number(selectedGpu?.capacity) - Number(selectedGpu?.allocated) - 1 ||
1
}
disabled={formik.isSubmitting || disabled}
error={formik.errors.ideGpuResource}
touched={true}
/>
</Fragment>
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/CFGridButton/CFGridButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export default function CFGridButton({
}: ICFGridButton): ReactElement {
return (
<div
className={`transition-300 flex items-center justify-center rounded border-2 px-1 py-3 text-xs capitalize text-layer-dark-700 hover:scale-95
className={`transition-300 flex items-center justify-center rounded border-2 px-1 py-3 text-xs capitalize text-layer-dark-700
${selected && "border-layer-primary-600 shadow"}
${disabled ? "cursor-not-allowed" : "cursor-pointer"}`}
${disabled ? "cursor-not-allowed" : "cursor-pointer hover:scale-95"}`}
onClick={onClick}
>
{text}
Expand Down
2 changes: 1 addition & 1 deletion src/components/CFInfoBar/CFInfoBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export default function CFInfoBar({
<InfoTip content={tip} />
</div>
{children}
<InputError error={error} touched={touched} />
</div>
<InputError error={error} touched={touched} />
</div>
);
}
4 changes: 2 additions & 2 deletions src/components/CirclePercentageBar/CirclePercentageBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface ICirclePercentageBar {

export default function CirclePercentageBar({
percentage,
size = 60,
size = 50,
title = "",
}: ICirclePercentageBar): ReactElement {
const strokeWidth = 4; // Border kalınlığı
Expand All @@ -24,7 +24,7 @@ export default function CirclePercentageBar({
className="flex flex-col items-center gap-1"
style={{ textAlign: "center" }}
>
{!percentage ? (
{typeof percentage !== "number" ? (
<ContentLoader
width={100}
height={120}
Expand Down
4 changes: 2 additions & 2 deletions src/components/CreateForms/CreateEnvironmentFormStep1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default function CreateEnvironmentFormStep1({
</CFSection>

<CFSection>
<CFStorageRange formik={formik} disabled={isImportRobot} />
<CFGpuResourceRange formik={formik} disabled={isImportRobot} />
<Seperator />
</CFSection>

Expand All @@ -123,7 +123,7 @@ export default function CreateEnvironmentFormStep1({
</CFSection>

<CFSection>
<CFGpuResourceRange formik={formik} disabled={isImportRobot} />
<CFStorageRange formik={formik} disabled={isImportRobot} />
<Seperator />
</CFSection>

Expand Down
12 changes: 11 additions & 1 deletion src/components/FormInputRange/FormInputRange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ interface IFormInputRange {
min?: number;
max?: number;
disabled?: boolean;
error?: any;
touched?: boolean;
}

export default function FormInputRange({
Expand All @@ -19,9 +21,17 @@ export default function FormInputRange({
min,
max,
disabled,
error,
touched,
}: IFormInputRange): ReactElement {
return (
<CFInfoBar label={label} tip={tip} dataTut={dataTut}>
<CFInfoBar
label={label}
tip={tip}
dataTut={dataTut}
error={error}
touched={touched}
>
<input
min={min}
max={max}
Expand Down
2 changes: 1 addition & 1 deletion src/components/UsagesWidget/UsagesWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function UsagesWidget({
subtitle={`${title} Usages`}
icon={<GoGraph size={20} className="text-layer-light-700" />}
>
<div className="flex h-full w-full items-center justify-center gap-10 p-10 lg:p-6 xl:p-2">
<div className="flex h-full w-full items-center justify-center gap-6 p-10 lg:p-6 xl:p-2">
{datas?.map((data: any) => {
return <CirclePercentageBar key={data?.title} {...data} size={88} />;
})}
Expand Down
2 changes: 1 addition & 1 deletion src/contexts/CreateRobotContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default ({ children }: any) => {
physicalInstanceName: "",
robotStorage: 40,
isEnabledIde: true,
ideGpuResource: 2,
ideGpuResource: 0,
ideGpuResourceType: "",
configureWorkspace: false,
isEnabledROS2Bridge: true,
Expand Down
16 changes: 1 addition & 15 deletions src/contexts/FunctionsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1252,21 +1252,7 @@ export default ({ children }: any) => {
devspaceVersion: robotData?.step1?.devspace?.version,
permittedDirectories: robotData?.step1?.permittedDirectories,
persistentDirectories: robotData?.step1?.persistentDirectories,
workspaces: withoutWorkspaces
? [
{
name: "ws1",
workspaceDistro: "",
robotRepositories: [
{
name: "repo1",
url: "https://github.com/robolaunch/robolaunch",
branch: "main",
},
],
},
]
: robotData?.step2.workspaces,
workspaces: withoutWorkspaces ? null : robotData?.step2.workspaces,
ideCustomPorts:
robotData.step1.ideCustomPorts
?.map((port) => {
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/instanceInferfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface IInstanceResource {
}

export interface IGpuUsage {
gpuModel: string;
gpuUtilization: string;
allocated: string;
capacity: string;
resourceName: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import useMain from "../../../hooks/useMain";
import { RiCpuLine } from "react-icons/ri";
import TourGuide from "../../../components/TourGuide/TourGuide";
import { getGuideItem } from "../../../functions/handleGuide";
import { BsGpuCard } from "react-icons/bs";

export default function CloudInstanceDashboardPage(): ReactElement {
const [responseFleets, setResponseFleets] = useState<any>(undefined);
Expand Down Expand Up @@ -230,7 +231,7 @@ export default function CloudInstanceDashboardPage(): ReactElement {
{
organizationId: pagesState?.organization?.organizationId!,
roboticsCloudName: pagesState?.roboticsCloud?.name!,
instanceId: pagesState?.instance?.instanceId,
instanceId: pagesState?.instance?.instanceId!,
region: pagesState?.roboticsCloud?.region!,
},
{
Expand All @@ -245,8 +246,8 @@ export default function CloudInstanceDashboardPage(): ReactElement {
{
organizationId: selectedState?.organization?.organizationId!,
roboticsCloudName: selectedState?.roboticsCloud?.name!,
instanceId: selectedState?.instance?.instanceId,
region: selectedState?.instance?.region,
instanceId: selectedState?.instance?.instanceId!,
region: selectedState?.instance?.region!,
},
{
ifErrorNavigateTo404: !responseFleets,
Expand Down Expand Up @@ -285,6 +286,15 @@ export default function CloudInstanceDashboardPage(): ReactElement {
percentage:
pagesState?.instance?.cloudInstanceResource?.cpuUsage || 0,
},
// {
// title: `GPU (${pagesState.instance?.cloudInstanceResource?.gpuUsage?.[0]?.gpuModel})`,
// percentage:
// Number(
// pagesState.instance?.cloudInstanceResource?.gpuUsage?.[0]?.gpuUtilization?.charAt(
// 0,
// ),
// ) || 1,
// },
{
title: `Memory (${
pagesState?.instance?.cloudInstanceResource?.memoryTotal || 0
Expand All @@ -299,13 +309,24 @@ export default function CloudInstanceDashboardPage(): ReactElement {
percentage:
Number(
(
(pagesState?.instance?.cloudInstanceResource?.storageTotal /
(pagesState?.instance?.cloudInstanceResource
?.storageTotal! /
100) *
(pagesState?.instance?.cloudInstanceResource?.storageTotal -
pagesState?.instance?.cloudInstanceResource?.storageUsage)
(pagesState?.instance?.cloudInstanceResource
?.storageTotal! -
pagesState?.instance?.cloudInstanceResource
?.storageUsage!)
).toFixed(),
) || 0,
},
{
title: `In Network (${pagesState.instance?.cloudInstanceResource?.networkUsage?.[0]?.trafficIn})`,
percentage: 1,
},
{
title: `Out Network (${pagesState.instance?.cloudInstanceResource?.networkUsage?.[0]?.trafficOut})`,
percentage: 1,
},
]}
/>
}
Expand Down Expand Up @@ -342,6 +363,13 @@ export default function CloudInstanceDashboardPage(): ReactElement {
value:
pagesState?.instance?.cloudInstanceResource?.kubernetesVersion,
},
{
icon: <BsGpuCard size={16} />,
title: "GPU Model",
value:
pagesState?.instance?.cloudInstanceResource?.gpuUsage?.[0]
?.gpuModel,
},
]}
/>
}
Expand Down
4 changes: 4 additions & 0 deletions src/validations/EnvironmentsValidations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export const CreateEnvironmentsFormStep1Validations = Yup.object().shape({
.max(65535, "Maximum 65535."),
}),
),

ideGpuResource: Yup.number()
.required("GPU Resource is required.")
.min(1, "Minimum 1 Core."),
ideGpuResourceType: Yup.string().required("GPU Resource Type is required."),
vdiCustomPorts: Yup.array().of(
Yup.object().shape({
Expand Down

0 comments on commit 3aae712

Please sign in to comment.