Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Job Launcher] - Client common fixes #885

Merged
merged 6 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Link } from 'react-router-dom';
import * as authService from '../../services/auth';
import { useAppDispatch } from '../../state';
import { fetchUserBalanceAsync, signIn } from '../../state/auth/reducer';
import { fetchUserJobsAsync } from '../../state/jobs/reducer';
import { Password } from './Password';
import { LoginValidationSchema } from './schema';

Expand Down Expand Up @@ -34,6 +35,7 @@ export const SignInForm = ({ onError }) => {
});
dispatch(signIn(data));
dispatch(fetchUserBalanceAsync());
dispatch(fetchUserJobsAsync());
} catch (err) {
onError(err?.response?.data?.message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const CreateJob = () => {
'0px 1px 5px 0px rgba(233, 235, 250, 0.20), 0px 2px 2px 0px rgba(233, 235, 250, 0.50), 0px 3px 1px -2px #E9EBFA',
}}
>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2, mb: 5 }}>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2, mb: 2 }}>
<FormControl variant="standard" sx={{ minWidth: 220 }}>
<InputLabel id="job-type-select-label">Job Type</InputLabel>
<Select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ import { Formik } from 'formik';
import React from 'react';
import { useCreateJobPageUI } from '../../../providers/CreateJobPageUIProvider';
import { CvatJobType } from '../../../types';
import { CvatJobRequestValidationSchema } from './schema';

export const CvatJobRequestForm = () => {
const { jobRequest, updateJobRequest, goToPrevStep, goToNextStep } =
useCreateJobPageUI();

const initialValues = {
labels: [],
type: CvatJobType.IMAGE_LABEL_BINARY,
type: CvatJobType.IMAGE_POINTS,
description: '',
dataUrl: '',
groundTruthUrl: '',
accuracyTarget: undefined,
userGuide: '',
accuracyTarget: 80,
};

const handleNext = ({
Expand All @@ -34,6 +36,7 @@ export const CvatJobRequestForm = () => {
description,
dataUrl,
groundTruthUrl,
userGuide,
accuracyTarget,
}: any) => {
updateJobRequest?.({
Expand All @@ -44,6 +47,7 @@ export const CvatJobRequestForm = () => {
description,
dataUrl,
groundTruthUrl,
userGuide,
accuracyTarget,
},
});
Expand All @@ -54,7 +58,7 @@ export const CvatJobRequestForm = () => {
<Box>
<Formik
initialValues={initialValues}
// validationSchema={RegisterValidationSchema}
validationSchema={CvatJobRequestValidationSchema}
onSubmit={handleNext}
>
{({
Expand All @@ -70,44 +74,10 @@ export const CvatJobRequestForm = () => {
<form>
<Grid container spacing={4} mb={4}>
<Grid item xs={12} sm={12} md={6}>
<FormControl fullWidth sx={{ mb: 4 }}>
<Autocomplete
clearIcon={false}
options={[]}
freeSolo
multiple
renderTags={(value, props) =>
value.map((option, index) => (
<Chip label={option} {...props({ index })} />
))
}
renderInput={(params) => (
<TextField label="Labels" {...params} />
)}
onChange={(e, value) => setFieldValue('labels', value)}
onBlur={handleBlur}
placeholder="Labels"
/>
</FormControl>
<FormControl fullWidth>
<TextField
name="description"
value={values.description}
onChange={(e) =>
setFieldValue('description', e.target.value)
}
onBlur={handleBlur}
placeholder="Description"
error={touched.description && Boolean(errors.description)}
helperText={errors.description}
multiline
rows={8}
/>
</FormControl>
</Grid>
<Grid item xs={12} sm={12} md={6}>
<FormControl variant="standard" fullWidth sx={{ mb: 4 }}>
<InputLabel id="cvat-job-type-select-label">Type</InputLabel>
<FormControl variant="standard" fullWidth sx={{ mb: 2 }}>
<InputLabel id="cvat-job-type-select-label">
Type of job
</InputLabel>
<Select
labelId="cvat-job-type-select-label"
id="cvat-job-type-select"
Expand All @@ -129,16 +99,49 @@ export const CvatJobRequestForm = () => {
error={touched.type && Boolean(errors.type)}
onBlur={handleBlur}
>
<MenuItem value={CvatJobType.IMAGE_LABEL_BINARY}>
Binary Classification
</MenuItem>
<MenuItem value={CvatJobType.IMAGE_POINTS}>Points</MenuItem>
<MenuItem value={CvatJobType.IMAGE_BOXES}>
Bounding Boxes
</MenuItem>
</Select>
</FormControl>
<FormControl fullWidth sx={{ mb: 3 }}>
<FormControl fullWidth>
<TextField
name="description"
value={values.description}
onChange={(e) =>
setFieldValue('description', e.target.value)
}
onBlur={handleBlur}
placeholder="Description"
error={touched.description && Boolean(errors.description)}
helperText={errors.description}
multiline
rows={11}
/>
</FormControl>
</Grid>
<Grid item xs={12} sm={12} md={6}>
<FormControl fullWidth sx={{ mb: 2 }}>
<Autocomplete
clearIcon={false}
options={[]}
freeSolo
multiple
renderTags={(value, props) =>
value.map((option, index) => (
<Chip label={option} {...props({ index })} />
))
}
renderInput={(params) => (
<TextField label="Labels" {...params} />
)}
onChange={(e, value) => setFieldValue('labels', value)}
onBlur={handleBlur}
placeholder="Labels"
/>
</FormControl>
<FormControl fullWidth sx={{ mb: 2 }}>
<TextField
name="dataUrl"
value={values.dataUrl}
Expand All @@ -149,7 +152,7 @@ export const CvatJobRequestForm = () => {
helperText={errors.dataUrl}
/>
</FormControl>
<FormControl fullWidth sx={{ mb: 3 }}>
<FormControl fullWidth sx={{ mb: 2 }}>
<TextField
name="groundTruthUrl"
value={values.groundTruthUrl}
Expand All @@ -164,6 +167,17 @@ export const CvatJobRequestForm = () => {
helperText={errors.groundTruthUrl}
/>
</FormControl>
<FormControl fullWidth sx={{ mb: 2 }}>
<TextField
name="userGuide"
value={values.userGuide}
onChange={(e) => setFieldValue('userGuide', e.target.value)}
onBlur={handleBlur}
placeholder="User Guide"
error={touched.userGuide && Boolean(errors.userGuide)}
helperText={errors.userGuide}
/>
</FormControl>
<FormControl fullWidth>
<TextField
name="accuracyTarget"
Expand All @@ -181,7 +195,6 @@ export const CvatJobRequestForm = () => {
/>
</FormControl>
</Grid>
<Grid item xs={12} sm={12} md={6}></Grid>
</Grid>
<Box
sx={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Box, Button, FormControl, Grid, TextField } from '@mui/material';
import { Formik } from 'formik';
import React from 'react';
import { useCreateJobPageUI } from '../../../providers/CreateJobPageUIProvider';
import { FortuneJobRequestValidationSchema } from './schema';

export const FortuneJobRequestForm = () => {
const { jobRequest, updateJobRequest, goToPrevStep, goToNextStep } =
Expand Down Expand Up @@ -29,7 +30,7 @@ export const FortuneJobRequestForm = () => {
<Box>
<Formik
initialValues={initialValues}
// validationSchema={RegisterValidationSchema}
validationSchema={FortuneJobRequestValidationSchema}
onSubmit={handleNext}
>
{({
Expand All @@ -43,7 +44,7 @@ export const FortuneJobRequestForm = () => {
setFieldValue,
}) => (
<form>
<Grid container spacing={4} mb={4}>
<Grid container spacing={2} mb={4}>
<Grid item xs={12} sm={12} md={6}>
<FormControl fullWidth>
<TextField
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as Yup from 'yup';

export const CvatJobRequestValidationSchema = Yup.object().shape({
title: Yup.string().required('Title is required'),
description: Yup.string().required('Description is required'),
dataUrl: Yup.string().required('Data URL is required').url('Invalid URL'),
groundTruthUrl: Yup.string()
.required('Ground Truth URL is required')
.url('Invalid URL'),
userGuide: Yup.string()
.required('User Guide URL is required')
.url('Invalid URL'),
accuracyTarget: Yup.number()
.required('Accuracy target is required')
.min(0)
.max(100),
});

export const FortuneJobRequestValidationSchema = Yup.object().shape({
title: Yup.string().required('Title is required'),
description: Yup.string().required('Description is required'),
fortunesRequested: Yup.number().required('FortunesRequested is required'),
});
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
import ToggleButton from '@mui/material/ToggleButton';
import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
import * as React from 'react';
import ToggleButtonGroup, {
ToggleButtonGroupProps,
} from '@mui/material/ToggleButtonGroup';
import React, { FC } from 'react';
import { JobStatus } from '../../types';

const RANGE_BUTTONS = [
{ label: 'All', value: 'All' },
{ label: 'Launched', value: 'Launched' },
{ label: 'Pending', value: 'Pending' },
{ label: 'Completed', value: 'Completed' },
{ label: 'Cancelled', value: 'Cancelled' },
{ label: 'Failed', value: 'Failed' },
{ label: 'All', value: JobStatus.ALL },
{ label: 'Launched', value: JobStatus.LAUNCHED },
{ label: 'Pending', value: JobStatus.PENDING },
{ label: 'Cancelled', value: JobStatus.CANCELED },
{ label: 'Failed', value: JobStatus.FAILED },
];

export function StatusToggleButtons() {
const handleChange = (
event: React.MouseEvent<HTMLElement>,
newValue: number
) => {
console.log(newValue);
};

export const StatusToggleButtons: FC<ToggleButtonGroupProps> = (props) => {
return (
<ToggleButtonGroup value={'All'} exclusive onChange={handleChange}>
<ToggleButtonGroup {...props}>
{RANGE_BUTTONS.map(({ label, value }) => (
<ToggleButton
key={label}
Expand All @@ -38,4 +33,4 @@ export function StatusToggleButtons() {
))}
</ToggleButtonGroup>
);
}
};
13 changes: 10 additions & 3 deletions packages/apps/job-launcher/client/src/components/Jobs/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { ChainId } from '@human-protocol/sdk';
import { Box, Button, IconButton, Typography } from '@mui/material';
import { Link, useNavigate } from 'react-router-dom';
import { CopyLinkIcon } from '../../components/Icons/CopyLinkIcon';
import { Table } from '../../components/Table';
import { useJobs } from '../../hooks/useJobs';
import { useJobs } from '../../state/jobs/hooks';
import { JobStatus } from '../../types';

export const JobTable = ({ status }: { status: JobStatus }) => {
export const JobTable = ({
status,
chainId,
}: {
status: JobStatus;
chainId?: ChainId;
}) => {
const { data, isLoading } = useJobs({ status, chainId });
const navigate = useNavigate();
const { data, isLoading } = useJobs(status);

return (
<Table
Expand Down
9 changes: 0 additions & 9 deletions packages/apps/job-launcher/client/src/hooks/useJobs.ts

This file was deleted.

2 changes: 2 additions & 0 deletions packages/apps/job-launcher/client/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { LOCAL_STORAGE_KEYS } from './constants';
import reportWebVitals from './reportWebVitals';
import { store } from './state';
import { fetchUserBalanceAsync, signIn } from './state/auth/reducer';
import { fetchUserJobsAsync } from './state/jobs/reducer';
import theme from './theme';
// import { isJwtExpired } from './utils/jwt';

Expand Down Expand Up @@ -108,6 +109,7 @@ loadStripe(publishableKey).then((stripePromise) => {
})
);
store.dispatch(fetchUserBalanceAsync());
store.dispatch(fetchUserJobsAsync());
}

root.render(
Expand Down
Loading