Skip to content

Commit 95b336d

Browse files
committed
Add checkbox for optimality (does not do anything yet)
1 parent b3b111a commit 95b336d

File tree

9 files changed

+63
-20
lines changed

9 files changed

+63
-20
lines changed

client/src/components/Field.tsx

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import {
22
AutocompleteProps,
3+
CheckboxProps,
34
Autocomplete as MuiAutocomplete,
45
SxProps,
6+
Checkbox as MuiCheckbox,
7+
FormControlLabel,
8+
FormControlLabelProps,
59
} from "@mui/material";
610
import Box, { BoxProps } from "@mui/material/Box";
711
import FormHelperText, {
@@ -18,11 +22,11 @@ import { ComponentProps, ComponentType, Ref, forwardRef } from "react";
1822
import { paper } from "theme";
1923

2024
export function Field<
21-
Schema extends Record<string, string | number | object> = Record<
25+
Schema extends Record<string, string | number | object | boolean> = Record<
2226
string,
23-
string | number | object
27+
string | number | object | boolean
2428
>,
25-
T extends ComponentType<object> = typeof TextField
29+
T extends ComponentType<object> = typeof TextField,
2630
>({
2731
slotProps = {},
2832
as,
@@ -79,15 +83,36 @@ export const Select = forwardRef(
7983
}}
8084
ref={ref}
8185
/>
82-
)
86+
),
87+
);
88+
89+
export const Checkbox = forwardRef(
90+
(props: Partial<FormControlLabelProps>, ref: Ref<HTMLButtonElement>) => {
91+
const form = useFormikContext();
92+
return (
93+
<FormControlLabel
94+
label="No label"
95+
{...props}
96+
ref={ref}
97+
control={
98+
<MuiCheckbox
99+
defaultChecked={!!props.value}
100+
onChange={(v) => {
101+
form.setFieldValue(props.name, v.target.checked);
102+
}}
103+
/>
104+
}
105+
/>
106+
);
107+
},
83108
);
84109

85110
export const Autocomplete = forwardRef(function <
86111
Value,
87112
Multiple extends boolean | undefined,
88113
DisableClearable extends boolean | undefined,
89114
FreeSolo extends boolean | undefined,
90-
ChipComponent extends React.ElementType = "div"
115+
ChipComponent extends React.ElementType = "div",
91116
>(
92117
{
93118
autoCompleteProps,
@@ -105,7 +130,7 @@ export const Autocomplete = forwardRef(function <
105130
"renderInput"
106131
>;
107132
} & TextFieldProps,
108-
ref: Ref<HTMLDivElement>
133+
ref: Ref<HTMLDivElement>,
109134
) {
110135
const form = useFormikContext();
111136
return (

client/src/components/data-grid/cellRenderers.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export const Bar = ({
134134
gap: 1,
135135
},
136136
},
137-
props
137+
props,
138138
)}
139139
>
140140
<Stack direction="row" sx={{ flex: 1 }}>
@@ -149,7 +149,9 @@ export const Bar = ({
149149
bgcolor: "transparent",
150150
transition: `flex 2s ${easeCircle}`,
151151
flex: value,
152-
"> .MuiLinearProgress-bar": { bgcolor: color ?? "info.main" },
152+
"> .MuiLinearProgress-bar": {
153+
bgcolor: color ?? "info.main",
154+
},
153155
}}
154156
value={100}
155157
variant="determinate"

client/src/forms/SubmissionKeyRequestForm.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createFilterOptions, Stack, Typography } from "@mui/material";
22
import { useQuery } from "@tanstack/react-query";
3-
import { Autocomplete, Field } from "components/Field";
3+
import { Autocomplete, Checkbox, Field } from "components/Field";
44
import { Form, Formik, FormikConfig, FormikProps } from "formik";
55
import { chain, noop, once } from "lodash";
66
import { toJson } from "queries/query";
@@ -133,11 +133,11 @@ export function SubmissionKeyRequestForm({
133133
label="Affiliation"
134134
placeholder="Monash University"
135135
required
136-
/>
136+
/>,
137137
)}
138138
{renderLabel(
139139
"About your algorithm",
140-
"Tell us about this algorithm you would like to submit results for."
140+
"Tell us about this algorithm you would like to submit results for.",
141141
)}
142142
{renderRow(
143143
<Field<Request>
@@ -153,7 +153,7 @@ export function SubmissionKeyRequestForm({
153153
label="Authors"
154154
placeholder="John Doe, Wei Zhang, Joe Smith"
155155
required
156-
/>
156+
/>,
157157
)}
158158
<Field<Request>
159159
name="paperReference"
@@ -164,9 +164,15 @@ export function SubmissionKeyRequestForm({
164164
minRows={3}
165165
required
166166
/>
167+
<Field<Request, typeof Checkbox>
168+
name="isOptimal"
169+
disabled={disabled || disabledValues?.isOptimal}
170+
label="My algorithm is optimal"
171+
as={Checkbox}
172+
/>
167173
{renderLabel(
168174
"Where your algorithm is published",
169-
"Make it easier for people to find your work once we list your results on our platform."
175+
"Make it easier for people to find your work once we list your results on our platform.",
170176
)}
171177
<Field<Request>
172178
name="googleScholar"
@@ -188,7 +194,7 @@ export function SubmissionKeyRequestForm({
188194
/>
189195
{renderLabel(
190196
"Other info",
191-
"Let us know why you would like to submit your algorithm to our tracker, as well as any other helpful information."
197+
"Let us know why you would like to submit your algorithm to our tracker, as well as any other helpful information.",
192198
)}
193199
<Field<Request>
194200
multiline

client/src/pages/algorithms/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const g = [
4444
function Table() {
4545
const { data: algorithms } = useAlgorithmDetailsData();
4646
const theme = useTheme();
47-
const total = max(flatMap(g, (c) => map(algorithms, c) || 1)) * 1.5;
47+
const total = max(flatMap(g, (c) => map(algorithms, c) || 1));
4848
const navigate = useNavigate();
4949
const columns: GridColDef<AlgorithmDetails>[] = [
5050
{

client/src/queries/useRequestQuery.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { useQueries, useQuery } from "@tanstack/react-query";
22
import { APIConfig } from "core/config";
33
import { map } from "lodash";
4-
import { InferType, object, string } from "yup";
4+
import { boolean, InferType, object, string } from "yup";
55
import { json } from "./query";
66
import { RequestWithReviewOutcome } from "./useRequestsQuery";
77

88
export type Request = InferType<typeof requestSchema> & { id?: string };
99

1010
export const requestSchema = object({
11+
isOptimal: boolean().default(false),
1112
requesterName: string().required("Requester name is required."),
1213
requesterEmail: string()
1314
.email("Please enter a valid email address.")
@@ -40,7 +41,7 @@ export const useRequestsData = (keys: string[]) =>
4041

4142
export const requestByEmailQueryFn = (email: string) => async () =>
4243
await json<RequestWithReviewOutcome[]>(
43-
`${APIConfig.apiUrl}/request/email/${email}`
44+
`${APIConfig.apiUrl}/request/email/${email}`,
4445
);
4546

4647
export const useRequestByEmailData = (email: string) =>

server/src/controllers/request.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const findByEmail = query(
1818
{
1919
requesterEmail: email,
2020
},
21-
]
21+
],
2222
);
2323

2424
export const findAll: RequestHandler = (req, res) => {
@@ -64,7 +64,7 @@ async function queueMail(args: Infer<typeof Request>) {
6464
"noreply@pathfinding.ai",
6565
args.requesterEmail,
6666
"We have received your request",
67-
a
67+
a,
6868
);
6969
}
7070

@@ -76,6 +76,7 @@ export const create: RequestHandler = async (req, res) => {
7676
}
7777

7878
const field = {
79+
isOptimal: req.body.isOptimal,
7980
requesterName: req.body.requesterName,
8081
requesterEmail: req.body.requesterEmail,
8182
requesterAffiliation: req.body.requesterAffiliation,
@@ -103,6 +104,7 @@ export const create: RequestHandler = async (req, res) => {
103104

104105
const requestSchema = {
105106
id: z.string(),
107+
isOptimal: z.boolean(),
106108
requesterName: z.string(),
107109
requesterEmail: z.string().email(),
108110
requesterAffiliation: z.string(),
@@ -127,7 +129,7 @@ const handleRequestUpdate = async ({
127129

128130
export const updateRequest = route(
129131
z.object(requestSchema),
130-
handleRequestUpdate
132+
handleRequestUpdate,
131133
);
132134

133135
export const updateRequestElevated = route(z.any(), handleRequestUpdate);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const algorithmCommon = {
2+
isOptimal: { type: Boolean, default: false },
3+
} as const;

server/src/models/Algorithm.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Schema, model as createModel } from "mongoose";
22
import { createSchema } from "./createSchema";
33
import { Types } from "mongoose";
44
import { queryClient } from "query";
5+
import { algorithmCommon } from "./Algorithm.common";
56

67
const schema = createSchema(
78
{
@@ -18,6 +19,7 @@ const schema = createSchema(
1819
instances_closed: Number,
1920
instances_solved: Number,
2021
submittedAt: Date,
22+
...algorithmCommon,
2123
requestId: { type: Types.ObjectId, ref: "users" },
2224
},
2325
{

server/src/models/Request.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Schema, model as createModel } from "mongoose";
22
import { createSchema } from "./createSchema";
33
import { queryClient } from "query";
4+
import { algorithmCommon } from "./Algorithm.common";
45

56
const schema = createSchema({
67
requesterName: String,
@@ -15,6 +16,7 @@ const schema = createSchema({
1516
githubLink: String,
1617
comments: String,
1718
isApproved: Boolean,
19+
...algorithmCommon,
1820
reviewStatus: {
1921
type: {
2022
status: {

0 commit comments

Comments
 (0)