automatic-annotation-progress.tsx 4.3 KB
Newer Older
1
// Copyright (C) 2020-2022 Intel Corporation
2 3 4 5 6
//
// SPDX-License-Identifier: MIT

import React from 'react';
import { Row, Col } from 'antd/lib/grid';
B
Boris Sekachev 已提交
7
import { CloseOutlined, LoadingOutlined } from '@ant-design/icons';
8 9 10
import Text from 'antd/lib/typography/Text';
import Progress from 'antd/lib/progress';
import Modal from 'antd/lib/modal';
11 12

import CVATTooltip from 'components/common/cvat-tooltip';
B
Boris Sekachev 已提交
13
import { RQStatus } from 'cvat-core-wrapper';
B
Boris Sekachev 已提交
14
import { ActiveInference } from 'reducers';
15 16 17 18 19 20 21 22 23 24

interface Props {
    activeInference: ActiveInference | null;
    cancelAutoAnnotation(): void;
}

export default function AutomaticAnnotationProgress(props: Props): JSX.Element | null {
    const { activeInference, cancelAutoAnnotation } = props;
    if (!activeInference) return null;

B
Boris Sekachev 已提交
25 26 27 28 29
    let textType: 'success' | 'danger' = 'success';
    if ([RQStatus.FAILED, RQStatus.UNKNOWN].includes(activeInference.status)) {
        textType = 'danger';
    }

30 31
    return (
        <>
32 33 34
            <Row justify='space-between' align='bottom'>
                <Col span={22} className='cvat-task-item-progress-wrapper'>
                    <div>
B
Boris Sekachev 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
                        <Text
                            type={activeInference.status === RQStatus.QUEUED ? undefined : textType}
                            strong
                        >
                            {((): JSX.Element => {
                                if (activeInference.status === RQStatus.QUEUED) {
                                    return (
                                        <>
                                            Automatic annotation request queued
                                            <LoadingOutlined />
                                        </>
                                    );
                                }

                                if (activeInference.status === RQStatus.STARTED) {
                                    return (
                                        <>
                                            Automatic annotation is in progress
                                            <LoadingOutlined />
                                        </>
                                    );
                                }

                                if (activeInference.status === RQStatus.FAILED) {
                                    return (<>Automatic annotation failed</>);
                                }

                                if (activeInference.status === RQStatus.UNKNOWN) {
                                    return (<>Unknown status received</>);
                                }

                                return <>Automatic annotation accomplisted</>;
                            })()}
68 69
                        </Text>
                    </div>
70 71 72 73 74 75 76 77 78 79 80 81
                    <Progress
                        percent={Math.floor(activeInference.progress)}
                        strokeColor={{
                            from: '#108ee9',
                            to: '#87d068',
                        }}
                        showInfo={false}
                        strokeWidth={5}
                        size='small'
                    />
                </Col>
                <Col span={1} className='close-auto-annotation-icon'>
B
Boris Sekachev 已提交
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
                    { activeInference.status !== RQStatus.FAILED && (
                        <CVATTooltip title='Cancel automatic annotation'>
                            <CloseOutlined
                                onClick={() => {
                                    Modal.confirm({
                                        title: 'You are going to cancel automatic annotation?',
                                        content: 'Reached progress will be lost. Continue?',
                                        okButtonProps: {
                                            type: 'primary',
                                            danger: true,
                                        },
                                        onOk() {
                                            cancelAutoAnnotation();
                                        },
                                    });
                                }}
                            />
                        </CVATTooltip>
                    )}
101 102 103 104 105
                </Col>
            </Row>
        </>
    );
}