Skip to content

Commit

Permalink
Merge pull request #265 from kthcloud/beta
Browse files Browse the repository at this point in the history
New quota scheme, Show gravatar in Discover, minor fixes
  • Loading branch information
pierrelefevre authored May 10, 2024
2 parents 4e4a92b + 4b9f774 commit 00960b1
Show file tree
Hide file tree
Showing 15 changed files with 286 additions and 169 deletions.
Binary file modified bun.lockb
Binary file not shown.
78 changes: 39 additions & 39 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,65 +12,65 @@
"format-check": "prettier --check ."
},
"dependencies": {
"@emotion/react": "^11.11.3",
"@emotion/styled": "^11.11.0",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@iconify/react": "^4.1.1",
"@kthcloud/go-deploy-types": "^1.0.3",
"@mui/icons-material": "^5.15.6",
"@mui/lab": "^5.0.0-alpha.162",
"@mui/material": "^5.15.15",
"@mui/material-next": "^6.0.0-alpha.120",
"@mui/x-tree-view": "^7.1.1",
"@kthcloud/go-deploy-types": "^1.0.8",
"@mui/icons-material": "^5.15.17",
"@mui/lab": "^5.0.0-alpha.170",
"@mui/material": "^5.15.17",
"@mui/material-next": "^6.0.0-alpha.126",
"@mui/x-tree-view": "^7.3.1",
"@react-keycloak/web": "^3.4.0",
"@react-three/fiber": "^8.15.15",
"@sanity/eventsource": "^5.0.1",
"@react-three/fiber": "^8.16.5",
"@sanity/eventsource": "^5.0.2",
"@types/crypto-js": "^4.2.2",
"@types/numeral": "^2.0.5",
"@types/punycode": "^2.1.4",
"@types/three": "^0.163.0",
"apexcharts": "^3.45.2",
"change-case": "^5.4.2",
"@types/three": "^0.164.0",
"apexcharts": "^3.49.0",
"change-case": "^5.4.4",
"crypto-js": "^4.2.0",
"http-status-codes": "^2.3.0",
"i18next": "^23.7.19",
"i18next-browser-languagedetector": "^7.2.0",
"js-base64": "^3.7.6",
"keycloak-js": "^24.0.2",
"i18next": "^23.11.4",
"i18next-browser-languagedetector": "^7.2.1",
"js-base64": "^3.7.7",
"keycloak-js": "^24.0.4",
"lodash": "^4.17.21",
"million": "latest",
"notistack": "^3.0.1",
"numeral": "^2.0.6",
"punycode": "^2.3.1",
"react": "^18.2.0",
"react": "^18.3.1",
"react-apexcharts": "^1.4.1",
"react-cookie": "^7.0.1",
"react-cookie": "^7.1.4",
"react-copy-to-clipboard": "^5.1.0",
"react-dom": "^18.2.0",
"react-helmet-async": "^2.0.4",
"react-i18next": "^14.0.1",
"react-router-dom": "^6.21.3",
"simplebar": "^6.2.5",
"simplebar-react": "^3.2.4",
"three": "^0.163.0",
"three-stdlib": "^2.29.6",
"yaml": "^2.3.4"
"react-dom": "^18.3.1",
"react-helmet-async": "^2.0.5",
"react-i18next": "^14.1.1",
"react-router-dom": "^6.23.0",
"simplebar": "^6.2.6",
"simplebar-react": "^3.2.5",
"three": "^0.164.1",
"three-stdlib": "^2.29.11",
"yaml": "^2.4.2"
},
"devDependencies": {
"@faker-js/faker": "^8.3.1",
"@types/react": "^18.2.73",
"@faker-js/faker": "^8.4.1",
"@types/react": "^18.3.1",
"@types/react-copy-to-clipboard": "^5.0.7",
"@types/react-dom": "^18.2.23",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"@vitejs/plugin-react": "^4.2.1",
"@vitejs/plugin-react-swc": "^3.5.0",
"eslint": "^8.57.0",
"@vitejs/plugin-react-swc": "^3.6.0",
"eslint": "^9.2.0",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"prettier": "^3.2.4",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-refresh": "^0.4.7",
"prettier": "^3.2.5",
"prettier-plugin-nginx": "^1.0.3",
"typescript": "^5.4.5",
"vite": "^5.2.0"
"vite": "^5.2.11"
}
}
9 changes: 2 additions & 7 deletions src/api/deploy/discover.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { Tier } from "../../pages/tiers/Tiers";
import { DiscoverRead } from "@kthcloud/go-deploy-types/types/v1/body";

export type DiscoverResponse = {
version: string;
roles: Tier[];
};

export const discover = async (): Promise<DiscoverResponse> => {
export const discover = async (): Promise<DiscoverRead> => {
const res = await fetch(import.meta.env.VITE_DEPLOY_API_URL + "/discover", {
method: "GET",
});
Expand Down
1 change: 1 addition & 0 deletions src/layouts/dashboard/HelpButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const resolveURL = () => {
if (path.startsWith("/profile")) return base_url + "/usage/profile";
if (path.startsWith("/teams")) return base_url + "/usage/teams";
if (path.startsWith("/inbox")) return base_url + "/usage/inbox";
if (path.startsWith("/gpu")) return base_url + "/usage/gpu";

return base_url;
};
Expand Down
4 changes: 3 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@
"days": "days",
"year": "year",
"security-details": "Security details",
"kubernetes-error": "Kubernetes error"
"kubernetes-error": "Kubernetes error",
"owner": "Owner",
"member": "Member"
}
}
4 changes: 3 additions & 1 deletion src/locales/se.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@
"days": "dagar",
"year": "år",
"security-details": "Säkerhetsuppgifter",
"kubernetes-error": "Fel från Kubernetes"
"kubernetes-error": "Fel från Kubernetes",
"owner": "Ägare",
"member": "Medlem"
}
}
9 changes: 0 additions & 9 deletions src/pages/admin/Admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -870,15 +870,6 @@ export const Admin = () => {
</TableCell>
<TableCell>
<Stack direction={"column"}>
<Typography
variant="caption"
key={user.id + "deployments"}
>
{"deployments: " +
user.usage.deployments +
"/" +
user.quota.deployments}
</Typography>
<Typography
variant="caption"
key={user.id + "cpuCores"}
Expand Down
32 changes: 17 additions & 15 deletions src/pages/create/CreateVm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export default function CreateVm({
const [selectedZone, setSelectedZone] = useState<string>("");
const [publicKey, setPublicKey] = useState<string>("");

const [cpuCores, setCpuCores] = useState<number>(2);
const [cpuCores, setCpuCores] = useState<number>(1);
const [diskSize, setDiskSize] = useState<number>(20);
const [ram, setRam] = useState<number>(4);
const [ram, setRam] = useState<number>(2);

const [cpuError, setCpuError] = useState<string | null>(null);
const [ramError, setRamError] = useState<string | null>(null);
Expand Down Expand Up @@ -86,8 +86,8 @@ export default function CreateVm({
return;
}

if (value < 2) {
setCpuError(t("create-vm-minimum-cpu") + ": 2");
if (value < 1) {
setCpuError(t("create-vm-minimum-cpu") + ": 1");
setCpuCores(value);

return;
Expand All @@ -101,7 +101,7 @@ export default function CreateVm({
const value = parseInt(raw);
if (!value) {
setRam(0);
setRamError(t("create-vm-input-number") + ", 4-" + availableRAM);
setRamError(t("create-vm-input-number") + ", 1-" + availableRAM);
return;
}

Expand All @@ -111,8 +111,8 @@ export default function CreateVm({
return;
}

if (value < 4) {
setRamError(t("create-vm-minimum-ram") + ": 4 GB");
if (value < 1) {
setRamError(t("create-vm-minimum-ram") + ": 1 GB");
setRam(value);
return;
}
Expand Down Expand Up @@ -148,8 +148,8 @@ export default function CreateVm({
const verifyUserCanCreate = () => {
if (!user) return false;
if (user.admin) return true;
if (availableCPU < 2) return false;
if (availableRAM < 4) return false;
if (availableCPU < 1) return false;
if (availableRAM < 1) return false;
if (availableDisk < 20) return false;
return true;
};
Expand Down Expand Up @@ -182,9 +182,9 @@ export default function CreateVm({
faker.word.words(3).replace(/[^a-z0-9]|\s+|\r?\n|\r/gim, "-")
);
setCleaned("");
setCpuCores(2);
setCpuCores(1);
setDiskSize(20);
setRam(4);
setRam(2);
}
} catch (error: any) {
errorHandler(error).forEach((e) =>
Expand Down Expand Up @@ -283,8 +283,8 @@ export default function CreateVm({
: cpuError
? cpuError
: t("create-vm-number-of-cpu-cores") +
", 2-" +
availableCPU
", 1-" +
Math.floor(availableCPU)
}
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }}
error={!user.admin && (cpuError ? true : false)}
Expand All @@ -301,7 +301,9 @@ export default function CreateVm({
? ""
: ramError
? ramError
: t("create-vm-amount-of-ram") + ", 4-" + availableRAM
: t("create-vm-amount-of-ram") +
", 1-" +
Math.floor(availableRAM)
}
inputProps={{
inputMode: "numeric",
Expand All @@ -323,7 +325,7 @@ export default function CreateVm({
? diskError
: t("create-vm-disk-size-helper") +
", 20-" +
availableDisk
Math.floor(availableDisk)
}
inputProps={{
inputMode: "numeric",
Expand Down
59 changes: 53 additions & 6 deletions src/pages/edit/DangerZone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,23 @@ import {
TextField,
Button,
Stack,
Grid,
Avatar,
} from "@mui/material";
import { Resource, User, Uuid } from "../../types";
import { TeamRead } from "@kthcloud/go-deploy-types/types/v1/body";
import {
TeamRead,
UserReadDiscovery,
} from "@kthcloud/go-deploy-types/types/v1/body";
import Iconify from "../../components/Iconify";

const DangerZone = ({ resource }: { resource: Resource }) => {
const { t } = useTranslation();
const { initialized, keycloak } = useKeycloak();
const { teams } = useResource();

const [users, setUsers] = useState<User[]>([]);
const [resultsUser, setResultsUser] = useState<string[]>([]);
const [users, setUsers] = useState<UserReadDiscovery[]>([]);
const [resultsUser, setResultsUser] = useState<UserReadDiscovery[]>([]);
const [selectedUser, setSelectedUser] = useState("");

const [teamsList, setTeamsList] = useState<TeamRead[]>([]);
Expand All @@ -42,7 +48,7 @@ const DangerZone = ({ resource }: { resource: Resource }) => {
if (!(initialized && keycloak.token)) return;
try {
const response = await searchUsers(keycloak.token, query);
let options: string[] = [];
let options: UserReadDiscovery[] = [];

response.forEach((user: User) => {
if (user.email) {
Expand All @@ -51,11 +57,11 @@ const DangerZone = ({ resource }: { resource: Resource }) => {
if (!users.find((u) => u.username === user.username)) {
setUsers((users) => [...users, user]);
}
options.push(user.username);
options.push(user);
});

options = [...new Set(options)];
options.sort((a, b) => a.localeCompare(b));
options.sort((a, b) => a.username.localeCompare(b.username));
setResultsUser(options);
} catch (error: any) {
errorHandler(error).forEach((e) =>
Expand Down Expand Up @@ -250,6 +256,47 @@ const DangerZone = ({ resource }: { resource: Resource }) => {
setSelectedUser(value);
userSearch(value);
}}
getOptionLabel={(option) => {
return option.username;
}}
isOptionEqualToValue={(option, value) => {
return option.id === value.id;
}}
renderOption={(props, option) => {
return (
<li {...props} key={option.id}>
<Grid container alignItems="center">
<Grid item sx={{ display: "flex", width: 44 }}>
{option.gravatarUrl ? (
<Avatar
src={option.gravatarUrl + "?s=32"}
sx={{ width: 20, height: 20 }}
/>
) : (
<Avatar sx={{ width: 20, height: 20 }}>
<Iconify
icon="mdi:account"
sx={{ width: 16, height: 16 }}
title="Profile"
/>
</Avatar>
)}
<Grid
item
sx={{
width: "calc(100% - 44px)",
wordWrap: "break-word",
paddingLeft: 1,
}}
></Grid>
<Typography variant="body2" color="text.secondary">
{option.username}
</Typography>
</Grid>
</Grid>
</li>
);
}}
renderInput={(params) => (
<TextField
{...params}
Expand Down
4 changes: 1 addition & 3 deletions src/pages/edit/deployments/ReplicaManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ export const ReplicaManager = ({ deployment }: { deployment: Deployment }) => {
return;
}

setMax(
user.quota.deployments - (user.usage.deployments - deployment.replicas)
);
setMax(20);

// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand Down
Loading

0 comments on commit 00960b1

Please sign in to comment.