Skip to content

Commit 09477f6

Browse files
committed
feat: add Queries activities banner
1 parent 77e9bf4 commit 09477f6

File tree

13 files changed

+665
-5
lines changed

13 files changed

+665
-5
lines changed

src/components/MetricChart/MetricChart.scss

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@
22
display: flex;
33
flex-direction: column;
44

5-
padding: 16px 16px 8px;
5+
padding: var(--g-spacing-4) var(--g-spacing-4) var(--g-spacing-2);
66

77
border: 1px solid var(--g-color-line-generic);
88
border-radius: 8px;
99

10+
&_noBorder {
11+
padding: 0;
12+
13+
border: none;
14+
}
15+
16+
&_fullWidth {
17+
width: 100%;
18+
}
19+
1020
&__title {
1121
margin-bottom: 10px;
1222
}

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: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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+
67+
&__stats {
68+
display: flex;
69+
flex-wrap: wrap;
70+
align-items: center;
71+
gap: var(--g-spacing-1);
72+
73+
padding: 0 var(--g-spacing-4);
74+
}
75+
76+
&__open-queries-button {
77+
margin-left: 4px;
78+
}
79+
80+
&__charts {
81+
display: flex;
82+
gap: var(--g-spacing-4);
83+
84+
padding: 0 var(--g-spacing-4);
85+
padding-top: var(--g-spacing-4);
86+
87+
@media (max-width: 1200px) {
88+
flex-direction: column;
89+
}
90+
}
91+
92+
&__chart-container {
93+
display: flex;
94+
flex: 1;
95+
flex-direction: column;
96+
gap: var(--g-spacing-3);
97+
}
98+
99+
// Focus states for accessibility
100+
&__header:focus-visible,
101+
&__open-queries-button:focus-visible {
102+
outline: 2px solid var(--g-color-line-focus);
103+
outline-offset: 2px;
104+
}
105+
}

0 commit comments

Comments
 (0)