-
Notifications
You must be signed in to change notification settings - Fork 67
/
RunDetailLayout.tsx
85 lines (76 loc) 路 3.11 KB
/
RunDetailLayout.tsx
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
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
79
80
81
82
83
84
85
import {Tabs, TabsProps} from 'antd';
import {useEffect, useMemo, useState} from 'react';
import {useParams} from 'react-router-dom';
import RunDetailTest from 'components/RunDetailTest';
import RunDetailTrace from 'components/RunDetailTrace';
import RunDetailTrigger from 'components/RunDetailTrigger';
import {RunDetailModes, TestState} from 'constants/TestRun.constants';
import TestRunAnalyticsService from 'services/Analytics/TestRunAnalytics.service';
import {useTestRun} from 'providers/TestRun/TestRun.provider';
import useDocumentTitle from 'hooks/useDocumentTitle';
import Test from 'models/Test.model';
import {useNotification} from 'providers/Notification/Notification.provider';
import HeaderLeft from './HeaderLeft';
import HeaderRight from './HeaderRight';
import * as S from './RunDetailLayout.styled';
interface IProps {
test: Test;
}
const renderTabBar: TabsProps['renderTabBar'] = (props, DefaultTabBar) => (
<S.ContainerHeader data-cy="run-detail-header">
<DefaultTabBar {...props} className="site-custom-tab-bar" />
</S.ContainerHeader>
);
const renderTab = (title: string, testId: string, runId: string, mode: string) => (
<S.TabLink $isActive={mode === title.toLowerCase()} to={`/test/${testId}/run/${runId}/${title.toLowerCase()}`}>
{title}
</S.TabLink>
);
const RunDetailLayout = ({test: {id, name, trigger, version = 1}, test}: IProps) => {
const {mode = RunDetailModes.TRIGGER} = useParams();
const {showNotification} = useNotification();
const {isError, run, runEvents} = useTestRun();
const [prevState, setPrevState] = useState(run.state);
useDocumentTitle(`${name} - ${run.state}`);
useEffect(() => {
if (run.state === TestState.FINISHED && prevState !== TestState.FINISHED) {
showNotification({
type: 'success',
title: 'Trace has been fetched successfully',
});
}
setPrevState(run.state);
}, [prevState, run.state, showNotification]);
const tabBarExtraContent = useMemo(
() => ({
left: <HeaderLeft name={name} triggerType={trigger.type.toUpperCase()} />,
right: <HeaderRight testId={id} testVersion={version} />,
}),
[id, name, trigger.type, version]
);
return (
<S.Container>
<Tabs
activeKey={mode}
centered
onChange={activeKey => {
TestRunAnalyticsService.onChangeMode(activeKey as RunDetailModes);
}}
renderTabBar={renderTabBar}
tabBarExtraContent={tabBarExtraContent}
destroyInactiveTabPane
>
<Tabs.TabPane tab={renderTab('Trigger', id, run.id, mode)} key={RunDetailModes.TRIGGER}>
<RunDetailTrigger test={test} run={run} runEvents={runEvents} isError={isError} />
</Tabs.TabPane>
<Tabs.TabPane tab={renderTab('Trace', id, run.id, mode)} key={RunDetailModes.TRACE}>
<RunDetailTrace run={run} runEvents={runEvents} testId={id} />
</Tabs.TabPane>
<Tabs.TabPane tab={renderTab('Test', id, run.id, mode)} key={RunDetailModes.TEST}>
<RunDetailTest run={run} runEvents={runEvents} testId={id} />
</Tabs.TabPane>
</Tabs>
</S.Container>
);
};
export default RunDetailLayout;