Skip to content

Commit ea08f2d

Browse files
committed
feat: add Queries activities banner
1 parent 7fca511 commit ea08f2d

File tree

13 files changed

+654
-4
lines changed

13 files changed

+654
-4
lines changed

src/components/MetricChart/MetricChart.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
border: 1px solid var(--g-color-line-generic);
88
border-radius: 8px;
99

10+
&_noBorder {
11+
border: none;
12+
}
13+
14+
&_fullWidth {
15+
width: 100%;
16+
}
17+
1018
&__title {
1119
margin-bottom: 10px;
1220
}

src/components/MetricChart/MetricChart.tsx

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import React from 'react';
33
import ChartKit, {settings} from '@gravity-ui/chartkit';
44
import type {YagrWidgetData} from '@gravity-ui/chartkit/yagr';
55
import {YagrPlugin} from '@gravity-ui/chartkit/yagr';
6+
import {Flex} from '@gravity-ui/uikit';
67

78
import {cn} from '../../utils/cn';
89
import type {TimeFrame} from '../../utils/timeframes';
910
import {ResponseError} from '../Errors/ResponseError';
1011
import {Loader} from '../Loader';
12+
import {TimeFrameDropdown} from '../TimeFrameDropdown/TimeFrameDropdown';
13+
import {TimeFrameSelector} from '../TimeFrameSelector/TimeFrameSelector';
1114

1215
import {colorToRGBA, colors} from './colors';
1316
import {getDefaultDataFormatter} from './getDefaultDataFormatter';
@@ -122,6 +125,21 @@ interface DiagnosticsChartProps {
122125
* Pass isChartVisible prop to ensure proper chart render
123126
*/
124127
isChartVisible?: boolean;
128+
129+
/** Remove border from chart */
130+
noBorder?: boolean;
131+
132+
/** Make chart take full width of container */
133+
fullWidth?: boolean;
134+
135+
/** Show timeframe selector to the right of chart title */
136+
withTimeframeSelector?: boolean;
137+
138+
/** Callback when timeframe is changed via the selector */
139+
onTimeFrameChange?: (timeFrame: TimeFrame) => void;
140+
141+
/** Timeframe component to choose between 'selector' and 'dropdown' */
142+
timeFrameComponent?: 'selector' | 'dropdown';
125143
}
126144

127145
export const MetricChart = ({
@@ -135,7 +153,16 @@ export const MetricChart = ({
135153
chartOptions,
136154
onChartDataStatusChange,
137155
isChartVisible,
156+
noBorder,
157+
fullWidth,
158+
withTimeframeSelector,
159+
onTimeFrameChange,
160+
timeFrameComponent = 'selector',
138161
}: DiagnosticsChartProps) => {
162+
// Use a reasonable default for maxDataPoints when fullWidth is true
163+
const effectiveWidth = fullWidth ? 600 : width;
164+
const maxDataPoints = effectiveWidth / 2;
165+
139166
const {currentData, error, isFetching, status} = chartApi.useGetChartDataQuery(
140167
// maxDataPoints param is calculated based on width
141168
// should be width > maxDataPoints to prevent points that cannot be selected
@@ -144,7 +171,7 @@ export const MetricChart = ({
144171
database,
145172
metrics,
146173
timeFrame,
147-
maxDataPoints: width / 2,
174+
maxDataPoints,
148175
},
149176
{pollingInterval: autorefresh},
150177
);
@@ -176,13 +203,22 @@ export const MetricChart = ({
176203

177204
return (
178205
<div
179-
className={b(null)}
206+
className={b({noBorder, fullWidth})}
180207
style={{
181208
height,
182-
width,
209+
width: fullWidth ? '100%' : width,
183210
}}
184211
>
185-
<div className={b('title')}>{title}</div>
212+
<Flex className={b('title')} justifyContent="space-between" alignItems="center">
213+
<div>{title}</div>
214+
{withTimeframeSelector &&
215+
onTimeFrameChange &&
216+
(timeFrameComponent === 'dropdown' ? (
217+
<TimeFrameDropdown value={timeFrame} onChange={onTimeFrameChange} />
218+
) : (
219+
<TimeFrameSelector value={timeFrame} onChange={onTimeFrameChange} />
220+
))}
221+
</Flex>
186222
{renderContent()}
187223
</div>
188224
);
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
@use '../../styles/mixins.scss';
2+
3+
.queries-activity-bar {
4+
$b: &;
5+
6+
margin-bottom: var(--diagnostics-section-title-margin);
7+
8+
border: 1px solid transparent;
9+
border-radius: var(--g-border-radius-m);
10+
11+
// Collapsed state (default)
12+
background-color: var(--g-color-base-float);
13+
14+
&_expanded {
15+
border: 1px solid var(--g-color-base-generic);
16+
border-radius: var(--g-border-radius-m);
17+
background-color: transparent;
18+
}
19+
20+
&__disclosure {
21+
width: 100%;
22+
}
23+
24+
&__header {
25+
display: flex;
26+
justify-content: space-between;
27+
align-items: center;
28+
gap: var(--g-spacing-3);
29+
30+
padding: var(--g-spacing-3) var(--g-spacing-4);
31+
32+
cursor: pointer;
33+
34+
border-radius: var(--g-border-radius-m);
35+
36+
transition: background-color 0.15s ease;
37+
38+
&:hover {
39+
background-color: var(--g-color-base-simple-hover);
40+
}
41+
42+
// When expanded, only round top corners
43+
#{$b}_expanded &:hover {
44+
background-color: transparent;
45+
}
46+
}
47+
48+
&__content-wrapper {
49+
display: flex;
50+
flex-grow: 1;
51+
align-items: center;
52+
gap: var(--g-spacing-2);
53+
}
54+
55+
&__metrics {
56+
display: flex;
57+
align-items: center;
58+
gap: var(--g-spacing-1);
59+
}
60+
61+
&__content {
62+
display: flex;
63+
flex-direction: column;
64+
gap: var(--g-spacing-4);
65+
66+
padding: 0 0 var(--g-spacing-2);
67+
}
68+
69+
&__stats {
70+
display: flex;
71+
flex-wrap: wrap;
72+
align-items: center;
73+
gap: var(--g-spacing-1);
74+
75+
padding: 0 var(--g-spacing-4);
76+
}
77+
78+
&__open-queries-button {
79+
margin-left: 4px;
80+
}
81+
82+
&__charts {
83+
display: flex;
84+
gap: var(--g-spacing-4);
85+
86+
padding: 0 var(--g-spacing-4);
87+
88+
@media (max-width: 1200px) {
89+
flex-direction: column;
90+
}
91+
}
92+
93+
&__chart-container {
94+
display: flex;
95+
flex: 1;
96+
flex-direction: column;
97+
gap: var(--g-spacing-3);
98+
}
99+
100+
// Focus states for accessibility
101+
&__header:focus-visible,
102+
&__open-queries-button:focus-visible {
103+
outline: 2px solid var(--g-color-line-focus);
104+
outline-offset: 2px;
105+
}
106+
}

0 commit comments

Comments
 (0)