Skip to content

Commit 125bac5

Browse files
authored
Merge pull request #53 from ProvideQ/feat/solver-settings
Adds solver specific settings
2 parents 30fa3bf + bdf0e09 commit 125bac5

13 files changed

+371
-235
lines changed

src/api/ToolboxAPI.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getInvalidProblemDto, ProblemDto } from "./data-model/ProblemDto";
22
import { ProblemSolverInfo } from "./data-model/ProblemSolverInfo";
33
import { ProblemState } from "./data-model/ProblemState";
4+
import { SolverSetting } from "./data-model/SolverSettings";
45
import { SubRoutineDefinitionDto } from "./data-model/SubRoutineDefinitionDto";
56

67
/**
@@ -61,11 +62,14 @@ export async function postProblem<T>(
6162
export async function patchProblem<T>(
6263
problemTypeId: string,
6364
problemId: string,
64-
updateParameters: { input?: any; solverId?: string; state?: ProblemState }
65+
updateParameters: {
66+
input?: any;
67+
solverId?: string;
68+
state?: ProblemState;
69+
solverSettings?: SolverSetting[];
70+
}
6571
): Promise<ProblemDto<T>> {
66-
let url = `${baseUrl()}/problems/${problemTypeId}/${problemId}`;
67-
console.log(url);
68-
return fetch(url, {
72+
return fetch(`${baseUrl()}/problems/${problemTypeId}/${problemId}`, {
6973
method: "PATCH",
7074
headers: {
7175
"Content-Type": "application/json",
@@ -105,9 +109,7 @@ export async function fetchSubRoutines(
105109
solverId: string
106110
): Promise<SubRoutineDefinitionDto[]> {
107111
return fetch(
108-
`${baseUrl()}/sub-routines/${problemTypeId}?${new URLSearchParams({
109-
id: solverId,
110-
})}`,
112+
`${baseUrl()}/solvers/${problemTypeId}/${solverId}/sub-routines`,
111113
{
112114
method: "GET",
113115
headers: {
@@ -123,18 +125,20 @@ export async function fetchSubRoutines(
123125
});
124126
}
125127

126-
// export async function fetchMetaSolverSettings(
127-
// problemTypeId: string
128-
// ): Promise<MetaSolverSetting[]> {
129-
// return fetch(`${baseUrl()}/meta-solver/settings/${problemTypeId}`, {
130-
// method: "GET",
131-
// headers: {
132-
// "Content-Type": "application/json",
133-
// },
134-
// })
135-
// .then((response) => response.json())
136-
// .catch((reason) => {
137-
// console.log(reason);
138-
// return [];
139-
// });
140-
// }
128+
export async function fetchSolverSettings(
129+
problemTypeId: string,
130+
solverId: string
131+
): Promise<[]> {
132+
return fetch(`${baseUrl()}/solvers/${problemTypeId}/${solverId}/settings`, {
133+
method: "GET",
134+
headers: {
135+
"Content-Type": "application/json",
136+
},
137+
})
138+
.then((response) => response.json())
139+
.catch((reason) => {
140+
console.error(reason);
141+
alert(`Could not retrieve subroutines of solver ${solverId}.`);
142+
return [];
143+
});
144+
}

src/api/data-model/MetaSolverSettings.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/api/data-model/ProblemDto.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ProblemState } from "./ProblemState";
22
import { getInvalidSolutionObject, SolutionObject } from "./SolutionObject";
3+
import { SolverSetting } from "./SolverSettings";
34
import { SubRoutineReferenceDto } from "./SubRoutineReferenceDto";
45

56
export interface ProblemDto<T> {
@@ -9,6 +10,7 @@ export interface ProblemDto<T> {
910
solution: SolutionObject;
1011
state: ProblemState;
1112
solverId?: string;
13+
solverSettings: SolverSetting[];
1214
subProblems: SubRoutineReferenceDto[];
1315
error: string;
1416
}
@@ -20,6 +22,7 @@ export function getInvalidProblemDto<T>(): ProblemDto<T> {
2022
input: {} as T,
2123
solution: getInvalidSolutionObject(),
2224
solverId: "",
25+
solverSettings: [],
2326
state: ProblemState.READY_TO_SOLVE,
2427
subProblems: [],
2528
typeId: "",

src/api/data-model/SolverSettings.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
export enum SolverSettingType {
2+
INTEGER = "INTEGER",
3+
DOUBLE = "DOUBLE",
4+
CHECKBOX = "CHECKBOX",
5+
TEXT = "TEXT",
6+
SELECT = "SELECT",
7+
}
8+
9+
export interface SolverSetting {
10+
name: string;
11+
description: string;
12+
type: SolverSettingType;
13+
required: boolean;
14+
}
15+
16+
export interface RangeSetting extends SolverSetting {
17+
min: number;
18+
max: number;
19+
value: number;
20+
}
21+
22+
export interface CheckboxSetting extends SolverSetting {
23+
state: boolean;
24+
}
25+
26+
export interface TextSetting extends SolverSetting {
27+
text: string;
28+
}
29+
30+
export interface SelectSetting extends SolverSetting {
31+
options: string[];
32+
selectedOption: string;
33+
}

src/components/solvers/Graph/ProblemDetails.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import {
1212
import { ReactNode } from "react";
1313
import { ProblemDto } from "../../../api/data-model/ProblemDto";
1414
import { ProblemState } from "../../../api/data-model/ProblemState";
15+
import { SettingsView } from "../settings/SettingsView";
1516
import { SolutionView } from "../SolutionView";
17+
import { useGraphUpdates } from "./ProblemGraphView";
1618
import { useSolvers } from "./SolverProvider";
1719

1820
function getHumanReadableState(state: ProblemState) {
@@ -46,22 +48,35 @@ function getAccordionItem(label: string, content: ReactNode) {
4648

4749
export const ProblemDetails = (props: { problemDto: ProblemDto<any> }) => {
4850
const { solvers, getSolvers } = useSolvers();
51+
const { updateProblem } = useGraphUpdates();
4952

5053
// Update solvers in case they are not loaded yet
5154
if (!solvers[props.problemDto.typeId]) getSolvers(props.problemDto.typeId);
5255

56+
const solver = solvers[props.problemDto.typeId]?.find(
57+
(s) => s.id === props.problemDto.solverId
58+
);
59+
5360
return (
5461
<VStack gap="20px" align="start">
5562
<Textarea readOnly resize="vertical" value={props.problemDto.input} />
5663
<Text>
5764
<b>Status:</b> {getHumanReadableState(props.problemDto.state)}
5865
</Text>
5966
<Text>
60-
<b>Solver:</b>{" "}
61-
{solvers[props.problemDto.typeId]?.find(
62-
(s) => s.id === props.problemDto.solverId
63-
)?.name ?? "-"}
67+
<b>Solver:</b> {solver?.name ?? "-"}
6468
</Text>
69+
{solver && (
70+
<VStack width="100%" align="stretch">
71+
<Text>Solver Settings:</Text>
72+
<SettingsView
73+
problemDto={props.problemDto}
74+
settingsChanged={(settings) => {
75+
updateProblem(props.problemDto.id);
76+
}}
77+
/>
78+
</VStack>
79+
)}
6580
{props.problemDto.subProblems.length === 0 ? (
6681
<b>No subroutines</b>
6782
) : (

src/components/solvers/SettingsView.tsx

Lines changed: 0 additions & 179 deletions
This file was deleted.

0 commit comments

Comments
 (0)