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

add: advanced controls support #12

Merged
merged 1 commit into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 9 additions & 8 deletions cvat-ui/src/actions/grades-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,23 @@ interface SubmitAnnotationFrameInput {
certificateId?: string | null;
}

export const submitAnnotationFrameToGradeAsync = (input: SubmitAnnotationFrameInput): ThunkAction => async (
dispatch,
getState,
) => {
export const submitAnnotationFrameToGradeAsync = (
input: SubmitAnnotationFrameInput & { withMasks?: boolean },
): ThunkAction => async (dispatch, getState) => {
if (!input.orientation) {
dispatch(setWarningAsync(orientationNotFound));
}

const state = getState() as CombinedState;
const { states } = state.annotation.annotations;
const { frame } = state.annotation.player;
const job = state.annotation.job.instance;
const image = await job.frames.frameData(frame.number);

const formData = new FormData();
formData.append('image', image, frame.filename);

if (input.withMasks) {
const job = state.annotation.job.instance;
const image = await job.frames.frameData(frame.number);
formData.append('image', image, frame.filename);
}

formData.append(
'payload',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.grades-form-advanced-controls {
position: relative;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (C) 2021 Intel Corporation
//
// SPDX-License-Identifier: MIT
import React, { useCallback } from 'react';
import './grades-form-advanced-controls.scss';
import Button from 'antd/lib/button';

interface Props {
onRobogradesAndMasks(): void;
}

function GradesFormAdvancedControls({ onRobogradesAndMasks }: Props): JSX.Element {
const [isExpanded, setIsExpanded] = React.useState(false);

const handleToggle = useCallback((): void => {
setIsExpanded((prev) => !prev);
}, []);

return (
<>
<div className='grades-form-advanced-controls-toggle'>
<Button type='link' block onClick={handleToggle}>
{isExpanded ? 'Hide Advanced' : 'Advanced'}
</Button>
</div>
{isExpanded && (
<Button block onClick={onRobogradesAndMasks}>
Generate Robogrades & Masks
</Button>
)}
</>
);
}

export default GradesFormAdvancedControls;
24 changes: 17 additions & 7 deletions cvat-ui/src/components/annotation-page/grades-form/grades-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import React, {
useCallback, useEffect, useMemo, useRef, useState,
} from 'react';
import { useDispatch, useSelector } from 'react-redux';
import Space from 'antd/lib/space';
import { setGradesFormState } from '../../../actions/annotation-actions';
import {
gradesActions,
Expand All @@ -23,6 +24,7 @@ import {
} from '../../../actions/grades-actions';
import { CombinedState } from '../../../reducers/interfaces';
import { parseFilename } from '../../../utils/grades';
import GradesFormAdvancedControls from './grades-form-advanced-controls';

interface Props {
task: {
Expand Down Expand Up @@ -63,11 +65,16 @@ export function GradesForm({ task }: Props): JSX.Element | null {
dispatch(setGradesFormState(false));
}, [dispatch]);

const handleSubmit = useCallback(async () => {
const handleRobogrades = useCallback(async () => {
dispatch(submitAnnotationFrameToGradeAsync(frameOptions));
formRef.current?.setFieldsValue({});
}, [frameOptions]);

const handleRobogradesAndMasks = useCallback(async () => {
dispatch(submitAnnotationFrameToGradeAsync({ ...frameOptions, withMasks: true }));
formRef.current?.setFieldsValue({});
}, [frameOptions]);

const handleUpdate = useCallback(async () => {
const formValues = await formRef.current?.validateFields();
if (formValues) {
Expand Down Expand Up @@ -368,12 +375,15 @@ export function GradesForm({ task }: Props): JSX.Element | null {
<span className='loading-text'>Loading...</span>
</div>
) : null}
<Button type='primary' onClick={handleUpdate} style={{ marginBottom: 8, width: '100%' }}>
Update grades
</Button>
<Button type='primary' onClick={handleSubmit} style={{ width: '100%' }}>
Generate Robo grades
</Button>
<Space direction='vertical' style={{ width: '100%' }}>
<Button type='primary' onClick={handleUpdate} block>
Update grades
</Button>
<Button type='primary' onClick={handleRobogrades} block>
Generate Robogrades
</Button>
<GradesFormAdvancedControls onRobogradesAndMasks={handleRobogradesAndMasks} />
</Space>
</div>
</Col>
</Row>
Expand Down