Skip to content

Commit

Permalink
feat: Added runner options limit in frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
MathisBurger committed Nov 20, 2024
1 parent a933dfe commit 1ac97d0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useForm } from "@mantine/form";
import { Assignment, RunnerConfig } from "@/service/types/tasky";
import { useTranslation } from "react-i18next";
import { removeObjectIds } from "@/utils/FileStructure";
import useRunnerOptions from "@/hooks/useRunnerOptions";

interface AssignmentCreateOrUpdateCodeTestModalProps {
onClose: () => void;
Expand All @@ -19,9 +20,6 @@ interface AssignmentCreateOrUpdateCodeTestModalProps {
refetch: () => void;
}

const cpuOptions = [".5", "1"];
const memoryOptions = ["50m", "100m", "200m", "300m", "500m"];
const timeoutOptions = ["20s", "60s", "120s", "180s", "240s", "300s"];

const AssignmentCreateOrUpdateCodeTestModal = ({
onClose,
Expand All @@ -37,6 +35,8 @@ const AssignmentCreateOrUpdateCodeTestModal = ({
const [files, setFiles] = useState<FileWithPath[]>([]);
const { t } = useTranslation(["assignment", "common"]);

const {cpuOptions, memoryOptions, timeoutOptions} = useRunnerOptions(groupId);

useEffect(() => {
if (assignment.file_structure) {
setFileStructure(assignment.file_structure);
Expand Down
24 changes: 24 additions & 0 deletions web/hooks/useRunnerOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import useApiServiceClient from "@/hooks/useApiServiceClient";
import {useMemo} from "react";
import useClientQuery from "@/hooks/useClientQuery";

/**
* Gets all runner options
*
* @param groupId The ID of the group
*/
const useRunnerOptions = (groupId: number) => {

const api = useApiServiceClient();
const [group] = useClientQuery(() => api.getGroup(groupId), [groupId]);

const verified = useMemo<boolean>(() => group?.verified ?? false, [group]);

const cpuOptions = verified ? [".5", "1"] :[".5"];
const memoryOptions = verified ? ["50m", "100m", "200m", "300m", "500m"] : ["50m", "100m", "200m"];
const timeoutOptions = verified ? ["20s", "60s", "120s", "180s", "240s", "300s"] : ["20s", "60s"];

return {cpuOptions, memoryOptions, timeoutOptions};
};

export default useRunnerOptions;

0 comments on commit 1ac97d0

Please sign in to comment.