Killjob.tsx 4.15 KB
Newer Older
1
2
import * as React from 'react';
import {
3
4
5
    Stack,
    FocusTrapCallout,
    DefaultButton,
6
    FocusZone,
7
8
9
10
    PrimaryButton,
    getTheme,
    mergeStyleSets,
    FontWeights
11
} from '@fluentui/react';
12
import { killJob } from '../../static/function';
13
import { blocked } from '../buttons/Icon';
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
68
69
70
71
72
73
74
75
76
77
78

const theme = getTheme();
const styles = mergeStyleSets({
    buttonArea: {
        verticalAlign: 'top',
        display: 'inline-block',
        textAlign: 'center',
        height: 32
    },
    callout: {
        maxWidth: 300
    },
    header: {
        padding: '18px 24px 12px'
    },
    title: [
        theme.fonts.xLarge,
        {
            margin: 0,
            color: theme.palette.neutralPrimary,
            fontWeight: FontWeights.semilight
        }
    ],
    inner: {
        height: '100%',
        padding: '0 24px 20px'
    },
    actions: {
        position: 'relative',
        marginTop: 20,
        width: '100%',
        whiteSpace: 'nowrap'
    },
    buttons: {
        display: 'flex',
        justifyContent: 'flex-end',
        padding: '0 24px 24px'
    },
    subtext: [
        theme.fonts.small,
        {
            margin: 0,
            color: theme.palette.neutralPrimary,
            fontWeight: FontWeights.semilight
        }
    ]
});

interface KillJobState {
    isCalloutVisible: boolean;
}

interface KillJobProps {
    trial: any;
}

class KillJob extends React.Component<KillJobProps, KillJobState> {
    private menuButtonElement!: HTMLElement | null;
    constructor(props: KillJobProps) {
        super(props);
        this.state = { isCalloutVisible: false };
    }

    onDismiss = (): void => {
        this.setState(() => ({ isCalloutVisible: false }));
79
    };
80
81
82
83

    onKill = (): void => {
        this.setState({ isCalloutVisible: false }, () => {
            const { trial } = this.props;
Lijiaoa's avatar
Lijiaoa committed
84
            killJob(trial.key, trial.id, trial.status);
85
        });
86
    };
87
88
89
90
91

    openPromot = (event: React.SyntheticEvent<EventTarget>): void => {
        event.preventDefault();
        event.stopPropagation();
        this.setState({ isCalloutVisible: true });
92
    };
93
94
95
96
97
98
99

    render(): React.ReactNode {
        const { isCalloutVisible } = this.state;
        const prompString = 'Are you sure to cancel this trial?';
        return (
            <div>
                <div className={styles.buttonArea} ref={(menuButton): any => (this.menuButtonElement = menuButton)}>
100
101
102
                    <PrimaryButton className='detail-button-operation' onClick={this.openPromot} title='kill'>
                        {blocked}
                    </PrimaryButton>
103
104
105
106
                </div>
                {isCalloutVisible ? (
                    <div>
                        <FocusTrapCallout
107
                            role='alertdialog'
108
109
110
111
112
113
114
                            className={styles.callout}
                            gapSpace={0}
                            target={this.menuButtonElement}
                            onDismiss={this.onDismiss}
                            setInitialFocus={true}
                        >
                            <div className={styles.header}>
115
116
117
                                <p className={styles.title} style={{ color: '#333' }}>
                                    Kill trial
                                </p>
118
119
120
                            </div>
                            <div className={styles.inner}>
                                <div>
121
122
123
                                    <p className={styles.subtext} style={{ color: '#333' }}>
                                        {prompString}
                                    </p>
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
                                </div>
                            </div>
                            <FocusZone>
                                <Stack className={styles.buttons} gap={8} horizontal>
                                    <DefaultButton onClick={this.onDismiss}>No</DefaultButton>
                                    <PrimaryButton onClick={this.onKill}>Yes</PrimaryButton>
                                </Stack>
                            </FocusZone>
                        </FocusTrapCallout>
                    </div>
                ) : null}
            </div>
        );
    }
}

140
export default KillJob;