TrialIdColumn.tsx 1.52 KB
Newer Older
1
import * as React from 'react';
2
import { Stack } from '@fluentui/react';
Lijiaoa's avatar
Lijiaoa committed
3
4
import { AllExperimentList } from '@static/interface';
import CopyButton from '../common/CopyButton';
5
6

interface TrialIdColumnProps {
7
    item: AllExperimentList;
8
9
10
11
12
13
14
15
}

class TrialIdColumn extends React.Component<TrialIdColumnProps, {}> {
    constructor(props: TrialIdColumnProps) {
        super(props);
    }

    render(): React.ReactNode {
16
        const { item } = this.props;
17
18
        const hostname = window.location.hostname;
        const protocol = window.location.protocol;
19
20
21
22
        const webuiPortal =
            item.prefixUrl === null
                ? `${protocol}//${hostname}:${item.port}/oview`
                : `${protocol}//${hostname}:${item.port}/${this.formatPrefix(item.prefixUrl)}/oview`;
23
        return (
24
            <Stack horizontal className='ellipsis idCopy'>
25
26
                {item.status === 'STOPPED' ? (
                    <div className='idColor'>{item.id}</div>
27
                ) : (
Lijiaoa's avatar
Lijiaoa committed
28
                    <a href={webuiPortal} className='link' target='_blank' rel='noopener noreferrer'>
29
                        {item.id}
30
31
                    </a>
                )}
32
                <CopyButton value={item.id} />
33
            </Stack>
34
35
        );
    }
36
37
38
39
40
41
42
43
44
45
46
47

    private formatPrefix(prefix): string {
        if (prefix.startsWith('/')) {
            prefix = prefix.slice(1);
        }

        if (prefix.endsWith('/')) {
            prefix = prefix.slice(0, prefix.length - 1);
        }

        return prefix;
    }
48
49
50
}

export default TrialIdColumn;