This repository was archived by the owner on Sep 10, 2024. It is now read-only.
forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstacktrace-nav.tsx
136 lines (121 loc) · 3.52 KB
/
stacktrace-nav.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import React, { useEffect, useState } from 'react';
import { EuiButtonGroup, EuiSpacer } from '@elastic/eui';
import { getTopN, groupSamplesByCategory } from '../../common';
export const StackTraceNavigation = ({ fetchTopN, setTopN }) => {
const topnButtonGroupPrefix = 'topnButtonGroup';
const topnButtons = [
{
id: `${topnButtonGroupPrefix}__0`,
label: 'Containers',
value: 'containers',
},
{
id: `${topnButtonGroupPrefix}__1`,
label: 'Deployments',
value: 'deployments',
},
{
id: `${topnButtonGroupPrefix}__2`,
label: 'Threads',
value: 'threads',
},
{
id: `${topnButtonGroupPrefix}__3`,
label: 'Hosts',
value: 'hosts',
},
{
id: `${topnButtonGroupPrefix}__4`,
label: 'Traces',
value: 'traces',
},
];
const [toggleTopNSelected, setToggleTopNSelected] = useState(`${topnButtonGroupPrefix}__0`);
const onTopNChange = (optionId) => {
if (optionId === toggleTopNSelected) {
return;
}
setToggleTopNSelected(optionId);
};
const dateButtonGroupPrefix = 'dateButtonGroup';
const dateButtons = [
{
id: `${dateButtonGroupPrefix}__0`,
label: '30m',
value: '1800',
},
{
id: `${dateButtonGroupPrefix}__1`,
label: '1h',
value: '3600',
},
{
id: `${dateButtonGroupPrefix}__2`,
label: '24h',
value: '86400',
},
{
id: `${dateButtonGroupPrefix}__3`,
label: '7d',
value: '604800',
},
{
id: `${dateButtonGroupPrefix}__4`,
label: '30d',
value: '2592000',
},
];
const [toggleDateSelected, setToggleDateSelected] = useState(`${dateButtonGroupPrefix}__0`);
const onDateChange = (optionId) => {
if (optionId === toggleDateSelected) {
return;
}
setToggleDateSelected(optionId);
};
useEffect(() => {
const topnValue = topnButtons.filter((button) => {
return button.id === toggleTopNSelected;
});
const dateValue = dateButtons.filter((button) => {
return button.id === toggleDateSelected;
});
console.log(new Date().toISOString(), 'started payload retrieval');
fetchTopN(topnValue[0].value, dateValue[0].value)
.then((response) => {
console.log(new Date().toISOString(), 'finished payload retrieval');
const samples = getTopN(response);
const series = groupSamplesByCategory(samples);
console.log('sample %o', samples);
console.log('series %o', series);
setTopN({ samples, series });
console.log(new Date().toISOString(), 'updated local state');
})
.catch((err) => {
console.log('error when reading topN data: ' + err.message);
});
}, [toggleTopNSelected, toggleDateSelected]);
return (
<div>
<EuiButtonGroup
legend="This is a basic group"
options={topnButtons}
idSelected={toggleTopNSelected}
onChange={(id) => onTopNChange(id)}
/>
<EuiSpacer size="s" />
<EuiButtonGroup
legend="This is a basic group"
options={dateButtons}
idSelected={toggleDateSelected}
onChange={(id) => onDateChange(id)}
/>
</div>
);
};