Skip to content

Commit

Permalink
feat(ui): use API to get launcher number of cores
Browse files Browse the repository at this point in the history
  • Loading branch information
hdinia committed Oct 23, 2023
1 parent ccd849e commit b7d51ee
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
1 change: 1 addition & 0 deletions webapp/public/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@
"study.error.exportOutput": "Failed to export the output",
"study.error.listOutputs": "Failed to retrieve output list",
"study.error.launcherVersions": "Failed to retrieve launcher versions",
"study.error.launcherCores": "Failed to retrieve launcher number of cores",
"study.error.fetchComments": "Failed to fetch comments",
"study.error.commentsNotSaved": "Comments not saved",
"study.error.studyIdCopy": "Failed to copy study ID",
Expand Down
1 change: 1 addition & 0 deletions webapp/public/locales/fr/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@
"study.error.exportOutput": "Échec lors de l'export de la sortie",
"study.error.listOutputs": "Échec de la récupération des sorties",
"study.error.launcherVersions": "Échec lors de la récupération des versions du launcher",
"study.error.launcherCores": "Échec lors de la récupération du nombre de cœurs du launcher",
"study.error.fetchComments": "Échec lors de la récupération des commentaires",
"study.error.commentsNotSaved": "Erreur lors de l'enregistrement des commentaires",
"study.error.studyIdCopy": "Erreur lors de la copie de l'identifiant de l'étude",
Expand Down
37 changes: 23 additions & 14 deletions webapp/src/components/App/Studies/LauncherDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
LaunchOptions,
} from "../../../common/types";
import {
getLauncherCores,
getLauncherLoad,
getLauncherVersions,
getStudyOutputs,
Expand All @@ -48,7 +49,6 @@ import { convertVersions } from "../../../services/utils";

const LAUNCH_DURATION_MAX_HOURS = 240;
const LAUNCH_LOAD_DEFAULT = 22;
const LAUNCH_LOAD_SLIDER = { step: 1, min: 1, max: 24 };

interface Props {
open: boolean;
Expand Down Expand Up @@ -79,6 +79,13 @@ function LauncherDialog(props: Props) {
deps: [open],
});

const { data: cores } = usePromiseWithSnackbarError(
() => getLauncherCores(),
{
errorMessage: t("study.error.launcherCores"),
},
);

const { data: outputList } = usePromiseWithSnackbarError(
() => Promise.all(studyIds.map((sid) => getStudyOutputs(sid))),
{ errorMessage: t("study.error.listOutputs"), deps: [studyIds] },
Expand Down Expand Up @@ -337,19 +344,21 @@ function LauncherDialog(props: Props) {
/>
)}
</Box>
<Slider
sx={{
width: "95%",
mx: 1,
}}
defaultValue={LAUNCH_LOAD_DEFAULT}
step={LAUNCH_LOAD_SLIDER.step}
min={LAUNCH_LOAD_SLIDER.min}
color="secondary"
max={LAUNCH_LOAD_SLIDER.max}
valueLabelDisplay="auto"
onChange={(event, val) => handleChange("nb_cpu", val as number)}
/>
{cores && (
<Slider
sx={{
width: "95%",
mx: 1,
}}
defaultValue={cores.defaultValue}
step={1}
min={cores.min}
max={cores.max}
valueLabelDisplay="auto"
color="secondary"
onChange={(event, val) => handleChange("nb_cpu", val as number)}
/>
)}
</FormControl>
<Typography sx={{ mt: 1 }}>Xpansion</Typography>
<FormGroup
Expand Down
5 changes: 5 additions & 0 deletions webapp/src/services/api/study.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ export const getLauncherVersions = async (): Promise<Array<string>> => {
return res.data;
};

export const getLauncherCores = async (): Promise<Record<string, number>> => {
const res = await client.get("/v1/launcher/nbcores");
return res.data;
};

export const getLauncherLoad = async (): Promise<LauncherLoadDTO> => {
const res = await client.get("/v1/launcher/load");
return res.data;
Expand Down

0 comments on commit b7d51ee

Please sign in to comment.