Skip to content

Commit ba79d39

Browse files
authored
Merge pull request #68 from ProvideQ/release/0.4.1
Release/0.4.1
2 parents 6e18d91 + 6764a69 commit ba79d39

File tree

8 files changed

+78
-54
lines changed

8 files changed

+78
-54
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "provideq",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"private": true,
55
"scripts": {
66
"dev": "next dev",

src/api/ToolboxAPI.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,12 @@ export async function fetchSolverSettings(
142142
return [];
143143
});
144144
}
145+
146+
export async function fetchExampleProblems(problemTypeId: string) {
147+
return fetch(`${baseUrl()}/problems/${problemTypeId}/examples`, {
148+
method: "GET",
149+
headers: {
150+
"Content-Type": "application/json",
151+
},
152+
}).then((response) => response.json());
153+
}

src/components/solvers/EditorControls.tsx

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ import {
22
ButtonGroup,
33
HStack,
44
IconButton,
5+
Select,
56
Text,
67
Tooltip,
78
} from "@chakra-ui/react";
9+
import { useEffect, useState } from "react";
810
import {
911
TbDownload,
1012
TbHelp,
1113
TbRepeat,
1214
TbTrash,
1315
TbUpload,
1416
} from "react-icons/tb";
15-
import { baseUrl } from "../../api/ToolboxAPI";
17+
import { baseUrl, fetchExampleProblems } from "../../api/ToolboxAPI";
1618
import { chooseFile } from "./FileInput";
1719

1820
export interface EditorControlsProps {
@@ -40,6 +42,11 @@ export interface EditorControlsProps {
4042
* If omitted, the documentation link will point to the API docs.
4143
*/
4244
documentationLink?: string;
45+
46+
/**
47+
* Problem type id.
48+
*/
49+
problemTypeId: string;
4350
}
4451

4552
/**
@@ -75,15 +82,40 @@ const upload = async (onUpload: (uploadContent: string) => void) => {
7582
* messages, an upload, a download and a help button.
7683
*/
7784
export const EditorControls = (props: EditorControlsProps) => {
78-
const documentationLink = props.documentationLink || baseUrl();
85+
const [examples, setExamples] = useState<string[]>([]);
86+
87+
const documentationLink = props.documentationLink ?? baseUrl();
88+
89+
useEffect(() => {
90+
fetchExampleProblems(props.problemTypeId).then((json) => setExamples(json));
91+
}, [props.problemTypeId]);
7992

8093
return (
8194
<HStack justifyContent={"space-between"} width="100%">
82-
{props.errorText ? (
83-
<Text textColor="tomato">{props.errorText}</Text>
84-
) : (
85-
<Text as="i">{props.idleText}</Text>
86-
)}
95+
<HStack>
96+
{examples.length > 0 && (
97+
<Select
98+
placeholder="Load example"
99+
overflow="hidden"
100+
textOverflow="ellipsis"
101+
width="10rem"
102+
onChange={(e) => props.setEditorContent(e.target.value)}
103+
>
104+
{examples.map((example) => (
105+
<option key={example} value={example}>
106+
{example.length > 100 ? example.slice(0, 100) + "..." : example}
107+
</option>
108+
))}
109+
</Select>
110+
)}
111+
112+
{props.errorText ? (
113+
<Text textColor="tomato">{props.errorText}</Text>
114+
) : (
115+
<Text as="i">{props.idleText}</Text>
116+
)}
117+
</HStack>
118+
87119
<ButtonGroup isAttached variant="outline" colorScheme="teal">
88120
<Tooltip label="Download problem from editor">
89121
<IconButton

src/components/solvers/Graph/ProblemGraphView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export const ProblemGraphView = (props: ProblemGraphViewProps) => {
234234
addNode({
235235
id: solverId,
236236
data: {
237-
problemTypeId: node.data.problemDtos[0].typeId,
237+
problemIds: node.data.problemDtos.map((x) => x.id),
238238
problemSolver: solvers[i],
239239
selectCallback: (problemSolver: ProblemSolverInfo) => {
240240
let edge = edges.find((e) =>

src/components/solvers/Graph/ProblemNode.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ export function ProblemNode(props: NodeProps<ProblemNodeData>) {
196196

197197
return (
198198
<VStack
199+
cursor="default"
199200
width="10rem"
200201
css={{
201202
// prevent this from consuming pointer events
@@ -239,7 +240,9 @@ export function ProblemNode(props: NodeProps<ProblemNodeData>) {
239240
{extended &&
240241
props.data.problemDtos.every((dto) =>
241242
canProblemSolverBeUpdated(dto)
242-
) && <FaXmark color="red" onClick={disconnect} />}
243+
) && (
244+
<FaXmark cursor="pointer" color="red" onClick={disconnect} />
245+
)}
243246
</div>
244247
)
245248
)}
@@ -261,7 +264,7 @@ export function ProblemNode(props: NodeProps<ProblemNodeData>) {
261264
{props.data.problemDtos[0].typeId}
262265
</Text>
263266
<div>
264-
<FaQuestionCircle size="1rem" onClick={onOpen} />
267+
<FaQuestionCircle cursor="pointer" size="1rem" onClick={onOpen} />
265268
</div>
266269

267270
<Modal
@@ -298,6 +301,7 @@ export function ProblemNode(props: NodeProps<ProblemNodeData>) {
298301
position="absolute"
299302
bg={nodeColor}
300303
borderRadius={10}
304+
cursor="pointer"
301305
onClick={() => setDropdownOpen(!dropdownOpen)}
302306
left="50%"
303307
transform="translate(-50%, -50%)"
@@ -338,7 +342,7 @@ export function ProblemNode(props: NodeProps<ProblemNodeData>) {
338342
marginTop="-10px"
339343
>
340344
<SolverNodeContent
341-
problemTypeId={typeId}
345+
problemIds={props.data.problemDtos.map((dto) => dto.id)}
342346
solver={{
343347
id: solverId,
344348
name: solverName,

src/components/solvers/Graph/SolverNode.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import { ProblemSolverInfo } from "../../../api/data-model/ProblemSolverInfo";
44
import { SolverNodeContent } from "./SolverNodeContent";
55

66
export interface SolverNodeData {
7-
problemTypeId: string;
7+
problemId: string[];
88
problemSolver: ProblemSolverInfo;
99
selectCallback: (problemSolver: ProblemSolverInfo) => void;
1010
}
1111

1212
export function SolverNode(props: NodeProps<SolverNodeData>) {
1313
return (
1414
<Box
15+
cursor="default"
1516
border="1px"
1617
borderRadius="10px"
1718
padding=".5rem"
@@ -44,7 +45,7 @@ export function SolverNode(props: NodeProps<SolverNodeData>) {
4445
<Handle type="target" position={Position.Top} />
4546
<VStack gap="0px">
4647
<SolverNodeContent
47-
problemTypeId={props.data.problemTypeId}
48+
problemIds={props.data.problemId}
4849
solver={props.data.problemSolver}
4950
button={{
5051
label: "Select",

src/components/solvers/Graph/SolverNodeContent.tsx

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
1-
import {
2-
Button,
3-
HStack,
4-
Popover,
5-
PopoverArrow,
6-
PopoverBody,
7-
PopoverCloseButton,
8-
PopoverContent,
9-
PopoverFooter,
10-
PopoverHeader,
11-
PopoverTrigger,
12-
Portal,
13-
Text,
14-
Tooltip,
15-
VStack,
16-
} from "@chakra-ui/react";
1+
import { Button, HStack, Text, Tooltip, VStack } from "@chakra-ui/react";
172
import { ReactNode } from "react";
18-
import { FaQuestionCircle } from "react-icons/fa";
193
import { FaGears } from "react-icons/fa6";
4+
import { IoMdRefresh } from "react-icons/io";
205
import { ProblemSolverInfo } from "../../../api/data-model/ProblemSolverInfo";
6+
import { useGraphUpdates } from "./ProblemGraphView";
217

228
export interface SolverNodeContentProps {
23-
problemTypeId: string;
9+
problemIds: string[];
2410
solver: ProblemSolverInfo;
2511
button: {
2612
label: ReactNode;
@@ -29,6 +15,8 @@ export interface SolverNodeContentProps {
2915
}
3016

3117
export const SolverNodeContent = (props: SolverNodeContentProps) => {
18+
const { updateProblem } = useGraphUpdates();
19+
3220
return (
3321
<VStack gap="0px">
3422
<HStack align="start" maxW="10rem" justifyContent="space-between" gap="0">
@@ -41,28 +29,17 @@ export const SolverNodeContent = (props: SolverNodeContentProps) => {
4129
{props.solver.name}
4230
</Text>
4331

44-
<Popover>
45-
<PopoverTrigger>
46-
<div>
47-
<FaQuestionCircle size="1rem" />
48-
</div>
49-
</PopoverTrigger>
50-
<Portal>
51-
<PopoverContent>
52-
<PopoverArrow />
53-
<PopoverCloseButton />
54-
<PopoverHeader>
55-
<Text fontWeight="semibold">{props.solver.name}</Text>
56-
</PopoverHeader>
57-
<PopoverBody>
58-
<Text>Solves {props.problemTypeId}</Text>
59-
</PopoverBody>
60-
<PopoverFooter>
61-
<Text fontSize="xs">{props.solver.id}</Text>
62-
</PopoverFooter>
63-
</PopoverContent>
64-
</Portal>
65-
</Popover>
32+
{props.problemIds !== undefined && (
33+
<IoMdRefresh
34+
cursor="pointer"
35+
size="2rem"
36+
onClick={() => {
37+
for (let problemId of props.problemIds) {
38+
updateProblem(problemId);
39+
}
40+
}}
41+
/>
42+
)}
6643
</HStack>
6744

6845
<div

src/components/solvers/TextInputMask.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const TextInputMask = (props: TextInputMaskProperties) => {
4747
</Head>
4848

4949
<EditorControls
50+
problemTypeId={props.problemTypeId}
5051
errorText={errorString}
5152
idleText={props.textPlaceholder + " 👇"}
5253
setEditorContent={onTextChanged}

0 commit comments

Comments
 (0)