Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/api/deploy/deployments.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Job } from "../../types";
import { DeploymentSpecsGPU, Job, Visibility } from "../../types";

export const getDeployment = async (token: string, id: string) => {
const url = `${import.meta.env.VITE_DEPLOY_API_URL}/deployments/${id}`;
Expand Down Expand Up @@ -90,7 +90,9 @@ export const createDeployment = async (
imageArgs: any,
envs: any,
volumes: any,
token: string
token: string,
visibility: Visibility,
specs?: DeploymentSpecsGPU
) => {
let body: any = {
name,
Expand All @@ -99,8 +101,14 @@ export const createDeployment = async (
if (zone) body = { ...body, zone };
if (image) body = { ...body, image };
if (imageArgs) body = { ...body, args: imageArgs };
if (visibility) body = { ...body, visibility };
if (envs) body = { ...body, envs };
if (volumes) body = { ...body, volumes };
if (specs?.cpuCores) body = { ...body, cpuCores: specs.cpuCores };
if (specs?.ram) body = { ...body, ram: specs.ram };
if (specs?.replicas != undefined)
body = { ...body, replicas: specs.replicas };
if (specs?.gpus) body = { ...body, gpus: specs.gpus };

const res = await fetch(
import.meta.env.VITE_DEPLOY_API_URL + "/deployments",
Expand Down
155 changes: 155 additions & 0 deletions src/components/create/EnvironmentVariableSelector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import {
Card,
CardContent,
CardHeader,
IconButton,
Paper,
Stack,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
TextField,
} from "@mui/material";
import { NoWrapTable as Table } from "../../components/NoWrapTable";
import Iconify from "../Iconify";
import { Dispatch, SetStateAction } from "react";
import { EnvVar } from "../../types";
import { useTranslation } from "react-i18next";

export type EnvironmentVariableSelectorProps = {
envs: EnvVar[];
setEnvs: Dispatch<SetStateAction<EnvVar[]>>;
currentEnv: EnvVar;
setCurrentEnv: Dispatch<SetStateAction<EnvVar>>;
};

export default function EnvironmentVariableSelector({
envs,
setEnvs,
currentEnv,
setCurrentEnv,
}: EnvironmentVariableSelectorProps) {
const { t } = useTranslation();

return (
<Card sx={{ boxShadow: 20 }}>
<CardHeader
title={t("create-deployment-env")}
subheader={t("create-deployment-env-subheader")}
/>
<CardContent>
<TableContainer component={Paper}>
<Table sx={{ minWidth: 650 }} aria-label="simple table">
<TableHead>
<TableRow>
<TableCell>{t("create-deployment-env-key")}</TableCell>
<TableCell>{t("create-deployment-env-value")}</TableCell>
<TableCell align="right">{t("admin-actions")}</TableCell>
</TableRow>
</TableHead>
<TableBody>
{envs.map((env) => (
<TableRow
key={"env_row_" + env.name}
sx={{
"&:last-child td, &:last-child th": { border: 0 },
}}
>
<TableCell component="th" scope="row">
<b style={{ fontFamily: "monospace" }}>{env.name}</b>
</TableCell>
<TableCell>
<b style={{ fontFamily: "monospace" }}>{env.value}</b>
</TableCell>
<TableCell align="right">
<Stack
direction="row"
spacing={1}
useFlexGap
alignItems={"center"}
justifyContent={"flex-end"}
>
<IconButton
color="primary"
aria-label="edit env"
component="label"
onClick={() => {
setCurrentEnv({ name: env.name, value: env.value });
setEnvs(
envs.filter((item) => item.name !== env.name)
);
}}
>
<Iconify icon="mdi:pencil" />
</IconButton>

<IconButton
color="error"
aria-label="delete env"
component="label"
onClick={() =>
setEnvs(envs.filter((item) => item.name !== env.name))
}
>
<Iconify icon="mdi:delete" />
</IconButton>
</Stack>
</TableCell>
</TableRow>
))}

<TableRow
sx={{
"&:last-child td, &:last-child th": { border: 0 },
}}
>
<TableCell component="th" scope="row">
<TextField
label={t("admin-name")}
variant="outlined"
value={currentEnv.name}
onChange={(e) => {
setCurrentEnv({ ...currentEnv, name: e.target.value });
}}
/>
</TableCell>
<TableCell>
<TextField
label={t("create-deployment-env-value")}
variant="outlined"
value={currentEnv.value}
onChange={(e) => {
setCurrentEnv({ ...currentEnv, value: e.target.value });
}}
fullWidth
/>
</TableCell>
<TableCell align="right">
<IconButton
color="primary"
component="label"
disabled={
!(currentEnv.name != "" && currentEnv.value != "")
}
onClick={() => {
if (!(currentEnv.name != "" && currentEnv.value != ""))
return;

setEnvs([...envs, currentEnv]);

setCurrentEnv({ name: "", value: "" });
}}
>
<Iconify icon="mdi:content-save" />
</IconButton>
</TableCell>
</TableRow>
</TableBody>
</Table>
</TableContainer>
</CardContent>
</Card>
);
}
Loading