BasicInfo.tsx 4.83 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import React, { useState, useCallback } from 'react';
import { Stack, Callout, Link, IconButton } from '@fluentui/react';
import LogDrawer from '../../modals/LogPanel';
import { EXPERIMENT } from '../../../static/datamodel';
import { formatTimestamp } from '../../../static/function';
import { useId } from '@uifabric/react-hooks';
import { BestMetricContext } from '../../Overview';
import { styles } from './basicInfoStyles';
import '../../../static/style/progress/progress.scss';
import '../../../static/style/progress/probar.scss';

export const ReBasicInfo = (): any => {
    const labelId: string = useId('callout-label');
    const descriptionId: string = useId('callout-description');
    const ref = React.createRef<HTMLDivElement>();
    const [isCalloutVisible, setCalloutVisible] = useState(false);
    const [isShowLogDrawer, setShowLogDrawer] = useState(false);
    const onDismiss = useCallback(() => setCalloutVisible(false), []);
    const showCallout = useCallback(() => setCalloutVisible(true), []);

    const closeLogDrawer = useCallback(() => setShowLogDrawer(false), []);
    const ShowLogDrawer = useCallback(() => setShowLogDrawer(true), []);

    return (
        <div>
            <div className='basic'>
27
28
29
                <p>
                    ID: <span>{EXPERIMENT.profile.id}</span>
                </p>
30
31
32
                <div>{EXPERIMENT.profile.params.experimentName}</div>
            </div>
            <div className='basic'>
33
34
35
36
37
38
39
40
41
42
                <p>Status</p>
                <Stack horizontal className='status'>
                    <span className={`${EXPERIMENT.status} status-text`}>{EXPERIMENT.status}</span>
                    {EXPERIMENT.status === 'ERROR' ? (
                        <div>
                            <div className={styles.buttonArea} ref={ref}>
                                <IconButton
                                    iconProps={{ iconName: 'info' }}
                                    onClick={isCalloutVisible ? onDismiss : showCallout}
                                />
43
                            </div>
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
                            {isCalloutVisible && (
                                <Callout
                                    className={styles.callout}
                                    ariaLabelledBy={labelId}
                                    ariaDescribedBy={descriptionId}
                                    role='alertdialog'
                                    gapSpace={0}
                                    target={ref}
                                    onDismiss={onDismiss}
                                    setInitialFocus={true}
                                >
                                    <div className={styles.header}>
                                        <p className={styles.title} id={labelId} style={{ color: '#333' }}>
                                            Error
                                        </p>
                                    </div>
                                    <div className={styles.inner}>
                                        <p className={styles.subtext} id={descriptionId} style={{ color: '#333' }}>
                                            {EXPERIMENT.error}
                                        </p>
                                        <div className={styles.actions}>
                                            <Link className={styles.link} onClick={ShowLogDrawer}>
                                                Learn about
                                            </Link>
                                        </div>
                                    </div>
                                </Callout>
                            )}
                        </div>
                    ) : null}
74
75
76
77
78
                </Stack>
            </div>
            <div className='basic'>
                <BestMetricContext.Consumer>
                    {(value): React.ReactNode => (
79
                        <Stack className='bestMetric'>
80
                            <p>Best metric</p>
81
82
83
                            <div className={EXPERIMENT.status}>
                                {isNaN(value.bestAccuracy) ? 'N/A' : value.bestAccuracy.toFixed(6)}
                            </div>
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
                        </Stack>
                    )}
                </BestMetricContext.Consumer>
            </div>
            <div className='basic'>
                <p>Start time</p>
                <div className='nowrap'>{formatTimestamp(EXPERIMENT.profile.startTime)}</div>
            </div>
            <div className='basic'>
                <p>End time</p>
                <div className='nowrap'>{formatTimestamp(EXPERIMENT.profile.endTime)}</div>
            </div>
            {/* learn about click -> default active key is dispatcher. */}
            {isShowLogDrawer ? <LogDrawer closeDrawer={closeLogDrawer} activeTab='dispatcher' /> : null}
        </div>
    );
};